├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── gnomecast.desktop ├── gnomecast.py ├── gnomecast.pyproj ├── gnomecast.sln ├── icons ├── gnomecast.svg ├── gnomecast_16.png └── gnomecast_48.png ├── launcher.png ├── receiver.html ├── requirements.txt ├── screenshot.png ├── setup.py ├── test_gnomecast.py ├── trending.png └── www ├── gnomecast.css └── screenshot.png /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset=utf-8 3 | end_of_line=lf 4 | insert_final_newline=false 5 | indent_style=space 6 | indent_size=2 7 | 8 | [{.babelrc,.stylelintrc,.eslintrc,jest.config,*.json,*.jsb3,*.jsb2,*.bowerrc}] 9 | indent_style=space 10 | indent_size=2 11 | 12 | [{*.yml,*.yaml}] 13 | indent_style=space 14 | indent_size=2 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | # PyCharm 104 | .idea/ 105 | 106 | # Exclude Visual Studio solution files 107 | *.sdf 108 | *.VC.opendb 109 | *.VC.db 110 | *.opensdf 111 | *.suo 112 | *.user 113 | *.orig 114 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](https://raw.githubusercontent.com/keredson/gnomecast/master/screenshot.png) 2 | 3 | Gnomecast ![logo](https://github.com/keredson/gnomecast/raw/master/icons/gnomecast_16.png) 4 | ========= 5 | 6 | This is a native Linux GUI for casting local files to Chromecast devices. It supports: 7 | 8 | - Both audio and video files (anything `ffmpeg` can read) 9 | - Realtime transcoding (only when needed) 10 | - Subtitles (embedded and external SRT files) 11 | - Fast scrubbing (waiting 20s for buffering to skip 30s ahead is wrong!) 12 | - 4K videos on the Chromecast Ultra! 13 | 14 | What's New 15 | ---------- 16 | 17 | * `1.9`: Multi video/audio stream support. 18 | * `1.8`: 5.1/7.1 surround sound E/AC3 support. 19 | * `1.7`: Drag and drop files into the main UI. 20 | * `1.6`: Mutiple file / queuing support. 21 | 22 | Install 23 | ------- 24 | Please run: 25 | 26 | ``` 27 | $ sudo apt install ffmpeg python3-pip python3-gi 28 | $ pip3 install gnomecast 29 | ``` 30 | 31 | If installing in a `mkvirtualenv` built virtual environment, make sure you include the `--system-site-packages` parameter to get the GTK bindings. 32 | 33 | Run 34 | --- 35 | 36 | After installing, log out and log back in. It will be in your launcher: 37 | 38 | ![alt text](https://raw.githubusercontent.com/keredson/gnomecast/master/launcher.png) 39 | 40 | You can also run it from the command line: 41 | 42 | ``` 43 | $ gnomecast 44 | ``` 45 | 46 | Or: 47 | 48 | ``` 49 | $ python3 -m gnomecast 50 | ``` 51 | 52 | You can also configure the port used for the HTTP server via the environment variable `GNOMECAST_HTTP_PORT`: 53 | 54 | ``` 55 | $ GNOMECAST_HTTP_PORT=8010 python3 -m gnomecast 56 | ``` 57 | 58 | *Please report bugs, including video files that don't work for you!* 59 | 60 | Tests 61 | ----- 62 | 63 | Run the tests from the commandline: 64 | ``` 65 | $ python3 test_gnomecast.py 66 | ``` 67 | 68 | My File Won't Play! 69 | ------------------- 70 | 71 | Chromecasts are picky, and the built in media receiver doesn't give any feedback regarding why it won't play something. (It just flashes and quits on the main TV.) If your file won't play, please click the info button: 72 | 73 | ![image](https://user-images.githubusercontent.com/2049665/66446007-978b5780-e9fd-11e9-87cc-c01f07c67271.png) 74 | 75 | And then the "Report File Doesn't Play" button: 76 | 77 | ![image](https://user-images.githubusercontent.com/2049665/66446040-b12c9f00-e9fd-11e9-8acf-b3bc0d28c971.png) 78 | 79 | So I can fix it! 80 | 81 | Thanks To... 82 | ------------ 83 | 84 | - https://github.com/balloob/pychromecast 85 | - https://github.com/pbs/pycaption 86 | - https://www.ffmpeg.org/ 87 | 88 | And everyone who made this project hit [HN's front page](https://news.ycombinator.com/item?id=16386173) and #2 on GitHub's trending list! That's so awesome!!! 89 | 90 | ![alt text](https://raw.githubusercontent.com/keredson/gnomecast/master/trending.png) 91 | 92 | 93 | Transcoding 94 | ----------- 95 | Chromecasts only support a handful of media formats. See: https://developers.google.com/cast/docs/media 96 | 97 | So some amount of transcoding is necessary if your video files don't conform. But we're smart about it. If you have an `.mkv` file with `h264` video and `AAC` audio, we use `ffmpeg` to simply rewrite the container (to `.mp4`) without touching the underlying streams, which my XPS 13 can at around 100x realtime (it's fully IO bound). 98 | 99 | Now if you have that same `.mkv` file with and `A3C` audio stream (which Chromecast doesn't support) we'll rewrite the container, copy the `h264` stream as is and only transcode the audio (at about 20x). 100 | 101 | If neither your file's audio or video streams are supported, then it'll do a full transcode (at around 5x). 102 | 103 | We write the entire transcoded file to your `/tmp` directory in order to make scrubbing fast and glitch-free, a good trade-off IMO. Hopefully you're not running your drive at less than one video's worth of free space! 104 | 105 | Subtitles 106 | --------- 107 | Chromecast only supports a handful of subtitle formats, `.srt` not included. But it does support [WebVTT](https://w3c.github.io/webvtt/). So we extract whatever subtitles are in your video, convert them to WebVTT, and then reattach them to the video through Chomecast's API. 108 | -------------------------------------------------------------------------------- /gnomecast.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Encoding=UTF-8 4 | Name=Gnomecast 5 | Comment=GTK Chromecast Streamer 6 | Categories=AudioVideo; 7 | Exec=gnomecast 8 | Icon=gnomecast.svg 9 | Terminal=false 10 | -------------------------------------------------------------------------------- /gnomecast.py: -------------------------------------------------------------------------------- 1 | import contextlib, os, re, signal, socket, subprocess, sys, tempfile, threading, time, traceback, urllib 2 | 3 | 4 | DEPS_MET = True 5 | try: 6 | import pychromecast 7 | import bottle 8 | import html5lib.treebuilders 9 | 10 | # hack fixing pycaption needing an old version of html5lib 11 | if not hasattr(html5lib.treebuilders, '_base'): 12 | html5lib.treebuilders._base = html5lib.treebuilders.base 13 | 14 | import pycaption 15 | except Exception as e: 16 | traceback.print_exc() 17 | print(e) 18 | DEPS_MET = False 19 | 20 | DBUS_AVAILABLE = False 21 | try: 22 | import dbus 23 | DBUS_AVAILABLE = True 24 | except Exception as e: 25 | print(e) 26 | 27 | 28 | try: 29 | import gi 30 | gi.require_version('Gtk', '3.0') 31 | from gi.repository import Gtk, Gdk, GLib, GdkPixbuf, Gio 32 | except ImportError: 33 | line = "-"*70 34 | ERROR_MESSAGE = """ 35 | {} 36 | Python package "gi" (for building the GU not found.\n 37 | If on Debian or Ubuntu, please run: 38 | $ sudo apt-get install python3-gi\n 39 | For other distributions please look up the equivalent package.\n 40 | If this doesn't work, please report the error here: 41 | https://github.com/keredson/gnomecast\n 42 | Thanks! - Gnomecast 43 | {} 44 | """ 45 | print(ERROR_MESSAGE.format(line,line)) 46 | sys.exit(1) 47 | 48 | __version__ = '1.9.11' 49 | 50 | if DEPS_MET: 51 | pycaption.WebVTTWriter._encode = lambda self, s: s 52 | 53 | 54 | class Device: 55 | def __init__(self, h265=None, ac3=None): 56 | self.h265 = h265 57 | self.ac3 = ac3 58 | 59 | HARDWARE = { 60 | ('Unknown manufacturer','Chromecast'): Device(h265=False, ac3=False), 61 | ('Unknown manufacturer','Chromecast Ultra'): Device(h265=True, ac3=True), 62 | ('Unknown manufacturer','Google Home Mini'): Device(h265=False, ac3=False), 63 | ('Unknown manufacturer','Google Home'): Device(h265=False, ac3=False), 64 | ('VIZIO','P75-F1'): Device(h265=True, ac3=True), 65 | } 66 | 67 | 68 | 69 | 70 | def throttle(seconds=2): 71 | def decorator(f): 72 | timer = None 73 | lastest_args, latest_kwargs = None, None 74 | def run_f(): 75 | nonlocal timer, lastest_args, latest_kwargs 76 | ret = f(*lastest_args, **latest_kwargs) 77 | timer = None 78 | return ret 79 | def wrapper(*args, **kwargs): 80 | nonlocal timer, lastest_args, latest_kwargs 81 | lastest_args, latest_kwargs = args, kwargs 82 | if timer == None: 83 | timer = threading.Timer(seconds, run_f) 84 | timer.start() 85 | return wrapper 86 | return decorator 87 | 88 | 89 | 90 | 91 | def find_screensaver_dbus_iface(bus): 92 | """ Searches the DBus names for Screensaver and returns correct Interface""" 93 | if not DBUS_AVAILABLE: return None 94 | for path, name in [('org.freedesktop.ScreenSaver', '/ScreenSaver'), ('org.mate.ScreenSaver', '/ScreenSaver')]: 95 | try: 96 | saver = bus.get_object(path, name) 97 | return dbus.Interface(saver, dbus_interface=path) 98 | except dbus.exceptions.DBusException as e: 99 | # wrong path, try next one 100 | print(e) 101 | return None 102 | 103 | 104 | AUDIO_EXTS = ('aac', 'mp3', 'wav') 105 | 106 | 107 | def parse_ffmpeg_time(time_s): 108 | """ 109 | Converts ffmpeg's time string to number of seconds 110 | :param time_s: 111 | :return: number of seconds 112 | """ 113 | hours, minutes, seconds = (float(s) for s in time_s.split(':')) 114 | return hours * 60 * 60 + minutes * 60 + seconds 115 | 116 | 117 | 118 | class StreamMetadata: 119 | 120 | def __init__(self, index, codec, title=None): 121 | self.index = index 122 | self.codec = codec 123 | self.title = title 124 | 125 | def __repr__(self): 126 | fields = ['%s:%s'%(k,v) for k,v in self.__dict__.items() if v is not None and not k.startswith('_')] 127 | return '%s(%s)' % (self.__class__.__name__, ', '.join(fields)) 128 | 129 | class AudioMetadata(StreamMetadata): 130 | def __init__(self, *args, **kwargs): 131 | super().__init__(*args, **kwargs) 132 | self.channels = 2 133 | 134 | def details(self): 135 | if self.channels == 1: channels = 'mono' 136 | elif self.channels == 2: channels = 'stereo' 137 | elif self.channels == 6: channels = '5.1' 138 | elif self.channels == 8: channels = '7.1' 139 | else: channels = str(self.channels) 140 | return '%s (%s/%s)' % (self.title, self.codec, channels) 141 | 142 | 143 | class FileMetadata(object): 144 | 145 | def __init__(self, fn, callback=None, _ffmpeg_output=None): 146 | self.fn = fn 147 | self.ready = False 148 | def parse(): 149 | self.thumbnail_fn = None 150 | thumbnail_fn = tempfile.mkstemp(suffix='.jpg', prefix='gnomecast_pid%i_thumbnail_' % os.getpid())[1] 151 | os.remove(thumbnail_fn) 152 | self._ffmpeg_output = _ffmpeg_output if _ffmpeg_output else subprocess.check_output( 153 | ['ffmpeg', '-i', fn, '-f', 'ffmetadata', '-', '-f', 'mjpeg', '-vframes', '1', '-ss', '27', '-vf', 'scale=600:-1', thumbnail_fn], 154 | stderr=subprocess.STDOUT 155 | ).decode() 156 | _important_ffmpeg = [] 157 | if os.path.isfile(thumbnail_fn): 158 | self.thumbnail_fn = thumbnail_fn 159 | output = self._ffmpeg_output.split('\n') 160 | self.container = fn.lower().split(".")[-1] 161 | self.video_streams = [] 162 | self.audio_streams = [] 163 | self.subtitles = [] 164 | stream = None 165 | for line in output: 166 | line = line.strip() 167 | if line.startswith('ffmpeg version'): 168 | _important_ffmpeg.append(line) 169 | if line.startswith('Stream') and 'Video' in line: 170 | _important_ffmpeg.append(line) 171 | id = line.split()[1].strip('#').strip(':') 172 | title = 'Video #%i' % (len(self.video_streams)+1) 173 | if '(' in id: 174 | title = id[id.index('(')+1:id.index(')')] 175 | id = id[:id.index('(')] 176 | video_codec = line.split()[3] 177 | stream = StreamMetadata(id, video_codec, title=title) 178 | self.video_streams.append(stream) 179 | elif line.startswith('Stream') and 'Audio' in line: 180 | _important_ffmpeg.append(line) 181 | title = 'Audio #%i' % (len(self.audio_streams)+1) 182 | id = line.split()[1].strip('#').strip(':') 183 | if '(' in id: 184 | title = id[id.index('(')+1:id.index(')')] 185 | id = id[:id.index('(')] 186 | audio_codec = line.split()[3].strip(',') 187 | stream = AudioMetadata(id, audio_codec, title=title) 188 | if ', stereo, ' in line: stream.channels = 1 189 | if ', stereo, ' in line: stream.channels = 2 190 | if ', 5.1' in line: stream.channels = 6 191 | if ', 7.1' in line: stream.channels = 8 192 | self.audio_streams.append(stream) 193 | elif line.startswith('Stream') and 'Subtitle' in line: 194 | _important_ffmpeg.append(line) 195 | id = line.split()[1].strip('#').strip(':') 196 | print(line, id) 197 | if '(' in id: 198 | title = id[id.index('(')+1:id.index(')')] 199 | id = id[:id.index('(')] 200 | stream = StreamMetadata(id, None, title=title) 201 | self.subtitles.append(stream) 202 | elif stream and line.startswith('title'): 203 | _important_ffmpeg.append(line) 204 | stream.title = line.split()[2] 205 | elif line.startswith('Output'): 206 | break 207 | self._important_ffmpeg = '\n'.join(_important_ffmpeg) 208 | if not _ffmpeg_output: 209 | self.load_subtitles() 210 | self.ready = True 211 | if callback: callback(self) 212 | threading.Thread(target=parse).start() 213 | 214 | def wait(self): 215 | while not self.ready: 216 | time.sleep(1) 217 | 218 | def load_subtitles(self): 219 | if not self.subtitles: return 220 | cmd = ['ffmpeg', '-y', '-i', self.fn, '-vn', '-an',] 221 | files = [] 222 | for stream in self.subtitles: 223 | srt_fn = tempfile.mkstemp(suffix='.srt', prefix='gnomecast_pid%i_subtitles_' % os.getpid())[1] 224 | files.append(srt_fn) 225 | cmd += ['-map', stream.index, '-codec', 'srt', srt_fn] 226 | 227 | print(cmd) 228 | try: 229 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) 230 | for stream, srt_fn in zip(self.subtitles, files): 231 | try: 232 | with open(srt_fn) as f: 233 | caps = f.read() 234 | #print('caps', caps) 235 | converter = pycaption.CaptionConverter() 236 | converter.read(caps, pycaption.detect_format(caps)()) 237 | stream._subtitles = converter.write(pycaption.WebVTTWriter()) 238 | except Exception as e: 239 | traceback.print_exc() 240 | finally: 241 | os.remove(srt_fn) 242 | except subprocess.CalledProcessError as e: 243 | print('ERROR processing subtitles:', e) 244 | self.subtitles = [] 245 | 246 | 247 | def __repr__(self): 248 | fields = ['%s:%s'%(k,v) for k,v in self.__dict__.items() if not k.startswith('_')] 249 | return 'FileMetadata(%s)' % ', '.join(fields) 250 | 251 | def details(self): 252 | fields = [ 253 | 'File: %s' % os.path.basename(self.fn), 254 | 'Video: %s' % ', '.join(['%s (%s)' % (s.title, s.codec) for s in self.video_streams]), 255 | 'Audio: %s' % ', '.join([s.details() for s in self.audio_streams]), 256 | 'Subtitles: %s' % ', '.join([s.title for s in self.subtitles]), 257 | ] 258 | return '\n'.join(fields) 259 | 260 | 261 | class Transcoder(object): 262 | 263 | def __init__(self, cast, fmd, video_stream, audio_stream, done_callback, error_callback, prev_transcoder=None, force_audio=False, force_video=False, fake=False): 264 | self.fmd = fmd 265 | self.video_stream = video_stream 266 | self.audio_stream = audio_stream 267 | fn = fmd.fn 268 | self.cast = cast 269 | self.source_fn = fn 270 | self.p = None 271 | 272 | if prev_transcoder: 273 | prev_transcoder.destroy() 274 | 275 | print('Transcoder', fn) 276 | transcode_container = fmd.container not in ('mp4', 'aac', 'mp3', 'wav') 277 | self.transcode_video = force_video or not self.can_play_video_codec(video_stream.codec) 278 | self.transcode_audio = force_audio or fmd.container not in AUDIO_EXTS or not self.can_play_audio_stream(self.audio_stream) 279 | self.transcode = transcode_container or self.transcode_video or self.transcode_audio 280 | self.trans_fn = None 281 | 282 | self.progress_bytes = 0 283 | self.progress_seconds = 0 284 | self.done_callback = done_callback 285 | self.error_callback = error_callback 286 | print('transcode, transcode_video, transcode_audio', self.transcode, self.transcode_video, self.transcode_audio) 287 | if self.transcode: 288 | self.done = False 289 | dir = '/var/tmp' if os.path.isdir('/var/tmp') else None 290 | self.trans_fn = tempfile.mkstemp(suffix='.mp4', prefix='gnomecast_pid%i_transcode_' % os.getpid(), dir=dir)[1] 291 | os.remove(self.trans_fn) 292 | 293 | device_info = HARDWARE.get((self.cast.cast_info.manufacturer, self.cast.cast_info.model_name)) 294 | ac3 = device_info.ac3 if device_info else None 295 | transcode_audio_to = 'ac3' if (ac3 or ac3 is None) and audio_stream and audio_stream.channels > 2 else 'mp3' 296 | 297 | self.transcode_cmd = ['ffmpeg', '-i', self.source_fn, '-map', self.video_stream.index] 298 | if self.audio_stream: 299 | self.transcode_cmd += ['-map', self.audio_stream.index, '-c:a', transcode_audio_to if self.transcode_audio else 'copy'] + (['-b:a', '256k'] if self.transcode_audio else []) 300 | self.transcode_cmd += ['-c:v', 'h264' if self.transcode_video else 'copy'] # '-movflags', 'faststart' 301 | self.transcode_cmd += [self.trans_fn] 302 | print(' '.join(["'%s'"%s if ' ' in s else s for s in self.transcode_cmd])) 303 | if fake: 304 | self.p = None 305 | self.monitor() 306 | else: 307 | print('---------------------') 308 | print(' starting ffmpeg at:') 309 | print('---------------------') 310 | traceback.print_stack() 311 | self.p = subprocess.Popen(self.transcode_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 312 | t = threading.Thread(target=self.monitor) 313 | t.daemon = True 314 | t.start() 315 | else: 316 | self.done = True 317 | self.done_callback() 318 | 319 | @property 320 | def fn(self): 321 | return self.trans_fn if self.transcode else self.source_fn 322 | 323 | def can_play_video_codec(self, video_codec): 324 | h265 = True 325 | if self.cast.cast_info.cast_type == 'audio': h265 = False 326 | device_info = HARDWARE.get((self.cast.cast_info.manufacturer, self.cast.cast_info.model_name)) 327 | if device_info and device_info.h265 is not None: 328 | h265 = device_info.h265 329 | if h265: 330 | return video_codec in ('h264', 'h265', 'hevc') 331 | else: 332 | return video_codec in ('h264',) 333 | 334 | def can_play_audio_stream(self, stream): 335 | if not stream: return True 336 | device_info = HARDWARE.get((self.cast.cast_info.manufacturer, self.cast.cast_info.model_name)) 337 | ac3 = device_info.ac3 if device_info else None 338 | if ac3: 339 | return stream.codec in ('aac', 'mp3', 'ac3') 340 | else: 341 | return stream.codec in ('aac', 'mp3') 342 | 343 | def wait_for_byte(self, offset, buffer=128 * 1024 * 1024): 344 | if self.done: return 345 | if self.source_fn.lower().split(".")[-1] == 'mp4': 346 | while offset > self.progress_bytes + buffer: 347 | print('waiting for', offset, 'at', self.progress_bytes + buffer) 348 | time.sleep(2) 349 | else: 350 | while not self.done: 351 | print('waiting for transcode to finish') 352 | time.sleep(2) 353 | print('done waiting') 354 | 355 | def monitor(self): 356 | line = b'' 357 | r = re.compile(r'=\s+') 358 | total_output = b'' 359 | while self.p: 360 | byte = self.p.stdout.read(1) 361 | total_output += byte 362 | if byte == b'' and self.p.poll() != None: 363 | break 364 | if byte != b'': 365 | line += byte 366 | if byte == b'\r': 367 | # frame=92578 fps=3937 q=-1.0 size= 1142542kB time=01:04:21.14 bitrate=2424.1kbits/s speed= 164x 368 | line = line.decode() 369 | line = r.sub('=', line) 370 | items = [s.split('=') for s in line.split()] 371 | d = dict([x for x in items if len(x) == 2]) 372 | print(d) 373 | self.progress_bytes = int(d.get('size', '0kb')[:-2]) * 1024 374 | self.progress_seconds = parse_ffmpeg_time(d.get('time', '00:00:00')) 375 | line = b'' 376 | if self.p: 377 | self.p.stdout.close() 378 | if self.p.returncode: 379 | print('--== transcode error ==--') 380 | print(total_output) 381 | self.error_callback(total_output.decode()) 382 | return 383 | self.done = True 384 | if self.done_callback: 385 | self.done_callback(did_transcode=True) 386 | 387 | def destroy(self): 388 | if self.p and self.p.poll() is None: 389 | self.p.terminate() 390 | if self.trans_fn and os.path.isfile(self.trans_fn): 391 | os.remove(self.trans_fn) 392 | 393 | def __del__(self): 394 | self.destroy() 395 | 396 | 397 | class Gnomecast(object): 398 | 399 | def __init__(self): 400 | self.ip = (([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) + [None])[0] 401 | if 'GNOMECAST_HTTP_PORT' in os.environ: 402 | self.port = int(os.environ['GNOMECAST_HTTP_PORT']) 403 | else: 404 | with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: 405 | s.bind(('0.0.0.0', 0)) 406 | self.port = s.getsockname()[1] 407 | self.app = bottle.Bottle() 408 | self.cast = None 409 | self.last_known_player_state = None 410 | self.last_known_current_time = None 411 | self.last_time_current_time = None 412 | self.fn = None 413 | self.video_stream = None 414 | self.audio_stream = None 415 | self.last_fn_played = None 416 | self.transcoder = None 417 | self.duration = None 418 | self.subtitles = None 419 | self.seeking = False 420 | self.last_known_volume_level = None 421 | bus = dbus.SessionBus() if DBUS_AVAILABLE else None 422 | self.saver_interface = find_screensaver_dbus_iface(bus) 423 | self.inhibit_screensaver_cookie = None 424 | self.autoplay = False 425 | 426 | def run(self, fn=None, device=None, subtitles=None): 427 | self.build_gui() 428 | self.init_casts(device=device) 429 | threading.Thread(target=self.check_ffmpeg).start() 430 | t = threading.Thread(target=self.start_server) 431 | t.daemon = True 432 | t.start() 433 | t = threading.Thread(target=self.monitor_cast) 434 | t.daemon = True 435 | t.start() 436 | if fn: 437 | self.queue_files([fn]) 438 | if subtitles: 439 | self.select_subtitles_file(subtitles) 440 | if fn and subtitles: 441 | self.autoplay = True 442 | Gtk.main() 443 | 444 | def check_ffmpeg(self): 445 | time.sleep(1) 446 | ffmpeg_available = True 447 | print('check_ffmpeg') 448 | try: 449 | print(subprocess.check_output(['which', 'ffmpeg'])) 450 | except Exception as e: 451 | print(e, e.output) 452 | ffmpeg_available = False 453 | if not ffmpeg_available: 454 | def f(): 455 | dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "FFMPEG not Found") 456 | dialog.format_secondary_text("Could not find ffmpeg. Please run 'sudo apt-get install ffmpeg'.") 457 | dialog.run() 458 | dialog.destroy() 459 | # TODO: there's a weird pause here closing the dialog. why? 460 | sys.exit(1) 461 | GLib.idle_add(f) 462 | 463 | def start_server(self): 464 | app = self.app 465 | 466 | @app.route('/subtitles.vtt') 467 | def subtitles(): 468 | # response = bottle.static_file(self.subtitles_fn, root='/', mimetype='text/vtt') 469 | response = bottle.response 470 | response.headers['Access-Control-Allow-Origin'] = '*' 471 | response.headers['Access-Control-Allow-Methods'] = 'GET, HEAD' 472 | response.headers['Access-Control-Allow-Headers'] = 'Content-Type' 473 | response.headers['Content-Type'] = 'text/vtt' 474 | return self.subtitles 475 | 476 | @app.get('/media/.') 477 | def video(id, ext): 478 | print(list(bottle.request.headers.items())) 479 | ranges = list(bottle.parse_range_header(bottle.request.environ['HTTP_RANGE'], 1000000000000)) 480 | print('ranges', ranges) 481 | offset, end = ranges[0] 482 | self.transcoder.wait_for_byte(offset) 483 | response = bottle.static_file(self.transcoder.fn, root='/') 484 | if 'Last-Modified' in response.headers: 485 | del response.headers['Last-Modified'] 486 | response.headers['Access-Control-Allow-Origin'] = '*' 487 | response.headers['Access-Control-Allow-Methods'] = 'GET, HEAD' 488 | response.headers['Access-Control-Allow-Headers'] = 'Content-Type' 489 | return response 490 | 491 | # app.run(host=self.ip, port=self.port, server='paste', daemon=True) 492 | from paste import httpserver 493 | from paste.translogger import TransLogger 494 | handler = TransLogger(app, setup_console_handler=True) 495 | httpserver.serve(handler, host=self.ip, port=str(self.port), daemon_threads=True) 496 | 497 | def update_status(self, did_transcode=False): 498 | if did_transcode: 499 | self.update_button_visible() 500 | self.prep_next_transcode() 501 | # if self.last_known_player_state and self.last_known_player_state!='UNKNOWN': 502 | # notes.append('Cast: %s' % self.last_known_player_state) 503 | def f(): 504 | for row in self.files_store: 505 | duration = row[2] 506 | transcoder = row[7] 507 | if transcoder: 508 | if duration: 509 | if transcoder.done: 510 | row[5] = 100 511 | else: 512 | row[5] = transcoder.progress_seconds*100 // duration 513 | GLib.idle_add(f) 514 | 515 | def monitor_cast(self): 516 | while True: 517 | time.sleep(1) 518 | if not self.cast: continue 519 | seeking = self.seeking 520 | cast = self.cast 521 | mc = cast.media_controller 522 | if mc.status.player_state != self.last_known_player_state: 523 | if mc.status.player_state=='PLAYING' and self.last_known_player_state=='BUFFERING' and seeking: 524 | self.seeking = False 525 | if mc.status.player_state=='IDLE' and self.last_known_player_state=='PLAYING': 526 | self.check_for_next_in_queue() 527 | if mc.status.player_state=='PLAYING': 528 | self.inhibit_screensaver() 529 | else: 530 | self.restore_screensaver() 531 | self.last_known_player_state = mc.status.player_state 532 | def f(): 533 | self.update_media_button_states() 534 | self.update_status() 535 | GLib.idle_add(f) 536 | elif self.transcoder and not self.transcoder.done: 537 | def f(): 538 | self.update_status() 539 | GLib.idle_add(f) 540 | if self.last_known_current_time != mc.status.current_time: 541 | self.last_known_current_time = mc.status.current_time 542 | self.last_time_current_time = time.time() 543 | if not seeking and mc.status.player_state=='PLAYING': 544 | GLib.idle_add(lambda: self.scrubber_adj.set_value(mc.status.current_time + time.time() - self.last_time_current_time)) 545 | 546 | def init_casts(self, widget=None, device=None): 547 | self.cast_store.clear() 548 | self.cast_store.append([None, "Searching local network - please wait..."]) 549 | self.cast_combo.set_active(0) 550 | threading.Thread(target=self.load_casts, kwargs={'device':device}).start() 551 | 552 | def inhibit_screensaver(self): 553 | if not self.saver_interface or self.inhibit_screensaver_cookie: return 554 | self.inhibit_screensaver_cookie = self.saver_interface.Inhibit("Gnomecast", "Player is playing...") 555 | print('disabled screensaver') 556 | 557 | def restore_screensaver(self): 558 | if self.saver_interface and self.inhibit_screensaver_cookie: 559 | self.saver_interface.UnInhibit(self.inhibit_screensaver_cookie) 560 | self.inhibit_screensaver_cookie = None 561 | print('restored screensaver') 562 | 563 | def load_casts(self, device=None): 564 | chromecasts = pychromecast.get_chromecasts() 565 | # workaround for https://github.com/home-assistant-libs/pychromecast/issues/398 566 | if isinstance(chromecasts, tuple) and len(chromecasts)==2: 567 | chromecasts = chromecasts[0] 568 | def f(): 569 | self.cast_store.clear() 570 | self.cast_store.append([None, "Select a cast device..."]) 571 | self.cast_store.append([-1, 'Add a non-local Chromecast...']) 572 | for cc in chromecasts: 573 | friendly_name = cc.cast_info.friendly_name 574 | if cc.cast_type!='cast': 575 | friendly_name = '%s (%s)' % (friendly_name, cc.cast_type) 576 | self.cast_store.append([cc, friendly_name]) 577 | if device: 578 | found = False 579 | for i, cc in enumerate(chromecasts): 580 | if device == cc.cast_info.friendly_name: 581 | self.cast_combo.set_active(i+1) 582 | found = True 583 | if not found: 584 | self.cast_combo.set_active(0) 585 | dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Chromecast Not Found") 586 | dialog.format_secondary_text("The Chromecast '%s' wasn't found." % device) 587 | dialog.run() 588 | dialog.destroy() 589 | else: 590 | self.cast_combo.set_active(2 if len(chromecasts) == 1 else 0) 591 | GLib.idle_add(f) 592 | 593 | def update_media_button_states(self): 594 | mc = self.cast.media_controller if self.cast else None 595 | self.play_button.set_sensitive(bool(self.transcoder and self.cast and mc.status.player_state in ('BUFFERING','PLAYING','PAUSED','IDLE','UNKNOWN') and self.fn)) 596 | self.volume_button.set_sensitive(bool(self.cast)) 597 | self.stop_button.set_sensitive(bool(self.transcoder and self.cast and mc.status.player_state in ('BUFFERING','PLAYING','PAUSED'))) 598 | self.rewind_button.set_sensitive(bool(self.transcoder and self.cast and mc.status.player_state in ('BUFFERING','PLAYING','PAUSED'))) 599 | self.forward_button.set_sensitive(bool(self.transcoder and self.cast and mc.status.player_state in ('BUFFERING','PLAYING','PAUSED'))) 600 | self.play_button.set_image(Gtk.Image(stock=Gtk.STOCK_MEDIA_PAUSE) if self.cast and mc.status.player_state=='PLAYING' else Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY)) 601 | if self.transcoder and self.duration: 602 | self.scrubber_adj.set_upper(self.duration) 603 | self.scrubber.set_sensitive(True) 604 | else: 605 | self.scrubber.set_sensitive(False) 606 | self.update_button_visible() 607 | 608 | 609 | def build_gui(self): 610 | self.win = win = Gtk.ApplicationWindow(title='Gnomecast v%s' % __version__) 611 | win.set_border_width(0) 612 | win.set_icon(self.get_logo_pixbuf(color='#000000')) 613 | enforce_target = Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags(4), 129) 614 | win.drag_dest_set(Gtk.DestDefaults.ALL, [enforce_target], Gdk.DragAction.COPY) 615 | win.connect("drag-data-received", self.on_drag_data_received) 616 | self.cast_store = cast_store = Gtk.ListStore(object, str) 617 | 618 | vbox_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) 619 | vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=16) 620 | 621 | self.thumbnail_image = Gtk.Image() 622 | self.thumbnail_image.set_from_pixbuf(self.get_logo_pixbuf()) 623 | vbox_outer.pack_start(self.thumbnail_image, True, False, 0) 624 | alignment = Gtk.Alignment(xscale=1, yscale=1) 625 | alignment.add(vbox) 626 | alignment.set_padding(16, 20, 16, 16) 627 | vbox_outer.pack_start(alignment, False, False, 0) 628 | 629 | hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8) 630 | vbox.pack_start(hbox, False, False, 0) 631 | self.cast_combo = cast_combo = Gtk.ComboBox.new_with_model(cast_store) 632 | cast_combo.set_entry_text_column(1) 633 | renderer_text = Gtk.CellRendererText() 634 | cast_combo.pack_start(renderer_text, True) 635 | cast_combo.add_attribute(renderer_text, "text", 1) 636 | hbox.pack_start(cast_combo, True, True, 0) 637 | refresh_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_REFRESH)) 638 | refresh_button.connect("clicked", self.init_casts) 639 | hbox.pack_start(refresh_button, False, False, 0) 640 | 641 | win.add(vbox_outer) 642 | 643 | # list of queued files 644 | self.files_store = Gtk.ListStore(str, str, int, str, str, int, str, object, object) # name, path, duration, duration_str, thumbnail_fn, transcode_progress, status_icon, transcoder, file_metadata 645 | self.files_store.connect("row-inserted", self.update_button_visible) 646 | self.files_store.connect("row-deleted", self.update_button_visible) 647 | self.files_view = Gtk.TreeView(self.files_store) 648 | self.files_view.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) 649 | self.files_view.set_headers_visible(False) 650 | self.files_view.set_rules_hint(True) 651 | column = Gtk.TreeViewColumn("Name", Gtk.CellRendererText(), text=0) 652 | column.set_expand(True) 653 | self.files_view.append_column(column) 654 | self.file_view_column_renderer = r = Gtk.CellRendererText() 655 | r.props.xalign = 1.0 656 | self.files_view.append_column(Gtk.TreeViewColumn("Duration", r, text=3)) 657 | self.files_view_progress_column = column_progress = Gtk.TreeViewColumn("Progress", Gtk.CellRendererProgress(), value=5) 658 | self.files_view.append_column(column_progress) 659 | 660 | column_pixbuf = Gtk.TreeViewColumn("Playing", Gtk.CellRendererPixbuf(), icon_name=6) 661 | self.files_view.append_column(column_pixbuf) 662 | 663 | select = self.files_view.get_selection() 664 | select.connect("changed", self.on_files_view_selection_changed) 665 | self.files_view.connect("row-activated", self.on_files_view_row_activated) 666 | 667 | 668 | # contains the files list and the buttons to add/del 669 | self.hbox = hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8) 670 | vbox.pack_start(hbox, False, False, 0) 671 | 672 | self.scrolled_window = Gtk.ScrolledWindow() 673 | self.scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) 674 | self.scrolled_window.add(self.files_view) 675 | hbox.pack_start(self.scrolled_window, True, True, 0) 676 | 677 | self.btn_vbox = btn_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8) 678 | hbox.pack_start(btn_vbox, True, True, 0) 679 | self.file_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_ADD)) 680 | self.file_button.set_tooltip_text('Add one or more audio or video files...') 681 | self.file_button.set_always_show_image(True) 682 | self.file_button.connect("clicked", self.on_file_clicked) 683 | btn_vbox.pack_start(self.file_button, True, True, 0) 684 | self.remove_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_REMOVE)) 685 | self.remove_button.set_tooltip_text('Overwrite original file with transcoded version.') 686 | self.remove_button.connect("clicked", self.remove_files) 687 | self.remove_button.set_sensitive(False) 688 | btn_vbox.pack_start(self.remove_button, False, False, 0) 689 | 690 | self.file_detail_row = hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8) 691 | vbox.pack_start(self.file_detail_row, False, False, 0) 692 | 693 | # audio/video track selection 694 | self.stream_store = Gtk.ListStore(str, object, object) 695 | self.audio_combo = Gtk.ComboBox.new_with_model(self.stream_store) 696 | self.audio_combo.connect("changed", self.on_audio_combo_changed) 697 | self.audio_combo.set_entry_text_column(0) 698 | renderer_text = Gtk.CellRendererText() 699 | self.audio_combo.pack_start(renderer_text, True) 700 | self.audio_combo.add_attribute(renderer_text, "text", 0) 701 | self.file_detail_row.pack_start(self.audio_combo, True, True, 0) 702 | 703 | # subtitle selection 704 | self.subtitle_store = Gtk.ListStore(str, object, object) # title, stream, callback 705 | self.subtitle_combo = Gtk.ComboBox.new_with_model(self.subtitle_store) 706 | self.subtitle_combo.connect("changed", self.on_subtitle_combo_changed) 707 | self.subtitle_combo.set_entry_text_column(0) 708 | renderer_text = Gtk.CellRendererText() 709 | self.subtitle_combo.pack_start(renderer_text, True) 710 | self.subtitle_combo.add_attribute(renderer_text, "text", 0) 711 | self.subtitle_combo.set_active(0) 712 | self.file_detail_row.pack_start(self.subtitle_combo, True, True, 0) 713 | 714 | file_info_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_DIALOG_INFO)) 715 | file_info_button.connect("clicked", self.show_file_info) 716 | self.file_detail_row.pack_start(file_info_button, False, False, 0) 717 | 718 | self.scrubber_adj = Gtk.Adjustment(0, 0, 100, 15, 60, 0) 719 | self.scrubber = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=self.scrubber_adj) 720 | self.scrubber.set_digits(0) 721 | def f(scale, s): 722 | notes = [self.humanize_seconds(s)] 723 | return ''.join(notes) 724 | self.scrubber.connect("format-value", f) 725 | self.scrubber.connect("change-value", self.scrubber_move_started) 726 | self.scrubber.connect("change-value", self.scrubber_moved) 727 | self.scrubber.set_sensitive(False) 728 | vbox.pack_start(self.scrubber, False, False, 0) 729 | 730 | hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=16) 731 | self.rewind_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_REWIND)) 732 | self.rewind_button.connect("clicked", self.rewind_clicked) 733 | self.rewind_button.set_sensitive(False) 734 | self.rewind_button.set_relief(Gtk.ReliefStyle.NONE) 735 | hbox.pack_start(self.rewind_button, True, False, 0) 736 | self.play_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY)) 737 | self.play_button.connect("clicked", self.play_clicked) 738 | self.play_button.set_sensitive(False) 739 | self.play_button.set_relief(Gtk.ReliefStyle.NONE) 740 | hbox.pack_start(self.play_button, True, False, 0) 741 | self.forward_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_FORWARD)) 742 | self.forward_button.connect("clicked", self.forward_clicked) 743 | self.forward_button.set_sensitive(False) 744 | self.forward_button.set_relief(Gtk.ReliefStyle.NONE) 745 | hbox.pack_start(self.forward_button, True, False, 0) 746 | self.stop_button = Gtk.Button(None, image=Gtk.Image(stock=Gtk.STOCK_MEDIA_STOP)) 747 | self.stop_button.connect("clicked", self.stop_clicked) 748 | self.stop_button.set_sensitive(False) 749 | self.stop_button.set_relief(Gtk.ReliefStyle.NONE) 750 | hbox.pack_start(self.stop_button, True, False, 0) 751 | self.volume_button = Gtk.VolumeButton() 752 | self.volume_button.set_value(1) 753 | self.volume_button.connect("value-changed", self.volume_moved) 754 | self.volume_button.set_sensitive(False) 755 | hbox.pack_start(self.volume_button, True, False, 0) 756 | vbox.pack_start(hbox, False, False, 0) 757 | 758 | cast_combo.connect("changed", self.on_cast_combo_changed) 759 | 760 | win.connect("delete-event", self.quit) 761 | win.connect("key_press_event", self.on_key_press) 762 | win.show_all() 763 | 764 | self.update_button_visible() 765 | 766 | win.resize(1,1) 767 | 768 | GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.quit) 769 | 770 | 771 | def add_extra_subtitle_options(self): 772 | self.subtitle_store.prepend(["No subtitles.", None, None]) 773 | self.subtitle_store.append(["Add subtitle file...", None, self.on_new_subtitle_clicked]) 774 | #self.subtitle_store.append(["Download...", None, self.on_download_subtitle_clicked]) 775 | self.subtitle_combo.set_active(0) 776 | 777 | def on_drag_data_received(self, widget, drag_context, x,y, data,info, time): 778 | fn = data.get_text() 779 | if fn.startswith('file://'): 780 | fn = urllib.parse.unquote(fn[len('file://'):]).strip() 781 | self.queue_files([fn]) 782 | 783 | def update_button_visible(self, x=None, y=None, z=None): 784 | print('update_button_visible') 785 | count = len(self.files_store) 786 | self.scrolled_window.set_visible(count) 787 | self.remove_button.set_visible(count) 788 | self.file_button.set_label('' if count else ' Add one or more audio or video files...') 789 | self.file_button.get_child().set_padding(1,0,2,0) # w/ an empty label the + icon isn't quite centered 790 | self.hbox.set_child_packing(self.btn_vbox, not count, not count, 0, Gtk.PackType.START) 791 | self.file_detail_row.set_visible(bool(self.fn)) 792 | 793 | def scrubber_move_started(self, scale, scroll_type, seconds): 794 | print('scrubber_move_started', seconds) 795 | self.seeking = True 796 | 797 | def on_files_view_selection_changed(self, selection): 798 | model, treeiter = selection.get_selected_rows() 799 | self.remove_button.set_sensitive(bool(treeiter)) 800 | 801 | def remove_files(self, w): 802 | store, paths = self.files_view.get_selection().get_selected_rows() 803 | for path in reversed(paths): 804 | print('remove', path) 805 | iterx = store.get_iter(path) 806 | transcoder = store.get_value(iterx, 7) 807 | if transcoder: 808 | transcoder.destroy() 809 | fn = store.get_value(iterx, 1) 810 | store.remove(iterx) 811 | if self.fn == fn: 812 | self.unselect_file() 813 | 814 | 815 | def on_files_view_row_activated(self, widget, row, col): 816 | model = widget.get_model() 817 | print('double-clicked', model[row][:]) 818 | fn = model[row][1] 819 | self.unselect_file() 820 | self.fn = fn 821 | self.transcoder = model[row][7] 822 | self.duration = model[row][2] 823 | thumbnail_fn = model[row][4] 824 | if thumbnail_fn and os.path.isfile(thumbnail_fn): 825 | self.thumbnail_image.set_from_file(thumbnail_fn) 826 | if self.cast: 827 | self.cast.media_controller.stop() 828 | def f(): 829 | self.win.resize(1,1) 830 | self.scrubber_adj.set_value(0) 831 | for row in self.files_store: 832 | if self.fn == row[1]: 833 | row[6] = 'video-x-generic' 834 | else: 835 | row[6] = None 836 | self.update_button_visible() 837 | self.update_media_button_states() 838 | GLib.idle_add(f) 839 | 840 | 841 | return True 842 | 843 | def queue_files(self, files): 844 | existing_files = set([row[1] for row in self.files_store]) 845 | files = [f for f in files if f not in existing_files] 846 | for fn in files: 847 | display = os.path.basename(fn) 848 | MAX_LEN = 40 849 | if len(display) > MAX_LEN: 850 | display = display[:MAX_LEN-10] + '...' + display[-10:] 851 | def callback(fmd): 852 | print(fmd) 853 | if os.path.isfile(fmd.thumbnail_fn): 854 | for row in self.files_store: 855 | if row[1]==fmd.fn: 856 | row[4] = fmd.thumbnail_fn 857 | def f(): 858 | if self.fn == fmd.fn and fmd.thumbnail_fn: 859 | self.thumbnail_image.set_from_file(fmd.thumbnail_fn) 860 | self.win.resize(1,1) 861 | self.update_status() 862 | GLib.idle_add(f) 863 | fmd = FileMetadata(fn, callback) 864 | self.files_store.append([display, fn, None, '...', None, None, None, None, fmd]) 865 | threading.Thread(target=self.get_info, args=[fn]).start() 866 | self.scrolled_window.set_visible(True) 867 | if len(files) and self.fn is None: 868 | self.select_file(files[0]) 869 | path = Gtk.TreePath().new_first() 870 | _1, _2, width, height = self.files_view_progress_column.cell_get_size() 871 | height += self.file_view_column_renderer.get_padding().ypad*2 872 | height += 2 # measured - row lines? 873 | self.scrolled_window.set_min_content_height(height*min(len(self.files_store),6)) 874 | 875 | 876 | @throttle(seconds=1) 877 | def volume_moved(self, button, volume): 878 | if self.last_known_volume_level != volume: 879 | self.last_known_volume_level = volume 880 | self.cast.set_volume(volume) 881 | print('setting volume', volume) 882 | 883 | @throttle() 884 | def scrubber_moved(self, scale, scroll_type, seconds): 885 | print('scrubber_moved', seconds) 886 | self.seeking = True 887 | self.cast.media_controller.seek(seconds) 888 | 889 | def humanize_seconds(self, s): 890 | s = int(s) 891 | hours = s // (60*60) 892 | minutes = (s // 60) % 60 893 | seconds = s % 60 894 | if hours: 895 | return '%ih %im %is' % (hours, minutes, seconds) 896 | if minutes: 897 | return '%im %is' % (minutes, seconds) 898 | else: 899 | return '%is' % (seconds) 900 | 901 | def stop_clicked(self, widget): 902 | if not self.cast: return 903 | self.cast.media_controller.stop() 904 | 905 | def get_logo_pixbuf(self, width=200, color=None): 906 | svg = LOGO_SVG 907 | if color: 908 | svg = svg.replace('#aaaaaa', color) 909 | f = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(svg.encode())) 910 | preserve_aspect_ratio = True 911 | pixbuf = GdkPixbuf.Pixbuf.new_from_stream(f, None) 912 | return pixbuf 913 | 914 | 915 | def quit(self, a=0, b=0): 916 | for row in self.files_store: 917 | transcoder = row[7] 918 | if transcoder: 919 | transcoder.destroy() 920 | thumbnail_fn = row[4] 921 | if thumbnail_fn and os.path.isfile(thumbnail_fn): 922 | os.remove(thumbnail_fn) 923 | self.restore_screensaver() 924 | Gtk.main_quit() 925 | 926 | def forward_clicked(self, widget): 927 | self.seek_delta(30) 928 | 929 | def rewind_clicked(self, widget): 930 | self.seek_delta(-10) 931 | 932 | def seek_delta(self, delta): 933 | seconds = self.cast.media_controller.status.current_time + time.time() - self.last_time_current_time + delta 934 | self.last_time_current_time = time.time() 935 | self.cast.media_controller.status.current_time = seconds 936 | self.scrubber_adj.set_value(seconds) 937 | self.seeking = True 938 | self.cast.media_controller.seek(seconds) 939 | 940 | def play_clicked(self, widget): 941 | if not self.cast: 942 | print('no cast selected') 943 | return 944 | cast = self.cast 945 | mc = cast.media_controller 946 | 947 | print('mc.status.player_state', mc.status.player_state, self.fn, hash(self.fn)) 948 | if mc.status.player_state in ('IDLE','UNKNOWN') or self.last_fn_played != self.fn: 949 | self.last_fn_played = self.fn 950 | cast.wait() 951 | mc = cast.media_controller 952 | kwargs = {} 953 | if self.subtitles: 954 | kwargs['subtitles'] = 'http://%s:%s/subtitles.vtt' % (self.ip, self.port) 955 | current_time = self.scrubber_adj.get_value() 956 | if current_time: 957 | kwargs['current_time'] = current_time 958 | ext = self.fn.split('.')[-1] 959 | ext = ''.join(ch for ch in ext if ch.isalnum()).lower() 960 | mc.play_media('http://%s:%s/media/%s.%s' % (self.ip, self.port, hash(self.fn), ext), 'audio/%s'%ext if ext in AUDIO_EXTS else 'video/mp4', **kwargs) 961 | print(cast.status) 962 | print(mc.status) 963 | self.prep_next_transcode() 964 | elif mc.status.player_state=='PLAYING': 965 | mc.pause() 966 | elif mc.status.player_state=='PAUSED': 967 | mc.play() 968 | 969 | def on_file_clicked(self, widget): 970 | dialog = Gtk.FileChooserDialog("Please choose an audio or video file...", self.win, 971 | Gtk.FileChooserAction.OPEN, 972 | (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, 973 | Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) 974 | dialog.set_select_multiple(True) 975 | 976 | downloads_dir = os.path.expanduser('~/Downloads') 977 | if os.path.isdir(downloads_dir): 978 | dialog.set_current_folder(downloads_dir) 979 | 980 | filter_py = Gtk.FileFilter() 981 | filter_py.set_name("Videos") 982 | filter_py.add_mime_type("video/*") 983 | filter_py.add_mime_type("audio/*") 984 | dialog.add_filter(filter_py) 985 | 986 | response = dialog.run() 987 | if response == Gtk.ResponseType.OK: 988 | print("Open clicked") 989 | print("File selected:", dialog.get_filenames()) 990 | self.queue_files(dialog.get_filenames()) 991 | #self.select_file(dialog.get_filename()) 992 | elif response == Gtk.ResponseType.CANCEL: 993 | print("Cancel clicked") 994 | 995 | dialog.destroy() 996 | 997 | def on_new_subtitle_clicked(self): 998 | dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win, 999 | Gtk.FileChooserAction.OPEN, 1000 | (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, 1001 | Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) 1002 | 1003 | if self.fn: 1004 | dialog.set_current_folder(os.path.dirname(self.fn)) 1005 | 1006 | filter_py = Gtk.FileFilter() 1007 | filter_py.set_name("Subtitles") 1008 | filter_py.add_pattern("*.srt") 1009 | filter_py.add_pattern("*.vtt") 1010 | dialog.add_filter(filter_py) 1011 | 1012 | response = dialog.run() 1013 | if response == Gtk.ResponseType.OK: 1014 | print("Open clicked") 1015 | print("File selected: " + dialog.get_filename()) 1016 | self.select_subtitles_file(dialog.get_filename()) 1017 | elif response == Gtk.ResponseType.CANCEL: 1018 | print("Cancel clicked") 1019 | self.subtitle_combo.set_active(0) 1020 | 1021 | dialog.destroy() 1022 | 1023 | def on_download_subtitle_clicked(self): 1024 | dialog = Gtk.FileChooserDialog("Please choose a subtitle file...", self.win, 1025 | Gtk.FileChooserAction.OPEN, 1026 | (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, 1027 | Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) 1028 | 1029 | if self.fn: 1030 | dialog.set_current_folder(os.path.dirname(self.fn)) 1031 | 1032 | filter_py = Gtk.FileFilter() 1033 | filter_py.set_name("Subtitles") 1034 | filter_py.add_pattern("*.srt") 1035 | filter_py.add_pattern("*.vtt") 1036 | dialog.add_filter(filter_py) 1037 | 1038 | response = dialog.run() 1039 | if response == Gtk.ResponseType.OK: 1040 | print("Open clicked") 1041 | print("File selected: " + dialog.get_filename()) 1042 | self.select_subtitles_file(dialog.get_filename()) 1043 | elif response == Gtk.ResponseType.CANCEL: 1044 | print("Cancel clicked") 1045 | self.subtitle_combo.set_active(0) 1046 | 1047 | dialog.destroy() 1048 | 1049 | def select_subtitles_file(self, fn): 1050 | if not os.path.isfile(fn): 1051 | def f(): 1052 | dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "File Not Found") 1053 | dialog.format_secondary_text("Could not find subtitles file: %s" % fn) 1054 | dialog.run() 1055 | dialog.destroy() 1056 | GLib.idle_add(f) 1057 | return 1058 | fn = os.path.abspath(fn) 1059 | ext = fn.split('.')[-1] 1060 | display_name = os.path.basename(fn) 1061 | if ext=='vtt': 1062 | with open(fn) as f: 1063 | self.subtitles = f.read() 1064 | else: 1065 | with open(fn,'rb') as f: 1066 | caps = f.read() 1067 | try: caps = caps.decode() 1068 | except UnicodeDecodeError: caps = caps.decode('latin-1') 1069 | if caps.startswith('\ufeff'): # BOM 1070 | caps = caps[1:] 1071 | converter = pycaption.CaptionConverter() 1072 | converter.read(caps, pycaption.detect_format(caps)()) 1073 | self.subtitles = converter.write(pycaption.WebVTTWriter()) 1074 | pos = len(self.subtitle_store) 1075 | stream = StreamMetadata(None, None, title=display_name) 1076 | stream._subtitles = self.subtitles 1077 | self.subtitle_store.append([display_name, stream, None]) 1078 | self.subtitle_combo.set_active(pos) 1079 | 1080 | def unselect_file(self): 1081 | self.thumbnail_image.set_from_pixbuf(self.get_logo_pixbuf()) 1082 | self.fn = None 1083 | self.stream_store.clear() 1084 | self.subtitle_store.clear() 1085 | self.subtitle_combo.set_active(0) 1086 | self.transcoder = None 1087 | self.duration = None 1088 | if self.cast: 1089 | self.cast.media_controller.stop() 1090 | def f(): 1091 | self.scrubber_adj.set_value(0) 1092 | for row in self.files_store: 1093 | row[6] = None 1094 | self.win.resize(1,1) 1095 | self.update_button_visible() 1096 | GLib.idle_add(f) 1097 | 1098 | def select_file(self, fn): 1099 | self.unselect_file() 1100 | if not os.path.isfile(fn): 1101 | def f(): 1102 | dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "File Not Found") 1103 | dialog.format_secondary_text("Could not find media file: %s" % fn) 1104 | dialog.run() 1105 | dialog.destroy() 1106 | GLib.idle_add(f) 1107 | return 1108 | fn = os.path.abspath(fn) 1109 | self.thumbnail_image.set_from_pixbuf(self.get_logo_pixbuf()) 1110 | self.fn = fn 1111 | self.stream_store.clear() 1112 | self.subtitle_store.clear() 1113 | if self.cast: 1114 | self.cast.media_controller.stop() 1115 | def f(): 1116 | self.scrubber_adj.set_value(0) 1117 | for row in self.files_store: 1118 | thumbnail_fn = row[4] 1119 | if self.fn == row[1]: 1120 | if thumbnail_fn: 1121 | self.thumbnail_image.set_from_file(thumbnail_fn) 1122 | self.win.resize(1,1) 1123 | row[6] = 'video-x-generic' 1124 | self.duration = row[2] 1125 | else: 1126 | row[6] = None 1127 | threading.Thread(target=self.update_transcoders).start() 1128 | threading.Thread(target=self.update_audio_tracks).start() 1129 | threading.Thread(target=self.update_subtitles).start() 1130 | self.update_button_visible() 1131 | self.update_media_button_states() 1132 | GLib.idle_add(f) 1133 | 1134 | update_transcoders_lock = threading.Lock() 1135 | 1136 | def update_transcoders(self): 1137 | with self.update_transcoders_lock: 1138 | if self.cast and self.fn: 1139 | transcoder = None 1140 | for row in self.files_store: 1141 | if row[1]!=self.fn: continue 1142 | transcoder = row[7] 1143 | fmd = row[8] 1144 | fmd.wait() 1145 | if not self.video_stream: self.video_stream = fmd.video_streams[0] 1146 | if not self.audio_stream and fmd.audio_streams: self.audio_stream = fmd.audio_streams[0] 1147 | if not transcoder or self.cast != transcoder.cast or self.fn != transcoder.source_fn or self.audio_stream!=transcoder.audio_stream: 1148 | self.transcoder = Transcoder(self.cast, fmd, self.video_stream, self.audio_stream, lambda did_transcode=None: GLib.idle_add(self.update_status, did_transcode), self.error_callback, transcoder) 1149 | row[7] = self.transcoder 1150 | if self.autoplay: 1151 | self.autoplay = False 1152 | self.play_clicked(None) 1153 | if not self.cast: 1154 | for row in self.files_store: 1155 | transcoder = row[7] 1156 | if transcoder: 1157 | transcoder.destroy() 1158 | row[7] = None 1159 | GLib.idle_add(self.update_media_button_states) 1160 | 1161 | def check_for_next_in_queue(self): 1162 | next = False 1163 | for row in self.files_store: 1164 | fn = row[1] 1165 | if next: 1166 | print('check_for_next_in_queue', fn) 1167 | self.autoplay = True 1168 | self.select_file(fn) 1169 | next = False 1170 | if self.cast and self.fn and self.fn == fn: 1171 | next = True 1172 | 1173 | def prep_next_transcode(self): 1174 | transcode_next = False 1175 | for row in self.files_store: 1176 | fn = row[1] 1177 | transcoder = row[7] 1178 | fmd = row[8] 1179 | if transcode_next and not transcoder: 1180 | print('prep_next_transcode', fn) 1181 | transcoder = Transcoder(self.cast, fmd, fmd.video_streams[0] if fmd.video_streams else None, fmd.audio_streams[0] if fmd.audio_streams else None, lambda did_transcode=None: GLib.idle_add(self.update_status, did_transcode), self.error_callback, transcoder) 1182 | row[7] = transcoder 1183 | transcode_next = False 1184 | if self.cast and self.fn and self.fn == fn and transcoder and transcoder.done: 1185 | transcode_next = True 1186 | 1187 | def get_info(self, fn): 1188 | cmd = ['ffprobe', '-i', fn] 1189 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) 1190 | for line in output.decode().split('\n'): 1191 | line = line.strip() 1192 | if line.startswith('Duration:'): 1193 | duration = parse_ffmpeg_time(line.split()[1].strip(',')) 1194 | if fn == self.fn: 1195 | self.duration = duration 1196 | for row in self.files_store: 1197 | if row[1]==fn: 1198 | row[2] = duration 1199 | row[3] = self.humanize_seconds(duration) 1200 | 1201 | def get_fmd(self): 1202 | for row in self.files_store: 1203 | fn = row[1] 1204 | fmd = row[8] 1205 | if self.fn == fn: 1206 | return fmd 1207 | 1208 | def update_subtitles(self): 1209 | fmd = self.get_fmd() 1210 | fmd.wait() 1211 | def f(): 1212 | self.subtitle_store.clear() 1213 | pos = len(self.subtitle_store) 1214 | for stream in fmd.subtitles: 1215 | self.subtitle_store.append([stream.title, stream, None]) 1216 | pos += 1 1217 | self.add_extra_subtitle_options() 1218 | GLib.idle_add(f) 1219 | ext = self.fn.split('.')[-1] 1220 | sexts = ['vtt', 'srt'] 1221 | for sext in sexts: 1222 | if os.path.isfile(self.fn[:-len(ext)] + sext): 1223 | self.select_subtitles_file(self.fn[:-len(ext)] + sext) 1224 | break 1225 | 1226 | def update_audio_tracks(self): 1227 | fmd = self.get_fmd() 1228 | fmd.wait() 1229 | def f(): 1230 | self.stream_store.clear() 1231 | for video_stream in fmd.video_streams: 1232 | for audio_stream in fmd.audio_streams: 1233 | self.stream_store.append(['%s - %s' % (video_stream.title, audio_stream.title), video_stream, audio_stream]) 1234 | self.audio_combo.set_active(0) 1235 | GLib.idle_add(f) 1236 | 1237 | def on_key_press(self, widget, event, user_data=None): 1238 | key = Gdk.keyval_name(event.keyval) 1239 | ctrl = (event.state & Gdk.ModifierType.CONTROL_MASK) 1240 | if key=='q' and ctrl: 1241 | self.quit() 1242 | return True 1243 | return False 1244 | 1245 | def select_cast(self, cast): 1246 | self.cast = cast 1247 | if cast: 1248 | # cast.media_controller.app_id = 'FF0F6B72' 1249 | self.last_known_volume_level = cast.media_controller.status.volume_level 1250 | self.volume_button.set_value(cast.media_controller.status.volume_level) 1251 | self.last_known_player_state = None 1252 | self.update_media_button_states() 1253 | threading.Thread(target=self.update_transcoders).start() 1254 | 1255 | 1256 | def error_callback(self, msg): 1257 | def f(): 1258 | dialogWindow = Gtk.MessageDialog(self.win, 1259 | Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, 1260 | Gtk.MessageType.INFO, 1261 | Gtk.ButtonsType.OK, 1262 | '\nGnomecast encountered an error converting your file.') 1263 | dialogWindow.set_title('Transcoding Error') 1264 | dialogWindow.set_default_size(1, 400) 1265 | 1266 | dialogBox = dialogWindow.get_content_area() 1267 | buffer1 = Gtk.TextBuffer() 1268 | buffer1.set_text(msg) 1269 | text_view = Gtk.TextView(buffer=buffer1) 1270 | text_view.set_editable(False) 1271 | scrolled_window = Gtk.ScrolledWindow() 1272 | scrolled_window.set_border_width(5) 1273 | # we scroll only if needed 1274 | scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 1275 | scrolled_window.add(text_view) 1276 | dialogBox.pack_end(scrolled_window, True, True, 0) 1277 | dialogWindow.show_all() 1278 | response = dialogWindow.run() 1279 | dialogWindow.destroy() 1280 | GLib.idle_add(f) 1281 | 1282 | 1283 | def show_file_info(self, b=None): 1284 | print('show_file_info') 1285 | fmd = self.get_fmd() 1286 | msg = '\n' + fmd.details() 1287 | if self.cast: 1288 | msg += '\nDevice: %s (%s)' % (self.cast.cast_info.model_name, self.cast.cast_info.manufacturer) 1289 | msg += '\nChromecast: v%s' % (__version__) 1290 | dialogWindow = Gtk.MessageDialog(self.win, 1291 | Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, 1292 | Gtk.MessageType.INFO, 1293 | Gtk.ButtonsType.OK, 1294 | msg) 1295 | dialogWindow.set_title('File Info') 1296 | dialogWindow.set_default_size(1, 400) 1297 | 1298 | if self.cast: 1299 | title = 'Error playing %s' % os.path.basename(self.fn) 1300 | body = ''' 1301 | [Please describe what happened here...] 1302 | 1303 | [Please link to the download here...] 1304 | 1305 | ``` 1306 | [If possible, please run `ffprobe -i ` and paste the output here...] 1307 | ``` 1308 | 1309 | ------------------------------------------------------------ 1310 | 1311 | %s 1312 | 1313 | %s 1314 | 1315 | ```%s```''' % (msg, fmd, fmd._important_ffmpeg) 1316 | url = 'https://github.com/keredson/gnomecast/issues/new?title=%s&body=%s' % (urllib.parse.quote(title), urllib.parse.quote(body)) 1317 | dialogWindow.add_action_widget(Gtk.LinkButton(url, label="Report File Doesn't Play"), 10) 1318 | 1319 | 1320 | dialogBox = dialogWindow.get_content_area() 1321 | buffer1 = Gtk.TextBuffer() 1322 | buffer1.set_text(fmd._ffmpeg_output) 1323 | text_view = Gtk.TextView(buffer=buffer1) 1324 | text_view.set_editable(False) 1325 | scrolled_window = Gtk.ScrolledWindow() 1326 | scrolled_window.set_border_width(5) 1327 | # we scroll only if needed 1328 | scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) 1329 | scrolled_window.add(text_view) 1330 | dialogBox.pack_end(scrolled_window, True, True, 0) 1331 | 1332 | dialogWindow.show_all() 1333 | response = dialogWindow.run() 1334 | dialogWindow.destroy() 1335 | 1336 | def get_nonlocal_cast(self): 1337 | dialogWindow = Gtk.MessageDialog(self.win, 1338 | Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, 1339 | Gtk.MessageType.QUESTION, 1340 | Gtk.ButtonsType.OK_CANCEL, 1341 | '\nPlease specify the IP address or hostname of a Chromecast device:') 1342 | 1343 | dialogWindow.set_title('Add a non-local Chromecast') 1344 | 1345 | dialogBox = dialogWindow.get_content_area() 1346 | userEntry = Gtk.Entry() 1347 | # userEntry.set_size_request(250,0) 1348 | dialogBox.pack_end(userEntry, False, False, 0) 1349 | 1350 | dialogWindow.show_all() 1351 | response = dialogWindow.run() 1352 | text = userEntry.get_text() 1353 | dialogWindow.destroy() 1354 | if (response == Gtk.ResponseType.OK) and (text != ''): 1355 | print(text) 1356 | try: 1357 | cast = pychromecast.Chromecast(text) 1358 | self.cast_store.append([cast, text]) 1359 | self.cast_combo.set_active(len(self.cast_store)-1) 1360 | except pychromecast.error.ChromecastConnectionError: 1361 | dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Chromecast Not Found") 1362 | dialog.format_secondary_text("The Chromecast '%s' wasn't found." % text) 1363 | dialog.run() 1364 | dialog.destroy() 1365 | 1366 | def on_cast_combo_changed(self, combo): 1367 | tree_iter = combo.get_active_iter() 1368 | if tree_iter is not None: 1369 | model = combo.get_model() 1370 | cast, name = model[tree_iter][:2] 1371 | if cast==-1: 1372 | self.get_nonlocal_cast() 1373 | else: 1374 | print(cast) 1375 | self.select_cast(cast) 1376 | else: 1377 | entry = combo.get_child() 1378 | 1379 | def on_subtitle_combo_changed(self, combo): 1380 | tree_iter = combo.get_active_iter() 1381 | if tree_iter is not None: 1382 | model = combo.get_model() 1383 | text, stream, callback = model[tree_iter] 1384 | print('chose subtitle', text, stream, callback) 1385 | if callback: callback() 1386 | else: 1387 | self.subtitles = stream._subtitles if stream else None 1388 | mc = self.cast.media_controller if self.cast else None 1389 | if mc and mc.status.player_state in ('BUFFERING','PLAYING','PAUSED'): 1390 | self.stop_clicked(None) 1391 | self.cast.wait() 1392 | def f(): self.play_clicked(None) 1393 | threading.Timer(1, lambda: GLib.idle_add(f)).start() 1394 | else: 1395 | entry = combo.get_child() 1396 | 1397 | def on_audio_combo_changed(self, combo): 1398 | tree_iter = combo.get_active_iter() 1399 | if tree_iter is not None: 1400 | model = combo.get_model() 1401 | text, video_stream, audio_stream = model[tree_iter] 1402 | print(text, video_stream, audio_stream) 1403 | self.video_stream = video_stream 1404 | self.audio_stream = audio_stream 1405 | threading.Thread(target=self.update_transcoders).start() 1406 | 1407 | 1408 | 1409 | # this is embedded here because i gave up trying to get pip to handle a non-python file 1410 | LOGO_SVG = ''' 1411 | 1412 | 1413 | 1427 | 1429 | 1430 | 1432 | image/svg+xml 1433 | 1435 | 1436 | 1437 | 1438 | 1439 | 1463 | 1465 | 1468 | 1471 | 1475 | 1478 | 1483 | 1488 | 1493 | 1498 | 1503 | 1504 | 1505 | 1506 | 1507 | 1510 | 1515 | 1516 | ''' 1517 | 1518 | def arg_parse(args, kw_synonyms, f, usage): 1519 | kw = None 1520 | f_args = [] 1521 | f_kwargs = {} 1522 | for arg in args: 1523 | if arg.startswith('-'): 1524 | if kw: 1525 | f_kwargs[kw] = True 1526 | arg = arg.lstrip('-') 1527 | kw = kw_synonyms.get(arg, arg) 1528 | else: 1529 | if kw: 1530 | f_kwargs[kw] = arg 1531 | else: 1532 | f_args.append(arg) 1533 | kw = None 1534 | if kw: 1535 | f_kwargs[kw] = True 1536 | try: 1537 | f(*f_args, **f_kwargs) 1538 | except TypeError as e: 1539 | msg = str(e).split('()',1)[1].strip() 1540 | print('ERROR:', msg) 1541 | print(usage) 1542 | sys.exit(1) 1543 | 1544 | USAGE = ''' 1545 | python gnomecast.py [] [-d|--device ] [-s|--subtitles ] 1546 | '''.strip() 1547 | 1548 | 1549 | def pid_running(pid): 1550 | try: 1551 | os.kill(pid, 0) 1552 | except OSError: 1553 | return False 1554 | else: 1555 | return True 1556 | 1557 | def delete_old_transcodes(): 1558 | # if process is killed old transcoded files can be left around 1559 | # delete if found 1560 | for tmpdir in ['/tmp','/var/tmp']: 1561 | for fn in os.listdir(tmpdir): 1562 | if not fn.startswith('gnomecast_'): continue 1563 | fn = os.path.join(tmpdir, fn) 1564 | match = re.search(r'gnomecast_pid(\d+)_', fn) 1565 | if match: 1566 | pid = int(match.group(1)) 1567 | if not pid_running(pid): 1568 | print('\tpid', pid, 'is dead, so deleting', fn) 1569 | os.remove(fn) 1570 | else: 1571 | print('old style gnomecast file', fn, 'found, so deleting...') 1572 | os.remove(fn) 1573 | 1574 | 1575 | def main(): 1576 | delete_old_transcodes() 1577 | caster = Gnomecast() 1578 | arg_parse(sys.argv[1:], {'s':'subtitles', 'd':'device'}, caster.run, USAGE) 1579 | 1580 | if DEPS_MET and __name__=='__main__': 1581 | main() 1582 | 1583 | 1584 | -------------------------------------------------------------------------------- /gnomecast.pyproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | 2.0 6 | {d27f42e0-77f0-4143-a8d1-2af05b9e1e51} 7 | 8 | gnomecast.py 9 | 10 | . 11 | . 12 | {888888a0-9f3d-457c-b088-3a5042f75d52} 13 | Standard Python launcher 14 | {9a7a9026-48c1-4688-9d5d-e5699d47d074} 15 | 3.4 16 | 17 | 18 | 19 | 20 | 10.0 21 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /gnomecast.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "gnomecast", "gnomecast.pyproj", "{D27F42E0-77F0-4143-A8D1-2AF05B9E1E51}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D27F42E0-77F0-4143-A8D1-2AF05B9E1E51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D27F42E0-77F0-4143-A8D1-2AF05B9E1E51}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /icons/gnomecast.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 20 | 21 | 23 | image/svg+xml 24 | 26 | 27 | 28 | 29 | 30 | 54 | 56 | 59 | 62 | 66 | 69 | 74 | 79 | 84 | 89 | 94 | 95 | 96 | 97 | 98 | 101 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /icons/gnomecast_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keredson/gnomecast/d42d8915838b01c5cadacb322909e08ffa455d4f/icons/gnomecast_16.png -------------------------------------------------------------------------------- /icons/gnomecast_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keredson/gnomecast/d42d8915838b01c5cadacb322909e08ffa455d4f/icons/gnomecast_48.png -------------------------------------------------------------------------------- /launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keredson/gnomecast/d42d8915838b01c5cadacb322909e08ffa455d4f/launcher.png -------------------------------------------------------------------------------- /receiver.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | html5lib==1.0b8 2 | pychromecast 3 | bottle 4 | pycaption 5 | paste 6 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keredson/gnomecast/d42d8915838b01c5cadacb322909e08ffa455d4f/screenshot.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from setuptools import setup 4 | 5 | def long_description(): 6 | os.system('pandoc --from=markdown --to=rst --output=README.rst README.md') 7 | readme_fn = os.path.join(os.path.dirname(__file__), 'README.rst') 8 | if os.path.exists(readme_fn): 9 | with open(readme_fn) as f: 10 | return f.read() 11 | else: 12 | return 'not available' 13 | 14 | setup( 15 | name='gnomecast', 16 | version=__import__('gnomecast').__version__, 17 | description='A native Linux GUI for Chromecasting local files.', 18 | long_description=long_description(), 19 | author='Derek Anderson', 20 | author_email='public@kered.org', 21 | url='https://github.com/keredson/gnomecast', 22 | py_modules=['gnomecast'], 23 | classifiers=[ 24 | 'Development Status :: 5 - Production/Stable', 25 | 'Intended Audience :: End Users/Desktop', 26 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 27 | 'Operating System :: OS Independent', 28 | 'Programming Language :: Python', 29 | 'Programming Language :: Python :: 3', 30 | ], 31 | install_requires=['pychromecast','bottle','pycaption','paste','html5lib'], 32 | data_files=[ 33 | ('share/icons/hicolor/16x16/apps', ['icons/gnomecast_16.png']), 34 | ('share/icons/hicolor/48x48/apps', ['icons/gnomecast_48.png']), 35 | ('share/icons/hicolor/scalable/apps', ['icons/gnomecast.svg']), 36 | ('share/applications', ['gnomecast.desktop']) 37 | ], 38 | entry_points={ 39 | 'gui_scripts': [ 40 | 'gnomecast = gnomecast:main', 41 | ] 42 | } 43 | ) 44 | 45 | 46 | -------------------------------------------------------------------------------- /test_gnomecast.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import gnomecast 3 | 4 | 5 | class FakeCast: 6 | def __init__(self, cast_type=None, manufacturer=None, model_name=None): 7 | self.device = FakeDevice(cast_type=cast_type, manufacturer=manufacturer, model_name=model_name) 8 | 9 | class FakeDevice: 10 | def __init__(self, **kwargs): 11 | self.__dict__.update(kwargs) 12 | 13 | 14 | 15 | class TestGnomecast(unittest.TestCase): 16 | 17 | def test_1(self): 18 | fmd = gnomecast.FileMetadata( 19 | 'pCU2GE07KW4.mkv', 20 | _ffmpeg_output = ''' 21 | ffprobe version 4.1.4 Copyright (c) 2007-2019 the FFmpeg developers 22 | built with gcc 9 (GCC) 23 | configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect 24 | libavutil 56. 22.100 / 56. 22.100 25 | libavcodec 58. 35.100 / 58. 35.100 26 | libavformat 58. 20.100 / 58. 20.100 27 | libavdevice 58. 5.100 / 58. 5.100 28 | libavfilter 7. 40.101 / 7. 40.101 29 | libavresample 4. 0. 0 / 4. 0. 0 30 | libswscale 5. 3.100 / 5. 3.100 31 | libswresample 3. 3.100 / 3. 3.100 32 | libpostproc 55. 3.100 / 55. 3.100 33 | Input #0, matroska,webm, from 'pCU2GE07KW4.mkv': 34 | Metadata: 35 | COMPATIBLE_BRANDS: iso6avc1mp41 36 | MAJOR_BRAND : dash 37 | MINOR_VERSION : 0 38 | ENCODER : Lavf58.20.100 39 | Duration: 00:41:45.28, start: -0.007000, bitrate: 1303 kb/s 40 | Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default) 41 | Metadata: 42 | HANDLER_NAME : ISO Media file produced by Google Inc. 43 | DURATION : 00:41:45.269000000 44 | Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default) 45 | Metadata: 46 | DURATION : 00:41:45.281000000 47 | ''') 48 | fmd.wait() 49 | 50 | self.assertEqual(fmd.container, 'mkv') 51 | self.assertEqual(len(fmd.video_streams), 1) 52 | self.assertEqual(fmd.video_streams[0].index, '0:0') 53 | self.assertEqual(fmd.video_streams[0].codec, 'h264') 54 | self.assertEqual(len(fmd.audio_streams), 1) 55 | self.assertEqual(fmd.audio_streams[0].index, '0:1') 56 | self.assertEqual(fmd.audio_streams[0].codec, 'opus') 57 | self.assertEqual(fmd.audio_streams[0].title, 'eng') 58 | self.assertEqual(fmd.audio_streams[0].channels, 2) 59 | self.assertEqual(len(fmd.subtitles), 0) 60 | 61 | cast = FakeCast(cast_type='video', manufacturer='Unknown manufacturer', model_name='Chromecast') 62 | transcoder = gnomecast.Transcoder(cast, fmd, fmd.video_streams[0], fmd.audio_streams[0], None, fake=True) 63 | 64 | self.assertEqual(transcoder.transcode_cmd[:-1], ['ffmpeg', '-i', 'pCU2GE07KW4.mkv', '-map', '0:0', '-map', '0:1', '-c:v', 'copy', '-c:a', 'mp3', '-b:a', '256k']) 65 | 66 | def test_2(self): 67 | fmd = gnomecast.FileMetadata( 68 | 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv', 69 | _ffmpeg_output = ''' 70 | Input #0, matroska,webm, from 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv': 71 | Metadata: 72 | title : Godzilla: King of the Monsters 73 | encoder : libebml v1.3.7 + libmatroska v1.5.0 74 | creation_time : 2019-08-23T10:49:27.000000Z 75 | Duration: 02:11:43.19, start: 0.000000, bitrate: 18112 kb/s 76 | Chapter #0:0: start 0.000000, end 653.694708 77 | Metadata: 78 | title : Chapter 01 79 | Chapter #0:1: start 653.694708, end 1086.585500 80 | Metadata: 81 | title : Chapter 02 82 | Chapter #0:2: start 1086.585500, end 1827.325500 83 | Metadata: 84 | title : Chapter 03 85 | Chapter #0:3: start 1827.325500, end 2718.632583 86 | Metadata: 87 | title : Chapter 04 88 | Chapter #0:4: start 2718.632583, end 3250.830917 89 | Metadata: 90 | title : Chapter 05 91 | Chapter #0:5: start 3250.830917, end 3941.646042 92 | Metadata: 93 | title : Chapter 06 94 | Chapter #0:6: start 3941.646042, end 4171.292125 95 | Metadata: 96 | title : Chapter 07 97 | Chapter #0:7: start 4171.292125, end 4771.308208 98 | Metadata: 99 | title : Chapter 08 100 | Chapter #0:8: start 4771.308208, end 5406.067333 101 | Metadata: 102 | title : Chapter 09 103 | Chapter #0:9: start 5406.067333, end 5916.785875 104 | Metadata: 105 | title : Chapter 10 106 | Chapter #0:10: start 5916.785875, end 6598.508583 107 | Metadata: 108 | title : Chapter 11 109 | Chapter #0:11: start 6598.508583, end 7168.536375 110 | Metadata: 111 | title : Chapter 12 112 | Chapter #0:12: start 7168.536375, end 7903.104000 113 | Metadata: 114 | title : Chapter 13 115 | Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x1600, SAR 1:1 DAR 12:5, 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default) 116 | Metadata: 117 | BPS-eng : 17115721 118 | DURATION-eng : 02:11:43.104000000 119 | NUMBER_OF_FRAMES-eng: 189485 120 | NUMBER_OF_BYTES-eng: 16908415995 121 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 122 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 123 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 124 | Stream #0:1(eng): Audio: aac (LC), 48000 Hz, 7.1, fltp (default) 125 | Metadata: 126 | BPS-eng : 901426 127 | DURATION-eng : 02:11:43.104000000 128 | NUMBER_OF_FRAMES-eng: 370458 129 | NUMBER_OF_BYTES-eng: 890507991 130 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 131 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 132 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 133 | Stream #0:2(eng): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp 134 | Metadata: 135 | title : Commentary 136 | BPS-eng : 65862 137 | DURATION-eng : 02:11:43.147000000 138 | NUMBER_OF_FRAMES-eng: 185230 139 | NUMBER_OF_BYTES-eng: 65064850 140 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 141 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 142 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 143 | Stream #0:3(eng): Subtitle: dvd_subtitle, 1920x1080 144 | Metadata: 145 | BPS-eng : 8966 146 | DURATION-eng : 02:11:18.819000000 147 | NUMBER_OF_FRAMES-eng: 1661 148 | NUMBER_OF_BYTES-eng: 8830829 149 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 150 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 151 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 152 | Stream #0:4(ara): Subtitle: dvd_subtitle, 1920x1080 153 | Metadata: 154 | BPS-eng : 4132 155 | DURATION-eng : 02:10:49.414000000 156 | NUMBER_OF_FRAMES-eng: 1373 157 | NUMBER_OF_BYTES-eng: 4055035 158 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 159 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 160 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 161 | Stream #0:5(chi): Subtitle: dvd_subtitle, 1920x1080 162 | Metadata: 163 | BPS-eng : 6291 164 | DURATION-eng : 02:10:44.329000000 165 | NUMBER_OF_FRAMES-eng: 1246 166 | NUMBER_OF_BYTES-eng: 6169396 167 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 168 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 169 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 170 | Stream #0:6(fre): Subtitle: dvd_subtitle, 1920x1080 171 | Metadata: 172 | BPS-eng : 6451 173 | DURATION-eng : 02:10:49.539000000 174 | NUMBER_OF_FRAMES-eng: 1276 175 | NUMBER_OF_BYTES-eng: 6330309 176 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 177 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 178 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 179 | Stream #0:7(kor): Subtitle: dvd_subtitle, 1920x1080 180 | Metadata: 181 | BPS-eng : 4593 182 | DURATION-eng : 02:10:44.333000000 183 | NUMBER_OF_FRAMES-eng: 1359 184 | NUMBER_OF_BYTES-eng: 4504269 185 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 186 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 187 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 188 | Stream #0:8(spa): Subtitle: dvd_subtitle, 1920x1080 189 | Metadata: 190 | BPS-eng : 7522 191 | DURATION-eng : 02:10:44.409000000 192 | NUMBER_OF_FRAMES-eng: 1392 193 | NUMBER_OF_BYTES-eng: 7376389 194 | _STATISTICS_WRITING_APP-eng: mkvmerge v32.0.0 ('Astral Progressions') 64-bit 195 | _STATISTICS_WRITING_DATE_UTC-eng: 2019-08-23 10:49:27 196 | _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES 197 | ''') 198 | fmd.wait() 199 | self.assertEqual(fmd.container, 'mkv') 200 | self.assertEqual(len(fmd.video_streams), 1) 201 | self.assertEqual(fmd.video_streams[0].index, '0:0') 202 | self.assertEqual(fmd.video_streams[0].codec, 'hevc') 203 | self.assertEqual(len(fmd.audio_streams), 2) 204 | self.assertEqual(fmd.audio_streams[0].index, '0:1') 205 | self.assertEqual(fmd.audio_streams[0].codec, 'aac') 206 | self.assertEqual(fmd.audio_streams[0].title, 'eng') 207 | self.assertEqual(fmd.audio_streams[0].channels, 8) 208 | self.assertEqual(fmd.audio_streams[1].index, '0:2') 209 | self.assertEqual(fmd.audio_streams[1].codec, 'aac') 210 | self.assertEqual(fmd.audio_streams[1].title, 'Commentary') 211 | self.assertEqual(fmd.audio_streams[1].channels, 2) 212 | self.assertEqual(len(fmd.subtitles), 6) 213 | self.assertEqual([s.title for s in fmd.subtitles], ['eng', 'ara', 'chi', 'fre', 'kor', 'spa']) 214 | 215 | print(fmd) 216 | 217 | cast = FakeCast(cast_type='video', manufacturer='Unknown manufacturer', model_name='Chromecast Ultra') 218 | 219 | transcoder = gnomecast.Transcoder(cast, fmd, fmd.video_streams[0], fmd.audio_streams[0], None, fake=True) 220 | self.assertEqual(transcoder.transcode_cmd[:-1], ['ffmpeg', '-i', 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv', '-map', '0:0', '-map', '0:1', '-c:v', 'copy', '-c:a', 'ac3', '-b:a', '256k']) 221 | 222 | transcoder = gnomecast.Transcoder(cast, fmd, fmd.video_streams[0], fmd.audio_streams[1], None, fake=True) 223 | self.assertEqual(transcoder.transcode_cmd[:-1], ['ffmpeg', '-i', 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv', '-map', '0:0', '-map', '0:2', '-c:v', 'copy', '-c:a', 'mp3', '-b:a', '256k']) 224 | 225 | cast = FakeCast(cast_type='video', manufacturer='Unknown manufacturer', model_name='Chromecast') 226 | transcoder = gnomecast.Transcoder(cast, fmd, fmd.video_streams[0], fmd.audio_streams[0], None, fake=True) 227 | self.assertEqual(transcoder.transcode_cmd[:-1], ['ffmpeg', '-i', 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv', '-map', '0:0', '-map', '0:1', '-c:v', 'h264', '-c:a', 'mp3', '-b:a', '256k']) 228 | 229 | cast = FakeCast(cast_type='video', manufacturer='VIZIO', model_name='P75-F1') 230 | transcoder = gnomecast.Transcoder(cast, fmd, fmd.video_streams[0], fmd.audio_streams[0], None, fake=True) 231 | self.assertEqual(transcoder.transcode_cmd[:-1], ['ffmpeg', '-i', 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv', '-map', '0:0', '-map', '0:1', '-c:v', 'copy', '-c:a', 'ac3', '-b:a', '256k']) 232 | 233 | cast = FakeCast(cast_type='video', manufacturer='UNK', model_name='UNK') 234 | transcoder = gnomecast.Transcoder(cast, fmd, fmd.video_streams[0], fmd.audio_streams[0], None, fake=True) 235 | self.assertEqual(transcoder.transcode_cmd[:-1], ['ffmpeg', '-i', 'Godzilla - King of the Monsters (2019) (2160p BluRay x265 10bit HDR Tigole).mkv', '-map', '0:0', '-map', '0:1', '-c:v', 'copy', '-c:a', 'ac3', '-b:a', '256k']) 236 | 237 | 238 | if __name__ == '__main__': 239 | unittest.main() 240 | -------------------------------------------------------------------------------- /trending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keredson/gnomecast/d42d8915838b01c5cadacb322909e08ffa455d4f/trending.png -------------------------------------------------------------------------------- /www/gnomecast.css: -------------------------------------------------------------------------------- 1 | .background { 2 | background: center no-repeat url(background.png); 3 | background-color: #999999; 4 | } 5 | 6 | .logo { 7 | background-image: url(screenshot.png); 8 | } 9 | 10 | .progressBar { 11 | background-color: rgb(238, 255, 165); 12 | } 13 | 14 | .splash { 15 | background-image: url(splash.png); 16 | } 17 | 18 | .watermark { 19 | background-image: url(watermark.png); 20 | background-size: 57px 57px; 21 | } 22 | -------------------------------------------------------------------------------- /www/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keredson/gnomecast/d42d8915838b01c5cadacb322909e08ffa455d4f/www/screenshot.png --------------------------------------------------------------------------------