├── .github └── workflows │ └── pythonpackage.yml ├── .gitignore ├── CONTRIBUTORS.md ├── LICENSE ├── MANIFEST.in ├── Pipfile ├── Pipfile.lock ├── README.rst ├── roku ├── __init__.py ├── core.py ├── discovery.py ├── emulator │ ├── __init__.py │ └── core.py ├── proxy.py ├── scripting.py ├── server.py ├── tests │ ├── __init__.py │ ├── conftest.py │ ├── responses │ │ ├── device-info.xml │ │ └── media-player.xml │ ├── scripts │ │ └── testscript.txt │ ├── test_roku.py │ └── test_scripting.py └── util.py └── setup.py /.github/workflows/pythonpackage.yml: -------------------------------------------------------------------------------- 1 | name: Python package 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | strategy: 10 | max-parallel: 4 11 | matrix: 12 | python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] 13 | 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up Python ${{ matrix.python-version }} 17 | uses: actions/setup-python@v4 18 | with: 19 | python-version: ${{ matrix.python-version }} 20 | - name: Install dependencies 21 | run: | 22 | python -m pip install --upgrade pip 23 | pip install pipenv 24 | pipenv install --dev --python `which python3` 25 | - name: Lint with flake8 26 | run: | 27 | # stop the build if there are Python syntax errors or undefined names 28 | pipenv run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 29 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 30 | pipenv run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 31 | - name: Test with pytest 32 | run: | 33 | pipenv run pytest 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | .DS_Store 3 | .env 4 | .cache/ 5 | .tox/ 6 | dist/ 7 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | These very nice people have helped create python-roku. 2 | 3 | * [jcarbaugh](https://github.com/jcarbaugh) 4 | * [bah2830](https://github.com/bah2830) - added support for currently running app 5 | * [ncmiller](https://github.com/ncmiller) - added device info endpoint 6 | * [dbehnke](https://github.com/dbehnke) - initial Python 3 support 7 | * [DavidCDean](https://github.com/DavidCDean) - bug fix 8 | * [alberthdev](https://github.com/alberthdev) - lowercase and symbol support for literals 9 | * [nharada1](https://github.com/nharada1) - active app property 10 | * [segadude](https://github.com/segadude) and [wilsoc5](https://github.com/wilsoc5) - volume key support 11 | * [bschlenk](https://github.com/bschlenk) - Roku TV commands 12 | * [keatontaylor](https://github.com/keatontaylor) - Enhanced Serach 13 | * [frdfsnlght](https://github.com/frdfsnlght) - fix lxml import 14 | * [bwarden](https://github.com/bwarden) - PowerOn command 15 | * [springstan](https://github.com/springstan) - fix for successful status codes 16 | * [zombielinux](https://github.com/zombielinux) - added support for hostnames 17 | * [kk7ds](https://github.com/kk7ds) - support for media-player query 18 | * [kyesh](https://github.com/kyesh) - added support for keyup and keydown 19 | * [ronnie-llamado](https://github.com/ronnie-llamado) - f-string conversion, better dir 20 | * [ctalkington](https://github.com/ctalkington) - added icon url 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023, Jeremy Carbaugh 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of python-roku nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | include requirements.txt -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | black = "*" 8 | flake8 = "<6" 9 | importlib-metadata = "*" 10 | pytest = "*" 11 | pytest-mock = "*" 12 | twine = "*" 13 | 14 | [packages] 15 | requests = "<3" 16 | typing-extensions = "*" 17 | exceptiongroup = "*" 18 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "4192b8d2773e176da7f63d924c559205c8f41816230c0ff084f7ac5e06afeb44" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": {}, 8 | "sources": [ 9 | { 10 | "name": "pypi", 11 | "url": "https://pypi.org/simple", 12 | "verify_ssl": true 13 | } 14 | ] 15 | }, 16 | "default": { 17 | "certifi": { 18 | "hashes": [ 19 | "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3", 20 | "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18" 21 | ], 22 | "markers": "python_version >= '3.6'", 23 | "version": "==2022.12.7" 24 | }, 25 | "charset-normalizer": { 26 | "hashes": [ 27 | "sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6", 28 | "sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1", 29 | "sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e", 30 | "sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373", 31 | "sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62", 32 | "sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230", 33 | "sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be", 34 | "sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c", 35 | "sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0", 36 | "sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448", 37 | "sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f", 38 | "sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649", 39 | "sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d", 40 | "sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0", 41 | "sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706", 42 | "sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a", 43 | "sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59", 44 | "sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23", 45 | "sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5", 46 | "sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb", 47 | "sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e", 48 | "sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e", 49 | "sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c", 50 | "sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28", 51 | "sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d", 52 | "sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41", 53 | "sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974", 54 | "sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce", 55 | "sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f", 56 | "sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1", 57 | "sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d", 58 | "sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8", 59 | "sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017", 60 | "sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31", 61 | "sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7", 62 | "sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8", 63 | "sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e", 64 | "sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14", 65 | "sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd", 66 | "sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d", 67 | "sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795", 68 | "sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b", 69 | "sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b", 70 | "sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b", 71 | "sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203", 72 | "sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f", 73 | "sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19", 74 | "sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1", 75 | "sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a", 76 | "sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac", 77 | "sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9", 78 | "sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0", 79 | "sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137", 80 | "sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f", 81 | "sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6", 82 | "sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5", 83 | "sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909", 84 | "sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f", 85 | "sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0", 86 | "sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324", 87 | "sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755", 88 | "sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb", 89 | "sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854", 90 | "sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c", 91 | "sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60", 92 | "sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84", 93 | "sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0", 94 | "sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b", 95 | "sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1", 96 | "sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531", 97 | "sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1", 98 | "sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11", 99 | "sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326", 100 | "sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df", 101 | "sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab" 102 | ], 103 | "markers": "python_full_version >= '3.7.0'", 104 | "version": "==3.1.0" 105 | }, 106 | "exceptiongroup": { 107 | "hashes": [ 108 | "sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e", 109 | "sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785" 110 | ], 111 | "index": "pypi", 112 | "version": "==1.1.1" 113 | }, 114 | "idna": { 115 | "hashes": [ 116 | "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4", 117 | "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2" 118 | ], 119 | "markers": "python_version >= '3.5'", 120 | "version": "==3.4" 121 | }, 122 | "requests": { 123 | "hashes": [ 124 | "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa", 125 | "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf" 126 | ], 127 | "index": "pypi", 128 | "version": "==2.28.2" 129 | }, 130 | "typing-extensions": { 131 | "hashes": [ 132 | "sha256:5cb5f4a79139d699607b3ef622a1dedafa84e115ab0024e0d9c044a9479ca7cb", 133 | "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4" 134 | ], 135 | "index": "pypi", 136 | "version": "==4.5.0" 137 | }, 138 | "urllib3": { 139 | "hashes": [ 140 | "sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305", 141 | "sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42" 142 | ], 143 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", 144 | "version": "==1.26.15" 145 | } 146 | }, 147 | "develop": { 148 | "black": { 149 | "hashes": [ 150 | "sha256:064101748afa12ad2291c2b91c960be28b817c0c7eaa35bec09cc63aa56493c5", 151 | "sha256:0945e13506be58bf7db93ee5853243eb368ace1c08a24c65ce108986eac65915", 152 | "sha256:11c410f71b876f961d1de77b9699ad19f939094c3a677323f43d7a29855fe326", 153 | "sha256:1c7b8d606e728a41ea1ccbd7264677e494e87cf630e399262ced92d4a8dac940", 154 | "sha256:1d06691f1eb8de91cd1b322f21e3bfc9efe0c7ca1f0e1eb1db44ea367dff656b", 155 | "sha256:3238f2aacf827d18d26db07524e44741233ae09a584273aa059066d644ca7b30", 156 | "sha256:32daa9783106c28815d05b724238e30718f34155653d4d6e125dc7daec8e260c", 157 | "sha256:35d1381d7a22cc5b2be2f72c7dfdae4072a3336060635718cc7e1ede24221d6c", 158 | "sha256:3a150542a204124ed00683f0db1f5cf1c2aaaa9cc3495b7a3b5976fb136090ab", 159 | "sha256:48f9d345675bb7fbc3dd85821b12487e1b9a75242028adad0333ce36ed2a6d27", 160 | "sha256:50cb33cac881766a5cd9913e10ff75b1e8eb71babf4c7104f2e9c52da1fb7de2", 161 | "sha256:562bd3a70495facf56814293149e51aa1be9931567474993c7942ff7d3533961", 162 | "sha256:67de8d0c209eb5b330cce2469503de11bca4085880d62f1628bd9972cc3366b9", 163 | "sha256:6b39abdfb402002b8a7d030ccc85cf5afff64ee90fa4c5aebc531e3ad0175ddb", 164 | "sha256:6f3c333ea1dd6771b2d3777482429864f8e258899f6ff05826c3a4fcc5ce3f70", 165 | "sha256:714290490c18fb0126baa0fca0a54ee795f7502b44177e1ce7624ba1c00f2331", 166 | "sha256:7c3eb7cea23904399866c55826b31c1f55bbcd3890ce22ff70466b907b6775c2", 167 | "sha256:92c543f6854c28a3c7f39f4d9b7694f9a6eb9d3c5e2ece488c327b6e7ea9b266", 168 | "sha256:a6f6886c9869d4daae2d1715ce34a19bbc4b95006d20ed785ca00fa03cba312d", 169 | "sha256:a8a968125d0a6a404842fa1bf0b349a568634f856aa08ffaff40ae0dfa52e7c6", 170 | "sha256:c7ab5790333c448903c4b721b59c0d80b11fe5e9803d8703e84dcb8da56fec1b", 171 | "sha256:e114420bf26b90d4b9daa597351337762b63039752bdf72bf361364c1aa05925", 172 | "sha256:e198cf27888ad6f4ff331ca1c48ffc038848ea9f031a3b40ba36aced7e22f2c8", 173 | "sha256:ec751418022185b0c1bb7d7736e6933d40bbb14c14a0abcf9123d1b159f98dd4", 174 | "sha256:f0bd2f4a58d6666500542b26354978218a9babcdc972722f4bf90779524515f3" 175 | ], 176 | "index": "pypi", 177 | "version": "==23.3.0" 178 | }, 179 | "bleach": { 180 | "hashes": [ 181 | "sha256:1a1a85c1595e07d8db14c5f09f09e6433502c51c595970edc090551f0db99414", 182 | "sha256:33c16e3353dbd13028ab4799a0f89a83f113405c766e9c122df8a06f5b85b3f4" 183 | ], 184 | "markers": "python_version >= '3.7'", 185 | "version": "==6.0.0" 186 | }, 187 | "certifi": { 188 | "hashes": [ 189 | "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3", 190 | "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18" 191 | ], 192 | "markers": "python_version >= '3.6'", 193 | "version": "==2022.12.7" 194 | }, 195 | "charset-normalizer": { 196 | "hashes": [ 197 | "sha256:04afa6387e2b282cf78ff3dbce20f0cc071c12dc8f685bd40960cc68644cfea6", 198 | "sha256:04eefcee095f58eaabe6dc3cc2262f3bcd776d2c67005880894f447b3f2cb9c1", 199 | "sha256:0be65ccf618c1e7ac9b849c315cc2e8a8751d9cfdaa43027d4f6624bd587ab7e", 200 | "sha256:0c95f12b74681e9ae127728f7e5409cbbef9cd914d5896ef238cc779b8152373", 201 | "sha256:0ca564606d2caafb0abe6d1b5311c2649e8071eb241b2d64e75a0d0065107e62", 202 | "sha256:10c93628d7497c81686e8e5e557aafa78f230cd9e77dd0c40032ef90c18f2230", 203 | "sha256:11d117e6c63e8f495412d37e7dc2e2fff09c34b2d09dbe2bee3c6229577818be", 204 | "sha256:11d3bcb7be35e7b1bba2c23beedac81ee893ac9871d0ba79effc7fc01167db6c", 205 | "sha256:12a2b561af122e3d94cdb97fe6fb2bb2b82cef0cdca131646fdb940a1eda04f0", 206 | "sha256:12d1a39aa6b8c6f6248bb54550efcc1c38ce0d8096a146638fd4738e42284448", 207 | "sha256:1435ae15108b1cb6fffbcea2af3d468683b7afed0169ad718451f8db5d1aff6f", 208 | "sha256:1c60b9c202d00052183c9be85e5eaf18a4ada0a47d188a83c8f5c5b23252f649", 209 | "sha256:1e8fcdd8f672a1c4fc8d0bd3a2b576b152d2a349782d1eb0f6b8e52e9954731d", 210 | "sha256:20064ead0717cf9a73a6d1e779b23d149b53daf971169289ed2ed43a71e8d3b0", 211 | "sha256:21fa558996782fc226b529fdd2ed7866c2c6ec91cee82735c98a197fae39f706", 212 | "sha256:22908891a380d50738e1f978667536f6c6b526a2064156203d418f4856d6e86a", 213 | "sha256:3160a0fd9754aab7d47f95a6b63ab355388d890163eb03b2d2b87ab0a30cfa59", 214 | "sha256:322102cdf1ab682ecc7d9b1c5eed4ec59657a65e1c146a0da342b78f4112db23", 215 | "sha256:34e0a2f9c370eb95597aae63bf85eb5e96826d81e3dcf88b8886012906f509b5", 216 | "sha256:3573d376454d956553c356df45bb824262c397c6e26ce43e8203c4c540ee0acb", 217 | "sha256:3747443b6a904001473370d7810aa19c3a180ccd52a7157aacc264a5ac79265e", 218 | "sha256:38e812a197bf8e71a59fe55b757a84c1f946d0ac114acafaafaf21667a7e169e", 219 | "sha256:3a06f32c9634a8705f4ca9946d667609f52cf130d5548881401f1eb2c39b1e2c", 220 | "sha256:3a5fc78f9e3f501a1614a98f7c54d3969f3ad9bba8ba3d9b438c3bc5d047dd28", 221 | "sha256:3d9098b479e78c85080c98e1e35ff40b4a31d8953102bb0fd7d1b6f8a2111a3d", 222 | "sha256:3dc5b6a8ecfdc5748a7e429782598e4f17ef378e3e272eeb1340ea57c9109f41", 223 | "sha256:4155b51ae05ed47199dc5b2a4e62abccb274cee6b01da5b895099b61b1982974", 224 | "sha256:49919f8400b5e49e961f320c735388ee686a62327e773fa5b3ce6721f7e785ce", 225 | "sha256:53d0a3fa5f8af98a1e261de6a3943ca631c526635eb5817a87a59d9a57ebf48f", 226 | "sha256:5f008525e02908b20e04707a4f704cd286d94718f48bb33edddc7d7b584dddc1", 227 | "sha256:628c985afb2c7d27a4800bfb609e03985aaecb42f955049957814e0491d4006d", 228 | "sha256:65ed923f84a6844de5fd29726b888e58c62820e0769b76565480e1fdc3d062f8", 229 | "sha256:6734e606355834f13445b6adc38b53c0fd45f1a56a9ba06c2058f86893ae8017", 230 | "sha256:6baf0baf0d5d265fa7944feb9f7451cc316bfe30e8df1a61b1bb08577c554f31", 231 | "sha256:6f4f4668e1831850ebcc2fd0b1cd11721947b6dc7c00bf1c6bd3c929ae14f2c7", 232 | "sha256:6f5c2e7bc8a4bf7c426599765b1bd33217ec84023033672c1e9a8b35eaeaaaf8", 233 | "sha256:6f6c7a8a57e9405cad7485f4c9d3172ae486cfef1344b5ddd8e5239582d7355e", 234 | "sha256:7381c66e0561c5757ffe616af869b916c8b4e42b367ab29fedc98481d1e74e14", 235 | "sha256:73dc03a6a7e30b7edc5b01b601e53e7fc924b04e1835e8e407c12c037e81adbd", 236 | "sha256:74db0052d985cf37fa111828d0dd230776ac99c740e1a758ad99094be4f1803d", 237 | "sha256:75f2568b4189dda1c567339b48cba4ac7384accb9c2a7ed655cd86b04055c795", 238 | "sha256:78cacd03e79d009d95635e7d6ff12c21eb89b894c354bd2b2ed0b4763373693b", 239 | "sha256:80d1543d58bd3d6c271b66abf454d437a438dff01c3e62fdbcd68f2a11310d4b", 240 | "sha256:830d2948a5ec37c386d3170c483063798d7879037492540f10a475e3fd6f244b", 241 | "sha256:891cf9b48776b5c61c700b55a598621fdb7b1e301a550365571e9624f270c203", 242 | "sha256:8f25e17ab3039b05f762b0a55ae0b3632b2e073d9c8fc88e89aca31a6198e88f", 243 | "sha256:9a3267620866c9d17b959a84dd0bd2d45719b817245e49371ead79ed4f710d19", 244 | "sha256:a04f86f41a8916fe45ac5024ec477f41f886b3c435da2d4e3d2709b22ab02af1", 245 | "sha256:aaf53a6cebad0eae578f062c7d462155eada9c172bd8c4d250b8c1d8eb7f916a", 246 | "sha256:abc1185d79f47c0a7aaf7e2412a0eb2c03b724581139193d2d82b3ad8cbb00ac", 247 | "sha256:ac0aa6cd53ab9a31d397f8303f92c42f534693528fafbdb997c82bae6e477ad9", 248 | "sha256:ac3775e3311661d4adace3697a52ac0bab17edd166087d493b52d4f4f553f9f0", 249 | "sha256:b06f0d3bf045158d2fb8837c5785fe9ff9b8c93358be64461a1089f5da983137", 250 | "sha256:b116502087ce8a6b7a5f1814568ccbd0e9f6cfd99948aa59b0e241dc57cf739f", 251 | "sha256:b82fab78e0b1329e183a65260581de4375f619167478dddab510c6c6fb04d9b6", 252 | "sha256:bd7163182133c0c7701b25e604cf1611c0d87712e56e88e7ee5d72deab3e76b5", 253 | "sha256:c36bcbc0d5174a80d6cccf43a0ecaca44e81d25be4b7f90f0ed7bcfbb5a00909", 254 | "sha256:c3af8e0f07399d3176b179f2e2634c3ce9c1301379a6b8c9c9aeecd481da494f", 255 | "sha256:c84132a54c750fda57729d1e2599bb598f5fa0344085dbde5003ba429a4798c0", 256 | "sha256:cb7b2ab0188829593b9de646545175547a70d9a6e2b63bf2cd87a0a391599324", 257 | "sha256:cca4def576f47a09a943666b8f829606bcb17e2bc2d5911a46c8f8da45f56755", 258 | "sha256:cf6511efa4801b9b38dc5546d7547d5b5c6ef4b081c60b23e4d941d0eba9cbeb", 259 | "sha256:d16fd5252f883eb074ca55cb622bc0bee49b979ae4e8639fff6ca3ff44f9f854", 260 | "sha256:d2686f91611f9e17f4548dbf050e75b079bbc2a82be565832bc8ea9047b61c8c", 261 | "sha256:d7fc3fca01da18fbabe4625d64bb612b533533ed10045a2ac3dd194bfa656b60", 262 | "sha256:dd5653e67b149503c68c4018bf07e42eeed6b4e956b24c00ccdf93ac79cdff84", 263 | "sha256:de5695a6f1d8340b12a5d6d4484290ee74d61e467c39ff03b39e30df62cf83a0", 264 | "sha256:e0ac8959c929593fee38da1c2b64ee9778733cdf03c482c9ff1d508b6b593b2b", 265 | "sha256:e1b25e3ad6c909f398df8921780d6a3d120d8c09466720226fc621605b6f92b1", 266 | "sha256:e633940f28c1e913615fd624fcdd72fdba807bf53ea6925d6a588e84e1151531", 267 | "sha256:e89df2958e5159b811af9ff0f92614dabf4ff617c03a4c1c6ff53bf1c399e0e1", 268 | "sha256:ea9f9c6034ea2d93d9147818f17c2a0860d41b71c38b9ce4d55f21b6f9165a11", 269 | "sha256:f645caaf0008bacf349875a974220f1f1da349c5dbe7c4ec93048cdc785a3326", 270 | "sha256:f8303414c7b03f794347ad062c0516cee0e15f7a612abd0ce1e25caf6ceb47df", 271 | "sha256:fca62a8301b605b954ad2e9c3666f9d97f63872aa4efcae5492baca2056b74ab" 272 | ], 273 | "markers": "python_full_version >= '3.7.0'", 274 | "version": "==3.1.0" 275 | }, 276 | "click": { 277 | "hashes": [ 278 | "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e", 279 | "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48" 280 | ], 281 | "markers": "python_version >= '3.7'", 282 | "version": "==8.1.3" 283 | }, 284 | "docutils": { 285 | "hashes": [ 286 | "sha256:33995a6753c30b7f577febfc2c50411fec6aac7f7ffeb7c4cfe5991072dcf9e6", 287 | "sha256:5e1de4d849fee02c63b040a4a3fd567f4ab104defd8a5511fbbc24a8a017efbc" 288 | ], 289 | "markers": "python_version >= '3.7'", 290 | "version": "==0.19" 291 | }, 292 | "flake8": { 293 | "hashes": [ 294 | "sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db", 295 | "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248" 296 | ], 297 | "index": "pypi", 298 | "version": "==5.0.4" 299 | }, 300 | "idna": { 301 | "hashes": [ 302 | "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4", 303 | "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2" 304 | ], 305 | "markers": "python_version >= '3.5'", 306 | "version": "==3.4" 307 | }, 308 | "importlib-metadata": { 309 | "hashes": [ 310 | "sha256:03ba783c3a2c69d751b109fc0c94a62c51f581b3d6acf8ed1331b6d5729321ff", 311 | "sha256:7a8bdf1bc3a726297f5cfbc999e6e7ff6b4fa41b26bba4afc580448624460045" 312 | ], 313 | "index": "pypi", 314 | "version": "==6.5.0" 315 | }, 316 | "iniconfig": { 317 | "hashes": [ 318 | "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", 319 | "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374" 320 | ], 321 | "markers": "python_version >= '3.7'", 322 | "version": "==2.0.0" 323 | }, 324 | "jaraco.classes": { 325 | "hashes": [ 326 | "sha256:2353de3288bc6b82120752201c6b1c1a14b058267fa424ed5ce5984e3b922158", 327 | "sha256:89559fa5c1d3c34eff6f631ad80bb21f378dbcbb35dd161fd2c6b93f5be2f98a" 328 | ], 329 | "markers": "python_version >= '3.7'", 330 | "version": "==3.2.3" 331 | }, 332 | "keyring": { 333 | "hashes": [ 334 | "sha256:771ed2a91909389ed6148631de678f82ddc73737d85a927f382a8a1b157898cd", 335 | "sha256:ba2e15a9b35e21908d0aaf4e0a47acc52d6ae33444df0da2b49d41a46ef6d678" 336 | ], 337 | "markers": "python_version >= '3.7'", 338 | "version": "==23.13.1" 339 | }, 340 | "markdown-it-py": { 341 | "hashes": [ 342 | "sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30", 343 | "sha256:7c9a5e412688bc771c67432cbfebcdd686c93ce6484913dccf06cb5a0bea35a1" 344 | ], 345 | "markers": "python_version >= '3.7'", 346 | "version": "==2.2.0" 347 | }, 348 | "mccabe": { 349 | "hashes": [ 350 | "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", 351 | "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e" 352 | ], 353 | "markers": "python_version >= '3.6'", 354 | "version": "==0.7.0" 355 | }, 356 | "mdurl": { 357 | "hashes": [ 358 | "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", 359 | "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba" 360 | ], 361 | "markers": "python_version >= '3.7'", 362 | "version": "==0.1.2" 363 | }, 364 | "more-itertools": { 365 | "hashes": [ 366 | "sha256:cabaa341ad0389ea83c17a94566a53ae4c9d07349861ecb14dc6d0345cf9ac5d", 367 | "sha256:d2bc7f02446e86a68911e58ded76d6561eea00cddfb2a91e7019bbb586c799f3" 368 | ], 369 | "markers": "python_version >= '3.7'", 370 | "version": "==9.1.0" 371 | }, 372 | "mypy-extensions": { 373 | "hashes": [ 374 | "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", 375 | "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782" 376 | ], 377 | "markers": "python_version >= '3.5'", 378 | "version": "==1.0.0" 379 | }, 380 | "packaging": { 381 | "hashes": [ 382 | "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61", 383 | "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f" 384 | ], 385 | "markers": "python_version >= '3.7'", 386 | "version": "==23.1" 387 | }, 388 | "pathspec": { 389 | "hashes": [ 390 | "sha256:2798de800fa92780e33acca925945e9a19a133b715067cf165b8866c15a31687", 391 | "sha256:d8af70af76652554bd134c22b3e8a1cc46ed7d91edcdd721ef1a0c51a84a5293" 392 | ], 393 | "markers": "python_version >= '3.7'", 394 | "version": "==0.11.1" 395 | }, 396 | "pkginfo": { 397 | "hashes": [ 398 | "sha256:4b7a555a6d5a22169fcc9cf7bfd78d296b0361adad412a346c1226849af5e546", 399 | "sha256:8fd5896e8718a4372f0ea9cc9d96f6417c9b986e23a4d116dda26b62cc29d046" 400 | ], 401 | "markers": "python_version >= '3.6'", 402 | "version": "==1.9.6" 403 | }, 404 | "platformdirs": { 405 | "hashes": [ 406 | "sha256:d5b638ca397f25f979350ff789db335903d7ea010ab28903f57b27e1b16c2b08", 407 | "sha256:ebe11c0d7a805086e99506aa331612429a72ca7cd52a1f0d277dc4adc20cb10e" 408 | ], 409 | "markers": "python_version >= '3.7'", 410 | "version": "==3.2.0" 411 | }, 412 | "pluggy": { 413 | "hashes": [ 414 | "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", 415 | "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3" 416 | ], 417 | "markers": "python_version >= '3.6'", 418 | "version": "==1.0.0" 419 | }, 420 | "pycodestyle": { 421 | "hashes": [ 422 | "sha256:2c9607871d58c76354b697b42f5d57e1ada7d261c261efac224b664affdc5785", 423 | "sha256:d1735fc58b418fd7c5f658d28d943854f8a849b01a5d0a1e6f3f3fdd0166804b" 424 | ], 425 | "markers": "python_version >= '3.6'", 426 | "version": "==2.9.1" 427 | }, 428 | "pyflakes": { 429 | "hashes": [ 430 | "sha256:4579f67d887f804e67edb544428f264b7b24f435b263c4614f384135cea553d2", 431 | "sha256:491feb020dca48ccc562a8c0cbe8df07ee13078df59813b83959cbdada312ea3" 432 | ], 433 | "markers": "python_version >= '3.6'", 434 | "version": "==2.5.0" 435 | }, 436 | "pygments": { 437 | "hashes": [ 438 | "sha256:8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c", 439 | "sha256:db2db3deb4b4179f399a09054b023b6a586b76499d36965813c71aa8ed7b5fd1" 440 | ], 441 | "markers": "python_version >= '3.7'", 442 | "version": "==2.15.1" 443 | }, 444 | "pytest": { 445 | "hashes": [ 446 | "sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362", 447 | "sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3" 448 | ], 449 | "index": "pypi", 450 | "version": "==7.3.1" 451 | }, 452 | "pytest-mock": { 453 | "hashes": [ 454 | "sha256:f4c973eeae0282963eb293eb173ce91b091a79c1334455acfac9ddee8a1c784b", 455 | "sha256:fbbdb085ef7c252a326fd8cdcac0aa3b1333d8811f131bdcc701002e1be7ed4f" 456 | ], 457 | "index": "pypi", 458 | "version": "==3.10.0" 459 | }, 460 | "readme-renderer": { 461 | "hashes": [ 462 | "sha256:cd653186dfc73055656f090f227f5cb22a046d7f71a841dfa305f55c9a513273", 463 | "sha256:f67a16caedfa71eef48a31b39708637a6f4664c4394801a7b0d6432d13907343" 464 | ], 465 | "markers": "python_version >= '3.7'", 466 | "version": "==37.3" 467 | }, 468 | "requests": { 469 | "hashes": [ 470 | "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa", 471 | "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf" 472 | ], 473 | "index": "pypi", 474 | "version": "==2.28.2" 475 | }, 476 | "requests-toolbelt": { 477 | "hashes": [ 478 | "sha256:18565aa58116d9951ac39baa288d3adb5b3ff975c4f25eee78555d89e8f247f7", 479 | "sha256:62e09f7ff5ccbda92772a29f394a49c3ad6cb181d568b1337626b2abb628a63d" 480 | ], 481 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", 482 | "version": "==0.10.1" 483 | }, 484 | "rfc3986": { 485 | "hashes": [ 486 | "sha256:50b1502b60e289cb37883f3dfd34532b8873c7de9f49bb546641ce9cbd256ebd", 487 | "sha256:97aacf9dbd4bfd829baad6e6309fa6573aaf1be3f6fa735c8ab05e46cecb261c" 488 | ], 489 | "markers": "python_version >= '3.7'", 490 | "version": "==2.0.0" 491 | }, 492 | "rich": { 493 | "hashes": [ 494 | "sha256:22b74cae0278fd5086ff44144d3813be1cedc9115bdfabbfefd86400cb88b20a", 495 | "sha256:b5d573e13605423ec80bdd0cd5f8541f7844a0e71a13f74cf454ccb2f490708b" 496 | ], 497 | "markers": "python_full_version >= '3.7.0'", 498 | "version": "==13.3.4" 499 | }, 500 | "six": { 501 | "hashes": [ 502 | "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", 503 | "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" 504 | ], 505 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", 506 | "version": "==1.16.0" 507 | }, 508 | "twine": { 509 | "hashes": [ 510 | "sha256:929bc3c280033347a00f847236564d1c52a3e61b1ac2516c97c48f3ceab756d8", 511 | "sha256:9e102ef5fdd5a20661eb88fad46338806c3bd32cf1db729603fe3697b1bc83c8" 512 | ], 513 | "index": "pypi", 514 | "version": "==4.0.2" 515 | }, 516 | "urllib3": { 517 | "hashes": [ 518 | "sha256:8a388717b9476f934a21484e8c8e61875ab60644d29b9b39e11e4b9dc1c6b305", 519 | "sha256:aa751d169e23c7479ce47a0cb0da579e3ede798f994f5816a74e4f4500dcea42" 520 | ], 521 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", 522 | "version": "==1.26.15" 523 | }, 524 | "webencodings": { 525 | "hashes": [ 526 | "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78", 527 | "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923" 528 | ], 529 | "version": "==0.5.1" 530 | }, 531 | "zipp": { 532 | "hashes": [ 533 | "sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b", 534 | "sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556" 535 | ], 536 | "markers": "python_version >= '3.7'", 537 | "version": "==3.15.0" 538 | } 539 | } 540 | } 541 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | python-roku 2 | =========== 3 | 4 | Screw remotes. Control your `Roku `_ via Python. 5 | 6 | Supports Python 3.7 to 3.11. 7 | 8 | 9 | Installation 10 | ------------ 11 | 12 | :: 13 | 14 | pip install roku 15 | 16 | 17 | Usage 18 | ----- 19 | 20 | 21 | The Basics 22 | ~~~~~~~~~~ 23 | 24 | To start, import the Roku object and create it with the IP address or hostname of your Roku. 25 | :: 26 | 27 | >>> from roku import Roku 28 | >>> roku = Roku('192.168.10.163') 29 | 30 | The Roku object has a method for each of the buttons on the remote. 31 | :: 32 | 33 | >>> roku.home() 34 | >>> roku.right() 35 | >>> roku.select() 36 | 37 | To support keyup and keydown events simply pass "keyup" or "keydown" when you call the command. 38 | :: 39 | 40 | >>> roku.right("keydown") 41 | >>> roku.right("keyup") 42 | 43 | To see a full list of available commands, use the *commands* property. 44 | :: 45 | 46 | >>> roku.commands 47 | ['back', 'backspace', 'down', 'enter', 'forward', 'home', 'info', 'left', 'literal', 'play', 'replay', 'reverse', 'right', 'search', 'select', 'up'] 48 | 49 | If you are following along on your home network and are connected to your Roku, you should see it doing stuff. *Cool!* 50 | 51 | 52 | Apps 53 | ~~~~ 54 | 55 | The *apps* property will return a list of the applications on your device. 56 | :: 57 | 58 | >>> roku.apps 59 | [, , ] 60 | 61 | Apps have *id*, *name*, and *version* properties. 62 | :: 63 | 64 | >>> app = roku.apps[0] 65 | >>> print(app.id, app.name, app.version) 66 | 2285 Hulu Plus 2.7.6 67 | 68 | You can get an individual app from the Roku object by either its *name* or *id*. 69 | :: 70 | 71 | >>> roku['Hulu Plus'] 72 | 73 | >>> roku[2285] 74 | 75 | 76 | Seeing the reference to this Hulu Plus app makes me really want to watch the latest episode of `Nashville `_. Let's launch it! 77 | :: 78 | 79 | >>> hulu = roku['Hulu Plus'] 80 | >>> hulu.launch() 81 | 82 | Again, if you are following along at home, you should see that your Roku has launched the Hulu Plus app. Want to see the app's entry in the Channel Store? 83 | :: 84 | 85 | >>> hulu.store() 86 | 87 | You can also get the app's icon. 88 | :: 89 | 90 | >>> with open('hulu.png', 'w') as f: 91 | ... f.write(hulu.icon) 92 | 93 | >>> print hulu.icon_url 94 | http://0.0.0.0:8060/query/icon/2285 95 | 96 | You can get the current running app. 97 | :: 98 | 99 | >>> roku.active_app 100 | 101 | 102 | 103 | Entering Text 104 | ~~~~~~~~~~~~~ 105 | 106 | Okay, I've already seen all of the available episodes of Nashville, so I'm going to search for *Stargate*. With the search open and waiting for text entry:: 107 | 108 | >>> roku.literal('stargate') 109 | 110 | What if I now want to watch *The Informant!*? Again, with the search open and waiting for text entry:: 111 | 112 | >>> roku.literal('The Informant!') 113 | 114 | This will iterate over each character, sending it individually to the Roku. 115 | 116 | 117 | Advanced Stuff 118 | -------------- 119 | 120 | 121 | Discovery 122 | ~~~~~~~~~ 123 | 124 | Roku devices can be discovered using `SSDP `_. A class method is available on the Roku object that will return Roku object instances for each device found on the same network. 125 | :: 126 | 127 | >>> Roku.discover() 128 | [] 129 | 130 | It may take a few seconds for a device to be found. You can call discover again or change the *timeout* or *retries* parameters on the discover method. This will take longer, but will find more devices. 131 | :: 132 | 133 | >>> Roku.discover(timeout=10) 134 | [, ] 135 | 136 | Thanks to `Dan Krause `_ for his `SSDP code `_. 137 | 138 | 139 | Sensors 140 | ~~~~~~~ 141 | 142 | Newer Roku remotes have extra sensors built into them that measure acceleration, orientation, and other things.You can mimic these sensors using the provided helper methods. 143 | :: 144 | 145 | >>> roku.orientation(1, 1, 1) 146 | 147 | The parameters to all of the sensor methods are x, y, and z values. Available methods include: 148 | 149 | * acceleration - in each dimension relative to free fall measured in meters/sec^2 150 | * magnetic - magnetic field strength in microtesla 151 | * orientation - angular displacement from flat/level and north in radians 152 | * rotation - angular rotation rate about each axis using the right hand rule in radians/sec 153 | 154 | 155 | Touch 156 | ~~~~~ 157 | 158 | Some Roku input devices support touch. The parameters to the *touch* method are the *x* and *y* coordinates of the touch. 159 | :: 160 | 161 | >>> roku.touch(10, 40) 162 | 163 | You can change the event triggered by passing an optional *op* parameter. 164 | :: 165 | 166 | >>> roku.touch(10, 40, op='up') 167 | 168 | Supported events are: 169 | 170 | * down 171 | * up 172 | * press (down and up) 173 | * move 174 | * cancel 175 | 176 | Multitouch is not yet supported in this package. 177 | 178 | Integrations 179 | ~~~~~~~~~~~~ 180 | * `pyrokuserve `_ 181 | * `Home Assistant `_ 182 | 183 | Generic Input 184 | ~~~~~~~~~~~~~ 185 | 186 | Both the sensor and touch methods rely on the generic *input* method for sending data to a running application. If you refuse to use covenience methods because they make people lazy and weak, you can call the sensor and touch methods directly. 187 | :: 188 | 189 | >>> params = {'touch.0.x': 10, 'touch.0.y': 20, 'touch.0.op': 'press'} 190 | >>> roku.input(params) 191 | 192 | More information about input, touch, and sensors is available in the `Roku External Control docs `_. 193 | 194 | 195 | TODO 196 | ---- 197 | 198 | * Tests, of course. 199 | * Multitouch support. 200 | * A Flask proxy server that can listen to requests and forward them to devices on the local network. Control multiple devices at once, eh? 201 | * A server that mimics the Roku interface so you can make your own Roku-like stuff. 202 | * A task runner that will take a set of commands and run them with delays that are appropriate for most devices. 203 | -------------------------------------------------------------------------------- /roku/__init__.py: -------------------------------------------------------------------------------- 1 | from roku.core import Roku, Application, Channel, RokuException, __version__ # noqa 2 | -------------------------------------------------------------------------------- /roku/core.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import xml.etree.ElementTree as ET 3 | from urllib.parse import quote_plus, urlparse 4 | import socket 5 | import requests 6 | 7 | from . import discovery 8 | from .util import deserialize_apps, deserialize_channels 9 | 10 | 11 | __version__ = "4.1.0" 12 | 13 | 14 | COMMANDS = { 15 | # Standard Keys 16 | "home": "Home", 17 | "reverse": "Rev", 18 | "forward": "Fwd", 19 | "play": "Play", 20 | "select": "Select", 21 | "left": "Left", 22 | "right": "Right", 23 | "down": "Down", 24 | "up": "Up", 25 | "back": "Back", 26 | "replay": "InstantReplay", 27 | "info": "Info", 28 | "backspace": "Backspace", 29 | "search": "Search", 30 | "enter": "Enter", 31 | "literal": "Lit", 32 | # For devices that support "Find Remote" 33 | "find_remote": "FindRemote", 34 | # For Roku TV 35 | "volume_down": "VolumeDown", 36 | "volume_up": "VolumeUp", 37 | "volume_mute": "VolumeMute", 38 | # For Roku TV while on TV tuner channel 39 | "channel_up": "ChannelUp", 40 | "channel_down": "ChannelDown", 41 | # For Roku TV current input 42 | "input_tuner": "InputTuner", 43 | "input_hdmi1": "InputHDMI1", 44 | "input_hdmi2": "InputHDMI2", 45 | "input_hdmi3": "InputHDMI3", 46 | "input_hdmi4": "InputHDMI4", 47 | "input_av1": "InputAV1", 48 | # For devices that support being turned on/off 49 | "power": "Power", 50 | "poweroff": "PowerOff", 51 | "poweron": "PowerOn", 52 | } 53 | 54 | SENSORS = ("acceleration", "magnetic", "orientation", "rotation") 55 | 56 | TOUCH_OPS = ("up", "down", "press", "move", "cancel") 57 | 58 | 59 | roku_logger = logging.getLogger("roku") 60 | 61 | 62 | class RokuException(Exception): 63 | pass 64 | 65 | 66 | class Application(object): 67 | def __init__(self, id, version, name, roku=None, is_screensaver=False): 68 | self.id = str(id) 69 | self.version = version 70 | self.name = name 71 | self.is_screensaver = is_screensaver 72 | self.roku = roku 73 | 74 | def __eq__(self, other): 75 | return isinstance(other, Application) and (self.id, self.version) == ( 76 | other.id, 77 | other.version, 78 | ) 79 | 80 | def __repr__(self): 81 | return f"" 82 | 83 | @property 84 | def icon(self): 85 | if self.roku: 86 | return self.roku.icon(self) 87 | 88 | @property 89 | def icon_url(self): 90 | if self.roku: 91 | return self.roku.icon_url(self) 92 | 93 | def launch(self): 94 | if self.roku: 95 | self.roku.launch(self) 96 | 97 | def store(self): 98 | if self.roku: 99 | self.roku.store(self) 100 | 101 | 102 | class Channel(object): 103 | def __init__(self, number, name, roku=None): 104 | self.number = str(number) 105 | self.name = name 106 | self.roku = roku 107 | 108 | def __eq__(self, other): 109 | return isinstance(other, Channel) and (self.number, self.name) == ( 110 | other.number, 111 | other.name, 112 | ) 113 | 114 | def __repr__(self): 115 | return f"" 116 | 117 | def launch(self): 118 | if self.roku: 119 | tv_app = Application( 120 | id="tvinput.dtv", version=None, name="TV", roku=self.roku 121 | ) 122 | self.roku.launch(tv_app, {"ch": self.number}) 123 | 124 | 125 | class DeviceInfo(object): 126 | def __init__( 127 | self, 128 | model_name, 129 | model_num, 130 | software_version, 131 | serial_num, 132 | user_device_name, 133 | roku_type, 134 | ): 135 | self.model_name = model_name 136 | self.model_num = model_num 137 | self.software_version = software_version 138 | self.serial_num = serial_num 139 | self.user_device_name = user_device_name 140 | self.roku_type = roku_type 141 | 142 | def __repr__(self): 143 | return ( 144 | f"" 147 | ) 148 | 149 | 150 | class MediaPlayer(object): 151 | def __init__(self, state, app, position, duration): 152 | self.state = state 153 | self.app = app 154 | self.position = position 155 | self.duration = duration 156 | 157 | def __repr__(self): 158 | return "" % ( 159 | self.state, 160 | self.app.name, 161 | self.position, 162 | self.duration, 163 | ) 164 | 165 | 166 | class Roku(object): 167 | @classmethod 168 | def discover(self, *args, **kwargs): 169 | rokus = [] 170 | for device in discovery.discover(*args, **kwargs): 171 | o = urlparse(device.location) 172 | rokus.append(Roku(o.hostname, o.port)) 173 | return rokus 174 | 175 | def __init__(self, host, port=8060, timeout=10): 176 | self.host = socket.gethostbyname(host) 177 | self.port = port 178 | self._conn = None 179 | self.timeout = timeout 180 | 181 | def __repr__(self): 182 | return f"" 183 | 184 | def __getattr__(self, name): 185 | if name not in COMMANDS and name not in SENSORS: 186 | raise AttributeError(f"{name} is not a valid method") 187 | 188 | def command(*args, **kwargs): 189 | if name in SENSORS: 190 | keys = [f"{name}.{axis}" for axis in ("x", "y", "z")] 191 | params = dict(zip(keys, args)) 192 | self.input(params) 193 | elif name == "literal": 194 | for char in args[0]: 195 | path = f"/keypress/{COMMANDS[name]}_{quote_plus(char)}" 196 | self._post(path) 197 | elif name == "search": 198 | path = "/search/browse" 199 | params = {k.replace("_", "-"): v for k, v in kwargs.items()} 200 | self._post(path, params=params) 201 | else: 202 | if len(args) > 0 and (args[0] == "keydown" or args[0] == "keyup"): 203 | path = f"/{args[0]}/{COMMANDS[name]}" 204 | else: 205 | path = f"/keypress/{COMMANDS[name]}" 206 | self._post(path) 207 | 208 | return command 209 | 210 | def __getitem__(self, key): 211 | key = str(key) 212 | app = self._app_for_name(key) 213 | if not app: 214 | app = self._app_for_id(key) 215 | return app 216 | 217 | def __dir__(self): 218 | return sorted( 219 | dir(type(self)) 220 | + list(self.__dict__.keys()) 221 | + list(COMMANDS.keys()) 222 | + list(SENSORS) 223 | ) 224 | 225 | def _app_for_name(self, name): 226 | for app in self.apps: 227 | if app.name == name: 228 | return app 229 | 230 | def _app_for_id(self, app_id): 231 | for app in self.apps: 232 | if app.id == app_id: 233 | return app 234 | 235 | def _connect(self): 236 | if self._conn is None: 237 | self._conn = requests.Session() 238 | 239 | def _get(self, path, *args, **kwargs): 240 | return self._call("GET", path, *args, **kwargs) 241 | 242 | def _post(self, path, *args, **kwargs): 243 | return self._call("POST", path, *args, **kwargs) 244 | 245 | def _call(self, method, path, *args, **kwargs): 246 | self._connect() 247 | 248 | roku_logger.debug(path) 249 | 250 | url = f"http://{self.host}:{self.port}{path}" 251 | 252 | if method not in ("GET", "POST"): 253 | raise ValueError("only GET and POST HTTP methods are supported") 254 | 255 | func = getattr(self._conn, method.lower()) 256 | resp = func(url, timeout=self.timeout, *args, **kwargs) 257 | 258 | if resp.status_code < 200 or resp.status_code > 299: 259 | raise RokuException(resp.content) 260 | 261 | return resp.content 262 | 263 | @property 264 | def apps(self): 265 | resp = self._get("/query/apps") 266 | applications = deserialize_apps(resp) 267 | for a in applications: 268 | a.roku = self 269 | return applications 270 | 271 | @property 272 | def active_app(self): 273 | resp = self._get("/query/active-app") 274 | active_app = deserialize_apps(resp) 275 | if len(active_app): 276 | return active_app[0] 277 | else: 278 | return None 279 | 280 | @property 281 | def tv_channels(self): 282 | resp = self._get("/query/tv-channels") 283 | channels = deserialize_channels(resp) 284 | for c in channels: 285 | c.roku = self 286 | return channels 287 | 288 | @property 289 | def device_info(self): 290 | resp = self._get("/query/device-info") 291 | root = ET.fromstring(resp) 292 | 293 | roku_type = "Box" 294 | if root.find("is-tv") is not None and root.find("is-tv").text == "true": 295 | roku_type = "TV" 296 | elif root.find("is-stick") is not None and root.find("is-stick").text == "true": 297 | roku_type = "Stick" 298 | dinfo = DeviceInfo( 299 | model_name=root.find("model-name").text, 300 | model_num=root.find("model-number").text, 301 | software_version=f"{root.find('software-version').text}.{root.find('software-build').text}", 302 | serial_num=root.find("serial-number").text, 303 | user_device_name=root.find("user-device-name").text, 304 | roku_type=roku_type, 305 | ) 306 | return dinfo 307 | 308 | @property 309 | def media_player(self): 310 | resp = self._get("/query/media-player") 311 | root = ET.fromstring(resp) 312 | 313 | mp = MediaPlayer( 314 | state=root.get("state"), 315 | app=self[int(root.find("plugin").get("id"))], 316 | position=int(root.find("position").text.split(" ", 1)[0]), 317 | duration=int(root.find("duration").text.split(" ", 1)[0]), 318 | ) 319 | return mp 320 | 321 | @property 322 | def commands(self): 323 | return sorted(COMMANDS.keys()) 324 | 325 | @property 326 | def power_state(self): 327 | resp = self._get("/query/device-info") 328 | root = ET.fromstring(resp) 329 | if root.find("power-mode").text: 330 | if root.find("power-mode").text == "PowerOn": 331 | return "On" 332 | else: 333 | return "Off" 334 | return "Unknown" 335 | 336 | def icon(self, app): 337 | return self._get(f"/query/icon/{app.id}") 338 | 339 | def icon_url(self, app): 340 | return "http://%s:%s/query/icon/%s" % (self.host, self.port, app.id) 341 | 342 | def launch(self, app, params={}): 343 | if app.roku and app.roku != self: 344 | raise RokuException("this app belongs to another Roku") 345 | params["contentID"] = app.id 346 | return self._post(f"/launch/{app.id}", params=params) 347 | 348 | def store(self, app): 349 | return self._post("/launch/11", params={"contentID": app.id}) 350 | 351 | def input(self, params): 352 | return self._post("/input", params=params) 353 | 354 | def touch(self, x, y, op="down"): 355 | if op not in TOUCH_OPS: 356 | raise RokuException(f"{op} is not a valid touch operation") 357 | 358 | params = { 359 | "touch.0.x": x, 360 | "touch.0.y": y, 361 | "touch.0.op": op, 362 | } 363 | 364 | self.input(params) 365 | 366 | @property 367 | def current_app(self): 368 | resp = self._get("/query/active-app") 369 | root = ET.fromstring(resp) 370 | is_screensaver = True 371 | 372 | app_node = root.find("screensaver") 373 | if app_node is None: 374 | app_node = root.find("app") 375 | is_screensaver = False 376 | 377 | if app_node is None: 378 | return None 379 | 380 | return Application( 381 | id=app_node.get("id"), 382 | version=app_node.get("version"), 383 | name=app_node.text, 384 | is_screensaver=is_screensaver, 385 | roku=self, 386 | ) 387 | -------------------------------------------------------------------------------- /roku/discovery.py: -------------------------------------------------------------------------------- 1 | """ 2 | Code adapted from Dan Krause. 3 | https://gist.github.com/dankrause/6000248 4 | http://github.com/dankrause 5 | """ 6 | import socket 7 | from http.client import HTTPResponse 8 | from io import BytesIO 9 | 10 | ST_DIAL = "urn:dial-multiscreen-org:service:dial:1" 11 | ST_ECP = "roku:ecp" 12 | 13 | 14 | class _FakeSocket(BytesIO): 15 | def makefile(self, *args, **kw): 16 | return self 17 | 18 | 19 | class SSDPResponse(object): 20 | def __init__(self, response): 21 | self.location = response.getheader("location") 22 | self.usn = response.getheader("usn") 23 | self.st = response.getheader("st") 24 | self.cache = response.getheader("cache-control").split("=")[1] 25 | 26 | def __repr__(self): 27 | return f"\w+)(?:\:(?P[\w\s]+))?(?:\@(?P\d+))?(?:\*(?P[\d\.]+))?" 9 | ) # noqa 10 | 11 | Command = namedtuple("Command", ["command", "param", "count", "sleep"]) 12 | 13 | logger = logging.getLogger("roku.scripting") 14 | 15 | 16 | def load_script(path, params=None, raw=False): 17 | if not os.path.exists(path): 18 | raise ValueError(f"script at {path} not found") 19 | with open(path) as infile: 20 | content = infile.read() 21 | if params: 22 | content = content.format(**params) 23 | if not raw: 24 | content = content.strip().split("\n") 25 | return content 26 | 27 | 28 | def parse_script(script): 29 | commands = [] 30 | for line in script: 31 | if not line: 32 | continue 33 | m = SCRIPT_RE.match(line) 34 | if m: 35 | data = m.groupdict() 36 | data["count"] = int(data["count"] or 1) 37 | data["sleep"] = float(data["sleep"]) if data["sleep"] else None 38 | commands.append(Command(**data)) 39 | return commands 40 | 41 | 42 | def run_script(roku, script, sleep=0.5): 43 | for cmd in script: 44 | logger.debug(cmd) 45 | for i in range(cmd.count or 1): 46 | func = getattr(roku, cmd.command) 47 | if func: 48 | if cmd.param: 49 | func(cmd.param) 50 | else: 51 | func() 52 | time.sleep(cmd.sleep or sleep) 53 | -------------------------------------------------------------------------------- /roku/server.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request 2 | 3 | app = Flask(__name__) 4 | 5 | 6 | @app.route("/keypress/") 7 | def keypress(key): 8 | pass 9 | 10 | 11 | @app.route("/launch/") 12 | def launch(code): 13 | request.args.get("contentID", None) 14 | 15 | 16 | @app.route("/query/apps") 17 | def list_apps(): 18 | pass 19 | 20 | 21 | @app.route("/query/active-app") 22 | def active_app(): 23 | pass 24 | 25 | 26 | @app.route("/query/icon/") 27 | def app_icon(app_id): 28 | pass 29 | 30 | 31 | if __name__ == "__main__": 32 | app.run(port=8060, debug=True) 33 | -------------------------------------------------------------------------------- /roku/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jcarbaugh/python-roku/b88125abca91573f4882d1265a38490a4bbff8ba/roku/tests/__init__.py -------------------------------------------------------------------------------- /roku/tests/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from roku import Application, Roku 4 | 5 | 6 | class Fauxku(Roku): 7 | def __init__(self, *args, **kwargs): 8 | super(Fauxku, self).__init__(*args, **kwargs) 9 | self._calls = [] 10 | 11 | def _call(self, method, path, *args, **kwargs): 12 | self._calls.append((method, path, args, kwargs)) 13 | return "" 14 | 15 | def calls(self): 16 | return self._calls 17 | 18 | def last_call(self): 19 | return self._calls[-1] 20 | 21 | 22 | @pytest.fixture 23 | def roku(): 24 | return Fauxku("0.0.0.0") 25 | 26 | 27 | @pytest.fixture 28 | def apps(roku): 29 | faux_apps = [ 30 | Application("11", "1.0.1", "Fauxku Channel Store", roku), 31 | Application("22", "2.0.2", "Faux Netflix", roku), 32 | Application("33", "3.0.3", "Faux YouTube", roku), 33 | Application("44HL", "4.0.4", "Faux Hulu", roku), 34 | ] 35 | return faux_apps 36 | -------------------------------------------------------------------------------- /roku/tests/responses/device-info.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 00000000-1111-2222-3333-444444444444 4 | 111111111111 5 | 222222222222 6 | Roku 7 | 4200X 8 | Roku 3 9 | false 10 | true 11 | 00:11:22:33:44:55 12 | 00:11:22:33:44:56 13 | ethernet 14 | 15 | 7.00 16 | 09044 17 | true 18 | en 19 | US 20 | en_US 21 | US/Eastern 22 | -300 23 | PowerOn 24 | false 25 | true 26 | true 27 | true 28 | false 29 | false 30 | 31 | -------------------------------------------------------------------------------- /roku/tests/responses/media-player.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11187 5 | 1858000 6 | 7 | -------------------------------------------------------------------------------- /roku/tests/scripts/testscript.txt: -------------------------------------------------------------------------------- 1 | literal:barbecue 2 | literal:{avar} 3 | -------------------------------------------------------------------------------- /roku/tests/test_roku.py: -------------------------------------------------------------------------------- 1 | import os 2 | from urllib.parse import quote_plus 3 | 4 | import pytest 5 | 6 | from roku.core import Application, Roku, COMMANDS 7 | from roku.util import serialize_apps 8 | 9 | 10 | TESTS_PATH = os.path.abspath(os.path.dirname(__file__)) 11 | 12 | 13 | class Fauxku(Roku): 14 | def __init__(self, *args, **kwargs): 15 | super(Fauxku, self).__init__(*args, **kwargs) 16 | self._calls = [] 17 | 18 | def _call(self, method, path, *args, **kwargs): 19 | self._calls.append((method, path, args, kwargs)) 20 | return "" 21 | 22 | def calls(self): 23 | return self._calls 24 | 25 | def last_call(self): 26 | return self._calls[-1] 27 | 28 | 29 | @pytest.fixture 30 | def roku(): 31 | return Fauxku("0.0.0.0") 32 | 33 | 34 | @pytest.fixture 35 | def apps(roku): 36 | faux_apps = [ 37 | Application("11", "1.0.1", "Fauxku Channel Store", roku), 38 | Application("22", "2.0.2", "Faux Netflix", roku), 39 | Application("33", "3.0.3", "Faux YouTube", roku), 40 | Application("44HL", "4.0.4", "Faux Hulu", roku), 41 | ] 42 | return faux_apps 43 | 44 | 45 | def test_apps(mocker, roku): 46 | faux_apps = (Application("0x", "1.2.3", "Fauxku Channel Store"),) 47 | 48 | mocked_get = mocker.patch.object(Roku, "_get") 49 | mocked_get.return_value = serialize_apps(faux_apps) 50 | 51 | apps = roku.apps 52 | 53 | assert len(apps) == 1 54 | assert apps[0].id == "0x" 55 | assert apps[0].version == "1.2.3" 56 | assert apps[0].name == "Fauxku Channel Store" 57 | 58 | 59 | def test_app_selector(mocker, apps): 60 | mocked_get = mocker.patch.object(Roku, "_get") 61 | mocked_get.return_value = serialize_apps(apps) 62 | 63 | for app in apps: 64 | roku = app.roku 65 | assert roku[app.id] == app 66 | assert roku[app.name] == app 67 | 68 | 69 | def test_device_info(mocker, roku): 70 | xml_path = os.path.join(TESTS_PATH, "responses", "device-info.xml") 71 | with open(xml_path) as infile: 72 | content = infile.read() 73 | 74 | mocked_get = mocker.patch.object(Roku, "_get") 75 | mocked_get.return_value = content.encode("utf-8") 76 | 77 | d = roku.device_info 78 | 79 | assert d.model_name == "Roku 3" 80 | assert d.model_num == "4200X" 81 | assert d.software_version == "7.00.09044" 82 | assert d.serial_num == "111111111111" 83 | assert d.roku_type == "Stick" 84 | 85 | 86 | def test_media_player(mocker, roku): 87 | xml_path = os.path.join(TESTS_PATH, "responses", "media-player.xml") 88 | with open(xml_path) as infile: 89 | content = infile.read() 90 | 91 | faux_apps = (Application(33, "1.2.3", "Faux YouTube"),) 92 | 93 | mocked_get = mocker.patch.object(Roku, "_get") 94 | mocked_get.return_value = content.encode("utf-8") 95 | mocker.patch.object(Roku, "apps", new=faux_apps) 96 | 97 | m = roku.media_player 98 | 99 | assert m.state == "pause" 100 | assert m.app.name == "Faux YouTube" 101 | assert m.position == 11187 102 | assert m.duration == 1858000 103 | 104 | 105 | def test_commands(roku): 106 | for cmd in roku.commands: 107 | if cmd in ["literal", "search"]: 108 | # there is a separate test for the literal and search command 109 | continue 110 | 111 | getattr(roku, cmd)() 112 | call = roku.last_call() 113 | 114 | assert call == ("POST", f"/keypress/{COMMANDS[cmd]}", (), {}) 115 | 116 | 117 | def test_search(roku): 118 | text = "Stargate" 119 | roku.search(title=text) 120 | 121 | call = roku.last_call() 122 | 123 | assert call == ("POST", "/search/browse", (), {"params": {"title": text}}) 124 | 125 | 126 | def test_literal(roku): 127 | text = "Stargate" 128 | roku.literal(text) 129 | 130 | for i, call in enumerate(roku.calls()): 131 | assert call == ("POST", f"/keypress/Lit_{quote_plus(text[i])}", (), {}) 132 | 133 | 134 | def test_literal_fancy(roku): 135 | text = r"""~!@#$%^&*()_+`-=[]{};':",./<>?\|€£""" 136 | roku.literal(text) 137 | 138 | for i, call in enumerate(roku.calls()): 139 | assert call == ("POST", f"/keypress/Lit_{quote_plus(text[i])}", (), {}) 140 | 141 | 142 | def test_store(apps): 143 | for app in apps: 144 | roku = app.roku 145 | roku.store(app) 146 | call = roku.last_call() 147 | 148 | params = {"params": {"contentID": app.id}} 149 | assert call == ("POST", "/launch/11", (), params) 150 | 151 | 152 | def test_launch(apps): 153 | for app in apps: 154 | roku = app.roku 155 | roku.launch(app) 156 | call = roku.last_call() 157 | 158 | params = {"params": {"contentID": app.id}} 159 | assert call == ("POST", f"/launch/{app.id}", (), params) 160 | 161 | 162 | def test_icon_url(apps): 163 | for app in apps: 164 | assert app.roku.icon_url(app) == f"http://0.0.0.0:8060/query/icon/{app.id}" 165 | assert app.icon_url == f"http://0.0.0.0:8060/query/icon/{app.id}" 166 | -------------------------------------------------------------------------------- /roku/tests/test_scripting.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from roku import scripting 4 | 5 | 6 | SCRIPT_PATH = "roku/tests/scripts/testscript.txt" 7 | 8 | 9 | def test_loading(): 10 | scripting.load_script(SCRIPT_PATH) 11 | 12 | 13 | def test_loading_params(): 14 | params = { 15 | "avar": "here", 16 | "notavar": "missing", 17 | } 18 | content = scripting.load_script(SCRIPT_PATH, params=params, raw=True) 19 | assert "literal:here" in content 20 | assert "literal:missing" not in content 21 | 22 | 23 | def test_loading_notfound(): 24 | with pytest.raises(ValueError): 25 | scripting.load_script("thisisnotarealscript.txt") 26 | 27 | 28 | def test_parse_command_only(): 29 | content = ("home",) 30 | script = scripting.parse_script(content) 31 | command = script[0] 32 | assert command == scripting.Command("home", None, 1, None) 33 | 34 | 35 | def test_parse_command_param(): 36 | content = ("literal:barbecue",) 37 | script = scripting.parse_script(content) 38 | command = script[0] 39 | assert command == scripting.Command("literal", "barbecue", 1, None) 40 | 41 | 42 | def test_parse_command_count(): 43 | content = ("left@10",) 44 | script = scripting.parse_script(content) 45 | command = script[0] 46 | assert command == scripting.Command("left", None, 10, None) 47 | 48 | 49 | def test_parse_command_sleep(): 50 | content = ("left*2",) 51 | script = scripting.parse_script(content) 52 | command = script[0] 53 | assert command == scripting.Command("left", None, 1, 2.0) 54 | 55 | 56 | def test_parse_command_all(): 57 | content = ("literal:barbecue@3*5.1",) 58 | script = scripting.parse_script(content) 59 | command = script[0] 60 | assert command == scripting.Command("literal", "barbecue", 3, 5.1) 61 | 62 | 63 | def test_run_script(roku): 64 | content = ("home", "literal:x") 65 | script = scripting.parse_script(content) 66 | scripting.run_script(roku, script) 67 | calls = roku.calls() 68 | assert "keypress/Home" in calls[0][1] 69 | assert "keypress/Lit_x" in calls[1][1] 70 | -------------------------------------------------------------------------------- /roku/util.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | from contextlib import closing 3 | 4 | from io import BytesIO 5 | 6 | 7 | def deserialize_apps(doc, roku=None): 8 | from .core import Application 9 | 10 | applications = [] 11 | root = ET.fromstring(doc) 12 | for elem in root: 13 | app = Application( 14 | id=elem.get("id"), version=elem.get("version"), name=elem.text 15 | ) 16 | applications.append(app) 17 | return applications 18 | 19 | 20 | def serialize_apps(apps): 21 | root = ET.Element("apps") 22 | 23 | for app in apps: 24 | attrs = {"id": app.id, "version": app.version} 25 | elem = ET.SubElement(root, "app", attrs) 26 | elem.text = app.name 27 | 28 | with closing(BytesIO()) as bffr: 29 | tree = ET.ElementTree(root) 30 | tree.write(bffr, xml_declaration=True, encoding="utf-8") 31 | content = bffr.getvalue() 32 | 33 | return content 34 | 35 | 36 | def deserialize_channels(doc, roku=None): 37 | from .core import Channel 38 | 39 | channels = [] 40 | root = ET.fromstring(doc) 41 | 42 | for elem in root: 43 | channel = Channel( 44 | number=elem.find("number").text, 45 | name=elem.find("name").text, 46 | roku=roku, 47 | ) 48 | channels.append(channel) 49 | return channels 50 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | import os 3 | 4 | f = open(os.path.join(os.path.dirname(__file__), "README.rst")) 5 | readme = f.read() 6 | f.close() 7 | 8 | setup( 9 | name="roku", 10 | version="5.0", 11 | description="Client for the Roku media player", 12 | long_description=readme, 13 | author="Jeremy Carbaugh", 14 | author_email="jeremy@jcarbaugh.com", 15 | url="https://github.com/jcarbaugh/python-roku", 16 | packages=find_packages(), 17 | install_requires=[ 18 | "requests<3", 19 | ], 20 | license="BSD License", 21 | platforms=["any"], 22 | classifiers=[ 23 | "Development Status :: 5 - Production/Stable", 24 | "Intended Audience :: Developers", 25 | "License :: OSI Approved :: BSD License", 26 | "Natural Language :: English", 27 | "Programming Language :: Python", 28 | "Programming Language :: Python :: 3.7", 29 | "Programming Language :: Python :: 3.8", 30 | "Programming Language :: Python :: 3.9", 31 | "Programming Language :: Python :: 3.10", 32 | "Programming Language :: Python :: 3.11", 33 | ], 34 | ) 35 | --------------------------------------------------------------------------------