Repository: ReolinkCameraAPI/reolinkapipy Branch: master Commit: 87cd38263a37 Files: 69 Total size: 184.9 KB Directory structure: gitextract_j36vvviq/ ├── .github/ │ └── workflows/ │ └── python-package.yaml ├── .gitignore ├── LICENSE.md ├── Pipfile ├── README.md ├── examples/ │ ├── basic_usage.py │ ├── custom_ssl_session.py │ ├── download_motions.py │ ├── download_playback_video.py │ ├── network_config.py │ ├── response/ │ │ ├── GetAlarmMotion.json │ │ ├── GetDSTInfo.json │ │ ├── GetDevInfo.json │ │ ├── GetEnc.json │ │ ├── GetGeneralSystem.json │ │ ├── GetHddInfo.json │ │ ├── GetMask.json │ │ ├── GetNetworkAdvanced.json │ │ ├── GetNetworkDDNS.json │ │ ├── GetNetworkEmail.json │ │ ├── GetNetworkFtp.json │ │ ├── GetNetworkGeneral.json │ │ ├── GetNetworkNTP.json │ │ ├── GetNetworkPush.json │ │ ├── GetOnline.json │ │ ├── GetOsd.json │ │ ├── GetPerformance.json │ │ ├── GetPtzCheckState.json │ │ ├── GetPtzPresets.json │ │ ├── GetRec.json │ │ ├── GetUser.json │ │ ├── Login.json │ │ ├── Logout.json │ │ ├── PtzCheck.json │ │ ├── PtzCtrl.json │ │ ├── Reboot.json │ │ ├── SetAdvImageSettings.json │ │ ├── SetImageSettings.json │ │ └── SetPtzPreset.json │ ├── stream_gui.py │ ├── streaming_video.py │ └── video_review_gui.py ├── make-and-publish-package.sh ├── reolinkapi/ │ ├── __init__.py │ ├── camera.py │ ├── handlers/ │ │ ├── __init__.py │ │ ├── api_handler.py │ │ └── rest_handler.py │ ├── mixins/ │ │ ├── __init__.py │ │ ├── alarm.py │ │ ├── device.py │ │ ├── display.py │ │ ├── download.py │ │ ├── image.py │ │ ├── motion.py │ │ ├── network.py │ │ ├── nvrdownload.py │ │ ├── ptz.py │ │ ├── record.py │ │ ├── stream.py │ │ ├── system.py │ │ ├── user.py │ │ └── zoom.py │ └── utils/ │ ├── __init__.py │ ├── rtsp_client.py │ └── util.py ├── requirements.txt ├── setup.py └── tests/ └── test_camera.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/python-package.yaml ================================================ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python name: Python package on: push: branches: [ "master" ] pull_request: branches: [ "master" ] jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: ["3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 pytest build if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Build run: | python -m build # - name: Test with pytest # run: | # pytest ================================================ FILE: .gitignore ================================================ secrets.cfg # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ .idea/ venv/ ================================================ FILE: LICENSE.md ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: {project} Copyright (C) {year} {fullname} This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Pipfile ================================================ [[source]] name = "pypi" url = "https://pypi.org/simple" verify_ssl = true [dev-packages] [packages] pillow = "*" pyyaml = "*" requests = "*" numpy = "*" opencv-python = "*" pysocks = "*" [requires] ================================================ FILE: README.md ================================================

Reolink Python Api Client

Reolink Approval GitHub GitHub tag (latest SemVer) PyPI Discord

--- A Reolink Camera client written in Python. This repository's purpose **(with Reolink's full support)** is to deliver a complete API for the Reolink Cameras, although they have a basic API document - it does not satisfy the need for extensive camera communication. Check out our documentation for more information on how to use the software at [https://reolink.oleaintueri.com](https://reolink.oleaintueri.com) Other Supported Languages: - Go: [reolinkapigo](https://github.com/ReolinkCameraAPI/reolinkapigo) ### Join us on Discord https://discord.gg/8z3fdAmZJP ### Sponsorship [Oleaintueri](https://oleaintueri.com) is sponsoring the development and maintenance of these projects within their organisation. --- ### Get started Implement a "Camera" object by passing it an IP address, Username and Password. By instantiating the object, it will try retrieve a login token from the Reolink Camera. This token is necessary to interact with the Camera using other commands. See the `examples` directory. ### Using the library as a Python Module Install the package via PyPi pip install reolinkapi Install from GitHub pip install git+https://github.com/ReolinkCameraAPI/reolinkapipy.git If you want to include the video streaming functionality you need to include the streaming "extra" dependencies pip install 'reolinkapi[streaming]' ## Contributors --- ### Styling and Standards This project intends to stick with [PEP8](https://www.python.org/dev/peps/pep-0008/) ### How can I become a contributor? #### Step 1 Get the Restful API calls by looking through the HTTP Requests made in the camera's web UI. I use Google Chrome developer mode (ctr + shift + i) -> Network. #### Step 2 - Fork the repository - pip install -r requirements.txt - Make your changes #### Step 3 Make a pull request. ### API Requests Implementation Plan: Stream: - [X] Blocking RTSP stream - [X] Non-Blocking RTSP stream GET: - [X] Login - [X] Logout - [X] Display -> OSD - [X] Recording -> Encode (Clear and Fluent Stream) - [X] Recording -> Advance (Scheduling) - [X] Network -> General - [X] Network -> Advanced - [X] Network -> DDNS - [X] Network -> NTP - [X] Network -> E-mail - [X] Network -> FTP - [X] Network -> Push - [X] Network -> WIFI - [X] Alarm -> Motion - [X] System -> General - [X] System -> DST - [X] System -> Information - [ ] System -> Maintenance - [X] System -> Performance - [ ] System -> Reboot - [X] User -> Online User - [X] User -> Add User - [X] User -> Manage User - [X] Device -> HDD/SD Card - [x] PTZ -> Presets, Calibration Status - [x] Zoom - [x] Focus - [ ] Image (Brightness, Contrast, Saturation, Hue, Sharp, Mirror, Rotate) - [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR) - [X] Image Data -> "Snap" Frame from Video Stream SET: - [X] Display -> OSD - [X] Recording -> Encode (Clear and Fluent Stream) - [ ] Recording -> Advance (Scheduling) - [X] Network -> General - [X] Network -> Advanced - [ ] Network -> DDNS - [ ] Network -> NTP - [ ] Network -> E-mail - [ ] Network -> FTP - [ ] Network -> Push - [X] Network -> WIFI - [ ] Alarm -> Motion - [ ] System -> General - [ ] System -> DST - [X] System -> Reboot - [X] User -> Online User - [X] User -> Add User - [X] User -> Manage User - [X] Device -> HDD/SD Card (Format) - [x] PTZ (including calibrate) - [x] Zoom - [x] Focus - [X] Image (Brightness, Contrast, Saturation, Hue, Sharp, Mirror, Rotate) - [X] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR) ### Supported Cameras Any Reolink camera that has a web UI should work. The other's requiring special Reolink clients do not work and is not supported here. - RLC-411WS - RLC-423 - RLC-420-5MP - RLC-410-5MP - RLC-510A - RLC-520 - RLC-823A - C1-Pro - D400 - E1 Zoom ================================================ FILE: examples/basic_usage.py ================================================ import reolinkapi if __name__ == "__main__": cam = reolinkapi.Camera("192.168.0.102", defer_login=True) # must first login since I defer have deferred the login process cam.login() dst = cam.get_dst() ok = cam.add_user("foo", "bar", "admin") alarm = cam.get_alarm_motion() cam.set_device_name(name='my_camera') ================================================ FILE: examples/custom_ssl_session.py ================================================ from reolinkapi import Camera import urllib3 import requests from urllib3.util import create_urllib3_context class CustomSSLContextHTTPAdapter(requests.adapters.HTTPAdapter): def __init__(self, ssl_context=None, **kwargs): self.ssl_context = ssl_context super().__init__(**kwargs) def init_poolmanager(self, connections, maxsize, block=False): self.poolmanager = urllib3.poolmanager.PoolManager( num_pools=connections, maxsize=maxsize, block=block, ssl_context=self.ssl_context) urllib3.disable_warnings() ctx = create_urllib3_context() ctx.load_default_certs() ctx.set_ciphers("AES128-GCM-SHA256") ctx.check_hostname = False session = requests.session() session.adapters.pop("https://", None) session.mount("https://", CustomSSLContextHTTPAdapter(ctx)) ## Add a custom http handler to add in different ciphers that may ## not be aloud by default in openssl which urlib uses cam = Camera("url", "user", "password", https=True, session=session) cam.reboot_camera() ================================================ FILE: examples/download_motions.py ================================================ """Downloads all motion events from camera from the past hour.""" import os from configparser import RawConfigParser from datetime import datetime as dt, timedelta from reolinkapi import Camera def read_config(props_path: str) -> dict: """Reads in a properties file into variables. NB! this config file is kept out of commits with .gitignore. The structure of this file is such: # secrets.cfg [camera] ip={ip_address} username={username} password={password} """ config = RawConfigParser() assert os.path.exists(props_path), f"Path does not exist: {props_path}" config.read(props_path) return config # Read in your ip, username, & password # (NB! you'll likely have to create this file. See tests/test_camera.py for details on structure) config = read_config('camera.cfg') ip = config.get('camera', 'ip') un = config.get('camera', 'username') pw = config.get('camera', 'password') # Connect to camera cam = Camera(ip, un, pw, https=True) start = dt.combine(dt.now(), dt.min.time()) end = dt.now() # Collect motion events between these timestamps for substream processed_motions = cam.get_motion_files(start=start, end=end, streamtype='main', channel=0) processed_motions += cam.get_motion_files(start=start, end=end, streamtype='main', channel=1) start = dt.now() - timedelta(days=1) end = dt.combine(start, dt.max.time()) processed_motions += cam.get_motion_files(start=start, end=end, streamtype='main', channel=1) output_files = [] for i, motion in enumerate(processed_motions): fname = motion['filename'] # Download the mp4 print("Getting %s" % (fname)) output_path = os.path.join('/tmp/', fname.replace('/','_')) output_files += output_path if not os.path.isfile(output_path): resp = cam.get_file(fname, output_path=output_path) ================================================ FILE: examples/download_playback_video.py ================================================ """Downloads a video from camera from start to end time.""" import os from configparser import RawConfigParser from datetime import datetime as dt, timedelta from reolinkapi import Camera import requests import pandas as pd def read_config(props_path: str) -> dict: """Reads in a properties file into variables. NB! this config file is kept out of commits with .gitignore. The structure of this file is such: # secrets.cfg [camera] ip={ip_address} username={username} password={password} """ config = RawConfigParser() assert os.path.exists(props_path), f"Path does not exist: {props_path}" config.read(props_path) return config # Read in your ip, username, & password # (NB! you'll likely have to create this file. See tests/test_camera.py for details on structure) config = read_config('camera.cfg') ip = config.get('camera', 'ip') un = config.get('camera', 'username') pw = config.get('camera', 'password') # Connect to camera cam = Camera(ip, un, pw) start = dt.now() - timedelta(minutes=10) end = dt.now() - timedelta(minutes=9) channel = 0 files = cam.get_playback_files(start=start, end=end, channel= channel) print(files) dl_dir = os.path.join(os.path.expanduser('~'), 'Downloads') for fname in files: print(fname) # Download the mp4 cam.get_file(fname, output_path=os.path.join(dl_dir, fname)) ================================================ FILE: examples/network_config.py ================================================ import os from configparser import RawConfigParser from reolinkapi import Camera def read_config(props_path: str) -> dict: """Reads in a properties file into variables. NB! this config file is kept out of commits with .gitignore. The structure of this file is such: # secrets.cfg [camera] ip={ip_address} username={username} password={password} """ config = RawConfigParser() assert os.path.exists(props_path), f"Path does not exist: {props_path}" config.read(props_path) return config # Read in your ip, username, & password # (NB! you'll likely have to create this file. See tests/test_camera.py for details on structure) config = read_config('camera.cfg') ip = config.get('camera', 'ip') un = config.get('camera', 'username') pw = config.get('camera', 'password') # Connect to camera cam = Camera(ip, un, pw) # Set NTP cam.set_ntp(enable=True, interval=1440, port=123, server="time-b.nist.gov") # Get current network settings current_settings = cam.get_network_general() print("Current settings:", current_settings) # Configure DHCP cam.set_network_settings( ip="", gateway="", mask="", dns1="", dns2="", mac=current_settings[0]['value']['LocalLink']['mac'], use_dhcp=True, auto_dns=True ) # Configure static IP # cam.set_network_settings( # ip="192.168.1.102", # gateway="192.168.1.1", # mask="255.255.255.0", # dns1="8.8.8.8", # dns2="8.8.4.4", # mac=current_settings[0]['value']['LocalLink']['mac'], # use_dhcp=False, # auto_dns=False # ) ================================================ FILE: examples/response/GetAlarmMotion.json ================================================ [ { "cmd": "GetAlarm", "code": 0, "initial": { "Alarm": { "action": { "mail": 1, "push": 1, "recChannel": [0] }, "channel": 0, "enable": 1, "schedule": { "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, "scope": { "cols": 80, "rows": 45, "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, "sens": [ { "beginHour": 0, "beginMin": 0, "endHour": 6, "endMin": 0, "sensitivity": 10 }, { "beginHour": 6, "beginMin": 0, "endHour": 12, "endMin": 0, "sensitivity": 10 }, { "beginHour": 12, "beginMin": 0, "endHour": 18, "endMin": 0, "sensitivity": 10 }, { "beginHour": 18, "beginMin": 0, "endHour": 23, "endMin": 59, "sensitivity": 10 } ], "type": "md" } }, "range": { "Alarm": { "action": { "mail": "boolean", "push": "boolean", "recChannel": [0] }, "channel": 0, "enable": "boolean", "schedule": { "table": { "maxLen": 168, "minLen": 168 } }, "scope": { "cols": { "max": 80, "min": 80 }, "rows": { "max": 45, "min": 45 }, "table": { "maxLen": 8159 } }, "sens": [ { "beginHour": { "max": 23, "min": 0 }, "beginMin": { "max": 59, "min": 0 }, "endHour": { "max": 23, "min": 0 }, "endMin": { "max": 59, "min": 0 }, "id": 0, "sensitivity": { "max": 50, "min": 1 } }, { "beginHour": { "max": 23, "min": 0 }, "beginMin": { "max": 59, "min": 0 }, "endHour": { "max": 23, "min": 0 }, "endMin": { "max": 59, "min": 0 }, "id": 1, "sensitivity": { "max": 50, "min": 1 } }, { "beginHour": { "max": 23, "min": 0 }, "beginMin": { "max": 59, "min": 0 }, "endHour": { "max": 23, "min": 0 }, "endMin": { "max": 59, "min": 0 }, "id": 2, "sensitivity": { "max": 50, "min": 1 } }, { "beginHour": { "max": 23, "min": 0 }, "beginMin": { "max": 59, "min": 0 }, "endHour": { "max": 23, "min": 0 }, "endMin": { "max": 59, "min": 0 }, "id": 3, "sensitivity": { "max": 50, "min": 1 } } ], "type": "md" } }, "value": { "Alarm": { "action": { "mail": 1, "push": 1, "recChannel": [0] }, "channel": 0, "enable": 1, "schedule": { "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, "scope": { "cols": 80, "rows": 45, "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, "sens": [ { "beginHour": 0, "beginMin": 0, "endHour": 6, "endMin": 0, "id": 0, "sensitivity": 10 }, { "beginHour": 6, "beginMin": 0, "endHour": 12, "endMin": 0, "id": 1, "sensitivity": 10 }, { "beginHour": 12, "beginMin": 0, "endHour": 18, "endMin": 0, "id": 2, "sensitivity": 10 }, { "beginHour": 18, "beginMin": 0, "endHour": 23, "endMin": 59, "id": 3, "sensitivity": 10 } ], "type": "md" } } } ] ================================================ FILE: examples/response/GetDSTInfo.json ================================================ [ { "cmd": "GetTime", "code": 0, "value": { "Dst": { "enable": 1, "endHour": 2, "endMin": 0, "endMon": 11, "endSec": 0, "endWeek": 1, "endWeekday": 0, "offset": 1, "startHour": 2, "startMin": 0, "startMon": 3, "startSec": 0, "startWeek": 1, "startWeekday": 0 }, "Time": { "day": 27, "hour": 18, "hourFmt": 0, "min": 50, "mon": 10, "sec": 46, "timeFmt": "MM/DD/YYYY", "timeZone": 21600, "year": 2020 } } } ] ================================================ FILE: examples/response/GetDevInfo.json ================================================ [ { "cmd": "GetDevInfo", "code": 0, "value": { "DevInfo": { "B485": 0, "IOInputNum": 0, "IOOutputNum": 0, "audioNum": 0, "buildDay": "build 18081408", "cfgVer": "v2.0.0.0", "channelNum": 1, "detail": "IPC_3816M100000000100000", "diskNum": 1, "firmVer": "v2.0.0.1389_18081408", "hardVer": "IPC_3816M", "model": "RLC-411WS", "name": "Camera1_withpersonality", "serial": "00000000000000", "type": "IPC", "wifi": 1 } } } ] ================================================ FILE: examples/response/GetEnc.json ================================================ [ { "cmd": "GetEnc", "code": 0, "initial": { "Enc": { "audio": 0, "channel": 0, "mainStream": { "bitRate": 4096, "frameRate": 15, "profile": "High", "size": "3072*1728" }, "subStream": { "bitRate": 160, "frameRate": 7, "profile": "High", "size": "640*360" } } }, "range": { "Enc": [ { "audio": "boolean", "mainStream": { "bitRate": [ 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192 ], "default": { "bitRate": 4096, "frameRate": 15 }, "frameRate": [ 20, 18, 16, 15, 12, 10, 8, 6, 4, 2 ], "profile": [ "Base", "Main", "High" ], "size": "3072*1728" }, "subStream": { "bitRate": [ 64, 128, 160, 192, 256, 384, 512 ], "default": { "bitRate": 160, "frameRate": 7 }, "frameRate": [ 15, 10, 7, 4 ], "profile": [ "Base", "Main", "High" ], "size": "640*360" } }, { "audio": "boolean", "mainStream": { "bitRate": [ 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192 ], "default": { "bitRate": 4096, "frameRate": 15 }, "frameRate": [ 20, 18, 16, 15, 12, 10, 8, 6, 4, 2 ], "profile": [ "Base", "Main", "High" ], "size": "2592*1944" }, "subStream": { "bitRate": [ 64, 128, 160, 192, 256, 384, 512 ], "default": { "bitRate": 160, "frameRate": 7 }, "frameRate": [ 15, 10, 7, 4 ], "profile": [ "Base", "Main", "High" ], "size": "640*360" } }, { "audio": "boolean", "mainStream": { "bitRate": [ 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192 ], "default": { "bitRate": 3072, "frameRate": 15 }, "frameRate": [ 30, 22, 20, 18, 16, 15, 12, 10, 8, 6, 4, 2 ], "profile": [ "Base", "Main", "High" ], "size": "2560*1440" }, "subStream": { "bitRate": [ 64, 128, 160, 192, 256, 384, 512 ], "default": { "bitRate": 160, "frameRate": 7 }, "frameRate": [ 15, 10, 7, 4 ], "profile": [ "Base", "Main", "High" ], "size": "640*360" } }, { "audio": "boolean", "mainStream": { "bitRate": [ 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192 ], "default": { "bitRate": 3072, "frameRate": 15 }, "frameRate": [ 30, 22, 20, 18, 16, 15, 12, 10, 8, 6, 4, 2 ], "profile": [ "Base", "Main", "High" ], "size": "2048*1536" }, "subStream": { "bitRate": [ 64, 128, 160, 192, 256, 384, 512 ], "default": { "bitRate": 160, "frameRate": 7 }, "frameRate": [ 15, 10, 7, 4 ], "profile": [ "Base", "Main", "High" ], "size": "640*360" } }, { "audio": "boolean", "mainStream": { "bitRate": [ 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192 ], "default": { "bitRate": 3072, "frameRate": 15 }, "frameRate": [ 30, 22, 20, 18, 16, 15, 12, 10, 8, 6, 4, 2 ], "profile": [ "Base", "Main", "High" ], "size": "2304*1296" }, "subStream": { "bitRate": [ 64, 128, 160, 192, 256, 384, 512 ], "default": { "bitRate": 160, "frameRate": 7 }, "frameRate": [ 15, 10, 7, 4 ], "profile": [ "Base", "Main", "High" ], "size": "640*360" } } ] }, "value": { "Enc": { "audio": 0, "channel": 0, "mainStream": { "bitRate": 2048, "frameRate": 20, "profile": "Main", "size": "3072*1728" }, "subStream": { "bitRate": 64, "frameRate": 4, "profile": "High", "size": "640*360" } } } } ] ================================================ FILE: examples/response/GetGeneralSystem.json ================================================ [ { "cmd": "GetTime", "code": 0, "initial": { "Dst": { "enable": 0, "endHour": 2, "endMin": 0, "endMon": 10, "endSec": 0, "endWeek": 5, "endWeekday": 0, "offset": 1, "startHour": 2, "startMin": 0, "startMon": 3, "startSec": 0, "startWeek": 2, "startWeekday": 0 }, "Time": { "day": 1, "hour": 0, "hourFmt": 0, "min": 0, "mon": 0, "sec": 0, "timeFmt": "DD/MM/YYYY", "timeZone": 28800, "year": 0 } }, "range": { "Dst": { "enable": "boolean", "endHour": { "max": 23, "min": 0 }, "endMin": { "max": 59, "min": 0 }, "endMon": { "max": 12, "min": 1 }, "endSec": { "max": 59, "min": 0 }, "endWeek": { "max": 5, "min": 1 }, "endWeekday": { "max": 6, "min": 0 }, "offset": { "max": 2, "min": 1 }, "startHour": { "max": 23, "min": 0 }, "startMin": { "max": 59, "min": 0 }, "startMon": { "max": 12, "min": 1 }, "startSec": { "max": 59, "min": 0 }, "startWeek": { "max": 5, "min": 1 }, "startWeekday": { "max": 6, "min": 0 } }, "Time": { "day": { "max": 31, "min": 1 }, "hour": { "max": 23, "min": 0 }, "hourFmt": { "max": 1, "min": 0 }, "min": { "max": 59, "min": 0 }, "mon": { "max": 12, "min": 1 }, "sec": { "max": 59, "min": 0 }, "timeFmt": ["MM/DD/YYYY", "YYYY/MM/DD", "DD/MM/YYYY"], "timeZone": { "max": 43200, "min": -46800 }, "year": { "max": 2100, "min": 1900 } } }, "value": { "Dst": { "enable": 1, "endHour": 2, "endMin": 0, "endMon": 11, "endSec": 0, "endWeek": 1, "endWeekday": 0, "offset": 1, "startHour": 2, "startMin": 0, "startMon": 3, "startSec": 0, "startWeek": 1, "startWeekday": 0 }, "Time": { "day": 9, "hour": 15, "hourFmt": 0, "min": 33, "mon": 12, "sec": 58, "timeFmt": "MM/DD/YYYY", "timeZone": 21600, "year": 2020 } } }, { "cmd": "GetNorm", "code": 0, "initial": { "norm": "NTSC" }, "range": { "norm": ["PAL", "NTSC"] }, "value": { "norm": "NTSC" } } ] ================================================ FILE: examples/response/GetHddInfo.json ================================================ [ { "cmd": "GetHddInfo", "code": 0, "value": { "HddInfo": [ { "capacity": 15181, "format": 1, "id": 0, "mount": 1, "size": 15181 } ] } } ] ================================================ FILE: examples/response/GetMask.json ================================================ [ { "cmd": "GetMask", "code": 0, "initial": { "Mask": { "area": [ { "block": { "height": 0, "width": 0, "x": 0, "y": 0 }, "screen": { "height": 0, "width": 0 } } ], "channel": 0, "enable": 0 } }, "range": { "Mask": { "channel": 0, "enable": "boolean", "maxAreas": 4 } }, "value": { "Mask": { "area": null, "channel": 0, "enable": 0 } } } ] ================================================ FILE: examples/response/GetNetworkAdvanced.json ================================================ [ { "cmd": "GetNetPort", "code": 0, "initial": { "NetPort": { "httpPort": 80, "httpsPort": 443, "mediaPort": 9000, "onvifPort": 8000, "rtmpPort": 1935, "rtspPort": 554 } }, "range": { "NetPort": { "httpPort": { "max": 65535, "min": 1 }, "httpsPort": { "max": 65535, "min": 1 }, "mediaPort": { "max": 65535, "min": 1 }, "onvifPort": { "max": 65535, "min": 1 }, "rtmpPort": { "max": 65535, "min": 1 }, "rtspPort": { "max": 65535, "min": 1 } } }, "value": { "NetPort": { "httpPort": 80, "httpsPort": 443, "mediaPort": 9000, "onvifPort": 8000, "rtmpPort": 1935, "rtspPort": 554 } } }, { "cmd": "GetUpnp", "code": 0, "value": { "Upnp": { "enable": 0 } } }, { "cmd": "GetP2p", "code": 0, "value": { "P2p": { "enable": 0, "uid": "99999999999999" } } } ] ================================================ FILE: examples/response/GetNetworkDDNS.json ================================================ [ { "cmd": "GetDdns", "code": 0, "value": { "Ddns": { "domain": "", "enable": 0, "password": "", "type": "no-ip", "userName": "" } } } ] ================================================ FILE: examples/response/GetNetworkEmail.json ================================================ [ { "cmd": "GetEmail", "code": 0, "value": { "Email": { "addr1": "", "addr2": "", "addr3": "", "attachment": "picture", "interval": "5 Minutes", "nickName": "", "password": "", "schedule": { "enable": 1, "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, "smtpPort": 465, "smtpServer": "smtp.gmail.com", "ssl": 1, "userName": "" } } } ] ================================================ FILE: examples/response/GetNetworkFtp.json ================================================ [ { "cmd": "GetFtp", "code": 0, "value": { "Ftp": { "anonymous": 0, "interval": 30, "maxSize": 100, "mode": 0, "password": "", "port": 21, "remoteDir": "", "schedule": { "enable": 1, "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" }, "server": "", "streamType": 0, "userName": "" } } } ] ================================================ FILE: examples/response/GetNetworkGeneral.json ================================================ [ { "cmd": "GetLocalLink", "code": 0, "value": { "LocalLink": { "activeLink": "LAN", "dns": { "auto": 1, "dns1": "192.168.255.4", "dns2": "192.168.255.4" }, "mac": "EC:71:DB:AA:59:CF", "static": { "gateway": "192.168.255.1", "ip": "192.168.255.58", "mask": "255.255.255.0" }, "type": "DHCP" } } } ] ================================================ FILE: examples/response/GetNetworkNTP.json ================================================ [ { "cmd": "GetNtp", "code": 0, "value": { "Ntp": { "enable": 1, "interval": 1440, "port": 123, "server": "ntp.moos.xyz" } } } ] ================================================ FILE: examples/response/GetNetworkPush.json ================================================ [ { "cmd": "GetPush", "code": 0, "value": { "Push": { "schedule": { "enable": 1, "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" } } } } ] ================================================ FILE: examples/response/GetOnline.json ================================================ [ { "cmd": "GetOnline", "code": 0, "value": { "User": [ { "canbeDisconn": 0, "ip": "192.168.1.100", "level": "admin", "sessionId": 1000, "userName": "admin" } ] } } ] ================================================ FILE: examples/response/GetOsd.json ================================================ [ { "cmd": "GetOsd", "code": 0, "initial": { "Osd": { "bgcolor": 0, "channel": 0, "osdChannel": { "enable": 1, "name": "Camera1", "pos": "Lower Right" }, "osdTime": { "enable": 1, "pos": "Top Center" } } }, "range": { "Osd": { "bgcolor": "boolean", "channel": 0, "osdChannel": { "enable": "boolean", "name": { "maxLen": 31 }, "pos": [ "Upper Left", "Top Center", "Upper Right", "Lower Left", "Bottom Center", "Lower Right" ] }, "osdTime": { "enable": "boolean", "pos": [ "Upper Left", "Top Center", "Upper Right", "Lower Left", "Bottom Center", "Lower Right" ] } } }, "value": { "Osd": { "bgcolor": 0, "channel": 0, "osdChannel": { "enable": 0, "name": "FarRight", "pos": "Lower Right" }, "osdTime": { "enable": 0, "pos": "Top Center" } } } } ] ================================================ FILE: examples/response/GetPerformance.json ================================================ [ { "cmd": "GetPerformance", "code": 0, "value": { "Performance": { "codecRate": 2154, "cpuUsed": 14, "netThroughput": 0 } } } ] ================================================ FILE: examples/response/GetPtzCheckState.json ================================================ [ { "cmd": "GetPtzCheckState", "code": 0, "initial": { "PtzCheckState": 2 }, "range": { "PtzCheckState": [ 0, 1, 2 ] }, "value": { "PtzCheckState": 2 } } ] ================================================ FILE: examples/response/GetPtzPresets.json ================================================ [ { "cmd": "GetPtzPreset", "code": 0, "initial": { "PtzPreset": [ { "channel": 0, "enable": 1, "id": 0, "imgName": "preset_00", "name": "namepos0" }, { "channel": 0, "enable": 1, "id": 1, "imgName": "preset_01", "name": "othernamepos1" }, { "channel": 0, "enable": 0, "id": 2, "imgName": "", "name": "pos3" }, { "channel": 0, "enable": 0, "id": 3, "imgName": "", "name": "pos4" }, { "channel": 0, "enable": 0, "id": 4, "imgName": "", "name": "pos5" }, { "channel": 0, "enable": 0, "id": 5, "imgName": "", "name": "pos6" }, { "channel": 0, "enable": 0, "id": 6, "imgName": "", "name": "pos7" }, { "channel": 0, "enable": 0, "id": 7, "imgName": "", "name": "pos8" }, { "channel": 0, "enable": 0, "id": 8, "imgName": "", "name": "pos9" }, { "channel": 0, "enable": 0, "id": 9, "imgName": "", "name": "pos10" }, { "channel": 0, "enable": 0, "id": 10, "imgName": "", "name": "pos11" }, { "channel": 0, "enable": 0, "id": 11, "imgName": "", "name": "pos12" }, { "channel": 0, "enable": 0, "id": 12, "imgName": "", "name": "pos13" }, { "channel": 0, "enable": 0, "id": 13, "imgName": "", "name": "pos14" }, { "channel": 0, "enable": 0, "id": 14, "imgName": "", "name": "pos15" }, { "channel": 0, "enable": 0, "id": 15, "imgName": "", "name": "pos16" }, { "channel": 0, "enable": 0, "id": 16, "imgName": "", "name": "pos17" }, { "channel": 0, "enable": 0, "id": 17, "imgName": "", "name": "pos18" }, { "channel": 0, "enable": 0, "id": 18, "imgName": "", "name": "pos19" }, { "channel": 0, "enable": 0, "id": 19, "imgName": "", "name": "pos20" }, { "channel": 0, "enable": 0, "id": 20, "imgName": "", "name": "pos21" }, { "channel": 0, "enable": 0, "id": 21, "imgName": "", "name": "pos22" }, { "channel": 0, "enable": 0, "id": 22, "imgName": "", "name": "pos23" }, { "channel": 0, "enable": 0, "id": 23, "imgName": "", "name": "pos24" }, { "channel": 0, "enable": 0, "id": 24, "imgName": "", "name": "pos25" }, { "channel": 0, "enable": 0, "id": 25, "imgName": "", "name": "pos26" }, { "channel": 0, "enable": 0, "id": 26, "imgName": "", "name": "pos27" }, { "channel": 0, "enable": 0, "id": 27, "imgName": "", "name": "pos28" }, { "channel": 0, "enable": 0, "id": 28, "imgName": "", "name": "pos29" }, { "channel": 0, "enable": 0, "id": 29, "imgName": "", "name": "pos30" }, { "channel": 0, "enable": 0, "id": 30, "imgName": "", "name": "pos31" }, { "channel": 0, "enable": 0, "id": 31, "imgName": "", "name": "pos32" }, { "channel": 0, "enable": 0, "id": 32, "imgName": "", "name": "pos33" }, { "channel": 0, "enable": 0, "id": 33, "imgName": "", "name": "pos34" }, { "channel": 0, "enable": 0, "id": 34, "imgName": "", "name": "pos35" }, { "channel": 0, "enable": 0, "id": 35, "imgName": "", "name": "pos36" }, { "channel": 0, "enable": 0, "id": 36, "imgName": "", "name": "pos37" }, { "channel": 0, "enable": 0, "id": 37, "imgName": "", "name": "pos38" }, { "channel": 0, "enable": 0, "id": 38, "imgName": "", "name": "pos39" }, { "channel": 0, "enable": 0, "id": 39, "imgName": "", "name": "pos40" }, { "channel": 0, "enable": 0, "id": 40, "imgName": "", "name": "pos41" }, { "channel": 0, "enable": 0, "id": 41, "imgName": "", "name": "pos42" }, { "channel": 0, "enable": 0, "id": 42, "imgName": "", "name": "pos43" }, { "channel": 0, "enable": 0, "id": 43, "imgName": "", "name": "pos44" }, { "channel": 0, "enable": 0, "id": 44, "imgName": "", "name": "pos45" }, { "channel": 0, "enable": 0, "id": 45, "imgName": "", "name": "pos46" }, { "channel": 0, "enable": 0, "id": 46, "imgName": "", "name": "pos47" }, { "channel": 0, "enable": 0, "id": 47, "imgName": "", "name": "pos48" }, { "channel": 0, "enable": 0, "id": 48, "imgName": "", "name": "pos49" }, { "channel": 0, "enable": 0, "id": 49, "imgName": "", "name": "pos50" }, { "channel": 0, "enable": 0, "id": 50, "imgName": "", "name": "pos51" }, { "channel": 0, "enable": 0, "id": 51, "imgName": "", "name": "pos52" }, { "channel": 0, "enable": 0, "id": 52, "imgName": "", "name": "pos53" }, { "channel": 0, "enable": 0, "id": 53, "imgName": "", "name": "pos54" }, { "channel": 0, "enable": 0, "id": 54, "imgName": "", "name": "pos55" }, { "channel": 0, "enable": 0, "id": 55, "imgName": "", "name": "pos56" }, { "channel": 0, "enable": 0, "id": 56, "imgName": "", "name": "pos57" }, { "channel": 0, "enable": 0, "id": 57, "imgName": "", "name": "pos58" }, { "channel": 0, "enable": 0, "id": 58, "imgName": "", "name": "pos59" }, { "channel": 0, "enable": 0, "id": 59, "imgName": "", "name": "pos60" }, { "channel": 0, "enable": 0, "id": 60, "imgName": "", "name": "pos61" }, { "channel": 0, "enable": 0, "id": 61, "imgName": "", "name": "pos62" }, { "channel": 0, "enable": 0, "id": 62, "imgName": "", "name": "pos63" }, { "channel": 0, "enable": 0, "id": 63, "imgName": "", "name": "pos64" } ] }, "range": { "PtzPreset": { "channel": 0, "enable": "boolean", "id": { "max": 64, "min": 1 }, "imgName": { "maxLen": 31 }, "name": { "maxLen": 31 } } }, "value": { "PtzPreset": [ { "channel": 0, "enable": 1, "id": 0, "imgName": "preset_00", "name": "0" }, { "channel": 0, "enable": 1, "id": 1, "imgName": "preset_01", "name": "1" }, { "channel": 0, "enable": 0, "id": 2, "imgName": "", "name": "pos3" }, { "channel": 0, "enable": 0, "id": 3, "imgName": "", "name": "pos4" }, { "channel": 0, "enable": 0, "id": 4, "imgName": "", "name": "pos5" }, { "channel": 0, "enable": 0, "id": 5, "imgName": "", "name": "pos6" }, { "channel": 0, "enable": 0, "id": 6, "imgName": "", "name": "pos7" }, { "channel": 0, "enable": 0, "id": 7, "imgName": "", "name": "pos8" }, { "channel": 0, "enable": 0, "id": 8, "imgName": "", "name": "pos9" }, { "channel": 0, "enable": 0, "id": 9, "imgName": "", "name": "pos10" }, { "channel": 0, "enable": 0, "id": 10, "imgName": "", "name": "pos11" }, { "channel": 0, "enable": 0, "id": 11, "imgName": "", "name": "pos12" }, { "channel": 0, "enable": 0, "id": 12, "imgName": "", "name": "pos13" }, { "channel": 0, "enable": 0, "id": 13, "imgName": "", "name": "pos14" }, { "channel": 0, "enable": 0, "id": 14, "imgName": "", "name": "pos15" }, { "channel": 0, "enable": 0, "id": 15, "imgName": "", "name": "pos16" }, { "channel": 0, "enable": 0, "id": 16, "imgName": "", "name": "pos17" }, { "channel": 0, "enable": 0, "id": 17, "imgName": "", "name": "pos18" }, { "channel": 0, "enable": 0, "id": 18, "imgName": "", "name": "pos19" }, { "channel": 0, "enable": 0, "id": 19, "imgName": "", "name": "pos20" }, { "channel": 0, "enable": 0, "id": 20, "imgName": "", "name": "pos21" }, { "channel": 0, "enable": 0, "id": 21, "imgName": "", "name": "pos22" }, { "channel": 0, "enable": 0, "id": 22, "imgName": "", "name": "pos23" }, { "channel": 0, "enable": 0, "id": 23, "imgName": "", "name": "pos24" }, { "channel": 0, "enable": 0, "id": 24, "imgName": "", "name": "pos25" }, { "channel": 0, "enable": 0, "id": 25, "imgName": "", "name": "pos26" }, { "channel": 0, "enable": 0, "id": 26, "imgName": "", "name": "pos27" }, { "channel": 0, "enable": 0, "id": 27, "imgName": "", "name": "pos28" }, { "channel": 0, "enable": 0, "id": 28, "imgName": "", "name": "pos29" }, { "channel": 0, "enable": 0, "id": 29, "imgName": "", "name": "pos30" }, { "channel": 0, "enable": 0, "id": 30, "imgName": "", "name": "pos31" }, { "channel": 0, "enable": 0, "id": 31, "imgName": "", "name": "pos32" }, { "channel": 0, "enable": 0, "id": 32, "imgName": "", "name": "pos33" }, { "channel": 0, "enable": 0, "id": 33, "imgName": "", "name": "pos34" }, { "channel": 0, "enable": 0, "id": 34, "imgName": "", "name": "pos35" }, { "channel": 0, "enable": 0, "id": 35, "imgName": "", "name": "pos36" }, { "channel": 0, "enable": 0, "id": 36, "imgName": "", "name": "pos37" }, { "channel": 0, "enable": 0, "id": 37, "imgName": "", "name": "pos38" }, { "channel": 0, "enable": 0, "id": 38, "imgName": "", "name": "pos39" }, { "channel": 0, "enable": 0, "id": 39, "imgName": "", "name": "pos40" }, { "channel": 0, "enable": 0, "id": 40, "imgName": "", "name": "pos41" }, { "channel": 0, "enable": 0, "id": 41, "imgName": "", "name": "pos42" }, { "channel": 0, "enable": 0, "id": 42, "imgName": "", "name": "pos43" }, { "channel": 0, "enable": 0, "id": 43, "imgName": "", "name": "pos44" }, { "channel": 0, "enable": 0, "id": 44, "imgName": "", "name": "pos45" }, { "channel": 0, "enable": 0, "id": 45, "imgName": "", "name": "pos46" }, { "channel": 0, "enable": 0, "id": 46, "imgName": "", "name": "pos47" }, { "channel": 0, "enable": 0, "id": 47, "imgName": "", "name": "pos48" }, { "channel": 0, "enable": 0, "id": 48, "imgName": "", "name": "pos49" }, { "channel": 0, "enable": 0, "id": 49, "imgName": "", "name": "pos50" }, { "channel": 0, "enable": 0, "id": 50, "imgName": "", "name": "pos51" }, { "channel": 0, "enable": 0, "id": 51, "imgName": "", "name": "pos52" }, { "channel": 0, "enable": 0, "id": 52, "imgName": "", "name": "pos53" }, { "channel": 0, "enable": 0, "id": 53, "imgName": "", "name": "pos54" }, { "channel": 0, "enable": 0, "id": 54, "imgName": "", "name": "pos55" }, { "channel": 0, "enable": 0, "id": 55, "imgName": "", "name": "pos56" }, { "channel": 0, "enable": 0, "id": 56, "imgName": "", "name": "pos57" }, { "channel": 0, "enable": 0, "id": 57, "imgName": "", "name": "pos58" }, { "channel": 0, "enable": 0, "id": 58, "imgName": "", "name": "pos59" }, { "channel": 0, "enable": 0, "id": 59, "imgName": "", "name": "pos60" }, { "channel": 0, "enable": 0, "id": 60, "imgName": "", "name": "pos61" }, { "channel": 0, "enable": 0, "id": 61, "imgName": "", "name": "pos62" }, { "channel": 0, "enable": 0, "id": 62, "imgName": "", "name": "pos63" }, { "channel": 0, "enable": 0, "id": 63, "imgName": "", "name": "pos64" } ] } } ] ================================================ FILE: examples/response/GetRec.json ================================================ [ { "cmd": "GetRec", "code": 0, "initial": { "Rec": { "channel": 0, "overwrite": 1, "postRec": "15 Seconds", "preRec": 1, "schedule": { "enable": 1, "table": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" } } }, "range": { "Rec": { "channel": 0, "overwrite": "boolean", "postRec": [ "15 Seconds", "30 Seconds", "1 Minute" ], "preRec": "boolean", "schedule": { "enable": "boolean" } } }, "value": { "Rec": { "channel": 0, "overwrite": 1, "postRec": "15 Seconds", "preRec": 1, "schedule": { "enable": 1, "table": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } } } } ] ================================================ FILE: examples/response/GetUser.json ================================================ [ { "cmd": "GetUser", "code": 0, "initial": { "User": { "level": "guest" } }, "range": { "User": { "level": [ "guest", "admin" ], "password": { "maxLen": 31, "minLen": 6 }, "userName": { "maxLen": 31, "minLen": 1 } } }, "value": { "User": [ { "level": "admin", "userName": "admin" } ] } } ] ================================================ FILE: examples/response/Login.json ================================================ [ { "cmd": "Login", "code": 0, "value": { "Token": { "leaseTime": 3600, "name": "xxxxxxxxxxxx" } } } ] ================================================ FILE: examples/response/Logout.json ================================================ [ { "cmd": "Logout", "code": 0, "value": { "rspCode": 200 } } ] ================================================ FILE: examples/response/PtzCheck.json ================================================ [{"cmd": "PtzCheck", "code": 0, "value": {"rspCode": 200}}] ================================================ FILE: examples/response/PtzCtrl.json ================================================ [ { "cmd" : "PtzCtrl", "code" : 0, "value" : { "rspCode" : 200 } } ] ================================================ FILE: examples/response/Reboot.json ================================================ [ { "cmd": "Reboot", "code": 0, "value": { "rspCode": 200 } } ] ================================================ FILE: examples/response/SetAdvImageSettings.json ================================================ [ { "cmd" : "SetIsp", "code" : 0, "value" : { "rspCode" : 200 } } ] ================================================ FILE: examples/response/SetImageSettings.json ================================================ [ { "cmd" : "SetImage", "code" : 0, "value" : { "rspCode" : 200 } } ] ================================================ FILE: examples/response/SetPtzPreset.json ================================================ [ { "cmd" : "SetPtzPreset", "code" : 0, "value" : { "rspCode" : 200 } } ] ================================================ FILE: examples/stream_gui.py ================================================ import sys import os from configparser import RawConfigParser from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QSlider from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput from PyQt6.QtMultimediaWidgets import QVideoWidget from PyQt6.QtCore import Qt, QUrl, QTimer from PyQt6.QtGui import QWheelEvent from reolinkapi import Camera from threading import Lock import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) def read_config(props_path: str) -> dict: config = RawConfigParser() assert os.path.exists(props_path), f"Path does not exist: {props_path}" config.read(props_path) return config class ZoomSlider(QSlider): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def keyPressEvent(self, event): if event.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right, Qt.Key.Key_Up, Qt.Key.Key_Down): event.ignore() else: super().keyPressEvent(event) class CameraPlayer(QWidget): def __init__(self, rtsp_url_wide, rtsp_url_telephoto, camera: Camera): super().__init__() self.setWindowTitle("Reolink PTZ Streamer") self.setGeometry(10, 10, 2400, 900) self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) self.camera = camera self.zoom_timer = QTimer(self) self.zoom_timer.timeout.connect(self.stop_zoom) # Create media players self.media_player_wide = QMediaPlayer() self.media_player_telephoto = QMediaPlayer() # Create video widgets self.video_widget_wide = QVideoWidget() self.video_widget_telephoto = QVideoWidget() self.media_player_wide.setVideoOutput(self.video_widget_wide) self.media_player_telephoto.setVideoOutput(self.video_widget_telephoto) self.video_widget_wide.wheelEvent = self.handle_wheel_event self.video_widget_telephoto.wheelEvent = self.handle_wheel_event # Create layout layout = QHBoxLayout() layout.addWidget(self.video_widget_wide, 2) layout.addWidget(self.video_widget_telephoto, 2) self.setLayout(layout) # Start playing the streams self.media_player_wide.setSource(QUrl(rtsp_url_wide)) self.media_player_telephoto.setSource(QUrl(rtsp_url_telephoto)) self.media_player_wide.play() self.media_player_telephoto.play() def keyPressEvent(self, event): if event.isAutoRepeat(): return if event.key() == Qt.Key.Key_Escape: self.close() elif event.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right, Qt.Key.Key_Up, Qt.Key.Key_Down): self.start_move(event.key()) def keyReleaseEvent(self, event): if event.isAutoRepeat(): return if event.key() in (Qt.Key.Key_Left, Qt.Key.Key_Right, Qt.Key.Key_Up, Qt.Key.Key_Down): self.stop_move() def start_move(self, key): direction = { Qt.Key.Key_Left: "left", Qt.Key.Key_Right: "right", Qt.Key.Key_Up: "up", Qt.Key.Key_Down: "down" }.get(key) if direction: self.move_camera(direction) def stop_move(self): response = self.camera.stop_ptz() print("Stop PTZ") if response[0].get('code') != 0: self.show_error_message("Failed to stop camera movement", str(response[0])) def move_camera(self, direction): speed = 25 if direction == "left": response = self.camera.move_left(speed) elif direction == "right": response = self.camera.move_right(speed) elif direction == "up": response = self.camera.move_up(speed) elif direction == "down": response = self.camera.move_down(speed) else: print(f"Invalid direction: {direction}") return if response[0].get('code') == 0: print(f"Moving camera {direction}") else: self.show_error_message(f"Failed to move camera {direction}", str(response[0])) def handle_wheel_event(self, event: QWheelEvent): delta = event.angleDelta().y() if delta > 0: self.zoom_in() elif delta < 0: self.zoom_out() def zoom_in(self): self.start_zoom('in') def zoom_out(self): self.start_zoom('out') def start_zoom(self, direction: str): self.zoom_timer.stop() # Stop any ongoing zoom timer speed = 60 # You can adjust this value as needed if direction == 'in': response = self.camera.start_zooming_in(speed) else: response = self.camera.start_zooming_out(speed) if response[0].get('code') == 0: print(f"Zooming {direction}") self.zoom_timer.start(200) # Stop zooming after 200ms else: self.show_error_message(f"Failed to start zooming {direction}", str(response[0])) def stop_zoom(self): response = self.camera.stop_zooming() if response[0].get('code') != 0: self.show_error_message("Failed to stop zooming", str(response[0])) def show_error_message(self, title, message): print(f"Error: {title} {message}") def handle_error(self, error): print(f"Media player error: {error}") if __name__ == '__main__': # Read in your ip, username, & password from the configuration file config = read_config('camera.cfg') ip = config.get('camera', 'ip') un = config.get('camera', 'username') pw = config.get('camera', 'password') # Connect to camera cam = Camera(ip, un, pw, https=True) rtsp_url_wide = f"rtsp://{un}:{pw}@{ip}/Preview_01_sub" rtsp_url_telephoto = f"rtsp://{un}:{pw}@{ip}/Preview_02_sub" # Connect to camera cam = Camera(ip, un, pw, https=True) app = QApplication(sys.argv) player = CameraPlayer(rtsp_url_wide, rtsp_url_telephoto, cam) player.show() sys.exit(app.exec()) ================================================ FILE: examples/streaming_video.py ================================================ import cv2 from reolinkapi import Camera def non_blocking(): print("calling non-blocking") def inner_callback(img): cv2.imshow("name", maintain_aspect_ratio_resize(img, width=600)) print("got the image non-blocking") key = cv2.waitKey(1) if key == ord('q'): cv2.destroyAllWindows() exit(1) c = Camera("192.168.1.112", "admin", "jUa2kUzi") # t in this case is a thread t = c.open_video_stream(callback=inner_callback) print(t.is_alive()) while True: if not t.is_alive(): print("continuing") break # stop the stream # client.stop_stream() def blocking(): c = Camera("192.168.1.112", "admin", "jUa2kUzi") # stream in this case is a generator returning an image (in mat format) stream = c.open_video_stream() # using next() # while True: # img = next(stream) # cv2.imshow("name", maintain_aspect_ratio_resize(img, width=600)) # print("got the image blocking") # key = cv2.waitKey(1) # if key == ord('q'): # cv2.destroyAllWindows() # exit(1) # or using a for loop for img in stream: cv2.imshow("name", maintain_aspect_ratio_resize(img, width=600)) print("got the image blocking") key = cv2.waitKey(1) if key == ord('q'): cv2.destroyAllWindows() exit(1) # Resizes a image and maintains aspect ratio def maintain_aspect_ratio_resize(image, width=None, height=None, inter=cv2.INTER_AREA): # Grab the image size and initialize dimensions dim = None (h, w) = image.shape[:2] # Return original image if no need to resize if width is None and height is None: return image # We are resizing height if width is none if width is None: # Calculate the ratio of the height and construct the dimensions r = height / float(h) dim = (int(w * r), height) # We are resizing width if height is none else: # Calculate the ratio of the 0idth and construct the dimensions r = width / float(w) dim = (width, int(h * r)) # Return the resized image return cv2.resize(image, dim, interpolation=inter) # Call the methods. Either Blocking (using generator) or Non-Blocking using threads # non_blocking() blocking() ================================================ FILE: examples/video_review_gui.py ================================================ # Video review GUI # https://github.com/sven337/ReolinkLinux/wiki#reolink-video-review-gui import os import signal import sys import re import datetime import subprocess import argparse from configparser import RawConfigParser from datetime import datetime as dt, timedelta from reolinkapi import Camera from PyQt6.QtWidgets import QApplication, QVBoxLayout, QHBoxLayout, QWidget, QTableWidget, QTableWidgetItem, QPushButton, QLabel, QFileDialog, QHeaderView, QStyle, QSlider, QStyleOptionSlider, QSplitter, QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput from PyQt6.QtMultimediaWidgets import QVideoWidget from PyQt6.QtCore import Qt, QUrl, QTimer, QThread, pyqtSignal, QMutex, QWaitCondition from PyQt6.QtGui import QColor, QBrush, QFont, QIcon from collections import deque import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) def path_name_from_camera_path(fname): # Mp4Record/2024-08-12/RecM13_DST20240812_214255_214348_1F1E828_4DDA4D.mp4 return fname.replace('/', '_') # Function to decode hex values into individual flags def decode_hex_to_flags(hex_value): flags_mapping = { 'resolution_index': (21, 7), 'tv_system': (20, 1), 'framerate': (13, 7), 'audio_index': (11, 2), 'ai_pd': (10, 1), # person 'ai_fd': (9, 1), # face 'ai_vd': (8, 1), # vehicle 'ai_ad': (7, 1), # animal 'encoder_type_index': (5, 2), 'is_schedule_record': (4, 1), #scheduled 'is_motion_record': (3, 1), # motion detected 'is_rf_record': (2, 1), 'is_doorbell_press_record': (1, 1), 'ai_other': (0, 1) } hex_value = int(hex_value, 16) # Convert hex string to integer flag_values = {} for flag, (bit_position, bit_size) in flags_mapping.items(): mask = ((1 << bit_size) - 1) << bit_position flag_values[flag] = (hex_value & mask) >> bit_position return flag_values def parse_filename(file_name): # Mp4Record_2024-08-12_RecM13_DST20240812_214255_214348_1F1E828_4DDA4D.mp4 # Mp4Record_2024-09-13-RecS09_DST20240907_084519_084612_0_55289080000000_307BC0.mp4 # https://github.com/sven337/ReolinkLinux/wiki/Figuring-out-the-file-names#file-name-structure pattern = r'.*?Mp4Record_(\d{4}-\d{2}-\d{2})_Rec[MS](\d)(\d)_(DST)?(\d{8})_(\d{6})_(\d{6})' v3_suffix = r'.*_(\w{4,8})_(\w{4,8})\.mp4' v9_suffix = r'.*_(\d)_(\w{7})(\w{7})_(\w{1,8})\.mp4' match = re.match(pattern, file_name) out = {} version = 0 if match: date = match.group(1) # YYYY-MM-DD channel = int(match.group(2)) version = int(match.group(3)) # version start_date = match.group(5) # YYYYMMDD start_time = match.group(6) # HHMMSS end_time = match.group(7) # HHMMSS # Combine date and start time into a datetime object start_datetime = datetime.datetime.strptime(f"{start_date} {start_time}", "%Y%m%d %H%M%S") out = {'start_datetime': start_datetime, 'channel': channel, 'end_time': end_time } else: print("parse error") return None if version == 9: match = re.match(v9_suffix, file_name) if not match: print(f"v9 parse error for {file_name}") return None animal_type = match.group(1) flags_hex1 = match.group(2) flags_hex2 = match.group(3) file_size = int(match.group(4), 16) triggers = decode_hex_to_flags(flags_hex1) out.update({'animal_type' : animal_type, 'file_size' : file_size, 'triggers' : triggers }) elif version == 2 or version == 3: match = re.match(v3_suffix, file_name) if not match: print(f"v3 parse error for {file_name}") return None flags_hex = match.group(1) file_size = int(match.group(2), 16) triggers = decode_hex_to_flags(flags_hex) out.update({'file_size' : file_size, 'triggers' : triggers }) return out class ClickableSlider(QSlider): def mousePressEvent(self, event): if event.button() == Qt.MouseButton.LeftButton: val = self.pixelPosToRangeValue(event.pos()) self.setValue(val) super().mousePressEvent(event) def pixelPosToRangeValue(self, pos): opt = QStyleOptionSlider() self.initStyleOption(opt) gr = self.style().subControlRect(QStyle.ComplexControl.CC_Slider, opt, QStyle.SubControl.SC_SliderGroove, self) sr = self.style().subControlRect(QStyle.ComplexControl.CC_Slider, opt, QStyle.SubControl.SC_SliderHandle, self) if self.orientation() == Qt.Orientation.Horizontal: sliderLength = sr.width() sliderMin = gr.x() sliderMax = gr.right() - sliderLength + 1 pos = pos.x() else: sliderLength = sr.height() sliderMin = gr.y() sliderMax = gr.bottom() - sliderLength + 1 pos = pos.y() return QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), pos - sliderMin, sliderMax - sliderMin, opt.upsideDown) class DownloadThread(QThread): download_complete = pyqtSignal(str, bool) download_start = pyqtSignal(str) def __init__(self, download_queue, cam): super().__init__() self.download_queue = download_queue self.cam = cam self.mutex = QMutex() self.wait_condition = QWaitCondition() self.is_running = True def run(self): while self.is_running: self.mutex.lock() if len(self.download_queue) == 0: self.wait_condition.wait(self.mutex) self.mutex.unlock() if not self.is_running: break try: fname, output_path = self.download_queue.popleft() output_path = os.path.join(video_storage_dir, output_path) print(f"Downloading: {fname}") self.download_start.emit(output_path) resp = self.cam.get_file(fname, output_path=output_path) if resp: print(f"Download complete: {output_path}") self.download_complete.emit(output_path, True) else: print(f"Download failed: {fname}") self.download_complete.emit(output_path, False) except IndexError: pass def stop(self): self.mutex.lock() self.is_running = False self.mutex.unlock() self.wait_condition.wakeAll() def add_to_queue(self, fname, output_path, left=False): self.mutex.lock() if left: self.download_queue.appendleft((fname, output_path)) else: self.download_queue.append((fname, output_path)) self.wait_condition.wakeOne() self.mutex.unlock() class VideoPlayer(QWidget): file_exists_signal = pyqtSignal(str, bool) def __init__(self, video_files): super().__init__() self.setWindowTitle("Reolink Video Review GUI") self.cam = cam self.download_queue = deque() self.download_thread = DownloadThread(self.download_queue, self.cam) self.download_thread.download_start.connect(self.on_download_start) self.download_thread.download_complete.connect(self.on_download_complete) self.download_thread.start() # Create media player self.media_player = QMediaPlayer() self.media_player.errorOccurred.connect(self.handle_media_player_error) # Create video widget self.video_widget = QVideoWidget() self.media_player.setVideoOutput(self.video_widget) self.media_player.setPlaybackRate(1.5) # Create table widget to display video files self.video_tree = QTreeWidget() self.video_tree.setColumnCount(10) self.video_tree.setHeaderLabels(["Status", "Video Path", "Start Datetime", "End Time", "Channel", "Person", "Vehicle", "Pet", "Motion", "Timer"]) self.video_tree.setSortingEnabled(True) self.video_tree.itemClicked.connect(self.play_video) # Set smaller default column widths self.video_tree.setColumnWidth(0, 35) # Status self.video_tree.setColumnWidth(1, 120) # Video Path self.video_tree.setColumnWidth(2, 130) # Start Datetime self.video_tree.setColumnWidth(3, 70) # End Time self.video_tree.setColumnWidth(4, 35) # Channel self.video_tree.setColumnWidth(5, 35) # Person self.video_tree.setColumnWidth(6, 35) # Vehicle self.video_tree.setColumnWidth(7, 35) # Pet self.video_tree.setColumnWidth(8, 35) # Motion self.video_tree.setColumnWidth(9, 30) # Timer self.video_tree.setIndentation(10) QIcon.setThemeName("Adwaita") # Create open button to select video files self.open_button = QPushButton("Open Videos") self.open_button.clicked.connect(self.open_videos) self.play_button = QPushButton() self.play_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_MediaPlay)) self.play_button.clicked.connect(self.play_pause) self.mpv_button = QPushButton("MPV") self.mpv_button.clicked.connect(self.open_in_mpv) self.get_highres_button = QPushButton("GetHighRes") self.get_highres_button.clicked.connect(self.get_highres_stream_for_file) self.get_highres_button.setEnabled(False) # Disable by default # Create seek slider self.seek_slider = ClickableSlider(Qt.Orientation.Horizontal) self.seek_slider.setRange(0, 0) self.seek_slider.sliderPressed.connect(self.seek_slider_pressed) self.seek_slider.sliderReleased.connect(self.seek_slider_released) self.seek_slider.sliderMoved.connect(self.seek_slider_moved) self.media_player.positionChanged.connect(self.update_position) self.media_player.durationChanged.connect(self.update_duration) # Create playback speed slider self.speed_slider = QSlider(Qt.Orientation.Horizontal) self.speed_slider.setRange(50, 300) self.speed_slider.setValue(200) self.speed_slider.valueChanged.connect(self.set_speed) speed_label = QLabel("Speed: 2.0x") self.speed_slider.valueChanged.connect(lambda v: speed_label.setText(f"Speed: {v/100:.1f}x")) main_layout = QHBoxLayout() # Create a splitter splitter = QSplitter(Qt.Orientation.Horizontal) # Left side (table and open button) left_widget = QWidget() left_layout = QVBoxLayout(left_widget) left_layout.addWidget(self.video_tree) left_layout.addWidget(self.open_button) splitter.addWidget(left_widget) # Right side (video player and controls) right_widget = QWidget() right_layout = QVBoxLayout(right_widget) right_layout.addWidget(self.video_widget, 1) controls_widget = QWidget() controls_layout = QVBoxLayout(controls_widget) control_layout = QHBoxLayout() control_layout.addWidget(self.play_button) control_layout.addWidget(self.seek_slider) control_layout.addWidget(self.mpv_button) control_layout.addWidget(self.get_highres_button) controls_layout.addLayout(control_layout) speed_layout = QHBoxLayout() speed_layout.addWidget(QLabel("Speed:")) speed_layout.addWidget(self.speed_slider) speed_layout.addWidget(speed_label) controls_layout.addLayout(speed_layout) right_layout.addWidget(controls_widget) splitter.addWidget(right_widget) # Set initial sizes splitter.setSizes([300, 700]) main_layout.addWidget(splitter) self.setLayout(main_layout) self.file_exists_signal.connect(self.on_download_complete) self.add_initial_videos(video_files) def add_initial_videos(self, video_files): for video_path in video_files: self.add_video(video_path) self.video_tree.sortItems(2, Qt.SortOrder.DescendingOrder) # self.video_tree.expandAll() def open_videos(self): file_dialog = QFileDialog(self) file_dialog.setNameFilters(["Videos (*.mp4 *.avi *.mov)"]) file_dialog.setFileMode(QFileDialog.FileMode.ExistingFiles) if file_dialog.exec(): self.video_tree.setSortingEnabled(False) for file in file_dialog.selectedFiles(): self.add_video(os.path.basename(file)) self.video_tree.setSortingEnabled(True) self.video_tree.sortItems(2, Qt.SortOrder.DescendingOrder) # self.video_tree.expandAll() def add_video(self, video_path): # We are passed the camera file name, e.g. Mp4Record/2024-08-12/RecM13_DST20240812_214255_214348_1F1E828_4DDA4D.mp4 file_path = path_name_from_camera_path(video_path) base_file_name = file_path parsed_data = parse_filename(file_path) if not parsed_data: print(f"Could not parse file {video_path}") return start_datetime = parsed_data['start_datetime'] channel = parsed_data['channel'] end_time = datetime.datetime.strptime(parsed_data['end_time'], "%H%M%S") end_time_str = end_time.strftime("%H:%M:%S") video_item = QTreeWidgetItem() video_item.setText(0, "") # Status video_item.setTextAlignment(0, Qt.AlignmentFlag.AlignCenter) video_item.setText(1, base_file_name) video_item.setText(2, start_datetime.strftime("%Y-%m-%d %H:%M:%S")) video_item.setData(2, Qt.ItemDataRole.UserRole, parsed_data['start_datetime']) video_item.setText(3, end_time_str) video_item.setText(4, str(channel)) video_item.setText(5, "✓" if parsed_data['triggers']['ai_pd'] else "") video_item.setText(6, "✓" if parsed_data['triggers']['ai_vd'] else "") video_item.setText(7, "✓" if parsed_data['triggers']['ai_ad'] else "") video_item.setText(8, "✓" if parsed_data['triggers']['is_motion_record'] else "") video_item.setText(9, "✓" if parsed_data['triggers']['is_schedule_record'] else "") if parsed_data['triggers']['ai_other']: print(f"File {file_path} has ai_other flag!") video_item.setToolTip(1, base_file_name) # Set the style for queued status grey_color = QColor(200, 200, 200) # Light grey video_item.setForeground(1, QBrush(grey_color)) font = QFont() font.setItalic(True) video_item.setFont(1, font) # Make the fields non-editable iterator = QTreeWidgetItemIterator(self.video_tree) while iterator.value(): item = iterator.value() item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEditable) iterator += 1 # Find a potentially pre-existing channel0 item for this datetime, if so, add as a child # This lets channel1 appear as a child, but also main & sub videos appear in the same group channel_0_item = self.find_channel_0_item(start_datetime) if channel_0_item: # Check if the current item is a main stream and the existing channel_0_item is a sub stream if "RecM" in base_file_name and "RecS" in channel_0_item.text(1): # Make the current main stream item the new parent new_parent = video_item # Move all children of the sub stream item to the new main stream item while channel_0_item.childCount() > 0: child = channel_0_item.takeChild(0) new_parent.addChild(child) # Remove the old sub stream item parent = channel_0_item.parent() if parent: parent.removeChild(channel_0_item) else: index = self.video_tree.indexOfTopLevelItem(channel_0_item) self.video_tree.takeTopLevelItem(index) # Add the new main stream item as a top-level item self.video_tree.addTopLevelItem(new_parent) else: # If it's not a main stream replacing a sub stream, add as a child as before channel_0_item.addChild(video_item) else: self.video_tree.addTopLevelItem(video_item) output_path = os.path.join(video_storage_dir, base_file_name) expected_size = parsed_data['file_size'] need_download = True if os.path.isfile(output_path): actual_size = os.path.getsize(output_path) if actual_size == expected_size: need_download = False self.file_exists_signal.emit(output_path, True) else: print(f"File size mismatch for {output_path}. Expected: {expected_size}, Actual: {actual_size}. Downloading again") if need_download: video_item.setIcon(1, self.style().standardIcon(QStyle.StandardPixmap.SP_CommandLink)) self.download_thread.add_to_queue(video_path, base_file_name) def find_channel_0_item(self, datetime_obj): # Truncate seconds to nearest 10 truncated_seconds = datetime_obj.second - (datetime_obj.second % 10) truncated_datetime = datetime_obj.replace(second=truncated_seconds) for i in range(self.video_tree.topLevelItemCount()): item = self.video_tree.topLevelItem(i) item_datetime = item.data(2, Qt.ItemDataRole.UserRole) item_truncated = item_datetime.replace(second=item_datetime.second - (item_datetime.second % 10)) if item_truncated == truncated_datetime: return item return None def find_item_by_path(self, path): iterator = QTreeWidgetItemIterator(self.video_tree) while iterator.value(): item = iterator.value() text = item.text(1) if text == path: return item iterator += 1 print(f"Could not find item by path {path}") return None def on_download_complete(self, video_path, success): item = self.find_item_by_path(os.path.basename(video_path)) if not item: print(f"on_download_complete {video_path} did not find item?!") return item.setForeground(1, QBrush(QColor(0, 0, 0))) # Black color for normal text font = item.font(1) font.setItalic(False) font.setBold(False) item.setFont(1, font) if success: if "RecS" in item.text(1): # One day (hopefully) offer the option to download the # high-res version This is not trivial because we have to # re-do a camera search for the relevant time period and # match based on start and end dates (+/- one second in my # experience) # For now simply display that this is low-res. item.setText(0, "sub") item.setIcon(1, QIcon()) else: item.setIcon(1, self.style().standardIcon(QStyle.StandardPixmap.SP_MessageBoxCritical)) def on_download_start(self, video_path): item = self.find_item_by_path(os.path.basename(video_path)) if item: grey_color = QColor(200, 200, 200) # Light grey item.setForeground(1, QBrush(grey_color)) font = item.font(1) font.setBold(True) item.setFont(1, font) item.setIcon(1, QIcon.fromTheme("emblem-synchronizing")) else: print(f"Cannot find item for {video_path}") def play_video(self, file_name_item, column): video_path = os.path.join(video_storage_dir, file_name_item.text(1)) if file_name_item.font(1).italic() or file_name_item.foreground(1).color().lightness() >= 200: print(f"Video {video_path} is not yet downloaded. Moving it to top of queue. Please wait for download.") # Find the item in the download_queue that matches the base file name found_item = None for item in list(self.download_queue): if item[1] == file_name_item.text(1): found_item = item break if found_item: # Remove the item from its current position in the queue self.download_queue.remove(found_item) # Add the item to the end of the queue self.download_thread.add_to_queue(*found_item, left=True) return # Enable/disable GetHighRes button based on whether it's a sub stream self.get_highres_button.setEnabled("RecS" in file_name_item.text(1)) print(f"Playing video: {video_path}") url = QUrl.fromLocalFile(video_path) self.media_player.setSource(url) self.video_widget.show() def start_playback(): # Seek to 5 seconds (pre-record) self.media_player.setPosition(5000) self.media_player.play() self.play_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_MediaPause)) print(f"Media player state: {self.media_player.playbackState()}") # Timer needed to be able to play at seek offset in the video, otherwise setPosition seems ignored QTimer.singleShot(20, start_playback) def get_highres_stream_for_file(self): current_item = self.video_tree.currentItem() if not current_item or "RecS" not in current_item.text(1): return parsed_data = parse_filename(current_item.text(1)) if not parsed_data: print(f"Could not parse file {current_item.text(1)}") return start_time = parsed_data['start_datetime'] - timedelta(seconds=1) end_time = datetime.datetime.strptime(f"{parsed_data['start_datetime'].strftime('%Y%m%d')} {parsed_data['end_time']}", "%Y%m%d %H%M%S") + timedelta(seconds=1) main_files = self.cam.get_motion_files(start=start_time, end=end_time, streamtype='main', channel=parsed_data['channel']) if main_files: for main_file in main_files: self.add_video(main_file['filename']) self.video_tree.sortItems(2, Qt.SortOrder.DescendingOrder) else: print(f"No main stream file found for {current_item.text(1)}") def play_pause(self): if self.media_player.playbackState() == QMediaPlayer.PlaybackState.PlayingState: self.media_player.pause() self.play_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_MediaPlay)) else: self.media_player.play() self.play_button.setIcon(self.style().standardIcon(QStyle.StandardPixmap.SP_MediaPause)) def handle_media_player_error(self, error): print(f"Media player error: {error}") def seek_slider_pressed(self): self.media_player.setPosition(self.seek_slider.value()) self.media_player.play() def seek_slider_released(self): self.media_player.setPosition(self.seek_slider.value()) self.media_player.play() def seek_slider_moved(self, position): # Update video frame while dragging self.media_player.setPosition(position) def update_position(self, position): self.seek_slider.setValue(position) def update_duration(self, duration): self.seek_slider.setRange(0, duration) def set_speed(self, speed): self.media_player.setPlaybackRate(speed / 100) def open_in_mpv(self): current_video = self.media_player.source().toString() if current_video: # Remove the 'file://' prefix if present video_path = current_video.replace('file://', '') try: subprocess.Popen(['mpv', video_path]) except FileNotFoundError: print("Error: MPV player not found. Make sure it's installed and in your system PATH.") else: print("No video is currently selected.") def closeEvent(self, event): self.download_thread.stop() self.download_thread.wait(1000) self.download_thread.terminate() self.cam.logout() super().closeEvent(event) def read_config(props_path: str) -> dict: """Reads in a properties file into variables. NB! this config file is kept out of commits with .gitignore. The structure of this file is such: # secrets.cfg [camera] ip={ip_address} username={username} password={password} """ config = RawConfigParser() assert os.path.exists(props_path), f"Path does not exist: {props_path}" config.read(props_path) return config def signal_handler(sig, frame): print("Exiting the application...") sys.exit(0) cam.logout() QApplication.quit() if __name__ == '__main__': signal.signal(signal.SIGINT, signal_handler) parser = argparse.ArgumentParser(description="Reolink Video Review GUI") parser.add_argument('--main', action='store_true', help="Search for main channel instead of sub channel") parser.add_argument('files', nargs='*', help="Optional video file names to process") args = parser.parse_args() config = read_config('camera.cfg') ip = config.get('camera', 'ip') un = config.get('camera', 'username') pw = config.get('camera', 'password') video_storage_dir = config.get('camera', 'video_storage_dir') # Connect to camera cam = Camera(ip, un, pw, https=True) start = dt.combine(dt.now(), dt.min.time()) end = dt.now() streamtype = 'sub' if not args.main else 'main' processed_motions = cam.get_motion_files(start=start, end=end, streamtype=streamtype, channel=0) processed_motions += cam.get_motion_files(start=start, end=end, streamtype=streamtype, channel=1) start = dt.now() - timedelta(days=1) end = dt.combine(start, dt.max.time()) processed_motions += cam.get_motion_files(start=start, end=end, streamtype=streamtype, channel=0) processed_motions += cam.get_motion_files(start=start, end=end, streamtype=streamtype, channel=1) if len(processed_motions) == 0: print("Camera did not return any video?!") video_files = [] for i, motion in enumerate(processed_motions): fname = motion['filename'] print("Processing %s" % (fname)) video_files.append(fname) video_files.extend([os.path.basename(file) for file in args.files]) app = QApplication(sys.argv) player = VideoPlayer(video_files) player.resize(2400, 1000) player.show() sys.exit(app.exec()) ================================================ FILE: make-and-publish-package.sh ================================================ rm -rf dist python setup.py sdist bdist_wheel twine upload dist/* ================================================ FILE: reolinkapi/__init__.py ================================================ from reolinkapi.handlers.api_handler import APIHandler from .camera import Camera __version__ = "0.4.1" ================================================ FILE: reolinkapi/camera.py ================================================ from reolinkapi.handlers.api_handler import APIHandler class Camera(APIHandler): def __init__(self, ip: str, username: str = "admin", password: str = "", https: bool = False, defer_login: bool = False, profile: str = "main", **kwargs): """ Initialise the Camera object by passing the ip address. The default details {"username":"admin", "password":""} will be used if nothing passed For deferring the login to the camera, just pass defer_login = True. For connecting to the camera behind a proxy pass a proxy argument: proxy={"http": "socks5://127.0.0.1:8000"} :param ip: :param username: :param password: :param https: connect to the camera over https :param defer_login: defer the login process :param proxy: Add a proxy dict for requests to consume. eg: {"http":"socks5://[username]:[password]@[host]:[port], "https": ...} More information on proxies in requests: https://stackoverflow.com/a/15661226/9313679 """ if profile not in ["main", "sub"]: raise Exception("Profile argument must be either \"main\" or \"sub\"") # For when you need to connect to a camera behind a proxy, pass # a proxy argument: proxy={"http": "socks5://127.0.0.1:8000"} APIHandler.__init__(self, ip, username, password, https=https, **kwargs) # Normal call without proxy: # APIHandler.__init__(self, ip, username, password) self.ip = ip self.username = username self.password = password self.profile = profile if not defer_login: super().login() ================================================ FILE: reolinkapi/handlers/__init__.py ================================================ ================================================ FILE: reolinkapi/handlers/api_handler.py ================================================ import requests from typing import Dict, List, Optional, Union from reolinkapi.mixins.alarm import AlarmAPIMixin from reolinkapi.mixins.device import DeviceAPIMixin from reolinkapi.mixins.display import DisplayAPIMixin from reolinkapi.mixins.download import DownloadAPIMixin from reolinkapi.mixins.image import ImageAPIMixin from reolinkapi.mixins.motion import MotionAPIMixin from reolinkapi.mixins.network import NetworkAPIMixin from reolinkapi.mixins.ptz import PtzAPIMixin from reolinkapi.mixins.record import RecordAPIMixin from reolinkapi.handlers.rest_handler import Request from reolinkapi.mixins.stream import StreamAPIMixin from reolinkapi.mixins.system import SystemAPIMixin from reolinkapi.mixins.user import UserAPIMixin from reolinkapi.mixins.zoom import ZoomAPIMixin from reolinkapi.mixins.nvrdownload import NvrDownloadAPIMixin class APIHandler(AlarmAPIMixin, DeviceAPIMixin, DisplayAPIMixin, DownloadAPIMixin, ImageAPIMixin, MotionAPIMixin, NetworkAPIMixin, PtzAPIMixin, RecordAPIMixin, SystemAPIMixin, UserAPIMixin, ZoomAPIMixin, StreamAPIMixin, NvrDownloadAPIMixin): """ The APIHandler class is the backend part of the API, the actual API calls are implemented in Mixins. This handles communication directly with the camera. Current camera's tested: RLC-411WS All Code will try to follow the PEP 8 standard as described here: https://www.python.org/dev/peps/pep-0008/ """ def __init__(self, ip: str, username: str, password: str, https: bool = False, **kwargs): """ Initialise the Camera API Handler (maps api calls into python) :param ip: :param username: :param password: :param https: connect over https :param proxy: Add a proxy dict for requests to consume. eg: {"http":"socks5://[username]:[password]@[host]:[port], "https": ...} More information on proxies in requests: https://stackoverflow.com/a/15661226/9313679 """ scheme = 'https' if https else 'http' self.url = f"{scheme}://{ip}/cgi-bin/api.cgi" self.ip = ip self.token = None self.username = username self.password = password Request.proxies = kwargs.get("proxy") # Defaults to None if key isn't found Request.session = kwargs.get("session") # Defaults to None if key isn't found def login(self) -> bool: """ Get login token Must be called first, before any other operation can be performed :return: bool """ try: body = [{"cmd": "Login", "action": 0, "param": {"User": {"userName": self.username, "password": self.password}}}] param = {"cmd": "Login", "token": "null"} response = Request.post(self.url, data=body, params=param) if response is not None: data = response.json()[0] code = data["code"] if int(code) == 0: self.token = data["value"]["Token"]["name"] print("Login success") return True print(self.token) return False else: # TODO: Verify this change w/ owner. Delete old code if acceptable. # A this point, response is NoneType. There won't be a status code property. # print("Failed to login\nStatus Code:", response.status_code) print("Failed to login\nResponse was null.") return False except Exception as e: print("Error Login\n", e) raise def logout(self) -> bool: """ Logout of the camera :return: bool """ try: data = [{"cmd": "Logout", "action": 0}] self._execute_command('Logout', data) # print(ret) return True except Exception as e: print("Error Logout\n", e) return False def _execute_command(self, command: str, data: List[Dict], multi: bool = False) -> \ Optional[Union[Dict, bool]]: """ Send a POST request to the IP camera with given data. :param command: name of the command to send :param data: object to send to the camera (send as json) :param multi: whether the given command name should be added to the url parameters of the request. Defaults to False. (Some multi-step commands seem to not have a single command name) :return: response JSON as python object """ params = {"token": self.token, 'cmd': command} if multi: del params['cmd'] try: if self.token is None: raise ValueError("Login first") if command == 'Download' or command == 'Playback': # Special handling for downloading an mp4 # Pop the filepath from data tgt_filepath = data[0].pop('filepath') # Apply the data to the params params.update(data[0]) with requests.get(self.url, params=params, stream=True, verify=False, timeout=(1, None), proxies=Request.proxies) as req: if req.status_code == 200: with open(tgt_filepath, 'wb') as f: f.write(req.content) return True else: print(f'Error received: {req.status_code}') return False else: response = Request.post(self.url, data=data, params=params) return response.json() except Exception as e: print(f"Command {command} failed: {e}") raise ================================================ FILE: reolinkapi/handlers/rest_handler.py ================================================ import requests from typing import List, Dict, Union, Optional class Request: proxies = None session = None @staticmethod def __getSession(): reqHandler = requests if Request.session is not None: reqHandler = Request.session return reqHandler @staticmethod def post(url: str, data: List[Dict], params: Dict[str, Union[str, float]] = None) -> \ Optional[requests.Response]: """ Post request :param params: :param url: :param data: :return: """ try: headers = {'content-type': 'application/json'} r = Request.__getSession().post(url, verify=False, params=params, json=data, headers=headers, proxies=Request.proxies) if r.status_code == 200: return r else: raise ValueError(f"Http Request had non-200 Status: {r.status_code}", r.status_code) except Exception as e: print("Post Error\n", e) raise @staticmethod def get(url: str, params: Dict[str, Union[str, float]], timeout: float = 1) -> Optional[requests.Response]: """ Get request :param url: :param params: :param timeout: :return: """ try: data = Request.__getSession().get(url=url, verify=False, params=params, timeout=timeout, proxies=Request.proxies) return data except Exception as e: print("Get Error\n", e) raise ================================================ FILE: reolinkapi/mixins/__init__.py ================================================ ================================================ FILE: reolinkapi/mixins/alarm.py ================================================ from typing import Dict class AlarmAPIMixin: """API calls for getting device alarm information.""" def get_alarm_motion(self) -> Dict: """ Gets the device alarm motion See examples/response/GetAlarmMotion.json for example response data. :return: response json """ body = [{"cmd": "GetAlarm", "action": 1, "param": {"Alarm": {"channel": 0, "type": "md"}}}] return self._execute_command('GetAlarm', body) ================================================ FILE: reolinkapi/mixins/device.py ================================================ from typing import List, Dict class DeviceAPIMixin: """API calls for getting device information.""" DEFAULT_HDD_ID = [0] def set_device_name(self, name: str) -> bool: """ Set the device name of the camera. :param name: The new name for the device :return: bool indicating success """ body = [{"cmd": "SetDevName", "action": 0, "param": {"DevName": {"name": name}}}] self._execute_command('SetDevName', body) print(f"Successfully set device name to: {name}") return True def get_device_name(self) -> Dict: """ Get the device name of the camera. :return: Dict containing the device name """ body = [{"cmd": "GetDevName", "action": 0, "param": {}}] return self._execute_command('GetDevName', body) def get_hdd_info(self) -> Dict: """ Gets all HDD and SD card information from Camera See examples/response/GetHddInfo.json for example response data. :return: response json """ body = [{"cmd": "GetHddInfo", "action": 0, "param": {}}] return self._execute_command('GetHddInfo', body) def format_hdd(self, hdd_id: List[float] = None) -> bool: """ Format specified HDD/SD cards with their id's :param hdd_id: List of id's specified by the camera with get_hdd_info api. Default is 0 (SD card) :return: bool """ if hdd_id is None: hdd_id = self.DEFAULT_HDD_ID body = [{"cmd": "Format", "action": 0, "param": {"HddInfo": {"id": hdd_id}}}] r_data = self._execute_command('Format', body)[0] if r_data["value"]["rspCode"] == 200: return True print("Could not format HDD/SD. Camera responded with:", r_data["value"]) return False ================================================ FILE: reolinkapi/mixins/display.py ================================================ from typing import Dict class DisplayAPIMixin: """API calls related to the current image (osd, on screen display).""" def get_osd(self) -> Dict: """ Get OSD information. See examples/response/GetOsd.json for example response data. :return: response json """ body = [{"cmd": "GetOsd", "action": 1, "param": {"channel": 0}}] return self._execute_command('GetOsd', body) def get_mask(self) -> Dict: """ Get the camera mask information. See examples/response/GetMask.json for example response data. :return: response json """ body = [{"cmd": "GetMask", "action": 1, "param": {"channel": 0}}] return self._execute_command('GetMask', body) def set_osd(self, bg_color: bool = 0, channel: float = 0, osd_channel_enabled: bool = 0, osd_channel_name: str = "", osd_channel_pos: str = "Lower Right", osd_time_enabled: bool = 0, osd_time_pos: str = "Lower Right", osd_watermark_enabled: bool = 0) -> bool: """ Set OSD :param bg_color: bool :param channel: int channel id :param osd_channel_enabled: bool :param osd_channel_name: string channel name :param osd_channel_pos: string channel position ["Upper Left","Top Center","Upper Right","Lower Left","Bottom Center","Lower Right"] :param osd_time_enabled: bool :param osd_time_pos: string time position ["Upper Left","Top Center","Upper Right","Lower Left","Bottom Center","Lower Right"] :return: whether the action was successful """ body = [{"cmd": "SetOsd", "action": 1, "param": { "Osd": { "bgcolor": bg_color, "channel": channel, "osdChannel": { "enable": osd_channel_enabled, "name": osd_channel_name, "pos": osd_channel_pos }, "osdTime": {"enable": osd_time_enabled, "pos": osd_time_pos}, "watermark": osd_watermark_enabled, }}}] r_data = self._execute_command('SetOsd', body)[0] if 'value' in r_data and r_data["value"]["rspCode"] == 200: return True print("Could not set OSD. Camera responded with status:", r_data["error"]) return False ================================================ FILE: reolinkapi/mixins/download.py ================================================ class DownloadAPIMixin: """API calls for downloading video files.""" def get_file(self, filename: str, output_path: str, method = 'Playback') -> bool: """ Download the selected video file On at least Trackmix Wifi, it was observed that the Playback method yields much improved download speeds over the Download method, for unknown reasons. :return: response json """ body = [ { "cmd": method, "source": filename, "output": filename, "filepath": output_path } ] resp = self._execute_command(method, body) return resp ================================================ FILE: reolinkapi/mixins/image.py ================================================ from typing import Dict class ImageAPIMixin: """API calls for image settings.""" def set_adv_image_settings(self, anti_flicker: str = 'Outdoor', exposure: str = 'Auto', gain_min: float = 1, gain_max: float = 62, shutter_min: float = 1, shutter_max: float = 125, blue_gain: float = 128, red_gain: float = 128, white_balance: str = 'Auto', day_night: str = 'Auto', back_light: str = 'DynamicRangeControl', blc: float = 128, drc: float = 128, rotation: float = 0, mirroring: float = 0, nr3d: float = 1) -> Dict: """ Sets the advanced camera settings. :param anti_flicker: string :param exposure: string :param gain_min: int :param gain_max: string :param shutter_min: int :param shutter_max: int :param blue_gain: int :param red_gain: int :param white_balance: string :param day_night: string :param back_light: string :param blc: int :param drc: int :param rotation: int :param mirroring: int :param nr3d: int :return: response """ body = [{ "cmd": "SetIsp", "action": 0, "param": { "Isp": { "channel": 0, "antiFlicker": anti_flicker, "exposure": exposure, "gain": {"min": gain_min, "max": gain_max}, "shutter": {"min": shutter_min, "max": shutter_max}, "blueGain": blue_gain, "redGain": red_gain, "whiteBalance": white_balance, "dayNight": day_night, "backLight": back_light, "blc": blc, "drc": drc, "rotation": rotation, "mirroring": mirroring, "nr3d": nr3d } } }] return self._execute_command('SetIsp', body) def set_image_settings(self, brightness: float = 128, contrast: float = 62, hue: float = 1, saturation: float = 125, sharpness: float = 128) -> Dict: """ Sets the camera image settings. :param brightness: int :param contrast: string :param hue: int :param saturation: int :param sharpness: int :return: response """ body = [ { "cmd": "SetImage", "action": 0, "param": { "Image": { "bright": brightness, "channel": 0, "contrast": contrast, "hue": hue, "saturation": saturation, "sharpen": sharpness } } } ] return self._execute_command('SetImage', body) ================================================ FILE: reolinkapi/mixins/motion.py ================================================ from typing import Union, List, Dict from datetime import datetime as dt # Type hints for input and output of the motion api response RAW_MOTION_LIST_TYPE = List[Dict[str, Union[str, float, Dict[str, str]]]] PROCESSED_MOTION_LIST_TYPE = List[Dict[str, Union[str, dt]]] class MotionAPIMixin: """API calls for past motion alerts.""" def get_motion_files(self, start: dt, end: dt = dt.now(), streamtype: str = 'sub', channel = 0) -> PROCESSED_MOTION_LIST_TYPE: """ Get the timestamps and filenames of motion detection events for the time range provided. Args: start: the starting time range to examine end: the end time of the time range to examine streamtype: 'main' or 'sub' - the stream to examine :return: response json """ search_params = { 'Search': { 'channel': channel, 'streamType': streamtype, 'onlyStatus': 0, 'StartTime': { 'year': start.year, 'mon': start.month, 'day': start.day, 'hour': start.hour, 'min': start.minute, 'sec': start.second }, 'EndTime': { 'year': end.year, 'mon': end.month, 'day': end.day, 'hour': end.hour, 'min': end.minute, 'sec': end.second } } } body = [{"cmd": "Search", "action": 1, "param": search_params}] resp = self._execute_command('Search', body)[0] if 'value' not in resp: return [] values = resp['value'] if 'SearchResult' not in values: return [] result = values['SearchResult'] files = result.get('File', []) if len(files) > 0: # Begin processing files processed_files = self._process_motion_files(files) return processed_files return [] @staticmethod def _process_motion_files(motion_files: RAW_MOTION_LIST_TYPE) -> PROCESSED_MOTION_LIST_TYPE: """Processes raw list of dicts containing motion timestamps and the filename associated with them""" # Process files processed_motions = [] replace_fields = {'mon': 'month', 'sec': 'second', 'min': 'minute'} for file in motion_files: time_range = {} for x in ['Start', 'End']: # Get raw dict raw = file[f'{x}Time'] # Replace certain keys for k, v in replace_fields.items(): if k in raw.keys(): raw[v] = raw.pop(k) time_range[x.lower()] = dt(**raw) start, end = time_range.values() processed_motions.append({ 'start': start, 'end': end, 'filename': file['name'] }) return processed_motions ================================================ FILE: reolinkapi/mixins/network.py ================================================ from typing import Dict class NetworkAPIMixin: """API calls for network settings.""" def set_network_settings(self, ip: str, gateway: str, mask: str, dns1: str, dns2: str, mac: str, use_dhcp: bool = True, auto_dns: bool = True) -> Dict: """ Set network settings including IP, gateway, subnet mask, DNS, and connection type (DHCP or Static). :param ip: str :param gateway: str :param mask: str :param dns1: str :param dns2: str :param mac: str :param use_dhcp: bool :param auto_dns: bool :return: Dict """ body = [{"cmd": "SetLocalLink", "action": 0, "param": { "LocalLink": { "dns": { "auto": 1 if auto_dns else 0, "dns1": dns1, "dns2": dns2 }, "mac": mac, "static": { "gateway": gateway, "ip": ip, "mask": mask }, "type": "DHCP" if use_dhcp else "Static" } }}] return self._execute_command('SetLocalLink', body) print("Successfully Set Network Settings") return True def set_net_port(self, http_port: float = 80, https_port: float = 443, media_port: float = 9000, onvif_port: float = 8000, rtmp_port: float = 1935, rtsp_port: float = 554) -> bool: """ Set network ports If nothing is specified, the default values will be used :param rtsp_port: int :param rtmp_port: int :param onvif_port: int :param media_port: int :param https_port: int :type http_port: int :return: bool """ body = [{"cmd": "SetNetPort", "action": 0, "param": {"NetPort": { "httpPort": http_port, "httpsPort": https_port, "mediaPort": media_port, "onvifPort": onvif_port, "rtmpPort": rtmp_port, "rtspPort": rtsp_port }}}] self._execute_command('SetNetPort', body, multi=True) print("Successfully Set Network Ports") return True def set_wifi(self, ssid: str, password: str) -> Dict: body = [{"cmd": "SetWifi", "action": 0, "param": { "Wifi": { "ssid": ssid, "password": password }}}] return self._execute_command('SetWifi', body) def set_ntp(self, enable: bool = True, interval: int = 1440, port: int = 123, server: str = "pool.ntp.org") -> Dict: """ Set NTP settings. :param enable: bool :param interval: int :param port: int :param server: str :return: Dict """ body = [{"cmd": "SetNtp", "action": 0, "param": { "Ntp": { "enable": int(enable), "interval": interval, "port": port, "server": server }}}] response = self._execute_command('SetNtp', body) print("Successfully Set NTP Settings") return response def get_net_ports(self) -> Dict: """ Get network ports See examples/response/GetNetworkAdvanced.json for example response data. :return: response json """ body = [{"cmd": "GetNetPort", "action": 1, "param": {}}, {"cmd": "GetUpnp", "action": 0, "param": {}}, {"cmd": "GetP2p", "action": 0, "param": {}}] return self._execute_command('GetNetPort', body, multi=True) def get_wifi(self) -> Dict: body = [{"cmd": "GetWifi", "action": 1, "param": {}}] return self._execute_command('GetWifi', body) def scan_wifi(self) -> Dict: body = [{"cmd": "ScanWifi", "action": 1, "param": {}}] return self._execute_command('ScanWifi', body) def get_network_general(self) -> Dict: """ Get the camera information See examples/response/GetNetworkGeneral.json for example response data. :return: response json """ body = [{"cmd": "GetLocalLink", "action": 0, "param": {}}] return self._execute_command('GetLocalLink', body) def get_network_ddns(self) -> Dict: """ Get the camera DDNS network information See examples/response/GetNetworkDDNS.json for example response data. :return: response json """ body = [{"cmd": "GetDdns", "action": 0, "param": {}}] return self._execute_command('GetDdns', body) def get_network_ntp(self) -> Dict: """ Get the camera NTP network information See examples/response/GetNetworkNTP.json for example response data. :return: response json """ body = [{"cmd": "GetNtp", "action": 0, "param": {}}] return self._execute_command('GetNtp', body) def get_network_email(self) -> Dict: """ Get the camera email network information See examples/response/GetNetworkEmail.json for example response data. :return: response json """ body = [{"cmd": "GetEmail", "action": 0, "param": {}}] return self._execute_command('GetEmail', body) def get_network_ftp(self) -> Dict: """ Get the camera FTP network information See examples/response/GetNetworkFtp.json for example response data. :return: response json """ body = [{"cmd": "GetFtp", "action": 0, "param": {}}] return self._execute_command('GetFtp', body) def get_network_push(self) -> Dict: """ Get the camera push network information See examples/response/GetNetworkPush.json for example response data. :return: response json """ body = [{"cmd": "GetPush", "action": 0, "param": {}}] return self._execute_command('GetPush', body) def get_network_status(self) -> Dict: """ Get the camera status network information See examples/response/GetNetworkGeneral.json for example response data. :return: response json """ return self.get_network_general() ================================================ FILE: reolinkapi/mixins/nvrdownload.py ================================================ from datetime import datetime as dt class NvrDownloadAPIMixin: """API calls for NvrDownload.""" def get_playback_files(self, start: dt, end: dt = dt.now(), channel: int = 0, streamtype: str = 'sub'): """ Get the filenames of the videos for the time range provided. Args: start: the starting time range to examine end: the end time of the time range to examine channel: which channel to download from streamtype: 'main' or 'sub' - the stream to examine :return: response json """ search_params = { 'NvrDownload': { 'channel': channel, 'iLogicChannel': 0, 'streamType': streamtype, 'StartTime': { 'year': start.year, 'mon': start.month, 'day': start.day, 'hour': start.hour, 'min': start.minute, 'sec': start.second }, 'EndTime': { 'year': end.year, 'mon': end.month, 'day': end.day, 'hour': end.hour, 'min': end.minute, 'sec': end.second } } } body = [{"cmd": "NvrDownload", "action": 1, "param": search_params}] try: resp = self._execute_command('NvrDownload', body)[0] except Exception as e: print(f"Error: {e}") return [] if 'value' not in resp: return [] values = resp['value'] if 'fileList' not in values: return [] files = values['fileList'] if len(files) > 0: return [file['fileName'] for file in files] return [] ================================================ FILE: reolinkapi/mixins/ptz.py ================================================ from typing import Dict class PtzAPIMixin: """ API for PTZ functions. """ def get_ptz_check_state(self) -> Dict: """ Get PTZ Check State Information that indicates whether calibration is required (0) running (1) or done (2) Value is contained in response[0]["value"]["PtzCheckState"]. See examples/response/GetPtzCheckState.json for example response data. :return: response json """ body = [{"cmd": "GetPtzCheckState", "action": 1, "param": { "channel": 0}}] return self._execute_command('GetPtzCheckState', body) def get_ptz_presets(self) -> Dict: """ Get ptz presets See examples/response/GetPtzPresets.json for example response data. :return: response json """ body = [{"cmd": "GetPtzPreset", "action": 1, "param": { "channel": 0}}] return self._execute_command('GetPtzPreset', body) def perform_calibration(self) -> Dict: """ Do the calibration (like app -> ptz -> three dots -> calibration). Moves camera to all end positions. If not calibrated, your viewpoint of presets might drift. So before setting new presets, or moving to preset, check calibration status (get_ptz_check_state -> 2 = calibrated) and perform calibration if not yet calibrated. As of 2024-01-23 (most recent firmware 3.1.0.1711_23010700 for E1 Zoom) does not do this on startup. Method blocks while calibrating. See examples/response/PtzCheck.json for example response data. :return: response json """ data = [{"cmd": "PtzCheck", "action": 0, "param": {"channel": 0}}] return self._execute_command('PtzCheck', data) def _send_operation(self, operation: str, speed: float, index: float = None) -> Dict: # Refactored to reduce redundancy param = {"channel": 0, "op": operation, "speed": speed} if index is not None: param['id'] = index data = [{"cmd": "PtzCtrl", "action": 0, "param": param}] return self._execute_command('PtzCtrl', data) def _send_noparm_operation(self, operation: str) -> Dict: data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": operation}}] return self._execute_command('PtzCtrl', data) def _send_set_preset(self, enable: float, preset: float = 1, name: str = 'pos1') -> Dict: data = [{"cmd": "SetPtzPreset", "action": 0, "param": { "PtzPreset": { "channel": 0, "enable": enable, "id": preset, "name": name}}}] return self._execute_command('PtzCtrl', data) def go_to_preset(self, speed: float = 60, index: float = 1) -> Dict: """ Move the camera to a preset location :return: response json """ return self._send_operation('ToPos', speed=speed, index=index) def add_preset(self, preset: float = 1, name: str = 'pos1') -> Dict: """ Adds the current camera position to the specified preset. :return: response json """ return self._send_set_preset(enable=1, preset=preset, name=name) def remove_preset(self, preset: float = 1, name: str = 'pos1') -> Dict: """ Removes the specified preset :return: response json """ return self._send_set_preset(enable=0, preset=preset, name=name) def move_right(self, speed: float = 25) -> Dict: """ Move the camera to the right The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('Right', speed=speed) def move_right_up(self, speed: float = 25) -> Dict: """ Move the camera to the right and up The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('RightUp', speed=speed) def move_right_down(self, speed: float = 25) -> Dict: """ Move the camera to the right and down The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('RightDown', speed=speed) def move_left(self, speed: float = 25) -> Dict: """ Move the camera to the left The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('Left', speed=speed) def move_left_up(self, speed: float = 25) -> Dict: """ Move the camera to the left and up The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('LeftUp', speed=speed) def move_left_down(self, speed: float = 25) -> Dict: """ Move the camera to the left and down The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('LeftDown', speed=speed) def move_up(self, speed: float = 25) -> Dict: """ Move the camera up. The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('Up', speed=speed) def move_down(self, speed: float = 25) -> Dict: """ Move the camera down. The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('Down', speed=speed) def stop_ptz(self) -> Dict: """ Stops the cameras current action. :return: response json """ return self._send_noparm_operation('Stop') def auto_movement(self, speed: float = 25) -> Dict: """ Move the camera in a clockwise rotation. The camera moves self.stop_ptz() is called. :return: response json """ return self._send_operation('Auto', speed=speed) ================================================ FILE: reolinkapi/mixins/record.py ================================================ from typing import Dict class RecordAPIMixin: """API calls for the recording settings""" def get_recording_encoding(self) -> Dict: """ Get the current camera encoding settings for "Clear" and "Fluent" profiles. See examples/response/GetEnc.json for example response data. :return: response json """ body = [{"cmd": "GetEnc", "action": 1, "param": {"channel": 0}}] return self._execute_command('GetEnc', body) def get_recording_advanced(self) -> Dict: """ Get recording advanced setup data See examples/response/GetRec.json for example response data. :return: response json """ body = [{"cmd": "GetRec", "action": 1, "param": {"channel": 0}}] return self._execute_command('GetRec', body) def set_recording_encoding(self, audio: float = 0, main_bit_rate: float = 8192, main_frame_rate: float = 8, main_profile: str = 'High', main_size: str = "2560*1440", sub_bit_rate: float = 160, sub_frame_rate: float = 7, sub_profile: str = 'High', sub_size: str = '640*480') -> Dict: """ Sets the current camera encoding settings for "Clear" and "Fluent" profiles. :param audio: int Audio on or off :param main_bit_rate: int Clear Bit Rate :param main_frame_rate: int Clear Frame Rate :param main_profile: string Clear Profile :param main_size: string Clear Size :param sub_bit_rate: int Fluent Bit Rate :param sub_frame_rate: int Fluent Frame Rate :param sub_profile: string Fluent Profile :param sub_size: string Fluent Size :return: response """ body = [ { "cmd": "SetEnc", "action": 0, "param": { "Enc": { "audio": audio, "channel": 0, "mainStream": { "bitRate": main_bit_rate, "frameRate": main_frame_rate, "profile": main_profile, "size": main_size }, "subStream": { "bitRate": sub_bit_rate, "frameRate": sub_frame_rate, "profile": sub_profile, "size": sub_size } } } } ] return self._execute_command('SetEnc', body) ================================================ FILE: reolinkapi/mixins/stream.py ================================================ import string from random import choices from typing import Any, Optional from urllib import parse from io import BytesIO import requests try: from PIL.Image import Image, open as open_image from reolinkapi.utils.rtsp_client import RtspClient class StreamAPIMixin: """ API calls for opening a video stream or capturing an image from the camera.""" def open_video_stream(self, callback: Any = None, proxies: Any = None) -> Any: """ 'https://support.reolink.com/hc/en-us/articles/360007010473-How-to-Live-View-Reolink-Cameras-via-VLC-Media-Player' Blocking function creates a generator and returns the frames as it is spawned :param callback: :param proxies: Default is none, example: {"host": "localhost", "port": 8000} """ rtsp_client = RtspClient( ip=self.ip, username=self.username, password=self.password, profile=self.profile, proxies=proxies, callback=callback) return rtsp_client.open_stream() def get_snap(self, timeout: float = 3, proxies: Any = None) -> Optional[Image]: """ Gets a "snap" of the current camera video data and returns a Pillow Image or None :param timeout: Request timeout to camera in seconds :param proxies: http/https proxies to pass to the request object. :return: Image or None """ data = { 'cmd': 'Snap', 'channel': 0, 'rs': ''.join(choices(string.ascii_uppercase + string.digits, k=10)), 'user': self.username, 'password': self.password, } parms = parse.urlencode(data, safe="!").encode("utf-8") try: response = requests.get(self.url, proxies=proxies, params=parms, timeout=timeout) if response.status_code == 200: return open_image(BytesIO(response.content)) print("Could not retrieve data from camera successfully. Status:", response.status_code) return None except Exception as e: print("Could not get Image data\n", e) raise except ImportError as err: print("ImportError", err) class StreamAPIMixin: """ API calls for opening a video stream or capturing an image from the camera.""" def open_video_stream(self, callback: Any = None, proxies: Any = None) -> Any: raise ImportError(f'open_video_stream requires streaming extra dependencies\nFor instance "pip install ' f'reolinkapi[streaming]"') def get_snap(self, timeout: float = 3, proxies: Any = None) -> Optional['Image']: raise ImportError( f'get_snap requires streaming extra dependencies\nFor instance "pip install reolinkapi[streaming]"') ================================================ FILE: reolinkapi/mixins/system.py ================================================ from typing import Dict class SystemAPIMixin: """API for accessing general system information of the camera.""" def get_general_system(self) -> Dict: """:return: response json""" body = [{"cmd": "GetTime", "action": 1, "param": {}}, {"cmd": "GetNorm", "action": 1, "param": {}}] return self._execute_command('get_general_system', body, multi=True) def get_performance(self) -> Dict: """ Get a snapshot of the current performance of the camera. See examples/response/GetPerformance.json for example response data. :return: response json """ body = [{"cmd": "GetPerformance", "action": 0, "param": {}}] return self._execute_command('GetPerformance', body) def get_information(self) -> Dict: """ Get the camera information See examples/response/GetDevInfo.json for example response data. :return: response json """ body = [{"cmd": "GetDevInfo", "action": 0, "param": {}}] return self._execute_command('GetDevInfo', body) def reboot_camera(self) -> Dict: """ Reboots the camera :return: response json """ body = [{"cmd": "Reboot", "action": 0, "param": {}}] return self._execute_command('Reboot', body) def get_dst(self) -> Dict: """ Get the camera DST information See examples/response/GetDSTInfo.json for example response data. :return: response json """ body = [{"cmd": "GetTime", "action": 0, "param": {}}] return self._execute_command('GetTime', body) ================================================ FILE: reolinkapi/mixins/user.py ================================================ from typing import Dict class UserAPIMixin: """User-related API calls.""" def get_online_user(self) -> Dict: """ Return a list of current logged-in users in json format See examples/response/GetOnline.json for example response data. :return: response json """ body = [{"cmd": "GetOnline", "action": 1, "param": {}}] return self._execute_command('GetOnline', body) def get_users(self) -> Dict: """ Return a list of user accounts from the camera in json format. See examples/response/GetUser.json for example response data. :return: response json """ body = [{"cmd": "GetUser", "action": 1, "param": {}}] return self._execute_command('GetUser', body) def add_user(self, username: str, password: str, level: str = "guest") -> bool: """ Add a new user account to the camera :param username: The user's username :param password: The user's password :param level: The privilege level 'guest' or 'admin'. Default is 'guest' :return: whether the user was added successfully """ body = [{"cmd": "AddUser", "action": 0, "param": {"User": {"userName": username, "password": password, "level": level}}}] r_data = self._execute_command('AddUser', body)[0] if r_data["value"]["rspCode"] == 200: return True print("Could not add user. Camera responded with:", r_data["value"]) return False def modify_user(self, username: str, password: str) -> bool: """ Modify the user's password by specifying their username :param username: The user which would want to be modified :param password: The new password :return: whether the user was modified successfully """ body = [{"cmd": "ModifyUser", "action": 0, "param": {"User": {"userName": username, "password": password}}}] r_data = self._execute_command('ModifyUser', body)[0] if r_data["value"]["rspCode"] == 200: return True print(f"Could not modify user: {username}\nCamera responded with: {r_data['value']}") return False def delete_user(self, username: str) -> bool: """ Delete a user by specifying their username :param username: The user which would want to be deleted :return: whether the user was deleted successfully """ body = [{"cmd": "DelUser", "action": 0, "param": {"User": {"userName": username}}}] r_data = self._execute_command('DelUser', body)[0] if r_data["value"]["rspCode"] == 200: return True print(f"Could not delete user: {username}\nCamera responded with: {r_data['value']}") return False ================================================ FILE: reolinkapi/mixins/zoom.py ================================================ from typing import Dict class ZoomAPIMixin: """ API for zooming and changing focus. Note that the API does not allow zooming/focusing by absolute values rather that changing focus/zoom for a given time. """ def _start_operation(self, operation: str, speed: float) -> Dict: data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": operation, "speed": speed}}] return self._execute_command('PtzCtrl', data) def _stop_zooming_or_focusing(self) -> Dict: """This command stops any ongoing zooming or focusing actions.""" data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": "Stop"}}] return self._execute_command('PtzCtrl', data) def get_zoom_focus(self) -> Dict: """This command returns the current zoom and focus values.""" data = [{"cmd": "GetZoomFocus", "action": 0, "param": {"channel": 0}}] return self._execute_command('GetZoomFocus', data) def start_zoom_pos(self, position: float) -> Dict: """This command sets the zoom position.""" data = [{"cmd": "StartZoomFocus", "action": 0, "param": {"ZoomFocus": {"channel": 0, "op": "ZoomPos", "pos": position}}}] return self._execute_command('StartZoomFocus', data) def start_focus_pos(self, position: float) -> Dict: """This command sets the focus position.""" data = [{"cmd": "StartZoomFocus", "action": 0, "param": {"ZoomFocus": {"channel": 0, "op": "FocusPos", "pos": position}}}] return self._execute_command('StartZoomFocus', data) def get_auto_focus(self) -> Dict: """This command returns the current auto focus status.""" data = [{"cmd": "GetAutoFocus", "action": 0, "param": {"channel": 0}}] return self._execute_command('GetAutoFocus', data) def set_auto_focus(self, disable: bool) -> Dict: """This command sets the auto focus status.""" data = [{"cmd": "SetAutoFocus", "action": 0, "param": {"AutoFocus": {"channel": 0, "disable": 1 if disable else 0}}}] return self._execute_command('SetAutoFocus', data) def start_zooming_in(self, speed: float = 60) -> Dict: """ The camera zooms in until self.stop_zooming() is called. :return: response json """ return self._start_operation('ZoomInc', speed=speed) def start_zooming_out(self, speed: float = 60) -> Dict: """ The camera zooms out until self.stop_zooming() is called. :return: response json """ return self._start_operation('ZoomDec', speed=speed) def stop_zooming(self) -> Dict: """ Stop zooming. :return: response json """ return self._stop_zooming_or_focusing() def start_focusing_in(self, speed: float = 32) -> Dict: """ The camera focuses in until self.stop_focusing() is called. :return: response json """ return self._start_operation('FocusInc', speed=speed) def start_focusing_out(self, speed: float = 32) -> Dict: """ The camera focuses out until self.stop_focusing() is called. :return: response json """ return self._start_operation('FocusDec', speed=speed) def stop_focusing(self) -> Dict: """ Stop focusing. :return: response json """ return self._stop_zooming_or_focusing() ================================================ FILE: reolinkapi/utils/__init__.py ================================================ ================================================ FILE: reolinkapi/utils/rtsp_client.py ================================================ import os from threading import ThreadError from typing import Any import cv2 from reolinkapi.utils.util import threaded class RtspClient: """ This is a wrapper of the OpenCV VideoCapture method Inspiration from: - https://benhowell.github.io/guide/2015/03/09/opencv-and-web-cam-streaming - https://stackoverflow.com/questions/19846332/python-threading-inside-a-class - https://stackoverflow.com/questions/55828451/video-streaming-from-ip-camera-in-python-using-opencv-cv2-videocapture """ def __init__(self, ip: str, username: str, password: str, port: float = 554, profile: str = "main", use_udp: bool = True, callback: Any = None, **kwargs): """ RTSP client is used to retrieve frames from the camera in a stream :param ip: Camera IP :param username: Camera Username :param password: Camera User Password :param port: RTSP port :param profile: "main" or "sub" :param use_upd: True to use UDP, False to use TCP :param proxies: {"host": "localhost", "port": 8000} """ self.capture = None self.thread_cancelled = False self.callback = callback capture_options = 'rtsp_transport;' self.ip = ip self.username = username self.password = password self.port = port self.proxy = kwargs.get("proxies") self.url = f'rtsp://{self.username}:{self.password}@{self.ip}:{self.port}//h264Preview_01_{profile}' capture_options += 'udp' if use_udp else 'tcp' os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = capture_options # opens the stream capture, but does not retrieve any frames yet. self._open_video_capture() def _open_video_capture(self): # To CAP_FFMPEG or not To ? self.capture = cv2.VideoCapture(self.url, cv2.CAP_FFMPEG) def _stream_blocking(self): while True: try: if self.capture.isOpened(): ret, frame = self.capture.read() if ret: yield frame else: print("stream closed") self.capture.release() return except Exception as e: print(e) self.capture.release() return @threaded def _stream_non_blocking(self): while not self.thread_cancelled: try: if self.capture.isOpened(): ret, frame = self.capture.read() if ret: self.callback(frame) else: print("stream is closed") self.stop_stream() except ThreadError as e: print(e) self.stop_stream() def stop_stream(self): self.capture.release() self.thread_cancelled = True def open_stream(self): """ Opens OpenCV Video stream and returns the result according to the OpenCV documentation https://docs.opencv.org/3.4/d8/dfe/classcv_1_1VideoCapture.html#a473055e77dd7faa4d26d686226b292c1 """ # Reset the capture object if self.capture is None or not self.capture.isOpened(): self._open_video_capture() print("opening stream") if self.callback is None: return self._stream_blocking() else: # reset the thread status if the object was not re-created if not self.thread_cancelled: self.thread_cancelled = False return self._stream_non_blocking() ================================================ FILE: reolinkapi/utils/util.py ================================================ from threading import Thread def threaded(fn): def wrapper(*args, **kwargs): thread = Thread(target=fn, args=args, kwargs=kwargs) thread.daemon = True thread.start() return thread return wrapper ================================================ FILE: requirements.txt ================================================ . ================================================ FILE: setup.py ================================================ #!/usr/bin/python3 import os import re import codecs from setuptools import setup, find_packages def read(*parts): with codecs.open(os.path.join(here, *parts), 'r') as fp: return fp.read() def find_version(*file_paths): version_file = read(*file_paths) version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) if version_match: return version_match.group(1) raise RuntimeError("Unable to find version string.") # Package meta-data. NAME = 'reolinkapi' DESCRIPTION = 'Reolink Camera API client written in Python 3' URL = 'https://github.com/ReolinkCameraAPI/reolinkapipy' AUTHOR_EMAIL = 'alanoterblanche@gmail.com' AUTHOR = 'Benehiko' LICENSE = 'GPL-3.0' INSTALL_REQUIRES = [ 'setuptools', 'PySocks==1.7.1', 'PyYaml==6.0.2', 'requests>=2.32.3', ] EXTRAS_REQUIRE = { 'streaming': [ 'numpy==2.0.1', 'opencv-python==4.10.0.84', 'Pillow==10.4.0', ], } here = os.path.abspath(os.path.dirname(__file__)) # read the contents of your README file with open(os.path.join(here, 'README.md'), encoding='utf-8') as f: long_description = f.read() setup( name=NAME, python_requires='>=3.12.4', version=find_version('reolinkapi', '__init__.py'), description=DESCRIPTION, long_description=long_description, long_description_content_type='text/markdown', author=AUTHOR, author_email=AUTHOR_EMAIL, url=URL, license=LICENSE, install_requires=INSTALL_REQUIRES, packages=find_packages(exclude=['examples', 'tests']), extras_require=EXTRAS_REQUIRE ) ================================================ FILE: tests/test_camera.py ================================================ import os from configparser import RawConfigParser import unittest from reolinkapi import Camera def read_config(props_path: str) -> dict: """Reads in a properties file into variables. NB! this config file is kept out of commits with .gitignore. The structure of this file is such: # secrets.cfg [camera] ip={ip_address} username={username} password={password} """ config = RawConfigParser() assert os.path.exists(props_path), f"Path does not exist: {props_path}" config.read(props_path) return config class TestCamera(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.config = read_config('../secrets.cfg') def setUp(self) -> None: self.cam = Camera(self.config.get('camera', 'ip'), self.config.get('camera', 'username'), self.config.get('camera', 'password')) def test_camera(self): """Test that camera connects and gets a token""" self.assertTrue(self.cam.ip == self.config.get('camera', 'ip')) self.assertTrue(self.cam.token != '') def test_snapshot(self): img = self.cam.get_snap() # write Pillow Image to file img.save('./tmp/snaps/camera.jpg') self.assertTrue(os.path.exists('./tmp/snaps/camera.jpg')) if __name__ == '__main__': unittest.main()