├── LICENSE ├── README.md ├── channels-transcoder.prefs ├── channels-transcoder.sh ├── com.getchannels.channels-transcoder.plist ├── ifttt-maker-transcode-plex.png ├── install.sh └── monitor_jobs.sh /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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | # Channels-DVR-to-Plex 2 | 3 | Channels DVR (https://community.getchannels.com/dvr/) is an extremely user friendly piece of software for recording TV from Silicondust HDHomeRun network TV tuners and, primarily, for serving to the Channels app on the Apple TV 4. However, it is somewhat limited in its ability to serve to other clients and outside of a local network. I have found it convenient to automatically transcode recorded shows to an h.264 format and add them to a Plex (http://plex.tv) server. This avoids the need for live transcoding to most devices, enabling lower power hardware and more optimized algorithms to minimize bandwidth. 4 | 5 | Please note that this has not been thoroughly tested on all systems, and that it is to be used at your own risk. It has so far been tested on (at least) Ubuntu 16.04 Xenial (arm64) and Mac OS Sierra 10.12 (intel x86-64). This is sub-beta quality right now! Feel free to take it and make it your own, or contribute to this archive, as long as you share your work and operate within the license. 6 | 7 | Pre-requisites on unix systems (including Mac) are working versions of Channels DVR and Plex Media Server, as well as the following utilities: jq, curl, coreutils, AtomicParsley (optional, preferably >= 0.9.6) and GNU parallel (>= 20161222). These can be installed e.g. `apt-get install jq curl coreutils atomicparsley parallel` on Debian/Ubuntu Linux. On a Mac, install the homebrew software first (http://brew.sh/), then run `brew install jq curl coreutils atomicparsley parallel`. Be sure to check version numbers installed against requirements, which may change over time. 8 | 9 | The Channels-DVR-to-Plex software can be installed using the *install.sh* script, thus: 10 | 11 | `curl https://raw.githubusercontent.com/karllmitchell/Channels-DVR-to-Plex/master/install.sh > install.sh; bash install.sh` 12 | 13 | Do NOT pipe to bash, or use any other type of shell, or it will fail. Note that this can also be used to update existing configurations. 14 | 15 | When running the install script, consider carefully the question about number of days backlog to transcode, as this can take a long time. DAYS=0 is pretty safe, and you can always transcode missed shows later from the command line. 16 | 17 | The final step is that you'll need to go to your Plex web interface and add the TV Shows and Movies folder within your desination directory to your Plex library. By default these are "${HOME}/Movies/Plex/TV Shows" and "${HOME}/Movies/Plex/Movies". 18 | 19 | For 90% of you, and the TL;DR crowd, that's probably enough to get you going. 20 | 21 | **The main script** 22 | 23 | *channels-transcoder.sh* requires bash, and is designed primarily to run as a nightly job, preferably after all commercial scanning is over (12:01 AM by default), although it has additional functionality when run via the command line too. It can be installed either on the same machine as runs Channels DVR, or on another machine as long as you set the HOST variable; Note that it will copy files across the network in this latter mode. The advantage of this is that you can run a very low powered machine (ARM board or NAS) for the recording, and then use another higher-powered machine for the transcoding, potentially letting it sleep most of the time. By default it lives in /usr/local/bin. 24 | 25 | At the core of the script is ffmpeg, which performs the transcoding via libx264; The same script that performs transcoding from the web interface of Channels DVR. By default I have it set up to produce high quality full resolution outputs that look good on a full HDTV with Apple TV, which also runs on most devices that are capable of 1080p playback. Both closed captions and sound are preserved from the original MPEG, and if surround sound exists then a stereo track is added for more universal compatibility. However, unfortunately Plex at the moment does not support the ability to play back these closed captions, something I'm hoping to fix eventually. 26 | 27 | Although the code will run on extremely underpowered systems, including low cost ARM-based SOCs runnings Linux, by default I do not recommend anything with less than 1 GByte, preferable 2 GBytes, of RAM (certainly at least 750 MBytes unused). If you are accessing the inputs files across a network, you will want a fast one (Gigabit throughout, ideally), or to set aside at least a few tens of GBytes of storage and use the TEMP_COPY=1 argument. Many modern intel systems can almost certainly process faster-than-realtime (i.e. a 1-hr show will take less than 1-hr), but an ARM SOC like a Raspberry Pi would probably be about 6x slower than real-time, and might not keep up with your TV viewing. 28 | 29 | **Set up, first run and the transcode database** 30 | 31 | On this first run (or install script), the code will initialise a database that lists previously transcoded recordings. Note that it will by default not transcode any previously recorded shows unless you respond to the DAYS prompt when asked (install script). You can reset this database using the command-line with these options: 32 | 33 | `channels-transcoder.sh CLEAR_DB=1 DAYS=N` 34 | 35 | where N is the number of days backlog you want clearing (so e.g. DAYS=7). This will reset the database and mark all previously recorded shows (before N days ago) as having already been transcoded. This may take a long time, depending on your system and how much stuff you have. DO NOT run transcode-plex.sh again until this is complete. The install script will handle most of this for you. 36 | 37 | **Subsequent runs** 38 | 39 | From now on, channels-transcoder.sh should work fine if run on a repeated cycle, e.g. every 24 hours. If an existing instance of it running is found, or if Channels DVR is recording or comskipping, it will wait up to a user-defined amount of time (default=82800 seconds or 23 hours) before executing. If more than one existing instance is found, channels-transcoder.sh will exit immediately. Note that HandBrakeCLI h.264 encoding is well optimized for multiple CPUs/threads, and so most of the time there is little benefit to running it multiple times. 40 | 41 | Setting BUSY_WAIT=0 will prevent waiting for Channels DVR or channels-transcoder activity to cease, although it will still quit if 2+ instances of channels-transcoder are found. 42 | 43 | If you want something specific transcoded ASAP, and have no concerns about resources, you can override this behaviour with BUSY_WAIT=0, typically in conjunction with DAYS=0. 44 | 45 | **Preferences file** 46 | 47 | The preferences file, typically in ~/.channels-transcoder/prefs or ~/Library/Application Support/channels-transcoder/prefs, has a lot of settings. This might seem intimidating, but most are not needed for regular users, and all are commented extensively within the file. The only critical one for MOST users is the DEST_DIR one, which points at somewhere Plex can see. The install script will prompt you for it. It is assumed that "TV Shows" and "Movies" are subdirectories in that file. Once set up, you should easily be able to add these folders to Plex. If you prefer to integrate with existing Plex folders, and your "TV Shows" and "Movies" folders are named or configured in that way, you can work around it using symbolic links. 48 | 49 | Some interesting options are CHAPTERS=1 (selected by default), which uses Channels DVR commercial markers as chapter markers in the output file, and COMTRIM=1, which actually completely removes the commercial breaks. I do not recommend using this latter mode unless you are very confident in the commercial detection, which in my experience produces quite a few blunders unless you have tuned your comskip.ini file extremely carefully. Note that if both are set, COMTRIM will "win". 50 | 51 | By default, the basic settings should be suitable for most modern devices and produce good quality output close to the original broadcast. I'll add more details here on the settings soon. 52 | 53 | If you would like something more suitable for limited upload bandwidth, I recommend using the MAXSIZE setting (e.g. MAXSIZE=720 for 720p; 576 is the lowest I would personally go for decent quality), which reduces resolution and substantially reduces filesize. You could also lowering the speed to e.g. veryslow, which supposedly trades speed to processing time, but in reality these slower settings do not always produce smaller files. 54 | 55 | Note that transcoding is done in software, and so will be a CPU hog on most systems, and thus it's worth running with "nice" set (default is 10, 0 is normal priority, 19 is lowest). It should be possible to edit the script to use hardware transcoding if desired, but I haven't tested that yet (please contact me if you're interested). I have attempted to balance output quality, file size and processor load so that it will work well for most end-users. 56 | 57 | Finally, some "bonus" feature described below utilize IFTTT for phone notifications, GNU parallel for offloading transcoding to other machines, and more. Some of these are documented below. 58 | 59 | **Command line operation** 60 | 61 | All of the default options within the script can be substituted for on the command line. In its most basic mode, simply run: 62 | 63 | `channels-transcoder.sh` 64 | 65 | from the command line and it will scan the source directory (the "TV" folder where Channels DVR stores its recordings). 66 | 67 | If you would like to overload any of the options above, simply add them as arguments, e.g. 68 | 69 | `channels-transcoder.sh DAYS=1 MAXSIZE=540 COMTRIM=1` 70 | 71 | will only search for files created in the last 6 hours (360 minutes) and will create smaller 540p files with commercials trimmed. Note that it will not transcode previously finished shows until you re=initate your database (CLEAR_DB=1). Also, it should be noted that the arguments are case-sensitive. 72 | 73 | An additional option for command line execution only is to specify specific recordings on the command line. This is done without the VAR="parameter" format, and can use either a part of the filename, or the specific Channels DVR recording ID, e.g.: 74 | 75 | `channels-transcoder.sh 11 12 14 OVERWRITE=1` 76 | 77 | Recordings specified in this manner will be transcoded regardless of whether there is a record of a previous transcoding in transcode.db, but by default they will not overwrite anything in the Plex file structure. The OVERWRITE=1 option forces it to copy over previous versions; leave it off if you don't need it. 78 | 79 | `channels-transcoder.sh "Sherlock"` 80 | 81 | This version is a search expression on the filename, and so in this instance it would find ALL shows containing the search term Sherlock. You can be as specific as you like with the search expression, and so the entire filename can be given to avoid ambiguity. However, if you choose to search by directories, note that these are relative to the root of the Channels DVR database, so "Sherlock" would work, so "channels/TV/Sherlock" wouldn't. If you had a file in "TV/Sherlock on Masterpiece/2017-01-19-0259 Sherlock on Masterpiece 2017-01-15 S04E03 The Final Problem.mpg", "Sherlock" would find it, and possibly multiple other matches. You could be more specific and add "Sherlock on Masterpiece 2017-01-15", but "Sherlock on Masterpiece S04E03" would not due to search parameter being split; I hope to improve on this soon, so that you can more easily specify Show and SxxExx code, but in the meantime be careful about how you word your searches. 82 | 83 | Given that there are limits to the number of instances (2) of channels-transcoder.sh that will run, there are circumstances under which running this manually may prevent automatic execution. Mostly this shouldn't happen, but I do not recommend trying to manually run more than one instance simultaneously. 84 | 85 | If, for whatever reason, you wish to reset your transcode database, you can always do so as per initial setup instructions, e.g. channels-transcoder.pl CLEAR_DB=1 DAYS=N. 86 | 87 | 88 | **Daemon/cron management** 89 | 90 | This should be set up for users that run the install script. 91 | 92 | For most Linux users it's probably easiest to run this as a cron job, e.g. the default: 93 | 94 | `1 0 * * * /usr/local/bin/channels-transcoder.sh >> ~/.channels-transcoder/log` 95 | 96 | This would running at 12:01am every night (by default the script will also wait internally for up to 4 hours for Channels DVR to stop recording/comskipping before starting). 97 | 98 | This would work for Mac users too, but it's better to use Launch Agents. I've included a LaunchAgent file in this archive (com.getchannels.channels-transcoder.plist), which is installed by default on Macs if you run the installation script. It is typically placed into the ~/Library/LaunchAgents directory. Once it's there, run the following: 99 | 100 | `launchctl load ${HOME}/Library/LaunchAgents/com.getchannels.channels-transcoder.plist` 101 | `launchctl start com.getchannels.channels-transcoder` 102 | 103 | The log file is also in the prefs director, and so can be monitored easily (e.g. tail -f ~/.channels-transcoder/log). 104 | 105 | I'm working on more daemon and file monitoring approaches, and would appreciate additions from others. 106 | 107 | **Phone notifications** 108 | 109 | This is a convenient way to monitor your jobs. Unfortunately IFTTT are restricting the ability to share applets at the moment, for anyone other than developers, but it's fairly easy to roll your own. 110 | 111 | You will need to set up an IFTTT account and the app installed on your phone. Then you should add the Notifications (https://ifttt.com/if_notifications) and Maker (https://ifttt.com/maker_webhooks) services, before going to Settings setting up the latter and copying the 22-digit code at the end of the URL and adding it to the IFTTT_MAKER_KEY variable in the script. Finally, you'll set up an IFTTT Applet as per the graphic (ifttt-maker-transcode-plex.png), noting that IFTTT undergoes cosmetic details a fair amount, and so it might look a little different. 112 | 113 | **Parallelization** 114 | 115 | I have been experimenting with GNU parallel, giving the ability to (i) farm your processes out to other computers, and (ii) wait for available resources before encoding. It looks to be working fairly well, and so I added it as a feature, which is by default turned off. However, IF you want to give it a go, be my guest. Simply add explicit reference to the PARALLEL_CLI entry under prefs, and set your -S (server) options within the PARALLEL_OPTS setting. You might want to try running with BUSY_WAIT=0, but there are some (admittedly unlikely) circumstances under which multiple instances might end up transcoding the same file multiple times. 116 | 117 | I do not recommend parallelizing between cores on a single machine (i.e. setting -j to more than 1), because (i) Handbrake with x264 is very scalable between cores already, and so even though you might see a marginal potential gain, there are plenty of other bottlenecks that could reverse that gain, and (ii) You'll actually see your files later on average, because of non-sequential delivery. 118 | 119 | *Parallelisation Requirements:* 120 | 121 | i) A RECENT version of GNU parallel installed both on this machine and any others you wish to send the commend to. 122 | ii) The DEST_DIR must be visible in the same location on your drive on your remote system. This will involve drive mounting using NFS, AFP or SMB. I do not recommend SMB due to erratic file access. I also do not recommend trying this unless you have very smooth Gigabit networking or better. I'll work on different ways to implement this in the future that might be more efficient. 123 | iii) Passwordless logins set up with ssh-keygen for remote ssh sessions on target machines. 124 | iv) To read documentation on GNU parallel. This is not for beginners, and you will need to set up your system correctly to be able to use it. 125 | 126 | Note that additional options (which can be edited in PARALLEL_OPTS) have been added to GNU parallel over the years, and at least one of those, specifically --memfree, I use. Please either update to a 2016+ version or, if you have problems, delete the "--memfree 700 M". (Note that my own tests have shown that the default settings {PRESET="AppleTV 3", SPEED="veryfast", MAXSIZE=1080} have shown that 700 MBytes is about right if the source is 1080p, and 425 Mbytes if the source is 720p. These things are best to tune for yourself.) 127 | 128 | **Other scripts** 129 | 130 | Over time I will be adding other scripts to this archive. 131 | -------------------------------------------------------------------------------- /channels-transcoder.prefs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## DEFAULT SETTINGS FOR channels-transcoder.sh 4 | # Install in one of the locations that channels-transcoder.sh searches as "prefs". 5 | # Mac default: ~/Library/Application Support/channels-transcoder/prefs 6 | # Linux default: ~/.channels-transcoder/prefs 7 | # All of the options set within the preferences file can be over-riden by adding them as command-line arguments: 8 | # e.g. transcode-plex.sh CHAPTERS=1 COMTRIM=0 DAYS=2 9 | 10 | # Information specific to your local system 11 | DEST_DIR="${HOME}/Movies/Plex" # Desination for video recordings. Should contain "TV Shows" and "Movies" subdirectories, or symlinks to them. 12 | SOURCE_DIR="" # Channels DVR folder (see Channels web interface settings) if NFS/SMB/AFP mounted. Leave blank if running locally. 13 | HOST="" # Default="localhost:8089". To run this remotely, add e.g. HOST="channels-dvr.local". If no port, 8089 assumed. 14 | SOURCE_PREFS="" # If left blank, will scan a default list of locations; CANNOT BE SET AS COMMAND LINE OVER-RIDE! OBSOLETE. 15 | BACKUP_DIR="" # Location to deposit files if server offline. Leave empty if not needed. 16 | WORKING_DIR="" # Default="/tmp". Useful if local space is limited, as can require many GB. 17 | TMP_PREFIX="" # Default="transcode". Prefix of temporary working directories within WORKING_DIR. Name must not contain spaces. 18 | 19 | # Options to tailor how the software runs: 20 | CHAPTERS=1 # Set to 1 to mark commercials as chapters. Doesn't work if COMTRIM enabled. 21 | COMTRIM=0 # Set to 1 to trim commercials from output file. Takes priority over comskip. Use at own risk. 22 | DELETE_ORIG=0 # OBSOLETE. Set to 1 to delete original files and 0 to disable. Should set expiry within Channels DVR. 23 | OVERWRITE=0 # Set to 1 to overwrite existing versions of show, rather than skip transcode. 24 | TEMP_COPY=0 # Copies input file to the working directory first; useful when running over erratic networks. 25 | LANG="en-US" # Force MP4 file tracks to have a language; Necessary for AppleTV 4 to see chapters. 26 | NICE=10 # For intensive tasks, set a "niceness" between 0 and 19, so as not to lock up the machine. 27 | VERBOSE=1 # 0 = quiet; 1 = normal; 2 = detailed. 28 | BUSY_WAIT=1 # Waits up to TIMEOUT duration for Channels to stop recording or comskipping if set. 29 | TIMEOUT="" # Max time, in seconds, to wait while Channels is busy before giving up. Only used if BUSY_WAIT=1. Default=14400. 30 | DEBUG=0 # For development. More explicit output. Doesn't remove TMPDIR at the end. 31 | 32 | # NEW FEATURE: A database is now kept of all converted files 33 | # This can be deleted by setting CLEAR_DB=1 from the command line, and specifying the number of DAYS for which you wish to re-initiate transcoding 34 | # e.g. if CLEAR_DB=0 and DAYS=1, the database will be repopulated with all existing files >1 day old, and anything from today will be transcoded. 35 | TRANSCODE_DB="" # If left blank, will search for file in same directory as SOURCE_PREFS 36 | CLEAR_DB=0 # Normally 0. Best set on command line. If 1, database is cleared, potentially restarting all transcode jobs again 37 | DAYS="" # Limit transcoding to shows recorded in the last N days. Useful if server has been down or establishing DB. 38 | # If no database exists, files older then DAYS will be listed as already done. Default is 10000, or 0 if CLEAR_DB=1. 39 | 40 | # VERY COOL FEATURE: Phone notifications 41 | # If you want phone notifications with IFTTT, enter your own IFTTT_MAKER_KEY here, and be sure to have curl on your system 42 | # Please do not use someone else's IFTTT_MAKER_KEY or it will spam them 43 | # Also, set up an IFTTT MAKER Applet event called "TVEvent" with a "Value1." notification format. 44 | IFTTT_MAKER_KEY="" # Set to "" if you do not want IFTTT Maker notifications. A 22-digit code. 45 | 46 | # Encoder presets. The defaults should work well for most people. Only edit if you know what you're doing. 47 | QUALITY="21" # Only change if you know what you're doing. This is the -crf value in ffmpeg x264 encoding. 48 | # Sane values for broadcast TV are from 18 (very high) to 28 (poor). 49 | # Note that this is the baseline for 1080p, script sets lower values for 720p (-1), 576p (-2) and 480p (-3) output. 50 | SPEED="veryfast" # This trades transcoding speed for filesize. In my own tests, veryfast often produces smaller files than medium! 51 | # Faster settings give theoretically larger filesizes and shorter transcode times; They do not affect quality. 52 | # The only recommended options are: slow, medium, fast, faster, fastest, veryfast. 53 | MAXSIZE=1080 # Sets resolution limit (based on height), and so e.g. set 720 for up to 720p output 54 | 55 | # Locations of programs if not in your path. If required, the software will look for it in your path if you're not explicit (e.g. =""). 56 | # AP_CLI (for iTunes tagging) must have value specified if order for this features to work. Just =1 will work if in PATH. 57 | # It is recommended that FFMPEG_CLI points at the version distributed with Channels DVR, from April 17th, 2017 onwards. 58 | CURL_CLI="" # Location of curl binary. This software is required for the code to work. 59 | JQ_CLI="" # Location of jq binary. This software is required for the code to work. 60 | FFMPEG_CLI="" # Location of ffmpeg binary. Only required if COMTRIM=1. 61 | AP_CLI="" # Location of AtomicParsley binary. Only required for iTunes file tagging. Leave blank if not required. 62 | # >0.9.6 non-mainline AtomicParsley is required. Recommend using fork: https://bitbucket.org/wez/atomicparsley/ 63 | 64 | # WARNING: Most people should leave PARALLEL_CLI blank 65 | # GNU parallel allows you to control the number of parallel transcoding jobs or farm out to other machines (target directory should be the same) 66 | # Anyone using this will should read GNU parallel documentation sufficient to set up their remote servers. Multiple PARALLEL_OPTS arguments should be added: 67 | # The memfree option requires a recent version of parallel >=2015, and should be tailored based on experience 68 | # If set up correctly, you can add multiple servers, e.g. "-S $SERVER1 -S $SERVER2", here too. Remember to set ssh keys for password-free login. 69 | # --memfree 700M (RAM needed) is appropriate for default settings. Some other quantities below: 70 | # "Apple 1080p30 Surround", veryfast, 1080i input: 700M 71 | # "Apple 1080p30 Surround", veryfast, 720p input: 425M 72 | # "Apple 1080p30 Surround", veryfast, 1080i input, MAXSIZE=720: 550M 73 | # T.B.D. etherwake to allow Wake-on-LAN functionality 74 | PARALLEL_CLI="" # Location of GNU parallel binary. Note that with -j 1 this will run like a normal non-parallel task. 75 | PARALLEL_OPTS=(-j 1 --nice $NICE --memfree 700M --noswap) 76 | 77 | # When multiple TV shows or movies have the same name, they need to be identified by year as well in order for Plex to identify them. 78 | # Showname substitutions go below, using the format examples: 79 | function showname_clean { 80 | local show="" 81 | case "$1" in 82 | "Bull") show="Bull (2016)";; 83 | "Conviction") show="Conviction (2016)";; 84 | "Doctor Who") show="Doctor Who (2005)";; 85 | "Once Upon a Time") show="Once Upon a Time (2011)";; 86 | "Poldark on Masterpiece") show="Poldark (2015)";; 87 | "Poldark") show="Poldark (2015)";; 88 | *) show="${1}";; 89 | esac 90 | echo "$show" 91 | } 92 | -------------------------------------------------------------------------------- /channels-transcoder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # (C) Karl Mitchell 2017, GPL: https://www.gnu.org/licenses/gpl-3.0.en.html 3 | # Converts Channels DVR recordings to m4v (h.264) format, for Plex, Kodi, iTunes & iOS m4v 4 | # This script is primarily intended to be run occasionally (e.g. daily), e.g. using launchd or cron job, during quiet time 5 | # It can also be run on specific recordings, can be used locally or remotely to Channels DVR computer, and can distribute jobs remotely, as required. 6 | # An installation script is provided on the GitHub site to automate most of the setup described below. 7 | # Pre-requisites: 8 | # Curl (for accessing web resources) 9 | # jq (for processing JSON databases) 10 | # realpath (note that this is not available on the Mac, in which case the install script will add an alias to simulate it) 11 | # Optional pre-requisites: 12 | # An IFTTT Maker Key for phone status notifications. 13 | # FFMPEG (a part of channels DVR, so you already have a copy, but you can use your own if you like) for commercial trimming/marking 14 | # Parallel (GNU software for parallel processing; Can run jobs in parallel across cores, processors or even computers if set up correctly) 15 | # AtomicParsley (software for writing iTunes tags) >= 0.9.6 recommended 16 | # Unix prerequisites for above packages (use e.g. apt-get/macports), in case you're compiling manually: 17 | # autoconf automake libtool pkgconfig argtable sdl coreutils curl ffmpeg realpath jq AtomicParsley 18 | # MAC OS: Run with launchd at ~/Library/LaunchAgents/com.getchannels.transcode-plex.plist. Edit to change when it runs (default = 12:01am daily). 19 | # Once in place and readable, run 20 | # sudo launchctl load ${HOME}/Library/LaunchAgents/com.getchannels.transcode-plex.plist 21 | # sudo launchctl start com.getchannels.transcode-plex 22 | # chmod 644 ~/Library/LaunchAgents/com.getchannels.transcode-plex.plist 23 | # If your computer sleeps, be sure to set something to wake it up on time. 24 | # LINUX: Run as a cron or service, e.g. "EDITOR=nedit crontab -e" then add line 1 12 * * * nice /usr/local/bin/channels-transcoder.sh 25 | # Edit default settings below. These may all be over-ridden from the command line, e.g. channels-transcoder.sh CHAPTERS=1 COMTRIM=0 DAYS=2 26 | # 27 | ## FIRST RUN 28 | # The first time you run this script, it will create a database, typically in the same location as the preferences file 29 | # Setting DAYS=N, e.g. DAYS=10, will list all shows older than N days as having been previously transcoded to prevent a massive backlog. 30 | # Setting DAYS=0 will prevent any shows from being backlogged. 31 | # You can force re-initialization of the database by adding CLEAN_DB=1 32 | # Note that if you do not have write access to the existing database, then a new one will be set up and initiated. 33 | 34 | ## SOME TRICKS 35 | # You can run without comparing with the transcode database and use current directory thus: 36 | # channels-transcoder.sh 62 63 DEST_DIR="" DAYS=0 TMPDIR="$(pwd)" 37 | # You can deliver to iTunes (only recommended if you have tagging working) rather than to a Plex-compatible structure, thus: 38 | # ITUNES_AUTO="${HOME}/Music/iTunes/iTunes Media/Automatically Add to iTunes.localized" 39 | # channels-transcoder.sh DEST_DIR="" BACKUP_DIR="${ITUNES_AUTO}" 40 | 41 | ## PREFERENCES FOR SYSTEM CONFIGURATION 42 | # The preferences file is normally called "prefs", and is typically placed in ~/.transcode-plex/prefs or ~/.channels-transcoder/prefs 43 | # Other locations are also searched if not specified, including Library/Application Support/channels-transcoder|transcode-plex 44 | # All of the options set within the preferences file can be over-riden by adding them as command-line arguments: 45 | # e.g. transcode-plex.sh CHAPTERS=1 COMTRIM=0 DAYS=2 46 | EXECUTABLE="${BASH_SOURCE[0]}" 47 | BN=$(basename "${EXECUTABLE}" .sh) 48 | DIR="${BASH_SOURCE%/*}" 49 | DEBUG=0 50 | 51 | # realpath is a handy utility to find the path of a referenced file. 52 | # It is used sparingly in this code. 53 | # An alias suggested for those that do not have it. 54 | if [ ! "$(which realpath)" ] ; then 55 | echo "Some functionality of this software will be absent if realpath is not installed." 56 | echo "Specifically, searching for files based on filename, something that most users do not use, will fail." 57 | echo "If you have problems, then please set up an alias in /etc/bashrc (or your system equivalent) thus:" 58 | echo "alias realpath='[[ \$1 = /* ]] && echo \"\$1\" || printf \"%s/\${1#./}\" \${PWD}'" 59 | echo "Alternatively, ensure that TRANSCODE_DB is set in prefs, and that if SOURCE_FILE used it is done so correctly." 60 | fi 61 | 62 | 63 | ## INITIATION OF ARGUMENTS 64 | # Reads initiation variables 65 | if [ $# -gt 0 ] ; then 66 | for var in "$@"; do 67 | regex="(.*)=(.*)" 68 | if [[ "${var}" =~ (.*)=(.*) ]] ; then 69 | variable=$(echo "$var" | cut -f1 -d=) 70 | value=$(echo "$var" | cut -f2- -d=) 71 | eval "${variable}=\"${value}\"" 72 | fi 73 | done 74 | fi 75 | if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi 76 | 77 | # Finds preferences file, sources it, then sets preferences directory 78 | if [ ! "${SOURCE_PREFS}" ]; then 79 | for i in "${HOME}/.${BN}/prefs" "${HOME}/.transcode-plex/prefs" \ 80 | "${HOME}/Library/Application Support/${BN}/prefs" "${HOME}/Library/Application Support/transcode-plex/prefs" ; do 81 | if [ -f "${i}" ]; then SOURCE_PREFS="${i}"; break ; fi 82 | done 83 | fi 84 | 85 | if [ "${SOURCE_PREFS}" ]; then 86 | # spellcheck source=/dev/null 87 | PREFS_DIR="$(dirname "${SOURCE_PREFS}")" 88 | PREFS_DIR="$(realpath "${PREFS_DIR}")" 89 | [ "$DEBUG" -eq 1 ] && echo "SOURCE_PREFS=${SOURCE_PREFS}" 90 | source "${SOURCE_PREFS}" || ( echo "Couldn't read SOURCE_PREFS=${SOURCE_PREFS}."; exit 1 ) 91 | else 92 | echo "Cannot find preferences file. Example at: https://github.com/karllmitchell/Channels-DVR-to-Plex/" 93 | exit 1 94 | fi 95 | [ "${DEBUG}" -eq 1 ] && echo "PREFS_DIR=${PREFS_DIR}" 96 | 97 | # Re-reads initation variables to over-ride any global variables set on the command line 98 | if [[ $# -gt 0 ]] ; then 99 | for var in "$@"; do 100 | regex="(.*)=(.*)" 101 | if [[ "${var}" =~ (.*)=(.*) ]] ; then 102 | variable=$(echo "$var" | cut -f1 -d=) 103 | value=$(echo "$var" | cut -f2- -d=) 104 | eval "${variable}=\"${value}\"" 105 | [ "$DEBUG" -eq 1 ] && echo "${variable}=${value}" 106 | else 107 | case $var in 108 | ''|*[0-9]*) apilist+="${var} " ;; 109 | *.*) filelist+="${var} " ;; 110 | *) echo "Cannot interpret argument: ${var}";; 111 | esac 112 | fi 113 | done 114 | fi 115 | 116 | 117 | ## REPORT PROGRESS, OPTIONALLY VIA PHONE NOTIFICATIONS 118 | # Customise if you have an alternative notification system 119 | function notify_me { 120 | echo "${1}" 121 | if [ "${IFTTT_MAKER_KEY}" ]; then 122 | IFTTT_MAKER="https://maker.ifttt.com/trigger/{TVevent}/with/key/${IFTTT_MAKER_KEY}" 123 | quiet="--silent" 124 | [ "${VERBOSE}" -eq 2 ] && quiet="--verbose" 125 | [ ! "${CURL_CLI}" ] && CURL_CLI="$(which curl)" 126 | [ ! -f "${CURL_CLI}" ] && CURL_CLI="$(which curl)" 127 | "${CURL_CLI}" $quiet -X POST -H "Content-Type: application/json" -d '{"value1":"'"${1}"'"}' "$IFTTT_MAKER" > /dev/null 128 | fi 129 | return 0 130 | } 131 | 132 | 133 | ## CREATE AND GO TO A TEMPORARY WORKING DIRECTORY 134 | cwd=$(pwd) 135 | [ "${WORKING_DIR}" ] || WORKING_DIR="/tmp" 136 | [ "${TMP_PREFIX}" ] || TMP_PREFIX="transcode" 137 | TMPDIR=$(mktemp -d "${WORKING_DIR}/${TMP_PREFIX}.XXXXXXXX") || exit 2 138 | cd "${TMPDIR}" || ( notify_me "Cannot access ${WORKING_DIR}"; exit 2 ) 139 | [ "$VERBOSE" -ne 0 ] && echo "Working directory: ${TMPDIR}" 140 | 141 | 142 | ## CREATE FUNCTION TO CLEAN UP AFTER YOURSELF 143 | ## 144 | function finish { 145 | cd "${cwd}" || ( cd && echo "Original directory gone" ) 146 | [ "$DEBUG" -eq 1 ] || [ "${TMPDIR}" == "${cwd}" ] || rm -rf "${TMPDIR}" || echo "Okay, that's strange: Temp directory missing" 147 | } 148 | trap finish EXIT 149 | 150 | # A useful little tool for evaluating version numbers 151 | function ver { 152 | printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' ' | head -n 4 ) 153 | } 154 | 155 | 156 | ### ESTABLISH PRESENCE OF API AND CLI INTERFACES 157 | 158 | # Essential command line programs 159 | [ -f "${CURL_CLI}" ] || CURL_CLI="$(which curl)" || (notify_me "curl missing"; exit 9) 160 | [ -f "${JQ_CLI}" ] || JQ_CLI="$(which jq)" || (notify_me "jq missing"; exit 9) 161 | 162 | # Determine appropriate API web address 163 | if [ ! "${HOST}" ]; then HOST="localhost:8089"; fi 164 | regex="(.*):(.*)" 165 | if [[ "${HOST}" =~ ${regex} ]]; then HOST="${BASH_REMATCH[1]}"; PORT="${BASH_REMATCH[2]}"; else PORT=8089; fi 166 | DATA_DIR="$(curl -s "http://${HOST}:${PORT}/system" | jq -r '.pwd')" 167 | [ -d "${DATA_DIR}" ] || (notify_me "Cannot find API at http://${HOST}:${PORT}/"; exit 14) # Check for presence of Channels DVR API 168 | [ "${VERBOSE}" -ne 0 ] && echo "Channels DVR API Interface Found" 169 | [ "${SOURCE_DIR}" ] || SOURCE_DIR=$(curl -s "http://${HOST}:${PORT}/dvr" | jq -r '.path') # Read Source Directory from API 170 | [ ! -d "${SOURCE_DIR}" ] && SOURCE_DIR="" && [ "${VERBOSE}" -ne 0 ] && echo "Cannot read Channels source directory. Functioning remotely via API only." 171 | CHANNELS_DB="http://${HOST}:${PORT}/dvr/files" 172 | 173 | # Confirm if operation via Parallel is being used and quit if it's not present. 174 | [ ! "${PARALLEL_CLI}" ] || [ -f "${PARALLEL_CLI}" ] || PARALLEL_CLI="$(which parallel)" || (notify_me "parallel missing"; exit 9) 175 | 176 | # Additional command-line programs for transcode function, only checked if not using remote execution with GNU parallel 177 | if [ ! "${PARALLEL_CLI}" ]; then 178 | [ -f "${FFMPEG_CLI}" ] || FFMPEG_CLI="$(dirname "${DATA_DIR}")/latest/ffmpeg" && [ -f "${FFMPEG_CLI}" ] || (notify_me "ffmpeg missing"; exit 9) 179 | if [ "${AP_CLI}" ]; then 180 | [ -f "${AP_CLI}" ] || AP_CLI="$(which AtomicParsley)" || (notify_me "AtomicParsley missing"; exit 9) 181 | regex="(.*)version: (.*) (.*)" 182 | apvers=$("${AP_CLI}" | grep version) 183 | if [[ "${apvers}" =~ ${regex} ]]; then 184 | [ "$(ver "${BASH_REMATCH[2]}")" -lt "$(ver "0.9.6")" ] && echo "Old version of AtomicParsley detected. If tagging fails, upgrade recommended." && AP_OLD=1 185 | else 186 | echo "Cannot determine version of AtomicParsley. If tagging fails, upgrade recommended." 187 | fi 188 | fi 189 | fi 190 | 191 | [ "${DEBUG}" -eq 1 ] && echo "All required programs found." 192 | 193 | 194 | 195 | ## CHECK FOR AND INITIATE TRANSCODE DATABASE IF NECESSARY 196 | [ "${TRANSCODE_DB}" ] || TRANSCODE_DB="${PREFS_DIR}/transcode.db" 197 | if [ ! -f "${TRANSCODE_DB}" ] || [ "${CLEAR_DB}" -eq 1 ] ; then 198 | [ "${DAYS}" ] || DAYS=0 199 | if [ ! -w "${TRANSCODE_DB}" ] ; then 200 | notify_me "Cannot write to ${TRANSCODE_DB}, using ${HOME}/.${BN}/transcode.db instead" 201 | TRANSCODE_DB="${HOME}/.${BN}/transcode.db" 202 | fi 203 | if [ "$(uname)" == "Darwin" ]; then since=$(date -v-${DAYS}d +%FT%H:%M); else since=$(date -d "$(date) - ${DAYS} days" +%FT%H:%M); fi 204 | [ "${DEBUG}" -eq 1 ] && echo "Initiating database with recordings up to ${since}. Using ${CURL_CLI} and ${JQ_CLI}." 205 | "${CURL_CLI}" -s "${CHANNELS_DB}" | "${JQ_CLI}" -r '.[] | select ((.Airing.Raw.endTime < "'"$since"'")) | {ID} | join(" ") ' > "${TRANSCODE_DB}" 206 | notify_me "Transcode database initialised at ${TRANSCODE_DB}" 207 | fi 208 | if [ ! -w "${TRANSCODE_DB}" ] ; then 209 | notify_me "Cannot write to ${TRANSCODE_DB}. I give up!" 210 | exit 13 211 | fi 212 | 213 | 214 | # FUNCTION TO USE ATOMIC PARSLEY FOR TAGGING, ACCESSING CHANNELS_DB 215 | function ap_tagger { 216 | # $1 is the Channels DVR ID, $2 is the output format height 217 | # Existence of ${1}.json and ${1}.m4v are assumed 218 | # Right now this over-writes many of the tags from FFMPEG, largely for the sake of portability of the function. 219 | 220 | # TAGGING 221 | subtype="$("${JQ_CLI}" -r '.Airing.Raw.program.subtype' < "${1}.json")" # Is Feature Film or part of Series? 222 | 223 | # Build some tags 224 | AP_OPTS=() 225 | 226 | case "$(jq -r '.Airing.Raw.program.subType' < "${1}.json")" in 227 | "Series") 228 | AP_OPTS+=(--genre "TV Shows" --stik "TV Show") 229 | showname="$(${JQ_CLI} -r '.Airing.Title' < "${1}.json")" 230 | [ "$(type "showname_clean" | grep -s function)" ] && showname="$(showname_clean "${showname}")" 231 | AP_OPTS+=(--TVShowName "${showname}") 232 | AP_OPTS+=(--title "$(${JQ_CLI} -r '.Airing.EpisodeTitle' < "${1}.json")") 233 | season="$(printf "%.02d" "$(jq -r '.Airing.SeasonNumber' < "${1}.json")")" 234 | episode="$(printf "%.02d" "$(jq -r '.Airing.EpisodeNumber' < "${1}.json")")" 235 | AP_OPTS+=(--TVEpisode "${season}${episode}" --TVEpisodeNum "${episode}" --TVSeason "${season}") 236 | ;; 237 | *) 238 | AP_OPTS+=(--genre "Movies" --stik "Movie") 239 | AP_OPTS+=(--title "$(${JQ_CLI} -r '.Airing.Title' < "${1}.json")") 240 | ;; 241 | esac 242 | 243 | AP_OPTS+=(--geID "$(${JQ_CLI} -r '.Airing.Genres[0]' < "${1}.json")") 244 | AP_OPTS+=(--contentRating "$(${JQ_CLI} -r '.Airing.Raw.ratings[0].code' < "${1}.json")") 245 | AP_OPTS+=(--year "$(${JQ_CLI} -r '.Airing.Raw.program.releaseYear' < "${1}.json")") 246 | AP_OPTS+=(--cnID "$(${JQ_CLI} -r '.Airing.ProgramID' < "${1}.json" | cut -c3-)") 247 | 248 | # HD tags - deprecated as ffmpeg now handles this, allowing older version of atomicparsley to be used. 249 | hdvideo=0 && [ "$2" -gt 700 ] && hdvideo=1 && [ "$2" -gt 1000 ] && hdvideo=2 250 | [ ! ${AP_OLD} ] && AP_OPTS+=(--hdvideo "$hdvideo") 251 | 252 | # Image tags 253 | imageloc="$(${JQ_CLI} -r '.Airing.Image' < "${1}.json")" 254 | artwork="${1}.jpg" 255 | "${CURL_CLI}" -s -o "${artwork}" -O "${imageloc}" 256 | [ -f "${artwork}" ] && AP_OPTS+=(--artwork "${artwork}") 257 | 258 | # Network name 259 | channel="$(${JQ_CLI} -r '.Airing.Channel' < "${1}.json")" 260 | network="$("${CURL_CLI}" -s "${CHANNELS_DB}/../guide/channels" | "${JQ_CLI}" -r '.[] | select(.Number=="'"$channel"'") | .Name')" 261 | AP_OPTS+=(--TVNetwork "${network}") 262 | 263 | # Command that actually does the tagging! 264 | if [ "$VERBOSE" -ne 0 ] ; then 265 | for arg in "${AP_CLI}" "${1}.m4v" "${AP_OPTS[@]}"; do 266 | if [[ $arg =~ \ ]]; then arg=\"$arg\"; fi 267 | echo -n "$arg " 268 | done; echo 269 | fi 270 | 271 | "${AP_CLI}" "${1}.m4v" "${AP_OPTS[@]}" || return 1 272 | return 0 273 | } 274 | 275 | 276 | function transcode { 277 | # Re-check required programs in case of remote execution 278 | if [ "${PARALLEL}" ] ; then 279 | errtxt="cannot be found on remote system. Critical error. Bailing." 280 | [ -f "${CURL_CLI}" ] || CURL_CLI="$(which curl)" || (notify_me "curl ${errtxt}"; exit 9) 281 | [ -f "${JQ_CLI}" ] || JQ_CLI="$(which jq)" || (notify_me "jq ${errtxt}"; exit 9) 282 | [ -f "${FFMPEG_CLI}" ] || FFMPEG_CLI="$(which ffmpeg)" || (notify_me "ffmpeg ${errtxt}"; exit 9) 283 | if [ "${AP_CLI}" ]; then 284 | [ -f "${AP_CLI}" ] || AP_CLI=$(which AtomicParsley) || (notify_me "AtomicParsley ${errtxt}"; exit 9) 285 | regex="(.*)version: (.*) (.*)" 286 | apvers=$("${AP_CLI}" | grep version) 287 | if [[ "${apvers}" =~ ${regex} ]]; then 288 | [ "$(ver "${BASH_REMATCH[2]}")" -lt "$(ver "0.9.6")" ] && notify_me "Old version of AtomicParsley detected. If tagging fails, upgrade recommended." 289 | exit 9 290 | else 291 | notify_me "Cannot determine version of AtomicParsley. If tagging fails, upgrade recommended" 292 | fi 293 | fi 294 | fi 295 | 296 | # Get filename 297 | "${CURL_CLI}" -s "${CHANNELS_DB}/${1}" > "${1}.json" 298 | "${CURL_CLI}" -s "${CHANNELS_DB}/${1}/mediainfo.json" > "${1}_mi.json" 299 | ifile="${SOURCE_DIR}/$(${JQ_CLI} -r '.Path' < "${1}.json")" 300 | [ "${DEBUG}" -eq 1 ] && echo "Source location: ${ifile}" 301 | fname=$(basename "${ifile}") # Name of original file 302 | bname="${fname%.*}" # Name of original file minus extension 303 | extension="${fname##*.}" # Name of extension 304 | 305 | # Check if deleted 306 | [ "$(${JQ_CLI} -r '.Deleted' < "${1}.json")" == "true" ] && ( echo "${bname} already deleted."; return 3 ) 307 | 308 | # Extract recording information from API to construct output filename in Plex-friendly format. 309 | case "$(jq -r '.Airing.Raw.program.subType' < "${1}.json")" in 310 | "Series") 311 | rectype="TV Show" 312 | showname="$(${JQ_CLI} -r '.Airing.Title' < "${1}.json")" 313 | season="$(${JQ_CLI} -r '.Airing.SeasonNumber' < "${1}.json" | xargs printf "%02g" )" 314 | episode="$(${JQ_CLI} -r '.Airing.EpisodeNumber' < "${1}.json" | xargs printf "%02g" )" 315 | title="$(${JQ_CLI} -r '.Airing.EpisodeTitle' < "${1}.json")" 316 | [ "$(type "showname_clean" | grep -s function)" ] && showname="$(showname_clean "${showname}")" 317 | bname="${showname} - S${season}E${episode} - ${title}" 318 | year="$(${JQ_CLI} -r '.Airing.Raw.program.releaseYear' < "${1}.json")" 319 | ;; 320 | *) 321 | rectype="Movie" 322 | showname="$(${JQ_CLI} -r '.Airing.Title' < "${1}.json")" 323 | bname="${showname}" 324 | year="$(${JQ_CLI} -r '.Airing.Raw.program.releaseYear' < "${1}.json")" 325 | ;; 326 | esac 327 | 328 | # Determine if input file already available on local system. Download via API if not. 329 | fname="${1}.${extension}" 330 | [ -f "${ifile}" ] && ln -s "${ifile}" "${fname}" 331 | [ ! -f "${fname}" ] && "${CURL_CLI}" -s -o "${fname}" "${CHANNELS_DB}/${1}/stream.${extension}" 332 | [ ! -f "${fname}" ] && ( notify_me "Cannot find ${bname}"; return 4 ) 333 | 334 | # Check to see if file exists at destination ... 335 | if [ "${DEST_DIR}" ]; then 336 | tdname="${DEST_DIR}/Movies/${showname}" 337 | [ "${rectype}" == "TV Show" ] && tdname="${DEST_DIR}/TV Shows/${showname}/Season $((10#${season}))" 338 | if [ -f "${tdname}/${bname}.m4v" ]; then 339 | if [ "${OVERWRITE}" -ne 1 ]; then 340 | echo "${tdname}/${bname}.m4v already exists at destination. OVERWRITE=1 to ignore." 341 | return 1 342 | else 343 | echo "${tdname}/${bname}.m4v already exists at destination. Overwriting." 344 | fi 345 | fi 346 | else 347 | echo "Functionining in local-mode only. Will not deliver to Plex or Plex-like file structure." 348 | fi 349 | 350 | # ... or is being created to in parallel 351 | [ "${TMP_PREFIX}" ] && [ "$(lsof 2>&1 | grep -s "${1}.m4v" | grep "ffmpeg" | grep "${TMP_PREFIX}")" ] && notify_me "${bname} transcoding already underway" && return 1 352 | 353 | 354 | # COMMERCIAL TRIMMING (optional) 355 | comskipped="$(jq -r 'select (( .Commercials[0] )) | {ID} | join (" ")' < "${1}.json" )" # Has comskip been run successfully? 356 | [ "${comskipped}" -ne "${1}" ] && [ "${COMTRIM}" -eq 1 ] && notify_me "${bname}: Cannot be comtrimmed due to lack of comskip results" 357 | if [ "${COMTRIM}" -eq 1 ] && [ "${comskipped}" -eq "${1}" ]; then 358 | # Perform the actual file splitting 359 | curl -s "${CHANNELS_DB}/${1}/comskip.ffsplit" > "${1}.ffsplit"; ffsplit="${1}.ffsplit" 360 | [ "$VERBOSE" -ne 0 ] && echo "Attempting to trim input file" 361 | while read -r split <&3; do 362 | "${FFMPEG_CLI}" -i "${fname}" "${split}" || ctfail=1 363 | done 3< "${ffsplit}" 364 | for i in segment*; do echo "file \'${i}\'" >> "${bname}.lis" ; done 365 | [ $ctfail -eq 1 ] || "${FFMPEG_CLI}" -f concat -i "${bname}.lis" -c copy "${1}_cut.${extension}" || ctfail=1 366 | [ $ctfail -eq 1 ] || mv -f "${1}_cut.${extension}" "${fname}" || ctfail=1 367 | [ $ctfail -eq 1 ] && notify_me "${bname} comtrim failed" 368 | rm -f segment* "${bname}.lis" 369 | fi 370 | 371 | 372 | # THE TRANSCODING PART 373 | echo "Attempting to transcode ${fname} ..." 374 | 375 | # Determine output video size 376 | height="$(${JQ_CLI} '.streams[] | select(.codec_type == "video") | .height' < "${1}_mi.json")" 377 | ht=$(( height < MAXSIZE ? height : MAXSIZE )) 378 | hdvideo=0 && [ "$ht" -gt 700 ] && hdvideo=1 && [ "$ht" -gt 1000 ] && hdvideo=2 379 | 380 | # Tag with metadata 381 | echo ";FFMETADATA1" > "${1}.ffmeta" 382 | echo hd_video=${hdvideo} >> "${1}.ffmeta" 383 | 384 | case "$(jq -r '.Airing.Raw.program.subType' < "${1}.json")" in 385 | "Series") 386 | echo media_type=10 >> "${1}.ffmeta" 387 | echo title=${title} >> "${1}.ffmeta" 388 | echo show=${showname} >> "${1}.ffmeta" 389 | echo episode_id=${episode} >> "${1}.ffmeta" 390 | echo season_number=${season} >> "${1}.ffmeta" 391 | channel="$(${JQ_CLI} -r '.Airing.Channel' < "${1}.json")" 392 | network="$("${CURL_CLI}" -s "${CHANNELS_DB}/../guide/channels" | "${JQ_CLI}" -r '.[] | select(.Number=="'"$channel"'") | .Name')" 393 | echo network=${network} >> "${1}.ffmeta" 394 | ;; 395 | *) 396 | echo media_type=9 >> "${1}.ffmeta" 397 | echo title=${showname} >> "${1}.ffmeta" 398 | echo date=${year} >> "${1}.ffmeta" 399 | ;; 400 | esac 401 | echo comment="$(${JQ_CLI} -r '.Airing.Raw.program.shortDescription' < "${1}.json")" >> "${1}.ffmeta" 402 | echo synopsis="$(${JQ_CLI} -r '.Airing.Raw.program.longDescription' < "${1}.json")" >> "${1}.ffmeta" 403 | 404 | # Add commercial markers if available 405 | [ "${CHAPTERS}" -eq 1 ] && [ "${comskipped}" -eq "${1}" ] && curl -s "${CHANNELS_DB}/${1}/comskip.ffmeta" | grep -v FFMETADATA >> "${1}.ffmeta" 406 | FFMPEG_OPTS+=(-i "${1}.ffmeta" -map_metadata 1) 407 | 408 | # Add album artwork if available: placeholder, as feature is currently unsupported by ffmpeg, although is a requested feature) 409 | # For now, you'll need AtomicParsley for this. 410 | #"${CURL_CLI}" -o ${1}.jpg "$(${JQ_CLI} -r '.Airing.Image' < "${1}.json")" 411 | #[ -s "${1}.ffmeta" ] 412 | #[ -s "${1}.jpg" ] && FFMPEG_OPTS+=(-i "${1}.jpg" ) 413 | 414 | # Video stream 415 | FFMPEG_OPTS+=(-map 0:0 -c:v libx264) # Specify video stream 416 | [ "$MAXSIZE" ] && [ "$MAXSIZE" -lt "$height" ] && height=${MAXSIZE} && FFMPEG_OPTS+=(-vf "scale=-1:${height}") # Limit width and height of video stream 417 | [ "${QUALITY}" ] || QUALITY=21 # Set default quality level (-crf flag for x264/ffmpeg) 418 | [ "${SPEED}" ] || SPEED="veryfast" # Set default speed level (-preset flag for x264/ffmpeg) 419 | [ "$height" -lt 1000 ] && QUALITY=$(( QUALITY - 1 )) && [ "$height" -lt 700 ] && QUALITY=$(( QUALITY - 1 )) && [ "$height" -lt 500 ] && QUALITY=$(( QUALITY - 1 )) 420 | QUALITY=$(( QUALITY > 18 ? QUALITY : 18 )) # Adjust quality sensibly 421 | FFMPEG_OPTS+=(-preset "${SPEED}" -crf "${QUALITY}" -profile:v high -level 4.0) # Video stream encoding options 422 | 423 | # Audio streams 424 | FFMPEG_OPTS+=(-map 0:1 -c:a:0 aac -b:a:0 160k) # Specify first audio stream 425 | FFMPEG_OPTS+=(-map 0:2 -c:a:1 copy) # Specify second audio stream 426 | FFMPEG_OPTS+=(-movflags faststart) # Optimize for streaming 427 | if [ "$VERBOSE" -ne 0 ] ; then 428 | for arg in "${FFMPEG_CLI}" -hide_banner -i "${fname}" "${FFMPEG_OPTS[@]}" "${1}.mp4"; do 429 | if [[ $arg =~ \ ]]; then arg=\"$arg\"; fi 430 | echo -n "$arg " 431 | done; echo 432 | fi 433 | 434 | # The actual transcoding command! Requires Channels DVR >= 2017.04.13.0150 435 | "${FFMPEG_CLI}" -hide_banner -i "${fname}" "${FFMPEG_OPTS[@]}" "${1}.m4v" || ( notify_me "${bname} transcode failed." ; return 6 ) 436 | rm -f "${fname}" # Delete tmp input file/link 437 | 438 | 439 | # TAG THE FILE FOR ITUNES 440 | # This adds episode artwork, content rating, production date and a fake cnID tag which effectively enables production of SD-HD files if desired 441 | [ -f "${1}.m4v" ] && [ "${AP_CLI}" ] && ap_tagger "${1}" "${height}" || ( notify_me "Tagging of ${bname} failed") 442 | 443 | 444 | # CLEAN UP AND DELIVER 445 | # Clean up some files 446 | [ "${DEBUG}" -ne 1 ] && rm -f "${1}.json" "${1}_mi.json" "${1}.jpg" "${1}.vdr" "${1}.ffsplit" "${1}.mpg" "${1}.ts" "${1}-temp-*.m4v" 447 | 448 | # Determine if destination directory exists on local system, and create target folder if so. 449 | # If not, bail. (Alternative approach to return file over GNU parallel protocol T.B.D.) 450 | if [ "${DEST_DIR}" ] && [ -d "${DEST_DIR}" ] && mkdir -p "${tdname}" && mv -f "${1}.m4v" "${tdname}/${bname}.m4v"; then 451 | notify_me "${bname}.m4v delivery succeeded." 452 | else 453 | msg="${bname}.m4v failed to write to ${tdname}/." 454 | [ -d "${DEST_DIR}" ] || msg+=" Specific desination directory does not exist." 455 | if [ "${BACKUP_DIR}" ]; then 456 | mv -f "${1}.m4v" "${BACKUP_DIR}/${bname}.m4v" && msg+=" File sent to backup directory." || msg+=" File backup failed." 457 | fi 458 | notify_me "${msg}" 459 | return 5 460 | fi 461 | return 0 462 | } 463 | 464 | ## WAIT UNTIL SYSTEM IS NOT BUSY THEN CLEAN UP DEAD JOBS AND TRANSCODE DATABASE 465 | # 466 | 467 | # Wait until the system is done with recording, commercial skipping and transcoding 468 | [ "${BUSY_WAIT}" ] || BUSY_WAIT=1 # Set Default behaviour 469 | transcode_jobs="$(pgrep -fa "/bin/bash channels-transcoder.sh" | grep -vw $$ | grep -c bash)" # Check for other transcoding jobs 470 | channels_busy="$(curl -s "${CHANNELS_DB}/../../dvr" | jq '.busy')" # Check to see if Channels DVR is busy 471 | 472 | # Loop until no transcoding jobs, channels is no longer busy, or timeout. Default is about a day. 473 | if [ "${BUSY_WAIT}" -eq 1 ] && [ "${transcode_jobs}" -ge 1 ] ; then 474 | #if [ "${BUSY_WAIT}" -eq 1 ] && ( [ "${channels_busy}" == true ] || [ "${transcode_jobs}" -ge 1 ] ) ; then 475 | [ "${TIMEOUT}" ] || TIMEOUT=82800 476 | delay="${TIMEOUT} seconds" ; [ "${TIMEOUT}" -ge 60 ] && delay="$((TIMEOUT/60)) minutes" ; [ "${TIMEOUT}" -ge 3600 ] && delay="$((TIMEOUT/3600)) hours" 477 | TIMER=0 478 | 479 | [ "${transcode_jobs}" -gt 1 ] && ( notify_me "Too many instances of channels-transcode.sh running. Preventing execution." ; exit 10 ) 480 | echo "Waiting ~${delay} until Channels is no longer busy and no transcode jobs exist. Set BUSY_WAIT=0 to prevent." 481 | 482 | # Loop until Channels DVR isn't busy and there are no other active transcode jobs. 483 | while [ "${channels_busy}" == true ] || [ "${transcode_jobs}" -ge 1 ]; do 484 | if [ "${TIMER}" -gt "${TIMEOUT}" ]; then notify_me "Instance of channels-transcoder.sh timed out at ${delay}." ; exit 11; fi 485 | sleep 60; TIMER=$((TIMER+60)) 486 | channels_busy="$(curl -s "${CHANNELS_DB}/../../dvr" | jq '.busy')" # Check if Channels DVR is busy 487 | transcode_jobs="$(pgrep -fa "/bin/bash channels-transcoder.sh" | grep -vw $$ | grep -c bash)" # Check for other transcoding jobs 488 | done 489 | fi 490 | 491 | # Search through temporary directory to find and clean up any stalled jobs from GNU parallel 492 | [ ! "$TMP_PREFIX" ] && TMP_PREFIX="transcode" 493 | for i in ${WORKING_DIR/ /\ }/${TMP_PREFIX}.*/progress.txt; do 494 | delete_tmp=1 495 | if [ -f "${i}" ] ; then 496 | old_tmpdir="$(dirname "${i}")" 497 | n="$(grep transcode < "${i}" | awk '$7 == 0 || $7 == 1 || $7 == 3 {print $10}')" 498 | for j in $n; do [ -f "${old_tmpdir}/${i}.m4v" ] && delete_tmp=0 || echo "${j}" >> "${TRANSCODE_DB}"; done 499 | if [ ${delete_tmp} -eq 0 ]; then 500 | notify_me "Transcoded files exist in ${old_tmpdir}. Please delete or move manually." 501 | else 502 | if rm -rf "${old_tmpdir}"; then notify_me "Cleaned up ${old_tmpdir}"; else notify_me "Couldn't delete ${old_tmpdir}"; fi 503 | fi 504 | fi 505 | done 506 | 507 | # Clean up transcode database 508 | uniq < "${TRANSCODE_DB}" | sort -n > "tmp.db" || (notify_me "Could not update transcode.db"; exit 13) 509 | mv -f tmp.db "${TRANSCODE_DB}" 510 | 511 | 512 | ## CREATE LIST OF SHOWS TO BE TRANSCODED. 513 | # If none can be accessed, quit, otherwise report on how many shows to do. 514 | rlist="${TMPDIR}/recordings.list" 515 | jlist="${TMPDIR}/recordings.json" 516 | "${CURL_CLI}" -s "${CHANNELS_DB}" > "${jlist}" 517 | 518 | # Add explicitly named files 519 | if [ "${filelist}" ] || [ "${SOURCE_FILE}" ] ; then 520 | [ "${DAYS}" ] || DAYS=0 521 | [ "${SOURCE_FILE}" ] && [ "${SOURCE_FILE}" == "$(realpath "${SOURCE_FILE}")" ] && SOURCE_FILE="$(basename "${SOURCE_FILE}")" 522 | for i in ${filelist} ${SOURCE_FILE}; do 523 | [ "${i}" == "$(realpath "${i}")" ] && i="$(basename "${i}")" 524 | "${JQ_CLI}" -r '.[] | select (.Path | contains("'"${i}"'")) | select (.Deleted == false) | select (.Processed == true) | {ID} | join(" ")' < "${jlist}" >> tmp.list 525 | done 526 | fi 527 | 528 | # Add explicitly numbered files 529 | if [ "${apilist}" ] ; then 530 | for i in ${apilist}; do 531 | [ "${DAYS}" ] || DAYS=0 532 | "${JQ_CLI}" -r '.[] | select (.Path) | select(.ID == "'"$i"'") | select (.Deleted == false) | select (.Processed == true) | {ID} | join(" ")' < "${jlist}" >> tmp.list 533 | done 534 | fi 535 | 536 | # Add list of new shows that have not previously been processed 537 | "${JQ_CLI}" -r '.[] | select ((.Airing.Raw.endTime >= "'"$since"'")) | select (.Deleted == false) | select (.Processed == true) | {ID} | join(" ")' \ 538 | < "${jlist}" | grep -Fxv -f "${TRANSCODE_DB}" >> tmp.list 539 | 540 | # Clean up list to avoid duplication and set recording order 541 | uniq < tmp.list > "${rlist}" 542 | rm -f tmp.list 543 | 544 | # Report how many news shows have been found 545 | count=$(wc -l "${rlist}" | cut -d" " -f1) 546 | if [ "$count" ]; then 547 | if [ "${count}" -eq 0 ] ; then notify_me "No new shows to transcode"; exit 0 ; fi 548 | notify_me "Found ${count} new shows to transcode." 549 | else 550 | notify_me "No new shows to transcode"; exit 0 551 | fi 552 | 553 | 554 | ## RUN THE MAIN LOOP TO ACTIVATE TRANSCODING JOBS 555 | # Optionally via GNU parallel 556 | # To do: Only add shows to transcode database if successful, or remove them if unsuccessful 557 | export MP4BOX_CLI JQ_CLI FFMPEG_CLI CURL_CLI AP_CLI TSNAME \ 558 | PRESET SPEED EXTRAS MAXSIZE ALLOW_EAC3 \ 559 | DEST_DIR SOURCE_DIR BACKUP_DIR CHANNELS_DB TMPDIR OVERWRITE \ 560 | COMTRIM CHAPTERS LANG DELETE_ORIG IFTTT_MAKER_KEY VERBOSE DEBUG AP_OLD 561 | export -f showname_clean notify_me transcode ap_tagger 562 | 563 | if [ "$PARALLEL_CLI" ]; then 564 | if [ "$COMTRIM" == 1 ]; then PARALLEL_OPTS+=(--delay 120); fi 565 | PARALLEL_OPTS+=(--joblog "progress.txt" --results progress --progress) 566 | # The following need to be exported to use GNU parallel: 567 | "${PARALLEL_CLI}" --record-env 568 | "${PARALLEL_CLI}" --env _ "${PARALLEL_OPTS[@]}" -a "${rlist}" transcode {} 569 | while read -r i; do 570 | exitcode="$(grep "${TSNAME} ${i}" < progress.txt | awk '{print $7}')" 571 | case $exitcode in 572 | 0) echo "${i}" >> "${TRANSCODE_DB}" ;; 573 | 1) echo "${i}" >> "${TRANSCODE_DB}" ;; 574 | 3) echo "${i}" >> "${TRANSCODE_DB}"; flist+="${i} " ;; 575 | *) flist+="${i} " ;; 576 | esac 577 | done < "${rlist}" 578 | else 579 | while read -r i ; do 580 | transcode "${i}" 581 | case $? in 582 | 0) echo "${i}" >> "${TRANSCODE_DB}" ;; 583 | 1) echo "${i}" >> "${TRANSCODE_DB}" ;; 584 | 3) echo "${i}" >> "${TRANSCODE_DB}"; flist+="${i} " ;; 585 | *) flist+="${i} " ;; 586 | esac 587 | done < "${rlist}" 588 | fi 589 | 590 | if [ "${flist}" ]; then 591 | notify_me "Transcoding complete. There were issues with: ${flist}. See log file for more details." 592 | else 593 | notify_me "Transcoding completed successfully" 594 | fi 595 | 596 | # Exit cleanly 597 | exit 0 598 | 599 | ## EXIT/RETURN CODES 600 | #0: E/R: All is good 601 | #1: E: Couldn't access SOURCE_PREFS 602 | #2: E/R: Problems accessing TEMPDIR 603 | #3: R: Input file already deleted 604 | #4: E: Cannot find input video 605 | #5: E/R: Cannot write to target directory 606 | #6: R: Transcoding failure 607 | #9: E: Unix program missing 608 | #10: E: Too many jobs for another instance. Quitting. 609 | #13: E: Cannot access TRANSCODE_BD 610 | #14: E: Cannot access API 611 | #15: E: Cannot delete old jobs 612 | -------------------------------------------------------------------------------- /com.getchannels.channels-transcoder.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Label 6 | com.getchannels.channels-transcoder.plist 7 | Nice 8 | 10 9 | StandardOutPath 10 | ${HOME}/Library/Application Support/channels-transcoder/log 11 | StandardErrorPath 12 | ${HOME}/Library/Application Support/channels-transcoder/log.err 13 | ProgramArguments 14 | 15 | caffeinate 16 | -s 17 | /usr/local/bin/channels-transcoder.sh 18 | 19 | StartCalendarInterval 20 | 21 | Hour 22 | 00 23 | Minute 24 | 01 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ifttt-maker-transcode-plex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karllmitchell/Channels-DVR-to-Plex/5661ee9fdfd4668b73807f3167c92087cc2b3450/ifttt-maker-transcode-plex.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Installer for Channels-DVR-to-Plex software 3 | # Should be safe for previous users, but check prefs folder after running, just in case 4 | # Run as "bash install.sh" or "chmod 700 install.sh; ./install.sh" 5 | 6 | set -e 7 | 8 | tplist="com.getchannels.channels-transcoder.plist" 9 | fname="channels-transcoder" 10 | oname="transcode-plex" 11 | targetdir="/usr/local/bin/" 12 | 13 | echo "If you're running this script on a machine other than the one running Channels DVR, you should specify the host here." 14 | echo -n "Enter the hostname and port number (leave blank for default \"localhost:8089\"), followed by [ENTER]: " 15 | read -r host_name # Host for video recordings 16 | [ "${host_name}" ] || host_name="localhost:8089" 17 | 18 | echo "Checking for critical pre-requisite programs:" 19 | echo " jq curl ffmpeg coreutils wget" 20 | echo "Optional packages include:" 21 | echo " AtomicParsley (preferably >= 0.9.6) and parallel >= 20161222" 22 | echo "If they do not exist on your system, please use whichever package manager" 23 | echo " works for your system to install them" 24 | echo "On Ubuntu/Debian Linux:" 25 | echo " sudo apt-get install jq curl ffmpeg coreutils wget" 26 | echo "On Mac, use homebrew, macports or fink similarly." 27 | 28 | [ ! "$(which curl)" ] && echo " curl not installed." && prfail=1 29 | [ ! "$(which jq)" ] && echo " jq not installed." && prfail=1 30 | 31 | datadir="$(curl -s "http://${host_name}/system" | jq -r '.pwd')" 32 | [ -d "${datadir}" ] || echo " Channels DVR API not present at defined host. Is Channels DVR installed?" && prfail=1 33 | idir="$(dirname "$datadir")" 34 | 35 | [ ! "$(which ffmpeg)" ] && [ ! -f "${idir}/latest/ffmpeg" ] && echo " ffmpeg not installed, or is inaccessible (ensure that "which ffmpeg" works before trying again)." && prfail=1 36 | [ ! "$(which wget)" ] && echo " wget not installed." && prfail=1 37 | [ ! "$(which jq)" ] && echo " jq not installed." && prfail=1 38 | [ ! "$(which curl)" ] && echo " curl not installed." && prfail=1 39 | [ ! "$(which realpath)" ] && echo " realpath, part of coreutils (a new requirement), not installed." && prfail=1 40 | 41 | [ "${prfail}" -eq 1 ] && [ "$1" != "force" ] && echo "Some pre-requisites not installed." && echo "Please try again or use \"bash install.sh force\" to proceed regardless, then edit your prefs file manually" && echo "You will need wget regardless for this install script to work" && exit 1 42 | 43 | 44 | # Download archive, unzip and change directories 45 | rm -f master.zip* 46 | wget https://github.com/karllmitchell/Channels-DVR-to-Plex/archive/master.zip 47 | unzip master.zip 48 | cd Channels-DVR-to-Plex-master || ( echo "Download did not work. Exiting" ; exit 1 ) 49 | chmod 755 "${fname}.sh" 50 | 51 | # Import obsolete folders 52 | echo "Checking for obsolete versions of preferences folder" 53 | if [ "$(uname)" == "Darwin" ]; then 54 | prefsdir="${HOME}/Library/Application Support/${fname}" 55 | if [ -d "${HOME}/Library/Application Support/${oname}" ] && [ -d "${HOME}/Library/Application Support/${fname}" ] ; then 56 | echo "Moving obsolete ${HOME}/Library/Application Support/${oname} to ${HOME}/Library/Application Support/${fname}" 57 | mv -f "${HOME}/Library/Application Support/${oname}" "${HOME}/Library/Application Support/${fname}" 58 | fi 59 | else 60 | prefsdir="${HOME}/.${fname}" 61 | if [ -d "${HOME}/.${oname}" ] && [ ! -d "${HOME}/.${fname}" ]; then 62 | echo "Moving obsolete ~/.${oname} to ~/.${fname}" 63 | mv -f "${HOME}/.${oname}" "${prefsdir}" 64 | fi 65 | fi 66 | echo "Done." 67 | echo 68 | 69 | # Generate prefs directory, with user inputs 70 | mkdir -p "${prefsdir}" 71 | if [ ! -f "${prefsdir}/prefs" ] ; then 72 | echo "The local destination directory is for producing Plex-like file structures." 73 | echo -n "Enter the desired destination directory (default \"${HOME}/Movies/Plex\"), followed by [ENTER]: " 74 | read -r destination # Destination for video recordings 75 | [ "${destination}" ] || destination="${HOME}/Movies/Plex" 76 | mkdir -p "${destination}" || ( echo "Destination directory unwritable. Bailing. Please re-run installation script." ; exit 1 ) 77 | 78 | 79 | # Install prefs file 80 | cat channels-transcoder.prefs | sed "/DEST_DIR*/c\DEST_DIR=\"${destination}\"" | sed "/HOST*/c\HOST=\"${host_name}\"" > "${prefsdir}/prefs" 81 | echo "Preferences file generated." 82 | else 83 | echo "Leaving old preferences file as is at: ${prefsdir}/prefs" 84 | fi 85 | echo 86 | 87 | # Install main binary 88 | echo "Installing main binary ..." 89 | nosudo=$(sudo -v 2>&1 >/dev/null) 90 | if [ "${nosudo}" ]; then 91 | targetdir="${HOME}/bin/" 92 | mkdir -p "${targetdir}" 93 | echo "Running completely in user-space. Ensure ${HOME}/bin is in your path." 94 | mv -f "${fname}.sh" "${targetdir}" 95 | chmod 755 "${targetdir}/${fname}.sh" 96 | else 97 | echo "Password may be required to install channels-transcoder to /usr/local/bin : " 98 | sudo mv -f "${fname}.sh" "${targetdir}" 99 | sudo chmod 755 "${targetdir}/${fname}.sh" 100 | fi 101 | echo "Main binary installed." 102 | echo 103 | 104 | # Transcode backlog if no transcode.db found 105 | if [ -f "${prefsdir}/transcode.db" ]; then 106 | echo "Existing transcode.db detected. If you would like to clear a backlog, enter the number of days below." 107 | echo "If show was previously transcoded and is listed in transcode.db, transcode will not transcode that show unless you delete ${prefsdir}/transcode.db first." 108 | else 109 | echo "No existing transcode.db detected. This will now be initiated." 110 | echo "If you would like to transcode previously transcoded shows, please pick a number of days worth of backlog to transcode, e.g. 1000" 111 | fi 112 | echo "If you have a lot of backlog, this will take significant time, so please do not close this terminal or reboot." 113 | echo -n "Enter the desired number of days of Channels DVR recordings backlog to transcode (default=0): " 114 | read -r days 115 | [ "${days}" ] || days=0 116 | [ "${days}" -gt 0 ] && echo "Please wait. You may check progress by opening another terminal and running: tail -f \"${prefsdir}/log\"" 117 | "${targetdir}/${fname}.sh" DAYS="${days}" > "${prefsdir}/log" 2>&1 118 | echo "Database OK." 119 | echo 120 | 121 | # Install launchagent (mac) or cronjob (other) in user space 122 | echo "Installing automation script..." 123 | if [ "$(uname)" == "Darwin" ] && [ "$(which launchctl)" ] ; then 124 | echo "Defaulting to using launchd under MacOS" >> "${2}/log" 125 | echo "If prompted, please enter your password now..." 126 | mv -f "${tplist}" "${HOME}/Library/LaunchAgents/${tplist}" 127 | launchctl load "${HOME}/Library/LaunchAgents/${tplist}" 128 | echo "Launch Agent installed. Inspect ${HOME}/Library/LaunchAgents/${tplist} if you would like to edit it." 129 | else 130 | # Update crontab 131 | count="$(crontab -l | sed "s/${oname}/${fname}/g" | grep -s "${fname}.sh" | wc -l)" 132 | case $count in 133 | 0) crontab -l > mycron 134 | echo "01 00 * * * nice \"${targetdir}/${fname}.sh\" >> \"${2}/log\"" >> mycron 135 | echo "Cronjob added, will run at 12:01 each night." 136 | ;; 137 | 1) crontab -l | sed "s/${oname}/${fname}/g" > mycron 138 | echo "Using/adapting existing crontab" 139 | ;; 140 | *) crontab -l | sed "s/${oname}/${fname}/g" | grep -v "${fname}" > mycron 141 | echo "01 00 * * * nice \"${targetdir}/${fname}.sh\" >> \"${2}/log\"" >> mycron 142 | echo "Cronjob had multiple entriees. Replaced with a single one that will run at 12:01 each night." 143 | esac 144 | crontab mycron 145 | rm -f mycron 146 | echo "Crontab installed. Run crontab -e if you would like to edit it." 147 | fi 148 | echo 149 | 150 | # Remove installation files 151 | cd .. 152 | rm -rf Channels-DVR-to-Plex-master master.zip || ( echo "Couldn't remove files, but everything else seems OK" && exit 1 ) 153 | echo "Installation files removed" 154 | echo "Done." 155 | 156 | exit 0 157 | -------------------------------------------------------------------------------- /monitor_jobs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Allows Channels-DVR-to-Plex jobs run with GNU parallels to be monitored in real-time 3 | # Usage: monitor_jobs.sh ${WORKING_DIR} 4 | 5 | find "${1} -name stdout -exec xterm -e tail -f {} \; 6 | --------------------------------------------------------------------------------