├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yaml │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── new_issue.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE.txt ├── Makefile ├── README.md ├── get_iplayer ├── get_iplayer.1 └── get_iplayer.cgi /.github/ISSUE_TEMPLATE/bug_report.yaml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report 3 | body: 4 | - type: markdown 5 | attributes: 6 | value: | 7 | ## Read First 8 | * Do not request help with using get_iplayer. User support will not be provided. 9 | * Do not request new features for get_iplayer. Feature requests will not be accepted. 10 | * All bug reports will automatically be closed and locked upon receipt. 11 | * If your report identifies a reproducible bug in get_iplayer, it will be re-opened until a fix is released. 12 | * You will receive no communication from the developers, so provide all the information required. 13 | - type: checkboxes 14 | attributes: 15 | label: Do not file a bug report if you are using get_iplayer outside the UK. If you do, your report will be ignored. 16 | options: 17 | - label: I am not using get_iplayer outside the UK 18 | required: true 19 | - type: checkboxes 20 | attributes: 21 | label: Do not file a bug report if you are using get_iplayer with a VPN or proxy from any location, including the UK. If you do, your report will be ignored. 22 | options: 23 | - label: I am not using get_iplayer with a VPN or proxy from any location, including the UK 24 | required: true 25 | - type: checkboxes 26 | attributes: 27 | label: Search the repository (search field at top left) to see if a report already exists for the bug in the issue tracker. Do not create a duplicate report. Duplicate reports will be ignored. 28 | description: See - **[Issue Tracker](https://github.com/get-iplayer/get_iplayer/issues)** 29 | options: 30 | - label: I have searched the repository and found no existing reports of the bug in the issue tracker 31 | required: true 32 | - type: checkboxes 33 | attributes: 34 | label: Review recent open and closed entries in the issue tracker to see if a report already exists for the bug. Do not create a duplicate report. Duplicate reports will be ignored. 35 | description: See - [Open Issues](https://github.com/get-iplayer/get_iplayer/issues?q=is%3Aopen+is%3Aissue), [Closed Issues](https://github.com/get-iplayer/get_iplayer/issues?q=is%3Aclosed+is%3Aissue) 36 | options: 37 | - label: I have reviewed recent open and closed entries in the issue tracker and found no existing reports of the bug 38 | required: true 39 | - type: checkboxes 40 | attributes: 41 | label: Ensure that you are using get_iplayer 3.36 or higher. If not, your report will be ignored. 42 | description: Check version with **`get_iplayer -V` or see the bottom of the Web PVR search page** 43 | options: 44 | - label: I am using get_iplayer 3.36 or higher 45 | required: true 46 | - type: input 47 | attributes: 48 | label: Identify the operating system and version where get_iplayer demonstrates the bug 49 | description: Examples - Ubuntu 20.04, Fedora 34, Arch, OpenBSD 6.8, macOS 10.14, macOS Monterey (M1), Windows 10 50 | validations: 51 | required: true 52 | - type: textarea 53 | attributes: 54 | label: Provide a clear and concise description of the bug. Do not paste get_iplayer output or screenshots into the field below. If you do, your report will be ignored. 55 | validations: 56 | required: true 57 | - type: input 58 | attributes: 59 | label: Provide the PID or URL of the programme you are attempting to download, if applicable. Provide the PID or URL for only one programme. 60 | validations: 61 | required: false 62 | - type: textarea 63 | attributes: 64 | label: Provide the complete get_iplayer command line that demonstrates the bug. Do not truncate or excerpt the command. If you do, your report will be ignored. If you are using the Web PVR, list the steps necessary to reproduce the bug, in as much detail as possible. 65 | validations: 66 | required: true 67 | - type: markdown 68 | attributes: 69 | value: | 70 | ## Create a verbose log file for the bug (e.g., "log.txt") using the `--verbose` option: 71 | ```bash 72 | get_iplayer [your options here] --verbose > log.txt 2>&1 73 | ``` 74 | ### Do not truncate or excerpt your verbose log file. If you do, your report will be ignored. If you are using the Web PVR, copy output from both your web browser and the Web PVR console window and paste it into a plain text file. Do not omit the console window output showing the get_iplayer command(s) invoked by the Web PVR. If you do, your report will be ignored. To minimise the amount of output in the console window, quit and restart the Web PVR, then immediately execute the command that demonstrates the bug. 75 | ### Do not submit screenshots instead of a log file. If you do, your report will be ignored. 76 | - type: textarea 77 | attributes: 78 | label: Drag your verbose log file into the field below to create an attachment. Your verbose log file must be added as an attachment. Do not paste its contents into the field below. If you do, your report will be ignored. You may enter a URL linking to your verbose log file on a pastebin site. If the bug prevents get_iplayer from running, enter "N/A" in the field below. If you enter any other text in the field below, your report will be ignored. 79 | validations: 80 | required: true 81 | - type: input 82 | attributes: 83 | label: If you are using the Web PVR, provide your web browser name and version. This information typically can be found from the application menu via Chrome/Firefox/Safari->About... (macOS) or Help->About... (Linux/Windows) 84 | description: Examples - Chrome 83.0.4103, Edge 83.0.478.56, Firefox 78.0.1, Safari 13.1.1 85 | validations: 86 | required: false 87 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Read first 2 | 3 | - Fixes for reproducible bugs are welcome. 4 | - New features will not be merged. 5 | - Enhancements will not be merged. 6 | - Breaking changes will not be merged. 7 | - Your pull request must be applied to the current master branch. 8 | - You will receive no communication from the developers, so ensure your pull request is complete. 9 | 10 | #### Delete this line and all text above before submitting your pull request. 11 | -------------------------------------------------------------------------------- /.github/workflows/new_issue.yml: -------------------------------------------------------------------------------- 1 | on: 2 | issues: 3 | types: 4 | - opened 5 | jobs: 6 | new-issue: 7 | runs-on: ubuntu-latest 8 | name: New Issue 9 | steps: 10 | - name: Close/Lock/Label 11 | shell: bash 12 | run: > 13 | gh issue close -R ${{ github.repository }} "${{ github.event.issue.number }}" && 14 | gh issue lock -R ${{ github.repository }} "${{ github.event.issue.number }}" && 15 | gh issue edit -R ${{ github.repository }} --add-label "invalid" "${{ github.event.issue.number }}" 16 | env: 17 | GH_TOKEN: ${{ github.token }} 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### See release notes: 2 | 3 | 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | See: 2 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | A. S. Budden 2 | Alexey Tourbin 3 | Andrew Elwell 4 | Andy Bircumshaw 5 | Bill Boughton 6 | Caius Durling 7 | Chris Reed, BBR 8 | Crispin Flowerday 9 | David Llewellyn-Jones 10 | David Woodhouse 11 | Edward Betts 12 | HenderHobbit 13 | Ian Praxil 14 | James 15 | James Laver 16 | James Ross 17 | James Teh 18 | John Henderson 19 | John Veness 20 | Jon Davies 21 | Jonathan Harris 22 | Jonathan Larmour 23 | Jonathan Wiltshire 24 | Matthew Boyle 25 | Mike Crowe 26 | Mike Fleetwood 27 | Murray 28 | Paul Martin 29 | Peter Oliver 30 | Phil Cole 31 | Ralf Baechle 32 | Sharon Kimble 33 | Shevek 34 | Steven Luo 35 | Stuart Henderson 36 | Vangelis forthnet 37 | Vangelis66 38 | Will Elwood 39 | dinkypumpkin 40 | fs ck 41 | fsck 42 | hintswen 43 | linuxcentrenet 44 | notnac 45 | wiehe 46 | willemw12 47 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | dummy: 2 | @echo No need to make anything. 3 | 4 | ifdef VERSION 5 | release: 6 | @git update-index --refresh --unmerged 7 | @if git diff-index --name-only HEAD | grep ^ ; then \ 8 | echo Uncommitted changes in above files; exit 1; fi 9 | @git checkout master 10 | @sed -i.bak -e 's/^\(my $$version = \).*/\1$(VERSION);/' get_iplayer 11 | @sed -i.bak -e 's/^\(my $$VERSION = \).*/\1$(VERSION);/' get_iplayer.cgi 12 | @sed -i.bak -e 's/\(get_iplayer \)[0-9.]\{1,\}\( or higher\)/\1$(VERSION)\2/g' .github/ISSUE_TEMPLATE/bug_report.yaml 13 | @rm -f get_iplayer.bak get_iplayer.cgi.bak .github/ISSUE_TEMPLATE/bug_report.yaml.bak 14 | @./get_iplayer --nocopyright --manpage get_iplayer.1 15 | @git diff --exit-code get_iplayer.1 > /dev/null || \ 16 | sed -i.bak -e 's/\(\.TH GET_IPLAYER "1" "\)[^"]*"/\1$(shell date +"%B %Y")\"/' get_iplayer get_iplayer.1 17 | @rm -f get_iplayer.bak get_iplayer.1.bak 18 | @git log --format='%aN' | sort -u > CONTRIBUTORS; git add CONTRIBUTORS 19 | @git commit -m "Release $(VERSION)" get_iplayer get_iplayer.cgi get_iplayer.1 CONTRIBUTORS .github/ISSUE_TEMPLATE/bug_report.yaml 20 | @git tag v$(VERSION) 21 | 22 | tarball: 23 | @git update-index --refresh --unmerged 24 | @if git diff-index --name-only v$(VERSION) | grep ^ ; then \ 25 | echo Uncommitted changes in above files; exit 1; fi 26 | git archive --format=tar --prefix=get_iplayer-$(VERSION)/ v$(VERSION) | gzip -9 > get_iplayer-$(VERSION).tar.gz 27 | endif 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## get_iplayer: BBC iPlayer/BBC Sounds Indexing Tool and PVR 2 | 3 | ## Features 4 | 5 | * Downloads TV and radio programmes from BBC iPlayer/BBC Sounds 6 | * Allows multiple programmes to be downloaded using a single command 7 | * Indexing of most available iPlayer/Sounds catch-up programmes from previous 30 days (not Red Button, iPlayer Exclusive, or Podcast-only) 8 | * Caching of programme index with automatic updating 9 | * Regex search on programme name 10 | * Regex search on programme description and episode title 11 | * Filter search results by channel 12 | * Direct download via programme ID or URL 13 | * PVR capability (may be used with cron or Task Scheduler) 14 | * HTTP proxy support 15 | * Perl 5.16+ required, plus LWP, LWP::Protocol::https, XML::LibXML, Mojolicious, and CGI modules 16 | * Requires ffmpeg for conversion to MP4 and AtomicParsley for metadata tagging 17 | * Runs on Linux/BSD (Ubuntu, Fedora, OpenBSD and others), macOS (10.10+), Windows (7/8/10) 18 | 19 | **NOTE:** 20 | 21 | - **get_iplayer can only search for programmes that were scheduled for broadcast on BBC linear services within the previous 30 days, even if some are available for more than 30 days on the iPlayer/Sounds sites. Red button programmes, iPlayer box sets, web-only content, and BBC podcasts are not searchable. Programmes that are still available after 30 days must be located on the iPlayer/Sounds sites and downloaded directly via PID or URL.** 22 | - **get_iplayer does not support downloading news/sport videos, other embedded media, archive programmes, special collections, educational material, programme clips or any content other than whole episodes of programmes scheduled for broadcast on BBC linear services within the previous 30 days. However, it is generally possible to download other content such as red button programmes, iPlayer box sets, or podcasts directly via PID or URL. get_iplayer DOES NOT support live recording from BBC channels.** 23 | 24 | ## Documentation 25 | 26 | 27 | 28 | ## Installation 29 | 30 | 31 | 32 | ## Usage 33 | 34 | get_iplayer --help 35 | get_iplayer --basic-help 36 | get_iplayer --long-help 37 | 38 | ## Examples 39 | 40 | * List all TV programmes (`--type=tv` set by default): 41 | 42 | `get_iplayer ".*"` 43 | 44 | Search output appears in this format: 45 | 46 | ... 47 | 208: Doctor Who: Series 7 Part 2 - 1. The Bells of Saint John, BBC One, b01rryzz 48 | 209: Doctor Who: Series 7 Part 2 - 2. The Rings Of Akhaten, BBC One, b01rx0lj 49 | 210: Doctor Who: Series 7 Part 2 - 3. Cold War, BBC One, b01s1cz7 50 | ... 51 | 52 | Format = `: - , , ` 53 | 54 | * List all TV programmes with long descriptions: 55 | 56 | `get_iplayer --long ".*"` 57 | 58 | * List all radio programmes: 59 | 60 | `get_iplayer --type=radio ".*"` 61 | 62 | * List all TV programmes with "doctor who" in the name (matching is case-insensitive): 63 | 64 | `get_iplayer "doctor who"` 65 | 66 | * List all TV and radio programmes with "doctor who" in the name: 67 | 68 | `get_iplayer --type tv,radio "doctor who"` 69 | 70 | * List all BBC One programmes: 71 | 72 | `get_iplayer --channel="BBC One" ".*"` 73 | 74 | * List Radio 4 and Radio 4 Extra programmes with "Book at Bedtime" in the title: 75 | 76 | `get_iplayer --type=radio --channel="Radio 4" "Book at Bedtime"` 77 | 78 | * List only Radio 4 programmes with "Book at Bedtime" in the title: 79 | 80 | `get_iplayer --type=radio --channel="Radio 4$" "Book at Bedtime"` 81 | 82 | *(The `$` regular expression metacharacter matches "Radio 4" only at the end of the channel name, thus avoiding matches against "Radio 4 Extra")* 83 | 84 | * Record TV programme number 208 (index from search results) in HD, with fallback to lower quality if not available: 85 | 86 | `get_iplayer --get 208` [default setting] 87 | 88 | or 89 | 90 | `get_iplayer --get 208 --tv-quality=hd,sd,web,mobile` [explicit setting] 91 | 92 | * Record TV programme number 208 in lower resolution only (704x396@50): 93 | 94 | `get_iplayer --get 208 --tv-quality=web` 95 | 96 | * Record TV programme number 208 and download subtitles in SubRip (SRT) format: 97 | 98 | `get_iplayer --get 208 --subtitles` 99 | 100 | * Record multiple TV programmes (using index numbers from search results): 101 | 102 | `get_iplayer --get 208 209 210` 103 | 104 | * Record a TV programme using its iPlayer URL: 105 | 106 | `get_iplayer https://www.bbc.co.uk/iplayer/episode/b01sc0wf/Doctors_Series_15_Perfect/` 107 | 108 | * Record a TV programme using the PID (b01sc0wf) from its iPlayer URL: 109 | 110 | `get_iplayer --pid=b01sc0wf` 111 | 112 | * Record a radio programme using its Sounds URL: 113 | 114 | `get_iplayer https://www.bbc.co.uk/sounds/play/b07gcv34` 115 | 116 | * Record a radio programme using the PID (b07gcv34) from its Sounds URL in high quality (320k), with fallback to lower quality if not available (default setting): 117 | 118 | `get_iplayer --pid=b07gcv34` [default setting] 119 | 120 | OR 121 | 122 | `get_iplayer --pid=b07gcv34 --radio-quality=high,std,med,low` [explicit setting] 123 | 124 | * Record a radio programme using the PID (b07gcv34) from its Sounds URL with lower bit rate only (96k): 125 | 126 | `get_iplayer --pid=b07gcv34 --radio-quality=med` 127 | 128 | * Record multiple radio programmes (using PIDs from Sounds URLs): 129 | 130 | `get_iplayer --pid=b07gcv34,b07h60ld` [comma-separated list] 131 | 132 | OR 133 | 134 | `get_iplayer --pid=b07gcv34 --pid=b07h60ld` [multiple arguments] 135 | 136 | NOTE: Sometimes you may not be able to download a listed programme immediately after broadcast (usually available within 24hrs of airing). Some BBC programmes may not be available from iPlayer/Sounds. 137 | -------------------------------------------------------------------------------- /get_iplayer.1: -------------------------------------------------------------------------------- 1 | .TH GET_IPLAYER "1" "May 2025" "Phil Lewis" "get_iplayer Manual" 2 | .SH NAME 3 | get_iplayer \- Stream Recording tool and PVR for BBC iPlayer and BBC Sounds 4 | .SH SYNOPSIS 5 | \fBget_iplayer\fR [] [ ...] 6 | .PP 7 | \fBget_iplayer\fR \fB\-\-get\fR [] ... 8 | .PP 9 | \fBget_iplayer\fR [\fB\-\-type\fR= ] 10 | .PP 11 | \fBget_iplayer\fR [\fB\-\-type\fR= ] 12 | .PP 13 | \fBget_iplayer\fR \fB\-\-refresh\fR [\fB\-\-type\fR= ] 14 | .SH DESCRIPTION 15 | \fBget_iplayer\fR lists, searches and records BBC iPlayer TV and BBC Sounds radio programmes. 16 | .PP 17 | \fBget_iplayer\fR has two modes: recording a complete programme for later playback, and as a Personal Video Recorder (PVR), subscribing to 18 | search terms and recording programmes automatically. 19 | .PP 20 | If given the regex ".*" (incl. quotes), \fBget_iplayer\fR updates and displays the list of currently available TV programmes. 21 | Use \-\-type=radio for radio programmes. Each available programme has an alphanumeric identifier (\fBPID\fR). 22 | .PP 23 | In PVR mode, \fBget_iplayer\fR can be called from cron to record programmes on a schedule. 24 | .SH "OPTIONS" 25 | .PP 26 | Boolean options can be negated by adding a "no\-" prefix, e.g., \-\-no\-subtitles or \-\-no\-whitespace. 27 | This applies even if the base option name already begins with "no\-", e.g., \-\-no\-no\-tag or \-\-no\-no\-artwork 28 | .SS "Search Options:" 29 | .TP 30 | \fB\-\-available\-before 31 | Limit search to programmes that became available before hours ago 32 | .TP 33 | \fB\-\-available\-since 34 | Limit search to programmes that have become available in the last hours 35 | .TP 36 | \fB\-\-before 37 | Limit search to programmes added to the cache before hours ago 38 | .TP 39 | \fB\-\-category 40 | Narrow search to matched categories (comma\-separated regex list). Defaults to substring match. Only works with \-\-history. 41 | .TP 42 | \fB\-\-channel 43 | Narrow search to matched channel(s) (comma\-separated regex list). Defaults to substring match. 44 | .TP 45 | \fB\-\-exclude 46 | Narrow search to exclude matched programme names (comma\-separated regex list). Defaults to substring match. 47 | .TP 48 | \fB\-\-exclude\-category 49 | Narrow search to exclude matched categories (comma\-separated regex list). Defaults to substring match. Only works with \-\-history. 50 | .TP 51 | \fB\-\-exclude\-channel 52 | Narrow search to exclude matched channel(s) (comma\-separated regex list). Defaults to substring match. 53 | .TP 54 | \fB\-\-expires\-after 55 | Limit search to programmes that will expire after hours from now 56 | .TP 57 | \fB\-\-expires\-before 58 | Limit search to programmes that will expire before hours from now 59 | .TP 60 | \fB\-\-fields ,,... 61 | Searches only in the specified fields. The fields are concatenated with spaces in the order specified and the search term is applied to the resulting string. 62 | .TP 63 | \fB\-\-future 64 | Additionally search future programme schedule if it has been indexed (refresh cache with: \-\-refresh \-\-refresh\-future). 65 | .TP 66 | \fB\-\-history 67 | Search recordings history (requires search term) 68 | .TP 69 | \fB\-\-long, \-l 70 | Additionally search in programme descriptions and episode names (same as \-\-fields=name,episode,desc ) 71 | .TP 72 | \fB\-\-search 73 | GetOpt compliant way of specifying search args 74 | .TP 75 | \fB\-\-since 76 | Limit search to programmes added to the cache in the last hours 77 | .TP 78 | \fB\-\-type ,,... 79 | Only search in these types of programmes: tv,radio,all (tv is default) 80 | .SS "Display Options:" 81 | .TP 82 | \fB\-\-conditions 83 | Shows GPLv3 conditions 84 | .TP 85 | \fB\-\-debug 86 | Debug output (very verbose and rarely useful) 87 | .TP 88 | \fB\-\-dump\-options 89 | Dumps all options with their internal option key names 90 | .TP 91 | \fB\-\-help, \-h 92 | Intermediate help text 93 | .TP 94 | \fB\-\-helpbasic, \-\-usage 95 | Basic help text 96 | .TP 97 | \fB\-\-helplong 98 | Advanced help text 99 | .TP 100 | \fB\-\-hide 101 | Hide previously recorded programmes 102 | .TP 103 | \fB\-\-info, \-i 104 | Show full programme metadata and availability of streams and subtitles (max 40 matches) 105 | .TP 106 | \fB\-\-list 107 | Show a list of distinct element values (with counts) for the selected programme type(s) and exit. Valid elements are: 'channel' 108 | .TP 109 | \fB\-\-listformat 110 | Display search results with a custom format. Use substitution parameters in format string (see docs for list). 111 | .TP 112 | \fB\-\-long, \-l 113 | Show extended programme info 114 | .TP 115 | \fB\-\-manpage 116 | Create man page based on current help text 117 | .TP 118 | \fB\-\-nocopyright 119 | Don't display copyright header 120 | .TP 121 | \fB\-\-page 122 | Page number to display for multipage output 123 | .TP 124 | \fB\-\-pagesize 125 | Number of matches displayed on a page for multipage output 126 | .TP 127 | \fB\-\-quiet, \-q 128 | Reduce logging output 129 | .TP 130 | \fB\-\-series 131 | Display programme series names only with number of episodes 132 | .TP 133 | \fB\-\-show\-cache\-age 134 | Display the age of the selected programme caches then exit 135 | .TP 136 | \fB\-\-show\-options 137 | Show options which are set and where they are defined 138 | .TP 139 | \fB\-\-silent 140 | No logging output except PVR download report. Cannot be saved in preferences or PVR searches. 141 | .TP 142 | \fB\-\-sort 143 | Field to use to sort displayed matches 144 | .TP 145 | \fB\-\-sortreverse 146 | Reverse order of sorted matches 147 | .TP 148 | \fB\-\-streaminfo 149 | Returns all of the media stream URLs of the programme(s) 150 | .TP 151 | \fB\-\-terse 152 | Only show terse programme info (does not affect searching) 153 | .TP 154 | \fB\-\-tree 155 | Display programme listings in a tree view 156 | .TP 157 | \fB\-\-verbose, \-v 158 | Show additional output (useful for diagnosing problems) 159 | .TP 160 | \fB\-\-warranty 161 | Displays warranty section of GPLv3 162 | .TP 163 | \fB\-V 164 | Show get_iplayer version and exit. 165 | .SS "Recording Options:" 166 | .TP 167 | \fB\-\-attempts 168 | Number of attempts to make or resume a failed connection. \-\-attempts is applied per\-stream. Programmes have multiple streams available for each recording quality. 169 | .TP 170 | \fB\-\-audio\-only 171 | Only download audio stream for TV programme. Produces .m4a file. Implies \-\-force. 172 | .TP 173 | \fB\-\-download\-abort\-onfail 174 | Exit immediately if any stream fails to download. Use to avoid repeated failed download attempts if connection is dropped or access is blocked. 175 | .TP 176 | \fB\-\-exclude\-format ,,... 177 | Comma\-separated list of media stream formats to ignore when recording. Valid values: hls,dash. 178 | .TP 179 | \fB\-\-exclude\-supplier ,,... 180 | Comma\-separated list of media stream suppliers (CDNs) to skip. Possible values: akamai,limelight,bidi,cloudfront. Synonym: \-\-exclude\-cdn. 181 | .TP 182 | \fB\-\-force 183 | Ignore programme history (unsets \-\-hide option also). 184 | .TP 185 | \fB\-\-get, \-g 186 | Start recording matching programmes. Search terms required. 187 | .TP 188 | \fB\-\-hash 189 | Show recording progress as hashes 190 | .TP 191 | \fB\-\-include\-format ,,... 192 | Comma\-separated list of media stream to use when recording. Overrides \-\-exclude\-format. Valid values: hls,dash 193 | .TP 194 | \fB\-\-include\-supplier ,,... 195 | Comma\-separated list of media stream suppliers (CDNs) to use if not included by default or if previously excluded by \-\-exclude\-supplier. Possible values: akamai,limelight,bidi,cloudfront. Synonym: \-\-include\-cdn. 196 | .TP 197 | \fB\-\-log\-progress 198 | Force HLS/DASH download progress display to be captured when screen output is redirected to file. Progress display is normally omitted unless writing to terminal. 199 | .TP 200 | \fB\-\-mark\-downloaded 201 | Mark programmes in search results or specified with \-\-pid/\-\-url as downloaded by inserting records in download history. 202 | .TP 203 | \fB\-\-no\-merge\-versions 204 | Do not merge programme versions with same name and duration. 205 | .TP 206 | \fB\-\-no\-proxy 207 | Ignore \-\-proxy setting in preferences and/or http_proxy environment variable. 208 | .TP 209 | \fB\-\-no\-resume 210 | Do not resume partial HLS/DASH downloads. 211 | .TP 212 | \fB\-\-no\-verify 213 | Do not verify size of downloaded HLS/DASH file segments or file resize upon resume. 214 | .TP 215 | \fB\-\-overwrite 216 | Overwrite recordings if they already exist 217 | .TP 218 | \fB\-\-partial\-proxy 219 | Only uses web proxy where absolutely required (try this extra option if your proxy fails). 220 | .TP 221 | \fB\-\-pid ,,... 222 | Record arbitrary PIDs that do not necessarily appear in the index. 223 | .TP 224 | \fB\-\-pid\-index 225 | Update (if necessary) and use programme index cache with \-\-pid. Cache is not searched for programme by default with \-\-pid. Synonym: \-\-pid\-refresh. 226 | .TP 227 | \fB\-\-proxy, \-p 228 | Web proxy URL, e.g., http://username:password@server:port or http://server:port. Value of http_proxy environment variable (if present) will be used unless \-\-proxy is specified. Used for both HTTP and HTTPS. Overridden by \-\-no\-proxy. 229 | .TP 230 | \fB\-\-quality ,,... 231 | TV and radio recording quality preference. See \-\-tv\-quality and \-\-radio\-quality for available values and defaults. Default: default for programme type. 232 | .TP 233 | \fB\-\-radio\-quality ,,... 234 | Radio recording quality preference (overrides \-\-quality): high,std,med,low,default (Aliases: 320k,128k,96k,48k). Comma\-delimited list in descending order of preference. Default: high,std,med,low. 235 | .TP 236 | \fB\-\-start 237 | Recording/streaming start offset (actual start may be several seconds earlier for HLS and DASH streams) 238 | .TP 239 | \fB\-\-stop 240 | Recording/streaming stop offset (actual stop may be several seconds later for HLS and DASH streams) 241 | .TP 242 | \fB\-\-subtitles\-required 243 | Do not download TV programme if subtitles are not available. 244 | .TP 245 | \fB\-\-test, \-t 246 | Test only \- no recording (only shows search results with \-\-pvr and \-\-pid\-recursive) 247 | .TP 248 | \fB\-\-tv\-lower\-bitrate, \-\-tvlbr 249 | Prefer 25fps (or lower\-bitrate 50fps) streams for TV programmes if available. 250 | .TP 251 | \fB\-\-tv\-quality ,,... 252 | TV recording quality preference (overrides \-\-quality): fhd,hd,sd,web,mobile,default (Aliases: 1080p,720p,540p,396p,288p). Comma\-delimited list in descending order of preference. Default: hd,sd,web,mobile 253 | .TP 254 | \fB\-\-url ,,... 255 | Record the PIDs contained in the specified iPlayer episode URLs. Alias for \-\-pid. 256 | .TP 257 | \fB\-\-versions 258 | Version of programme to record. List is processed from left to right and first version found is downloaded. Example: '\-\-versions=audiodescribed,default' will prefer audiodescribed programmes if available. Versions: 'default,audiodescribed,signed,combined'. Default: 'default'. 259 | .SS "Recursive Recording Options:" 260 | .TP 261 | \fB\-\-pid\-recursive 262 | Record all related episodes if value of \-\-pid is a series or brand PID. Requires \-\-pid. 263 | .TP 264 | \fB\-\-pid\-recursive\-channel [,,...] 265 | Filter episode list to include only programmes where (regex or comma\-separated list of substrings) appears in channel name. Requires \-\-pid\-recursive. 266 | .TP 267 | \fB\-\-pid\-recursive\-exclude [,,...] 268 | Filter episode list to exclude all programmes where (regex or comma\-separated list of substrings) appears in series name or episode title. Requires \-\-pid\-recursive. 269 | .TP 270 | \fB\-\-pid\-recursive\-exclude\-channel [,,...] 271 | Filter episode list to exclude all programmes where (regex or comma\-separated list of substrings) appears in channel name. Requires \-\-pid\-recursive. 272 | .TP 273 | \fB\-\-pid\-recursive\-list 274 | If value of \-\-pid is a series or brand PID, list available episodes but do not download. Implies \-\-pid\-recursive. Requires \-\-pid. 275 | .TP 276 | \fB\-\-pid\-recursive\-search [,,...] 277 | Filter episode list to include only programmes where (regex or comma\-separated list of substrings) appears in series name or episode title. Requires \-\-pid\-recursive. 278 | .TP 279 | \fB\-\-pid\-recursive\-type 280 | Filter episode list to include only programmes of type (radio or tv). Requires \-\-pid\-recursive. 281 | .SS "Output Options:" 282 | .TP 283 | \fB\-\-command, \-c 284 | User command to run after successful recording of programme. Use substitution parameters in command string (see docs for list). 285 | .TP 286 | \fB\-\-command\-radio 287 | User command to run after successful recording of radio programme. Use substitution parameters in command string (see docs for list). Overrides \-\-command. 288 | .TP 289 | \fB\-\-command\-tv 290 | User command to run after successful recording of TV programme. Use substitution parameters in command string (see docs for list). Overrides \-\-command. 291 | .TP 292 | \fB\-\-credits 293 | Download programme credits, if available. 294 | .TP 295 | \fB\-\-credits\-only 296 | Only download programme credits, if available. 297 | .TP 298 | \fB\-\-cuesheet 299 | Create cue sheet (.cue file) for programme, if data available. Radio programmes only. Cue sheet will be very inaccurate and will required further editing. Cue sheet may require addition of UTF\-8 BOM (byte\-order mark) for some applications to identify encoding. 300 | .TP 301 | \fB\-\-cuesheet\-offset [\-] 302 | Offset track times in cue sheet and track list by the specified number of seconds. Synonym: \-\-tracklist\-offset 303 | .TP 304 | \fB\-\-cuesheet\-only 305 | Only create cue sheet (.cue file) for programme, if data available. Radio programmes only. 306 | .TP 307 | \fB\-\-file\-prefix 308 | The filename prefix template (excluding dir and extension). Use substitution parameters in template (see docs for list). Default: \- 309 | .TP 310 | \fB\-\-limitprefixlength 311 | The maximum length for a file prefix. Defaults to 240 to allow space within standard 256 limit. 312 | .TP 313 | \fB\-\-metadata 314 | Create metadata info file after recording. Valid values: generic,json. XML generated for 'generic', JSON for 'json'. If no value specified, 'generic' is used. 315 | .TP 316 | \fB\-\-metadata\-only 317 | Create specified metadata info file without any recording or streaming. 318 | .TP 319 | \fB\-\-mpeg\-ts 320 | Ensure raw audio and video files are re\-muxed into MPEG\-TS file regardless of stream format. Overrides \-\-raw. 321 | .TP 322 | \fB\-\-no\-metadata 323 | Do not create metadata info file after recording (overrides \-\-metadata). 324 | .TP 325 | \fB\-\-no\-sanitise 326 | Do not sanitise output file and directory names. Implies \-\-whitespace. Invalid characters for Windows ("*:<>?|) and macOS (:) will be removed. 327 | .TP 328 | \fB\-\-output, \-o 329 | Recording output directory 330 | .TP 331 | \fB\-\-output\-radio 332 | Output directory for radio recordings (overrides \-\-output) 333 | .TP 334 | \fB\-\-output\-tv 335 | Output directory for tv recordings (overrides \-\-output) 336 | .TP 337 | \fB\-\-raw 338 | Don't remux or change the recording in any way. Saves output file in native container format (HLS\->MPEG\-TS, DASH\->MP4) 339 | .TP 340 | \fB\-\-subdir, \-s 341 | Save recorded files into subdirectory of output directory. Default: same name as programme (see \-\-subdir\-format). 342 | .TP 343 | \fB\-\-subdir\-format 344 | The format to be used for subdirectory naming. Use substitution parameters in format string (see docs for list). 345 | .TP 346 | \fB\-\-suboffset 347 | Offset the subtitle timestamps by the specified number of milliseconds. Requires \-\-subtitles. 348 | .TP 349 | \fB\-\-subs\-embed 350 | Embed soft subtitles in MP4 output file. Ignored with \-\-audio\-only and \-\-ffmpeg\-obsolete. Requires \-\-subtitles. Implies \-\-subs\-mono. 351 | .TP 352 | \fB\-\-subs\-mono 353 | Create monochrome titles, with leading hyphen used to denote change of speaker. Requires \-\-subtitles. Not required with \-\-subs\-embed. 354 | .TP 355 | \fB\-\-subs\-raw 356 | Additionally save the raw subtitles file. Requires \-\-subtitles. 357 | .TP 358 | \fB\-\-subtitles 359 | Download subtitles into srt/SubRip format if available and supported 360 | .TP 361 | \fB\-\-subtitles\-only 362 | Only download the subtitles, not the programme 363 | .TP 364 | \fB\-\-tag\-only 365 | Only update the programme metadata tag and not download the programme. Use with \-\-history or \-\-tag\-only\-filename. 366 | .TP 367 | \fB\-\-tag\-only\-filename 368 | Add metadata tags to specified file (ignored unless used with \-\-tag\-only) 369 | .TP 370 | \fB\-\-thumb 371 | Download thumbnail image if available 372 | .TP 373 | \fB\-\-thumb\-ext 374 | Thumbnail filename extension to use 375 | .TP 376 | \fB\-\-thumbnail\-only 377 | Only download thumbnail image if available, not the programme 378 | .TP 379 | \fB\-\-thumbnail\-series 380 | Force use of series/brand thumbnail (series preferred) instead of episode thumbnail 381 | .TP 382 | \fB\-\-thumbnail\-size 383 | Thumbnail size to use for the current recording and metadata. Specify width: 192,256,384,448,512,640,704,832,960,1280,1920. Invalid values will be mapped to nearest available. Default: 1920 (1280 with \-\-thumbnail\-square) 384 | .TP 385 | \fB\-\-thumbnail\-square 386 | Download square version of thumbnail image. Limits \-\-thumbnail\-size to 1280. 387 | .TP 388 | \fB\-\-tracklist 389 | Create track list of music played in programme, if data available. Track times and durations may be missing or incorrect. 390 | .TP 391 | \fB\-\-tracklist\-only 392 | Only create track list of music played in programme, if data available. 393 | .TP 394 | \fB\-\-whitespace, \-w 395 | Keep whitespace in file and directory names. Default behaviour is to replace whitespace with underscores. 396 | .SS "PVR Options:" 397 | .TP 398 | \fB\-\-comment 399 | Adds a comment to a PVR search 400 | .TP 401 | \fB\-\-pvr 402 | Runs the PVR using all saved PVR searches (intended to be run periodically, e.g., from cron or Task Manager). The list can be limited by adding a regex to the command. Synonyms: \-\-pvrrun, \-\-pvr\-run 403 | .TP 404 | \fB\-\-pvr\-add 405 | Save the named PVR search with the specified search terms. Search terms required unless \-\-pid specified. Synonyms: \-\-pvradd 406 | .TP 407 | \fB\-\-pvr\-del 408 | Remove the named search from the PVR searches. Synonyms: \-\-pvrdel 409 | .TP 410 | \fB\-\-pvr\-disable 411 | Disable (not delete) a named PVR search. Synonyms: \-\-pvrdisable 412 | .TP 413 | \fB\-\-pvr\-enable 414 | Enable a previously disabled named PVR search. Synonyms: \-\-pvrenable 415 | .TP 416 | \fB\-\-pvr\-exclude 417 | Exclude the PVR searches to run by search name (comma\-separated regex list). Defaults to substring match. Synonyms: \-\-pvrexclude 418 | .TP 419 | \fB\-\-pvr\-list 420 | Show the PVR search list. Synonyms: \-\-pvrlist 421 | .TP 422 | \fB\-\-pvr\-queue 423 | Add currently matched programmes to queue for later one\-off recording using the \-\-pvr option. Search terms required unless \-\-pid specified. Synonyms: \-\-pvrqueue 424 | .TP 425 | \fB\-\-pvr\-scheduler 426 | Runs the PVR using all saved PVR searches every . Synonyms: \-\-pvrscheduler 427 | .TP 428 | \fB\-\-pvr\-series 429 | Create PVR search for each unique series name in search results. Search terms required. Synonyms: \-\-pvrseries 430 | .TP 431 | \fB\-\-pvr\-single 432 | Runs a named PVR search. Synonyms: \-\-pvrsingle 433 | .SS "Config Options:" 434 | .TP 435 | \fB\-\-cache\-rebuild 436 | Rebuild cache with full 30\-day programme index. Use \-\-refresh\-limit to restrict cache window. 437 | .TP 438 | \fB\-\-expiry, \-e 439 | Cache expiry in seconds (default 4hrs) 440 | .TP 441 | \fB\-\-limit\-matches 442 | Limits the number of matching results for any search (and for every PVR search) 443 | .TP 444 | \fB\-\-prefs\-add 445 | Add/Change specified saved user or preset options 446 | .TP 447 | \fB\-\-prefs\-clear 448 | Remove *ALL* saved user or preset options 449 | .TP 450 | \fB\-\-prefs\-del 451 | Remove specified saved user or preset options 452 | .TP 453 | \fB\-\-prefs\-show 454 | Show saved user or preset options 455 | .TP 456 | \fB\-\-preset, \-z 457 | Use specified user options preset 458 | .TP 459 | \fB\-\-preset\-list 460 | Show all valid presets 461 | .TP 462 | \fB\-\-profile\-dir 463 | Override the user profile directory 464 | .TP 465 | \fB\-\-refresh 466 | Refresh cache 467 | .TP 468 | \fB\-\-refresh\-abort\-onerror 469 | Abort cache refresh for programme type if data for any channel fails to download. Use \-\-refresh\-exclude to temporarily skip failing channels. 470 | .TP 471 | \fB\-\-refresh\-exclude ,,... 472 | Exclude matched channel(s) when refreshing cache (comma\-separated regex list). Defaults to substring match. Overrides \-\-refresh\-include\-groups[\-{tv,radio}] status for specified channel(s) 473 | .TP 474 | \fB\-\-refresh\-exclude\-groups ,,... 475 | Exclude channel groups when refreshing radio or TV cache (comma\-separated values). Valid values: 'national', 'regional', 'local' 476 | .TP 477 | \fB\-\-refresh\-exclude\-groups\-radio ,,... 478 | Exclude channel groups when refreshing radio cache (comma\-separated values). Valid values: 'national', 'regional', 'local' 479 | .TP 480 | \fB\-\-refresh\-exclude\-groups\-tv ,,... 481 | Exclude channel groups when refreshing TV cache (comma\-separated values). Valid values: 'national', 'regional', 'local' 482 | .TP 483 | \fB\-\-refresh\-future 484 | Obtain future programme schedule when refreshing cache 485 | .TP 486 | \fB\-\-refresh\-include ,,... 487 | Include matched channel(s) when refreshing cache (comma\-separated regex list). Defaults to substring match. Overrides \-\-refresh\-exclude\-groups[\-{tv,radio}] status for specified channel(s) 488 | .TP 489 | \fB\-\-refresh\-include\-groups ,,... 490 | Include channel groups when refreshing radio or TV cache (comma\-separated values). Valid values: 'national', 'regional', 'local' 491 | .TP 492 | \fB\-\-refresh\-include\-groups\-radio ,,... 493 | Include channel groups when refreshing radio cache (comma\-separated values). Valid values: 'national', 'regional', 'local' 494 | .TP 495 | \fB\-\-refresh\-include\-groups\-tv ,,... 496 | Include channel groups when refreshing TV cache (comma\-separated values). Valid values: 'national', 'regional', 'local' 497 | .TP 498 | \fB\-\-refresh\-limit 499 | Minimum number of days of programmes to cache. Default: 7 Min: 1 Max: 30 500 | .TP 501 | \fB\-\-refresh\-limit\-radio 502 | Number of days of radio programmes to cache. Default: 7 Min: 1 Max: 30 503 | .TP 504 | \fB\-\-refresh\-limit\-tv 505 | Number of days of TV programmes to cache. Default: 7 Min: 1 Max: 30 506 | .TP 507 | \fB\-\-skipdeleted 508 | Skip the download of metadata/thumbs/subs if the media file no longer exists. Use with \-\-history & \-\-metadataonly/subsonly/thumbonly. 509 | .TP 510 | \fB\-\-webrequest 511 | Specify all options as a urlencoded string of "name=val&name=val&..." 512 | .SS "External Program Options:" 513 | .TP 514 | \fB\-\-atomicparsley 515 | Location of AtomicParsley binary 516 | .TP 517 | \fB\-\-ffmpeg 518 | Location of ffmpeg binary. Assumed to be ffmpeg 3.0 or higher unless \-\-ffmpeg\-obsolete is specified. 519 | .TP 520 | \fB\-\-ffmpeg\-force 521 | Bypass version checks and assume ffmpeg is version 3.0 or higher 522 | .TP 523 | \fB\-\-ffmpeg\-loglevel 524 | Set logging level for ffmpeg. Overridden by \-\-quiet and \-\-silent. Default: 'fatal' 525 | .TP 526 | \fB\-\-ffmpeg\-obsolete 527 | Indicates you are using an obsolete version of ffmpeg (<1.0) that may not support certain options. Without this option, MP4 conversion may fail with obsolete versions of ffmpeg. 528 | .SS "Tagging Options:" 529 | .TP 530 | \fB\-\-no\-artwork 531 | Do not embed thumbnail image in output file. Also removes existing artwork. All other metadata values will be written. 532 | .TP 533 | \fB\-\-no\-tag 534 | Do not tag downloaded programmes. 535 | .TP 536 | \fB\-\-tag\-credits 537 | Add programme credits (if available) to long description field. 538 | .TP 539 | \fB\-\-tag\-encoding 540 | (Windows only) Single\-byte character encoding for non\-ASCII characters in metadata tags. Encoding name must be known to Perl Encode module. Unicode (UTF* or UCS*) character encodings are not supported. Default: active code page or cp1252 (Windows code page 1252) 541 | .TP 542 | \fB\-\-tag\-format\-show 543 | Format template for programme name in tag metadata. Use substitution parameters in template (see docs for list). Default: 544 | .TP 545 | \fB\-\-tag\-format\-title 546 | Format template for episode title in tag metadata. Use substitution parameters in template (see docs for list). Default: 547 | .TP 548 | \fB\-\-tag\-isodate 549 | Use ISO8601 dates (YYYY\-MM\-DD) in album/show names and track titles 550 | .TP 551 | \fB\-\-tag\-no\-unicode 552 | (Windows only) Do not attempt to perform Unicode tagging and use single\-byte character encoding instead (see \-\-tag\-encoding) 553 | .TP 554 | \fB\-\-tag\-podcast 555 | Tag downloaded radio and tv programmes as iTunes podcasts (incompatible with Music/Podcasts/TV apps on macOS 10.15 and higher) 556 | .TP 557 | \fB\-\-tag\-podcast\-radio 558 | Tag only downloaded radio programmes as iTunes podcasts (incompatible with Music/Podcasts/TV apps on macOS 10.15 and higher) 559 | .TP 560 | \fB\-\-tag\-podcast\-tv 561 | Tag only downloaded tv programmes as iTunes podcasts (incompatible with Music/Podcasts/TV apps on macOS 10.15 and higher) 562 | .TP 563 | \fB\-\-tag\-tracklist 564 | Add track list of music played in programme (if available) to lyrics field. 565 | .SS "Misc Options:" 566 | .TP 567 | \fB\-\-encoding\-console\-in 568 | Character encoding for standard input (currently unused). Encoding name must be known to Perl Encode module. Default (only if auto\-detect fails): Linux/Unix/macOS = UTF\-8, Windows = cp850 569 | .TP 570 | \fB\-\-encoding\-console\-out 571 | Character encoding used to encode search results and other output. Encoding name must be known to Perl Encode module. Default (only if auto\-detect fails): Linux/Unix/macOS = UTF\-8, Windows = cp850 572 | .TP 573 | \fB\-\-encoding\-locale 574 | Character encoding used to decode command\-line arguments. Encoding name must be known to Perl Encode module. Default (only if auto\-detect fails): Linux/Unix/OSX = UTF\-8, Windows = cp1252 575 | .TP 576 | \fB\-\-encoding\-locale\-fs 577 | Character encoding used to encode file and directory names. Encoding name must be known to Perl Encode module. Default (only if auto\-detect fails): Linux/Unix/macOS = UTF\-8, Windows = cp1252 578 | .TP 579 | \fB\-\-encoding\-webrequest 580 | Character encoding used to encode commands sent from Web PVR. Encoding name must be known to Perl Encode module. Default = UTF\-8 581 | .TP 582 | \fB\-\-index\-maxconn 583 | Maximum number of connections to use for concurrent programme indexing. Default: 5 Min: 1 Max: 10 584 | .TP 585 | \fB\-\-release\-check 586 | Forces check for new release if used on command line. Checks for new release weekly if saved in preferences. 587 | .TP 588 | \fB\-\-throttle 589 | Bandwidth limit (in Mb/s) for media file download. Default: unlimited. Synonym: \-\-bw 590 | .SS "Deprecated Options:" 591 | .TP 592 | \fB\-\-no\-index\-concurrent 593 | Do not use concurrent indexing to update programme cache. Cache updates will be very slow. 594 | .SH AUTHOR 595 | get_iplayer was written by Phil Lewis and is now maintained by the contributors at https://github.com/get\-iplayer/get_iplayer 596 | .PP 597 | This manual page was originally written by Jonathan Wiltshire for the Debian project (but may be used by others). 598 | .SH COPYRIGHT NOTICE 599 | get_iplayer v3.36 600 | Copyright (C) 2008\-2010 Phil Lewis, 2010\- get_iplayer contributors 601 | This program comes with ABSOLUTELY NO WARRANTY; for details use \-\-warranty. 602 | This is free software, and you are welcome to redistribute it under certain 603 | conditions; use \-\-conditions for details. 604 | 605 | 606 | 607 | -------------------------------------------------------------------------------- /get_iplayer.cgi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 3 | # The world's most insecure web-based PVR manager and streaming proxy for get_iplayer 4 | # ** WARNING ** Never run this in an untrusted environment or facing the internet 5 | # 6 | # Copyright (C) 2008-2010 Phil Lewis, 2010- get_iplayer contributors 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | # 21 | # Authors: Phil Lewis, get_iplayer contributors 22 | # Web: https://github.com/get-iplayer/get_iplayer/wiki 23 | # License: GPLv3 (see LICENSE.txt) 24 | # 25 | 26 | my $VERSION = 3.36; 27 | my $VERSION_TEXT; 28 | $VERSION_TEXT = sprintf("v%.2f", $VERSION) unless $VERSION_TEXT; 29 | 30 | use CGI qw(-utf8 :all); 31 | use CGI::Cookie; 32 | use Cwd 'abs_path'; 33 | use Encode qw(:DEFAULT :fallback_all); 34 | use Getopt::Long; 35 | use File::Basename; 36 | use File::Copy; 37 | use HTML::Entities; 38 | use IO::File; 39 | use IO::Handle; 40 | use IPC::Open3; 41 | use LWP::ConnCache; 42 | #use LWP::Debug qw(+); 43 | use Unicode::Normalize; 44 | use LWP::UserAgent; 45 | use PerlIO::encoding; 46 | use strict; 47 | use constant FB_EMPTY => sub { '' }; 48 | use constant IS_WIN32 => $^O eq 'MSWin32' ? 1 : 0; 49 | use constant DEFAULT_THUMBNAIL => "https://ichef.bbci.co.uk/images/ic/480xn/p01tqv8z.png"; 50 | $PerlIO::encoding::fallback = XMLCREF; 51 | # suppress Perl 5.22/CGI 4 warning 52 | $CGI::LIST_CONTEXT_WARN = 0; 53 | $| = 1; 54 | 55 | my $opt_cmdline; 56 | $opt_cmdline->{debug} = 0; 57 | # Allow bundling of single char options 58 | Getopt::Long::Configure ("bundling"); 59 | # cmdline opts take precedence 60 | GetOptions( 61 | "help|h" => \$opt_cmdline->{help}, 62 | "listen|address|l=s" => \$opt_cmdline->{listen}, 63 | "port|p=n" => \$opt_cmdline->{port}, 64 | "getiplayer|get_iplayer|g=s" => \$opt_cmdline->{getiplayer}, 65 | "ffmpeg=s" => \$opt_cmdline->{ffmpeg}, 66 | "debug" => \$opt_cmdline->{debug}, 67 | "baseurl|base-url|b=s" => \$opt_cmdline->{baseurl}, 68 | "encodinglocale|encoding-locale=s" => \$opt_cmdline->{encodinglocale}, 69 | "encodinglocalefs|encoding-locale-fs=s" => \$opt_cmdline->{encodinglocalefs}, 70 | "encodingconsoleout|encoding-console-out=s" => \$opt_cmdline->{encodingconsoleout}, 71 | "encodingconsolein|encoding-console-in=s" => \$opt_cmdline->{encodingconsolein}, 72 | "encodingwebrequest|encoding-webrequest=s" => \$opt_cmdline->{encodingwebrequest}, 73 | ) || die usage(); 74 | 75 | # Display usage if old method of invocation is used or --help 76 | usage() if $opt_cmdline->{help} || @ARGV; 77 | 78 | 79 | # Usage 80 | sub usage { 81 | my $text = "get_iplayer Web PVR Manager $VERSION_TEXT\n"; 82 | $text .= <<'EOF'; 83 | Copyright (C) 2008-2010 Phil Lewis, 2010- get_iplayer contributors 84 | This program comes with ABSOLUTELY NO WARRANTY; This is free software, 85 | and you are welcome to redistribute it under certain conditions; 86 | See the GPLv3 for details. 87 | 88 | Options: 89 | --listen,-l Use the built-in web server and listen on this interface address (default: 0.0.0.0) 90 | --port,-p Use the built-in web server and listen on this TCP port 91 | --getiplayer,-g Path to the get_iplayer script 92 | --ffmpeg Path to the ffmpeg binary (for streaming) 93 | --debug Debug mode 94 | --baseurl,-b Base URL for link generation. Set to full proxy URL if running behind reverse proxy. 95 | --help,-h This help text 96 | --encodinglocale Encoding for command line (default: Linux/Unix/OSX = UTF-8, Windows = cp1252) 97 | --encodinglocalefs Encoding for file names (default: Linux/Unix/OSX = UTF-8, Windows = cp1252) 98 | --encodingconsoleout Encoding for STDOUT/STDERR (default: Linux/Unix/OSX = UTF-8, Windows = cp850) 99 | --encodingconsolein Encoding for STDIN (default: Linux/Unix/OSX = UTF-8, Windows = cp850) 100 | --encodingwebrequest Encoding for requests to get_iplayer (default: Linux/Unix/OSX = UTF-8, Windows = UTF-8) 101 | EOF 102 | print $text; 103 | exit 1; 104 | } 105 | 106 | 107 | # fallback encodings 108 | $opt_cmdline->{encodinglocale} = $opt_cmdline->{encodinglocalefs} = default_encodinglocale(); 109 | $opt_cmdline->{encodingconsoleout} = $opt_cmdline->{encodingconsolein} = default_encodingconsoleout(); 110 | $opt_cmdline->{encodingwebrequest} = default_encodingwebrequest(); 111 | # attempt to automatically determine encodings 112 | eval { 113 | require Encode::Locale; 114 | }; 115 | if (!$@) { 116 | # set encodings unless already set by PERL_UNICODE or perl -C 117 | $opt_cmdline->{encodinglocale} = $Encode::Locale::ENCODING_LOCALE unless (${^UNICODE} & 32); 118 | $opt_cmdline->{encodinglocalefs} = $Encode::Locale::ENCODING_LOCALE_FS unless (${^UNICODE} & 32); 119 | $opt_cmdline->{encodingconsoleout} = $Encode::Locale::ENCODING_CONSOLE_OUT unless (${^UNICODE} & 6); 120 | $opt_cmdline->{encodingconsolein} = $Encode::Locale::ENCODING_CONSOLE_IN unless (${^UNICODE} & 1); 121 | } 122 | binmode(STDOUT, ":encoding($opt_cmdline->{encodingconsoleout})"); 123 | binmode(STDERR, ":encoding($opt_cmdline->{encodingconsoleout})"); 124 | binmode(STDIN, ":encoding($opt_cmdline->{encodingconsolein})"); 125 | 126 | my $fh; 127 | # Send log messages to this fh 128 | my $se = *STDERR; 129 | binmode $se, ":encoding($opt_cmdline->{encodingconsoleout})"; 130 | 131 | for my $key ( keys %{$opt_cmdline} ) { 132 | # decode @ARGV unless already decoded by PERL_UNICODE or perl -C 133 | unless ( ${^UNICODE} & 32 ) { 134 | $opt_cmdline->{$key} = decode_cl($opt_cmdline->{$key}); 135 | } 136 | # compose UTF-8 args if necessary 137 | if ( $opt_cmdline->{encodinglocale} =~ /UTF-?8/i ) { 138 | $opt_cmdline->{$key} = NFKC($opt_cmdline->{$key}); 139 | } 140 | } 141 | 142 | # Some defaults 143 | my $default_modes = 'default'; 144 | $opt_cmdline->{listen} = '0.0.0.0' if ! $opt_cmdline->{listen}; 145 | $opt_cmdline->{baseurl} .= "/" if $opt_cmdline->{baseurl} && $opt_cmdline->{baseurl} !~ m{/$}; 146 | $opt_cmdline->{ffmpeg} = encode_fs($opt_cmdline->{ffmpeg}) || 'ffmpeg'; 147 | $opt_cmdline->{getiplayer} = encode_fs($opt_cmdline->{getiplayer}) if $opt_cmdline->{getiplayer}; 148 | 149 | # Search for get_iplayer 150 | if ( ! $opt_cmdline->{getiplayer} ) { 151 | for ( './get_iplayer', './get_iplayer.cmd', './get_iplayer.pl', '/usr/bin/get_iplayer', '/usr/local/bin/get_iplayer' ) { 152 | $opt_cmdline->{getiplayer} = $_ if -x $_; 153 | } 154 | } 155 | if ( ( ! $opt_cmdline->{getiplayer} ) || ! -f $opt_cmdline->{getiplayer} ) { 156 | print "ERROR: Cannot find get_iplayer, please specify its location using the --getiplayer option.\n"; 157 | exit 2; 158 | } 159 | 160 | my @gip_cmd_refresh = ( 161 | decode_fs($opt_cmdline->{getiplayer}), 162 | '--encoding-webrequest='.$opt_cmdline->{encodingwebrequest}, 163 | '--encoding-console-out=UTF-8', 164 | '--nocopyright', 165 | ); 166 | 167 | my @gip_cmd_base = @gip_cmd_refresh; 168 | push @gip_cmd_base, '--expiry=999999999'; 169 | 170 | # Path to get_iplayer (+ set HOME env var cos apache seems to not set it) 171 | my $home = $ENV{HOME}; 172 | 173 | my %prog; 174 | my @pids; 175 | my @displaycols; 176 | 177 | # Field names to be grabbed from get_iplayer 178 | my @headings = qw( 179 | index 180 | thumbnail 181 | pid 182 | available 183 | expires 184 | type 185 | name 186 | episode 187 | versions 188 | duration 189 | desc 190 | channel 191 | categories 192 | timeadded 193 | guidance 194 | web 195 | seriesnum 196 | episodenum 197 | filename 198 | mode 199 | ); 200 | 201 | # Default Displayed headings 202 | my @headings_default = qw( thumbnail type name episode desc channel timeadded ); 203 | 204 | # Lookup table for nice field name headings 205 | my %fieldname = ( 206 | index => 'Index', 207 | pid => 'PID', 208 | available => 'Available', 209 | expires => 'Expires', 210 | type => 'Type', 211 | name => 'Name', 212 | episode => 'Episode', 213 | versions => 'Versions', 214 | duration => 'Duration', 215 | desc => 'Description', 216 | channel => 'Channel', 217 | categories => 'Categories', 218 | thumbnail => 'Image', 219 | timeadded => 'Time Added', 220 | guidance => 'Guidance', 221 | web => 'Web Page', 222 | pvrsearch => 'PVR Search', 223 | comment => 'Comment', 224 | filename => 'Filename', 225 | mode => 'Mode', 226 | seriesnum => 'Series Number', 227 | episodenum => 'Episode Number', 228 | 'name,episode' => 'Name+Episode', 229 | 'name,episode,desc' => 'Name+Episode+Desc', 230 | ); 231 | 232 | my %cols_order = (); 233 | my %cols_names = (); 234 | 235 | my %prog_types = ( 236 | tv => 'BBC TV', 237 | radio => 'BBC Radio' 238 | ); 239 | 240 | my %prog_types_order = ( 241 | 1 => 'tv', 242 | 2 => 'radio' 243 | ); 244 | 245 | my $icons_base_url = './icons/'; 246 | 247 | my $cgi; 248 | my $nextpage; 249 | 250 | # Page routing based on NEXTPAGE CGI parameter 251 | my %nextpages = ( 252 | 'search_progs' => \&search_progs, # Main Programme Listings 253 | 'search_history' => \&search_history, # Recorded Programme Listings 254 | 'pvr_queue' => \&pvr_queue, # Queue Recording of Selected Progs 255 | 'recordings_delete' => \&recordings_delete, # Delete Files for Selected Recordings 256 | 'pvr_list' => \&show_pvr_list, # Show all current PVR searches 257 | 'pvr_del' => \&pvr_del, # Delete selected PVR searches 258 | 'pvr_add' => \&pvr_add, 259 | 'pvr_edit' => \&pvr_edit, 260 | 'pvr_save' => \&pvr_save, 261 | 'pvr_run' => \&pvr_run, 262 | 'record_now' => \&record_now, 263 | 'show_info' => \&show_info, 264 | 'refresh' => \&refresh, 265 | ); 266 | 267 | 268 | 269 | ##### Options ##### 270 | my $opt; 271 | 272 | # Options Layout on page tabs 273 | my $layout; 274 | $layout->{BASICTAB}->{title} = 'Search Options', 275 | $layout->{BASICTAB}->{heading} = 'Search Options:', 276 | $layout->{BASICTAB}->{order} = [ qw/ SEARCH SEARCHFIELDS PROGTYPES HISTORY URL / ]; 277 | 278 | $layout->{SEARCHTAB}->{title} = 'Advanced Search'; 279 | $layout->{SEARCHTAB}->{heading} = 'Advanced Search Options:'; 280 | $layout->{SEARCHTAB}->{order} = [ qw/ EXCLUDE CATEGORY EXCLUDECATEGORY CHANNEL EXCLUDECHANNEL SINCE BEFORE FUTURE / ], 281 | 282 | $layout->{DISPLAYTAB}->{title} = 'Display'; 283 | $layout->{DISPLAYTAB}->{heading} = 'Display Options:'; 284 | $layout->{DISPLAYTAB}->{order} = [ qw/ SORT REVERSE PAGESIZE HIDE HIDEDELETED / ]; 285 | 286 | $layout->{COLUMNSTAB}->{title} = 'Columns'; 287 | $layout->{COLUMNSTAB}->{heading} = 'Column Options:'; 288 | $layout->{COLUMNSTAB}->{order} = [ qw/ COLS / ]; 289 | 290 | $layout->{RECORDINGTAB}->{title} = 'Recording'; 291 | $layout->{RECORDINGTAB}->{heading} = 'Recording Options:'; 292 | $layout->{RECORDINGTAB}->{order} = [ qw/ OUTPUT VERSIONLIST MODES PROXY SUBTITLES METADATA THUMB PVRHOLDOFF FORCE AUTOWEBREFRESH AUTOPVRRUN REFRESHFUTURE FPS25 / ]; 293 | 294 | $layout->{STREAMINGTAB}->{title} = 'Streaming'; 295 | $layout->{STREAMINGTAB}->{heading} = 'Streaming Options:'; 296 | $layout->{STREAMINGTAB}->{order} = [ qw/ BITRATE VSIZE VFR STREAMTYPE / ]; 297 | 298 | $layout->{HIDDENTAB}->{title} = ''; 299 | $layout->{HIDDENTAB}->{heading} = ''; 300 | $layout->{HIDDENTAB}->{order} = [ qw/ SAVE SEARCHTAB COLUMNSTAB DISPLAYTAB RECORDINGTAB STREAMINGTAB PAGENO INFO NEXTPAGE ACTION / ]; 301 | 302 | # Order of displayed tab buttoms (BASICTAB and HIDDEN are always displayed regardless of order) 303 | $layout->{taborder} = [ qw/ BASICTAB SEARCHTAB DISPLAYTAB COLUMNSTAB RECORDINGTAB STREAMINGTAB HIDDENTAB / ]; 304 | 305 | # Any params that should never get into the get_iplayer pvr-add search 306 | my @nosearch_params = qw/ /; 307 | 308 | ### Perl CGI Web Server ### 309 | use Socket; 310 | use IO::Socket; 311 | use POSIX ":sys_wait_h"; 312 | my $IGNOREEXIT = 0; 313 | # If the port number is specified then run embedded web server 314 | if ( $opt_cmdline->{port} > 0 ) { 315 | # Autoreap zombies 316 | $SIG{CHLD} = 'IGNORE'; 317 | # Need this because with $SIG{CHLD} = 'IGNORE', backticks and systems calls always return -1 318 | $IGNOREEXIT = 1; 319 | for (;;) { 320 | # Setup and create socket 321 | my $server = new IO::Socket::INET( 322 | Proto => 'tcp', 323 | LocalAddr => $opt_cmdline->{listen}, 324 | LocalPort => $opt_cmdline->{port}, 325 | Listen => SOMAXCONN, 326 | Reuse => 1, 327 | ); 328 | $server or die "Unable to create server socket: $!"; 329 | print $se "INFO: Listening on $opt_cmdline->{listen}:$opt_cmdline->{port}\n"; 330 | print $se "WARNING: Insecure Remote access is allowed, use --listen=127.0.0.1 to limit to this host only\n" if $opt_cmdline->{listen} ne '127.0.0.1'; 331 | print $se "INFO: Using base URL $opt_cmdline->{baseurl}\n" if $opt_cmdline->{baseurl}; 332 | # Await requests and handle them as they arrive 333 | while (my $client = $server->accept()) { 334 | my $procid = fork(); 335 | die "Cannot fork" unless defined $procid; 336 | # Parent 337 | if ( $procid ) { 338 | close $client; 339 | # must call waitpid() on Windows 340 | if ( IS_WIN32 ) { 341 | while ( abs(waitpid(-1, WNOHANG)) > 1 ) {} 342 | } 343 | next; 344 | } 345 | # Child 346 | binmode $se, ":encoding($opt_cmdline->{encodingconsoleout})"; 347 | $client->autoflush(1); 348 | my %request = (); 349 | my $query_string; 350 | my %data; 351 | { 352 | # Read Request 353 | local $/ = Socket::CRLF; 354 | while (<$client>) { 355 | # Main http request 356 | chomp; 357 | if (/\s*(\w+)\s*([^\s]+)\s*HTTP\/(\d.\d)/) { 358 | $request{METHOD} = uc $1; 359 | $request{URL} = $2; 360 | $request{HTTP_VERSION} = $3; 361 | # Standard headers 362 | } elsif (/:/) { 363 | my ( $type, $val ) = split /:/, $_, 2; 364 | $type =~ s/^\s+//; 365 | for ($type, $val) { 366 | s/^\s+//; 367 | s/\s+$//; 368 | } 369 | $request{lc $type} = $val; 370 | print "REQUEST HEADER: $type: $val\n" if $opt_cmdline->{debug}; 371 | # POST data 372 | } elsif (/^$/) { 373 | read( $client, $request{CONTENT}, $request{'content-length'} ) if defined $request{'content-length'}; 374 | last; 375 | } 376 | } 377 | } 378 | 379 | # Determine method and parse parameters 380 | if ($request{METHOD} eq 'GET') { 381 | if ($request{URL} =~ /(.*)\?(.*)/) { 382 | $request{URL} = $1; 383 | $request{CONTENT} = $2; 384 | $query_string = $request{CONTENT}; 385 | } 386 | $data{"_method"} = "GET"; 387 | 388 | } elsif ($request{METHOD} eq 'POST') { 389 | $query_string = parse_post_form_string( $request{CONTENT} ); 390 | $data{"_method"} = "POST"; 391 | 392 | } else { 393 | $data{"_method"} = "ERROR"; 394 | } 395 | 396 | # Log Request 397 | print $se "$data{_method}: $request{URL}\n"; 398 | 399 | # Is this the CGI or some other file request? 400 | if ( $request{URL} =~ /^\/?(recordings_delete|playlist.+|genplaylist.+|)\/?$/ ) { 401 | # remove any vars that might affect the CGI 402 | #%ENV = (); 403 | @ARGV = (); 404 | # Setup CGI http vars 405 | print $se "QUERY_STRING = $query_string\n" if defined $query_string; 406 | $ENV{'QUERY_STRING'} = $query_string; 407 | $ENV{'REQUEST_URI'} = $request{URL}; 408 | $ENV{'COOKIE'} = $request{cookie}; 409 | $ENV{'SERVER_PORT'} = $opt_cmdline->{port}; 410 | my $request_host = "http://$request{host}/"; 411 | if ( $opt_cmdline->{baseurl} ) { 412 | $ENV{'REQUEST_URI'} = $opt_cmdline->{baseurl}; 413 | $request_host = $opt_cmdline->{baseurl}; 414 | } 415 | # respond OK to browser 416 | print $client "HTTP/1.1 200 OK", Socket::CRLF; 417 | # Invoke CGI 418 | run_cgi( $client, $query_string, $request{URL}, $request_host ); 419 | 420 | # Else 404 421 | } else { 422 | print $se "ERROR: 404 Not Found\n"; 423 | print $client "HTTP/1.1 404 Not Found", Socket::CRLF; 424 | print $client Socket::CRLF; 425 | print $client "404 Not Found"; 426 | $data{"_status"} = "404"; 427 | } 428 | 429 | # Close Connection 430 | close $client; 431 | # Exit child 432 | exit 0; 433 | } 434 | } 435 | 436 | # If we're running as a proper CGI from a web server... 437 | } else { 438 | # If we were called by a webserver and not the builtin webserver then seed some vars 439 | my $prefix = $ENV{REQUEST_URI}; 440 | my $request_uri; 441 | # remove trailing query 442 | $prefix =~ s/\?.*$//gi; 443 | my $query_string = $ENV{QUERY_STRING}; 444 | my $request_host = "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}${prefix}"; 445 | # determine whether http or https 446 | my $request_protocol = 'http'; 447 | if ( defined $ENV{'HTTPS'} ) { 448 | $request_protocol = $ENV{'HTTPS'}=='on'?'https':'http'; 449 | } 450 | my $request_host = "${request_protocol}://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}${prefix}"; 451 | $home = $ENV{HOME}; 452 | # Read POSTed data from STDIN if this is a form POST 453 | if ( $ENV{REQUEST_METHOD} eq 'POST' ) { 454 | my $content; 455 | while ( ) { 456 | $content .= $_; 457 | } 458 | $query_string = parse_post_form_string( $content ); 459 | } 460 | run_cgi( *STDOUT, $query_string, undef, $request_host ); 461 | } 462 | 463 | exit 0; 464 | 465 | 466 | sub default_encodinglocale { 467 | return 'UTF-8' if (${^UNICODE} & 32); 468 | return (IS_WIN32 ? 'cp1252' : 'UTF-8'); 469 | } 470 | 471 | sub default_encodingconsoleout { 472 | return 'UTF-8' if (${^UNICODE} & 6); 473 | return (IS_WIN32 ? 'cp850' : 'UTF-8'); 474 | } 475 | 476 | sub default_encodingwebrequest { 477 | return 'UTF-8'; 478 | } 479 | 480 | sub encode_fs { 481 | return encode($opt_cmdline->{encodinglocalefs}, shift, FB_EMPTY); 482 | } 483 | 484 | sub decode_fs { 485 | return decode($opt_cmdline->{encodinglocalefs}, shift, FB_EMPTY); 486 | } 487 | 488 | sub encode_cl { 489 | return encode($opt_cmdline->{encodinglocale}, shift, FB_EMPTY); 490 | } 491 | 492 | sub decode_cl { 493 | return decode($opt_cmdline->{encodinglocale}, shift, FB_EMPTY); 494 | } 495 | 496 | sub encode_wr { 497 | return encode($opt_cmdline->{encodingwebrequest}, shift, FB_EMPTY); 498 | } 499 | 500 | sub decode_wr { 501 | return decode($opt_cmdline->{encodingwebrequest}, shift, FB_EMPTY); 502 | } 503 | 504 | 505 | sub cleanup { 506 | my $signal = shift; 507 | print $se "INFO: Cleaning up PID $$ (signal = $signal)\n"; 508 | exit 0; 509 | } 510 | 511 | 512 | # wrap HTML::Entities::encode_entities to limit encoding 513 | sub encode_entities { 514 | my $value = shift; 515 | return HTML::Entities::encode_entities( $value, '&<>"\'' ); 516 | } 517 | 518 | 519 | sub parse_post_form_string { 520 | my $form = $_[0]; 521 | my @data; 522 | while ( $form =~ /Content-Disposition:(.+?)--/sg ) { 523 | $_ = $1; 524 | # form-data; name = "KEY" 525 | m{name.+?"(.+?)"[\n\r\s]*(.+)}sg; 526 | my ($key, $val) = ( $1, $2 ); 527 | next if ! $1; 528 | $val =~ s/[\r\n]//g; 529 | $val =~ s/\+/ /g; 530 | # Decode entities first 531 | decode_entities($val); 532 | # url encode each entry 533 | # $val =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; 534 | $val = CGI::escape($val); 535 | push @data, "$key=$val"; 536 | } 537 | return join '&', @data; 538 | } 539 | 540 | 541 | 542 | sub run_cgi { 543 | # Get filehandle for output 544 | $fh = shift; 545 | binmode $fh, ':utf8'; 546 | my $query_string = shift; 547 | my $request_uri = shift; 548 | my $request_host = shift; 549 | 550 | # Clean globals 551 | %prog = (); 552 | @pids = (); 553 | @displaycols = (); 554 | 555 | # new cgi instance 556 | $cgi->delete_all() if defined $cgi; 557 | $cgi = new CGI( $query_string ); 558 | 559 | # Get next page 560 | $nextpage = $cgi->param( 'NEXTPAGE' ) || 'search_progs'; 561 | 562 | # Process All options 563 | process_params(); 564 | 565 | # Set HOME env var for forked processes 566 | $ENV{HOME} = $home; 567 | 568 | my $action = $cgi->param( 'ACTION' ) || $request_uri; 569 | # Strip the leading '/' to get the action 570 | $action =~ s|^\/||g; 571 | 572 | # Stream from file (optionally transcoding if required) 573 | if ( $action eq 'direct' || $action eq 'playdirect' ) { 574 | binmode $fh, ':raw'; 575 | # get filename first 576 | my $progtype = $cgi->param( 'PROGTYPES' ); 577 | my $pid = $cgi->param( 'PID' ); 578 | my $mode = $cgi->param( 'MODES' ); 579 | my $filename = get_direct_filename( $pid, $mode, $progtype ); 580 | my $ext = lc( $cgi->param('STREAMTYPE') || $cgi->param( 'OUTTYPE' ) ); 581 | # get file source ext 582 | my $src_ext = $filename; 583 | $src_ext =~ s/^.*\.//g; 584 | # Stream mime types 585 | my %mimetypes = ( 586 | aac => 'audio/aac', 587 | adts => 'audio/aac', 588 | flac => 'audio/x-flac', 589 | m4a => 'audio/mp4', 590 | mp3 => 'audio/mpeg', 591 | oga => 'audio/vorbis', 592 | wav => 'audio/x-wav', 593 | asf => 'video/x-ms-asf', 594 | avi => 'video/avi', 595 | flv => 'video/x-flv', 596 | matroska => 'video/x-matroska', 597 | mkv => 'video/x-matroska', 598 | mov => 'video/quicktime', 599 | mp4 => 'video/mp4', 600 | mpegts => 'video/MP2T', 601 | rm => 'audio/x-pn-realaudio', 602 | ts => 'video/MP2T', 603 | ); 604 | 605 | # default recipes 606 | my $notranscode = 0; 607 | # Disable transcoding if none is specified as OUTTYPE/STREAMTYPE 608 | # Or if streaming MP4 via play direct 609 | if ( $ext =~ /none/i ) { 610 | print $se "INFO: Transcoding disabled (OUTTYPE=$ext)\n"; 611 | $ext = $src_ext; 612 | $notranscode = 1; 613 | # Else known types re-mux into flv unless play direct 614 | } elsif ( $action ne 'playdirect' && ! $ext && $src_ext =~ m{^(m4a|mp4|mp3|aac|avi|mkv|mov|ts)$} ) { 615 | $ext = 'flv'; 616 | # Else default to no transcoding 617 | } elsif ( ! $ext ) { 618 | $ext = $src_ext; 619 | } 620 | 621 | print $se "INFO: Streaming OUTTYPE:$ext MIMETYPE=$mimetypes{$ext} FILE:$filename to client\n"; 622 | 623 | # If type is defined 624 | if ( $mimetypes{$ext} ) { 625 | 626 | # Output headers 627 | # to stream 628 | # This will enable seekable -Accept_Ranges=>'bytes', 629 | my $headers = $cgi->header( -type => $mimetypes{$ext}, -Connection => 'close' ); 630 | 631 | # Send the headers to the browser 632 | print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug}; 633 | print $fh $headers; 634 | 635 | stream_file( $filename, $mimetypes{$ext}, $src_ext, $ext, $notranscode, $cgi->param( 'BITRATE' ), $cgi->param( 'VSIZE' ), $cgi->param( 'VFR' ) ); 636 | } else { 637 | print $se "ERROR: Aborting client thread - output mime type is undetermined\n"; 638 | } 639 | 640 | # Get a playlist for a specified 'PROGTYPES' 641 | } elsif ( $action eq 'playlistdirect' || $action eq 'playlistfiles' ) { 642 | # Output headers 643 | my $headers = $cgi->header( -type => 'audio/x-mpegurl' ); 644 | # To save file 645 | #my $headers = $cgi->header( -type => 'audio/x-mpegurl', -attachment => 'get_iplayer.m3u' ); 646 | 647 | # Send the headers to the browser 648 | print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug}; 649 | print $fh $headers; 650 | 651 | # determine output type 652 | my $outtype = $cgi->param('OUTTYPE'); 653 | $outtype = $cgi->param('STREAMTYPE') || $cgi->param('OUTTYPE') if $action eq 'playlistdirect'; 654 | 655 | # ( host, outtype, modes, progtype, bitrate, search, searchfields, action ) 656 | print $fh create_playlist_m3u_single( $request_host, $outtype, $opt->{MODES}->{current}, $opt->{PROGTYPES}->{current} , $cgi->param('BITRATE') || '', $opt->{SEARCH}->{current}, $opt->{SEARCHFIELDS}->{current} || 'name', $opt->{VERSIONLIST}->{current}, $action ); 657 | 658 | # Get a playlist for a selected progs in form 659 | } elsif ( $action eq 'genplaylistdirect' || $action eq 'genplaylistfile' ) { 660 | # Output headers 661 | my $headers = $cgi->header( -type => 'audio/x-mpegurl' ); 662 | # To save file 663 | #my $headers = $cgi->header( -type => 'audio/x-mpegurl', -attachment => 'get_iplayer.m3u' ); 664 | 665 | # Send the headers to the browser 666 | print $se "\r\nHEADERS:\n$headers\n"; #if $opt_cmdline->{debug}; 667 | print $fh $headers; 668 | 669 | # determine output type 670 | my $outtype = $cgi->param('OUTTYPE'); 671 | $outtype = $cgi->param('STREAMTYPE') || $cgi->param('OUTTYPE') if $action eq 'genplaylistdirect'; 672 | 673 | # ( host, outtype, modes, bitrate, action ) 674 | print $fh create_playlist_m3u_multi( $request_host, $outtype, $cgi->param('BITRATE') || '', $action ); 675 | 676 | # HTML page 677 | } else { 678 | # Output header and html start 679 | begin_html( $request_host ); 680 | 681 | # Page Routing 682 | form_header( $request_host ); 683 | #print $fh $cgi->Dump(); 684 | if ( $opt_cmdline->{debug} ) { 685 | print $fh $cgi->Dump(); 686 | #for my $key (sort keys %ENV) { 687 | # print $fh $key, " = ", $ENV{$key}, "\n"; 688 | #} 689 | } 690 | if ($nextpages{$nextpage}) { 691 | # call the correct subroutine 692 | $nextpages{$nextpage}->(); 693 | } 694 | 695 | form_footer(); 696 | html_end(); 697 | } 698 | 699 | $cgi->delete_all(); 700 | 701 | return 0; 702 | } 703 | 704 | 705 | sub pvr_run { 706 | print $fh "

The PVR will auto-run every $opt->{AUTOPVRRUN}->{current} hour(s) if you leave this page open

" if $opt->{AUTOPVRRUN}->{current}; 707 | if ( IS_WIN32 ) { 708 | print $fh "

Windows users: You may encounter errors if you perform other tasks in the Web PVR Manager while this page is reloading

" if $opt->{AUTOPVRRUN}->{current}; 709 | print $fh "

Windows users: The Web PVR Manager may crash if you leave this window open for a long period of time

" if $opt->{AUTOPVRRUN}->{current}; 710 | } 711 | print $se "INFO: Starting PVR Run\n"; 712 | my @cmd = ( 713 | @gip_cmd_refresh, 714 | '--hash', 715 | '--pvr', 716 | ); 717 | #print $se "DEBUG: running: $cmd\n"; 718 | print $fh '
';
 719 | 	# Redirect both STDOUT and STDERR to client browser socket
 720 | 	run_cmd_autorefresh( $fh, $fh, 1, @cmd );
 721 | 	print $fh '
'; 722 | print $fh p("PVR Run complete"); 723 | 724 | # Load the refresh tab if required 725 | my $autopvrrun = $cgi->cookie( 'AUTOPVRRUN' ) || $cgi->param( 'AUTOPVRRUN' ); 726 | 727 | # Render options actions 728 | print $fh div( { -class=>'action' }, 729 | ul( { -class=>'action' }, 730 | li( { -class=>'action' }, [ 731 | a( 732 | { 733 | -class=>'action', 734 | -title => 'Run PVR Now', 735 | -onClick => "RefreshTab( '?NEXTPAGE=pvr_run&AUTOPVRRUN=$autopvrrun', ".(1000*3600*$autopvrrun).", 1 );", 736 | }, 737 | 'PVR Run Now' 738 | ), 739 | a( 740 | { 741 | -class=>'action', 742 | -title => 'Close', 743 | -onClick => "window.close()", 744 | }, 745 | 'Close' 746 | ), 747 | ]), 748 | ), 749 | ); 750 | } 751 | 752 | 753 | 754 | sub record_now { 755 | my @record; 756 | # The 'Record' action button uses SEARCH to pass it's pvr_queue data 757 | if ( $cgi->param( 'SEARCH' ) ) { 758 | push @record, $cgi->param( 'SEARCH' ); 759 | } else { 760 | @record = ( $cgi->param( 'PROGSELECT' ) ); 761 | } 762 | 763 | my @params = get_search_params(); 764 | my $out; 765 | 766 | # If a URL was specified by the User (assume auto mode list is OK): 767 | if ( $opt->{URL}->{current} =~ m{^https?://} ) { 768 | push @record, "$opt->{PROGTYPES}->{current}|$opt->{URL}->{current}|$opt->{URL}->{current}|-"; 769 | } 770 | 771 | print $fh "

Please leave this page open until the recording completes

"; 772 | # Render options actions 773 | print $fh div( { -class=>'action' }, 774 | ul( { -class=>'action' }, 775 | li( { -class=>'action' }, [ 776 | a( 777 | { 778 | -class=>'action', 779 | -title => 'Close', 780 | -onClick => "window.close()", 781 | }, 782 | 'Close' 783 | ), 784 | ]), 785 | ), 786 | ); 787 | print $fh "

Recording The Following Programmes

    \n"; 788 | for (@record) { 789 | chomp(); 790 | my ( $type, $pid, $name, $episode ) = (split /\|/)[0,1,2,3]; 791 | next if ! ($type && $pid ); 792 | print $fh "
  • $name - $episode ($pid)
  • \n"; 793 | } 794 | print $fh "

\n"; 795 | print $se "INFO: Starting Recording Now\n"; 796 | # Queue all selected 'TYPE|PID|NAME|EPISODE|MODE|CHANNEL' entries in the PVR 797 | for (@record) { 798 | chomp(); 799 | my ( $type, $pid, $name, $episode ) = (split /\|/)[0,1,2,3]; 800 | next if ! ($type && $pid ); 801 | my $comment = "$name - $episode"; 802 | my @cmd = ( 803 | @gip_cmd_base, 804 | '--hash', 805 | '--webrequest', 806 | get_iplayer_webrequest_args( 807 | "pid=$pid", 808 | "type=$type", 809 | build_cmd_options( grep !/^(HISTORY|SINCE|BEFORE|HIDEDELETED|FUTURE|SEARCH|SEARCHFIELDS|PROGTYPES|EXCLUDEC.+)$/, @params ) 810 | ), 811 | ); 812 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 813 | print $fh '
';
 814 | 		# Redirect both STDOUT and STDERR to client browser socket
 815 | 		run_cmd_autorefresh( $fh, $fh, 1, @cmd );
 816 | 		print $fh '
'; 817 | } 818 | print $fh p("Recording complete"); 819 | return 0; 820 | } 821 | 822 | 823 | 824 | # Stream a file to browser/client 825 | sub stream_file { 826 | my ( $filename, $mimetype, $src_ext, $ext, $notranscode, $abitrate, $vsize, $vfr ) = ( @_ ); 827 | 828 | print $se "INFO: Start Direct Streaming $filename to browser using mimetype '$mimetype', output ext '$ext', audio bitrate '$abitrate', video size '$vsize', video frame rate '$vfr'\n"; 829 | 830 | # If transcoding required (i.e. output ext != source ext) - OR, if one of the transcoing options is set 831 | if ( ( ! $notranscode ) && ( lc( $ext ) ne lc( $src_ext ) || $abitrate || $vsize || $vfr ) ) { 832 | $fh->autoflush(0); 833 | 834 | my @cmd = build_ffmpeg_args( $filename, $mimetype, $ext, $abitrate, $vsize, $vfr, $src_ext ); 835 | run_cmd( $fh, $se, 100000, @cmd ); 836 | print $se "INFO: Finished Streaming and transcoding $filename to browser\n"; 837 | 838 | } else { 839 | print $se "INFO: Streaming file directly: $filename\n"; 840 | if ( ! open( STREAMIN, "< $filename" ) ) { 841 | print $se "INFO: Cannot Read file '$filename'\n"; 842 | exit 4; 843 | } 844 | 845 | # Read each char from command output and push to socket fh 846 | my $char; 847 | my $bytes; 848 | # Assume that we don't want to buffer STDERR output of the command 849 | my $size = 100000; 850 | while ( $bytes = read( STREAMIN, $char, $size ) ) { 851 | if ( $bytes <= 0 ) { 852 | close STREAMIN; 853 | print $se "DEBUG: Stream thread has completed\n"; 854 | exit 0; 855 | } else { 856 | print $fh $char; 857 | print $se '#'; 858 | } 859 | last if $bytes < $size; 860 | } 861 | close STREAMIN; 862 | print $se "INFO: Finished Streaming $filename to browser\n"; 863 | } 864 | 865 | return 0; 866 | } 867 | 868 | 869 | 870 | sub build_ffmpeg_args { 871 | my ( $filename, $mimetype, $ext, $abitrate, $vsize, $vfr, $src_ext ) = ( @_ ); 872 | my @cmd; 873 | my @cmd_vopts; 874 | my @cmd_aopts; 875 | if ( $abitrate =~ m{^\d+$} ) { 876 | push @cmd_aopts, ( '-ab', "${abitrate}k" ); 877 | } 878 | if ( lc( $ext ) eq 'flv' ) { 879 | push @cmd_aopts, ( '-ar', '44100' ); 880 | } 881 | # If conversion is necessary 882 | # Video 883 | if ( $mimetype =~ m{^video} && $filename !~ m{\.(aac|m4a|mp3)$} ) { 884 | # Apply video size 885 | push @cmd_vopts, ( '-s', "${vsize}" ) if $vsize =~ m{^\d+x\d+$}; 886 | # Apply video framerate - caveat - bitrate defaults to 200k if only vfr is set 887 | push @cmd_vopts, ( '-r', $vfr ) if $vfr =~ m{^\d+$}; 888 | # Add in the codec if we are transcoding and not remuxing the stream 889 | if ( @cmd_vopts ) { 890 | push @cmd_vopts, ( '-vcodec', 'libx264' ); 891 | } else { 892 | push @cmd_vopts, ( '-vcodec', 'copy' ); 893 | } 894 | # Audio 895 | } else { 896 | push @cmd_vopts, ( '-vn' ); 897 | } 898 | @cmd = ( 899 | decode_fs($opt_cmdline->{ffmpeg}), 900 | '-i', decode_fs($filename), 901 | @cmd_vopts, 902 | @cmd_aopts, 903 | '-ac', 2, 904 | '-f', $ext, 905 | '-', 906 | ); 907 | print $se "DEBUG: Command args: ".(join ' ', @cmd)."\n"; 908 | return @cmd; 909 | } 910 | 911 | 912 | 913 | sub create_playlist_m3u_single { 914 | my ( $request_host, $outtype, $modes, $type, $bitrate, $search, $searchfields, $versionlist, $request ) = ( @_ ); 915 | my @playlist; 916 | $outtype =~ s/^.*\.//g; 917 | 918 | my $searchterm = $search; 919 | # make search term regex friendly 920 | if ( $searchterm ne '.*' && $searchterm !~ m{^http} ) { 921 | $searchterm =~ s|([\/\.\?\+\-\*\^\(\)\[\]\{\}])|\\$1|g; 922 | } 923 | 924 | print $se "INFO: Getting playlist for type '$type' using modes '$modes' and bitrate '$bitrate'\n"; 925 | my @cmd = ( 926 | @gip_cmd_base, 927 | '--webrequest', 928 | get_iplayer_webrequest_args( 'history=1', 'skipdeleted=1', "type=$type", 'listformat=ENTRY||||||', "fields=$searchfields", "search=$searchterm", "versionlist=$versionlist" ), 929 | ); 930 | 931 | my @out = get_cmd_output( @cmd ); 932 | 933 | push @playlist, "#EXTM3U\n"; 934 | 935 | # Extract and rewrite into m3u format 936 | # /home/lewispj/mp3/Rock/radiohead/Ok Computer/radiohead - (07) fitter happier.mp3||(07) Fitter Happier|, , (256kbps/44.1kHz)|| 937 | for ( grep !/^(Added:|Matches|$)/ , @out ) { 938 | chomp(); 939 | my $url; 940 | my ( $pid, $name, $episode, $desc, $filename, $mode, $channel ) = (split /\|/)[1,2,3,4,5,6,7]; 941 | #print $se "DEBUG: $pid, $name, $episode, $desc, $filename, $mode\n"; 942 | # sanitze modes && filename 943 | $mode = '' if $mode eq ''; 944 | $filename = '' if $filename eq ''; 945 | 946 | # playlist with direct streaming for files through webserver 947 | if ( $request eq 'playlistdirect' ) { 948 | next if ! ( $pid && $type && $mode ); 949 | $url = build_url_direct( $request_host, $type, $pid, $mode, $outtype, $opt->{STREAMTYPE}->{current}, $opt->{HISTORY}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current}, $opt->{VERSIONLIST}->{current} ); 950 | 951 | # playlist with local files 952 | } elsif ( $request eq 'playlistfiles' ) { 953 | next if ! $filename; 954 | $url = search_absolute_path( $filename ); 955 | 956 | } 957 | 958 | push @playlist, "#EXTINF:-1,$type - $channel - $name - $episode - $desc"; 959 | push @playlist, "$url\n"; 960 | 961 | } 962 | print $se join ("\n", @playlist); 963 | return join ("\n", @playlist); 964 | } 965 | 966 | 967 | 968 | sub create_playlist_m3u_multi { 969 | my ( $request_host, $outtype, $bitrate, $request ) = ( @_ ); 970 | my @playlist; 971 | push @playlist, "#EXTM3U\n"; 972 | 973 | my @record = ( $cgi->param( 'PROGSELECT' ) ); 974 | 975 | # Create m3u from all selected 'TYPE|PID|NAME|EPISODE|MODE|CHANNEL' entries in the PVR 976 | for (@record) { 977 | my $url; 978 | chomp(); 979 | my ( $type, $pid, $name, $episode, $mode, $channel ) = (split /\|/)[0,1,2,3,4,5]; 980 | next if ! ($type && $pid ); 981 | 982 | # playlist with direct streaming fo files through webserver 983 | if ( $request eq 'genplaylistdirect' ) { 984 | $url = build_url_direct( $request_host, $type, $pid, $mode, $outtype, $opt->{STREAMTYPE}->{current}, $opt->{HISTORY}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current}, $opt->{VERSIONLIST}->{current} ); 985 | 986 | # playlist with local files 987 | } elsif ( $request eq 'genplaylistfile' ) { 988 | # Lookup filename (add it if defined - even if relative) 989 | # check for -f $filename if you want to exclude files that cannot be found 990 | my $filename = get_direct_filename( $pid, $mode, $type ); 991 | $url = $filename if -f $filename; 992 | } 993 | 994 | # Skip empty urls 995 | next if ! $url; 996 | 997 | push @playlist, "#EXTINF:-1,$type - $channel - $name - $episode"; 998 | push @playlist, "$url\n"; 999 | 1000 | } 1001 | print $se join ("\n", @playlist); 1002 | return join ("\n", @playlist); 1003 | } 1004 | 1005 | 1006 | 1007 | ### Playlist URL builders 1008 | sub build_url_direct { 1009 | my ( $request_host, $progtypes, $pid, $modes, $outtype, $streamtype, $history, $bitrate, $vsize, $vfr, $versionlist, $action ) = ( @_ ); 1010 | # Sanity check 1011 | #print $se "DEBUG: building direct playback request using: PROGTYPES=${progtypes} PID=${pid} MODES=${modes} OUTTYPE=${outtype}\n"; 1012 | # CGI::escape 1013 | $_ = CGI::escape($_) for ( $progtypes, $pid, $modes, $outtype, $streamtype, $history, $bitrate, $vsize ); 1014 | #print $se "DEBUG: building direct playback request using: PROGTYPES=${progtypes} PID=${pid} MODES=${modes} OUTTYPE=${outtype} BITRATE=${bitrate} VSIZE=${vsize} VFR=${vfr}\n"; 1015 | # Build URL 1016 | $action ||= 'direct'; 1017 | return "${request_host}?ACTION=$action&PROGTYPES=${progtypes}&PID=${pid}&MODES=${modes}&HISTORY=${history}&OUTTYPE=${outtype}&STREAMTYPE=${streamtype}&BITRATE=${bitrate}&VSIZE=${vsize}&VFR=${vfr}&VERSIONLIST=${versionlist}"; 1018 | } 1019 | 1020 | 1021 | # Play from Internet/'Play': ?ACTION=playlist &SEARCHFIELDS=pid &SEARCH=$pid &MODES=${modes} &PROGTYPES=${type} &OUTTYPE=${outtype}' 1022 | ## 'PlayFile' - works with vlc 1023 | # Play from local file/'PlayFile' ?ACTION=playlistfiles &SEARCHFIELDS=pid &SEARCH=$pid &MODES=${modes} &PROGTYPES=${type} 1024 | ## 'PlayWeb' - not on vlc 1025 | # Play from file on web server/'PlayWeb' ?ACTION=playlistdirect &SEARCHFIELDS=pid &SEARCH=$pid &MODES=${modes} 1026 | sub build_url_playlist { 1027 | my ( $request_host, $action, $searchfields, $search, $modes, $progtypes, $outtype, $streamtype, $bitrate, $vsize, $vfr, $versionlist ) = ( @_ ); 1028 | # Sanity check 1029 | #print $se "DEBUG: building $action request using: SEARCHFIELDS=${searchfields} SEARCH=${search} MODES=${modes} PROGTYPES=${progtypes} OUTTYPE=${outtype}\n"; 1030 | # CGI::escape 1031 | $_ = CGI::escape($_) for ( $action, $searchfields, $search, $modes, $progtypes, $outtype, $streamtype, $bitrate, $vsize, $vfr ); 1032 | #print $se "DEBUG: building $action request using: SEARCHFIELDS=${searchfields} SEARCH=${search} MODES=${modes} PROGTYPES=${progtypes} OUTTYPE=${outtype}\n"; 1033 | # Build URL 1034 | return "${request_host}?ACTION=${action}&SEARCHFIELDS=${searchfields}&SEARCH=${search}&MODES=${modes}&PROGTYPES=${progtypes}&OUTTYPE=${outtype}&STREAMTYPE=${streamtype}&BITRATE=${bitrate}&VSIZE=${vsize}&VFR=${vfr}&VERSIONLIST=${versionlist}"; 1035 | } 1036 | 1037 | 1038 | 1039 | # Generic 1040 | # Gets the contents of a URL and retries if it fails, returns '' if no page could be retrieved 1041 | # Usage = request_url_retry(, , , , []); 1042 | sub request_url_retry { 1043 | 1044 | my %OPTS = @LWP::Protocol::http::EXTRA_SOCK_OPTS; 1045 | $OPTS{SendTE} = 0; 1046 | @LWP::Protocol::http::EXTRA_SOCK_OPTS = %OPTS; 1047 | 1048 | my ($ua, $url, $retries, $succeedmsg, $failmsg) = @_; 1049 | my $res; 1050 | 1051 | # Malformed URL check 1052 | if ( $url !~ m{^\s*https?\:\/\/}i ) { 1053 | print $se "ERROR: Malformed URL: '$url'\n"; 1054 | return ''; 1055 | } 1056 | 1057 | my $i; 1058 | print $se "INFO: Getting page $url\n" if $opt->{verbose}; 1059 | for ($i = 0; $i < $retries; $i++) { 1060 | $res = $ua->request( HTTP::Request->new( GET => $url ) ); 1061 | if ( ! $res->is_success ) { 1062 | print $se $failmsg; 1063 | } else { 1064 | print $se $succeedmsg; 1065 | last; 1066 | } 1067 | } 1068 | # Return empty string if we failed 1069 | return '' if $i == $retries; 1070 | 1071 | return $res->content; 1072 | } 1073 | 1074 | 1075 | 1076 | # Invokes command in @args as a system call (hopefully) without using a shell 1077 | # Can also redirect all stdout and stderr to either: STDOUT, STDERR or unchanged 1078 | # Usage: run_cmd( <''|STDOUTFH>, <''|STDERRFH>, @args ) 1079 | # Returns: exit code 1080 | # Note: doesn't appear to work with 'in memory' filehandles 1081 | sub run_cmd_unix { 1082 | # Define what to do with STDOUT and STDERR of the child process 1083 | my $fh_child_out = shift || "STDOUT"; 1084 | my $fh_child_err = shift || "STDERR"; 1085 | my @cmd = ( @_ ); 1086 | my $rtn; 1087 | 1088 | print $se "INFO: Command: ".(join ' ', @cmd)."\n"; # if $opt->{verbose}; 1089 | 1090 | @cmd = map { encode_cl($_) } @cmd; 1091 | #print $se "INFO: open3( 0, \">&".fileno($fh_child_out).", \">&".fileno($fh_child_err).", )\n"; 1092 | # Don't use NULL for the 1st arg of open3 otherwise we end up with a messed up STDIN once it returns 1093 | my $procid = open3( 0, ">&".fileno($fh_child_out), ">&".fileno($fh_child_err), @cmd ); 1094 | # Wait for child to complete 1095 | waitpid( $procid, 0 ); 1096 | $rtn = $?; 1097 | 1098 | # Interpret return code 1099 | return interpret_return_code( $rtn ); 1100 | } 1101 | 1102 | 1103 | 1104 | # Invokes command in @args as a system call (hopefully) without using a shell 1105 | # Can also redirect all stdout and stderr to either: STDOUT, STDERR or unchanged 1106 | # Usage: run_cmd( $stdout_fh, $stderr_fh, , @args ) 1107 | # Returns: exit code 1108 | sub run_cmd { 1109 | 1110 | # win32 kludge cos win is so broken 1111 | return run_cmd_win32( @_ ) if IS_WIN32; 1112 | 1113 | # Define what to do with STDOUT and STDERR of the child process 1114 | use IO::Select; 1115 | use Symbol qw(gensym); 1116 | my $fh_cmd_out = shift; 1117 | my $fh_cmd_err = shift; 1118 | my $size = shift; 1119 | my $from = new IO::Handle; 1120 | my $err = new IO::Handle; 1121 | my @cmd = ( @_ ); 1122 | my $ffmpeg = decode_fs($opt_cmdline->{ffmpeg}); 1123 | my $direct = grep(/$ffmpeg/, @cmd); 1124 | my $is_hls = grep(/modes%3Dhl(s|x)/, @cmd); 1125 | my $stdout_raw = $direct; 1126 | my $rtn; 1127 | 1128 | $fh_cmd_out->autoflush(1); 1129 | $fh_cmd_err->autoflush(1); 1130 | 1131 | print $se "INFO: Command: ".(join ' ', @cmd)."\n"; # if $opt->{verbose}; 1132 | 1133 | my $procid; 1134 | # Setup signal handlers so that when the browser is closed the SIGPIPE results in sending a SIGTERM to the forked command. 1135 | local $SIG{PIPE} = sub { 1136 | my $signal = shift; 1137 | print $se "\nINFO: $$ Cleaning up (signal = $signal), killing cmd PID=$procid:\n"; 1138 | for my $sig ( qw/INT PIPE TERM KILL/ ) { 1139 | # Kill process with SIGs 1140 | print $se "INFO: $$ killing cmd PID=$procid with SIG${sig}\n"; 1141 | kill $sig, $procid; 1142 | sleep 1; 1143 | if ( ! kill 0, $procid ) { 1144 | print $se "INFO: $$ killed cmd PID=$procid\n"; 1145 | last; 1146 | } 1147 | sleep 4; 1148 | } 1149 | exit 0; 1150 | }; 1151 | 1152 | @cmd = map { encode_cl($_) } @cmd; 1153 | # Don't use NULL for the 1st arg of open3 otherwise we end up with a messed up STDIN once it returns 1154 | $procid = open3( gensym, $from, $err, @cmd ) || print $se "ERROR: Could not execute command: $!\n"; 1155 | 1156 | my $childpidout = fork(); 1157 | 1158 | # Fork a child process to read from the indirect (STDOUT) fh of the spawned command and write it to the selected fh (browser client) 1159 | if ( $childpidout <= 0 ) { 1160 | # Not sure if these are necessary: 1161 | $fh_cmd_out->autoflush(1); 1162 | $from->autoflush(1); 1163 | if ( $stdout_raw) { 1164 | binmode $from, ':raw'; 1165 | } else { 1166 | binmode $from, ':utf8'; 1167 | } 1168 | # Read each char from command output and push to socket fh 1169 | my $char; 1170 | my $bytes; 1171 | while ( $bytes = read( $from, $char, $size ) ) { 1172 | if ( $bytes <= 0 ) { 1173 | print $se "DEBUG: STDOUT fd closed - exiting thread\n"; 1174 | exit 0; 1175 | } else { 1176 | print $fh_cmd_out $char; 1177 | } 1178 | last if $bytes < $size; 1179 | } 1180 | #print $se "CMD STDOUT FH EMPTY\n"; 1181 | exit 0; 1182 | # Parent continues here 1183 | } elsif ( defined $childpidout ) { 1184 | print $se "DEBUG: Forked STDOUT reader with PID $childpidout\n"; 1185 | # Failed to fork 1186 | } else { 1187 | print $se "ERROR: Failed to fork STDOUT reader process: $!\n"; 1188 | exit 1; 1189 | } 1190 | 1191 | my $childpiderr = fork(); 1192 | 1193 | # Fork a child process to read from the indirect (STDERR) fh of the spawned command and write it to the selected fh (browser client) 1194 | if ( $childpiderr <= 0 ) { 1195 | # Not sure if these are necessary: 1196 | $fh_cmd_err->autoflush(1); 1197 | $err->autoflush(1); 1198 | binmode $err, ':utf8'; 1199 | # Read each char from command output and push to socket fh 1200 | my $char; 1201 | my $bytes; 1202 | # Assume that we don't want to buffer STDERR output of the command 1203 | $size = 1; 1204 | if ( $is_hls ) { 1205 | my ($count, $buf); 1206 | while ( $bytes = read( $err, $char, $size ) ) { 1207 | if ( $bytes <= 0 ) { 1208 | print $se "DEBUG: STDERR fd closed - exiting thread\n"; 1209 | exit 0; 1210 | } else { 1211 | if ( $char eq "#" ) { 1212 | print $fh_cmd_err $char; 1213 | } elsif ( $char =~ /[\r\n]/ ) { 1214 | if ( $buf =~ /size=/ ) { 1215 | $count++; 1216 | print $fh_cmd_err "#"; 1217 | print $fh_cmd_err "\n" if ! ($count % 100); 1218 | } else { 1219 | print $fh_cmd_err $buf; 1220 | print $fh_cmd_err "\n"; 1221 | } 1222 | $buf = ''; 1223 | } else { 1224 | $buf .= $char; 1225 | } 1226 | } 1227 | if ( $bytes < $size ) { 1228 | print $fh_cmd_err "$buf\n" if $buf; 1229 | last; 1230 | } 1231 | } 1232 | } else { 1233 | while ( $bytes = read( $err, $char, $size ) ) { 1234 | if ( $bytes <= 0 ) { 1235 | print $se "DEBUG: STDERR fd closed - exiting thread\n"; 1236 | exit 0; 1237 | } else { 1238 | print $fh_cmd_err $char; 1239 | } 1240 | last if $bytes < $size; 1241 | } 1242 | } 1243 | #print $se "CMD STDERR FH EMPTY\n"; 1244 | exit 0; 1245 | # Parent continues here 1246 | } elsif ( defined $childpiderr ) { 1247 | print $se "DEBUG: Forked STDERR reader with PID $childpiderr\n"; 1248 | # Failed to fork 1249 | } else { 1250 | print $se "ERROR: Failed to fork STDERR reader process: $!\n"; 1251 | exit 1; 1252 | } 1253 | 1254 | # Reap reader processes 1255 | waitpid( $childpidout, 0 ); 1256 | waitpid( $childpiderr, 0 ); 1257 | 1258 | # Reap command child 1259 | waitpid( $procid, 0 ); 1260 | $rtn = $?; 1261 | 1262 | # Restore sigpipe handler for reader and writer processes 1263 | $SIG{PIPE} = 'DEFAULT'; 1264 | 1265 | # Interpret return code 1266 | return interpret_return_code( $rtn ); 1267 | } 1268 | 1269 | 1270 | 1271 | # Works except for where both from and err go to fh - does not die when browser closes. 1272 | # Also the browser does not get closed after cmd completes... 1273 | # Uses shell when stderr needs to be redirected to stdout 1274 | sub run_cmd_win32 { 1275 | # Define what to do with STDOUT and STDERR of the child process 1276 | my $fh_child_out = shift; 1277 | my $fh_child_err = shift; 1278 | my $size = shift; 1279 | my @cmd = ( @_ ); 1280 | # eek! - works around win32 inability to redirect STDERR nicely 1281 | # If the stderr is supposed to go to the same fh and stdout then add '2>&1' 1282 | push @cmd, '2>&1' if fileno($fh_child_out) == fileno($fh_child_err); 1283 | my $rtn; 1284 | 1285 | # Disable buffering 1286 | $fh_child_out->autoflush(1); 1287 | 1288 | print $se "INFO: Win32 Command: ".(join ' ', @cmd)."\n"; # if $opt->{verbose}; 1289 | 1290 | # Redirect $fh_child_out to STDOUT 1291 | open(STDOUT, ">&", $fh_child_out ) || die "can't dup client to stdout"; 1292 | 1293 | @cmd = map { encode_cl($_) } @cmd; 1294 | $rtn = system( @cmd ); 1295 | 1296 | # Interpret return code 1297 | return interpret_return_code( $rtn ); 1298 | } 1299 | 1300 | # PVR Run and Refresh Cache pages will not auto-refresh if client socket 1301 | # is dup()-ed to STDOUT (as in run_cmd_win32). Run command in shell and 1302 | # copy get_iplayer output to client socket instead. 1303 | sub run_cmd_autorefresh { 1304 | return run_cmd( @_ ) unless IS_WIN32; 1305 | # Define what to do with STDOUT and STDERR of the child process 1306 | my $fh_child_out = shift; 1307 | my $fh_child_err = shift; 1308 | my $size = shift; 1309 | my @cmd = ( @_ ); 1310 | # workaround to add quotes around the args because we are using a shell here 1311 | for ( @cmd ) { 1312 | s/^(.+)$/"$1"/g if ! m{^[\-\"]}; 1313 | } 1314 | # eek! - works around win32 inability to redirect STDERR nicely 1315 | # If the stderr is supposed to go to the same fh and stdout then add '2>&1' 1316 | push @cmd, '2>&1' if fileno($fh_child_out) == fileno($fh_child_err); 1317 | 1318 | # Disable buffering 1319 | $fh_child_out->autoflush(1); 1320 | 1321 | print $se "INFO: Win32 Command: ".(join ' ', @cmd)."\n"; # if $opt->{verbose}; 1322 | 1323 | my $buf; 1324 | my $bytes; 1325 | @cmd = map { encode_cl($_) } @cmd; 1326 | open( CMD, ( join ' ', @cmd ).'|' ) || die "can't open pipe: $!\n"; 1327 | binmode CMD, ':utf8'; 1328 | while ( $bytes = read( CMD, $buf, $size ) ) { 1329 | if ( $bytes <= 0 ) { 1330 | print $se "DEBUG: pipe fd closed - exiting thread\n"; 1331 | exit 0; 1332 | } else { 1333 | print $fh_child_out $buf; 1334 | } 1335 | last if $bytes < $size; 1336 | } 1337 | close(CMD); 1338 | 1339 | # Interpret return code 1340 | return interpret_return_code( $? ); 1341 | } 1342 | 1343 | # Same as backticks but without needing a shell 1344 | # sets $? 1345 | # returns array of output 1346 | sub get_cmd_output { 1347 | 1348 | # win32 kludge cos win is so broken 1349 | return get_cmd_output_win32( @_ ) if IS_WIN32; 1350 | 1351 | use Symbol qw(gensym); 1352 | my @cmd = ( @_ ); 1353 | #my $to = new IO::Handle; 1354 | my $from = new IO::Handle; 1355 | my $error = new IO::Handle; 1356 | my $rtn; 1357 | my @out_from; 1358 | my @out_error; 1359 | 1360 | #$to->autoflush(1); 1361 | $from->autoflush(1); 1362 | $error->autoflush(1); 1363 | 1364 | print $se "INFO: Command: ".(join ' ', @cmd)."\n"; # if $opt->{verbose}; 1365 | 1366 | my $procid; 1367 | # Setup signal handlers so that when the browser is closed the SIGPIPE results in sending a SIGTERM to the forked command. 1368 | local $SIG{PIPE} = sub { 1369 | my $signal = shift; 1370 | print $se "\nINFO: $$ Cleaning up (signal = $signal), killing cmd PID=$procid:\n"; 1371 | for my $sig ( qw/INT PIPE TERM KILL/ ) { 1372 | # Kill process with SIGs 1373 | print $se "INFO: $$ killing cmd PID=$procid with SIG${sig}\n"; 1374 | kill $sig, $procid; 1375 | sleep 1; 1376 | if ( ! kill 0, $procid ) { 1377 | print $se "INFO: $$ killed cmd PID=$procid\n"; 1378 | last; 1379 | } 1380 | sleep 4; 1381 | } 1382 | exit 0; 1383 | }; 1384 | 1385 | @cmd = map { encode_cl($_) } @cmd; 1386 | #print $se "INFO: open3( 0, \">&".fileno($fh_child_out).", \">&".fileno($fh_child_err).", )\n"; 1387 | # Don't use NULL for the 1st arg of open3 otherwise we end up with a messed up STDIN once it returns 1388 | $procid = open3( gensym, $from, $error, @cmd ); 1389 | # Wait for child to complete 1390 | 1391 | my $childpid = fork(); 1392 | binmode $se, ":encoding($opt_cmdline->{encodingconsoleout})"; 1393 | # Child 1394 | if ( $childpid == 0 ) { 1395 | binmode $error, ':utf8'; 1396 | while ( <$error> ) { 1397 | print $se "CMD STDERR: $_"; 1398 | } 1399 | #print $se "CMD STDERR EMPTY\n"; 1400 | exit 0; 1401 | # Parent 1402 | } elsif ( defined $childpid ) { 1403 | binmode $from, ':utf8'; 1404 | while ( <$from> ) { 1405 | push @out_from, $_; 1406 | } 1407 | } else { 1408 | print $se "ERROR: Could not fork STDERR reader process\n"; 1409 | exit 1; 1410 | } 1411 | waitpid( $childpid, 0 ); 1412 | 1413 | waitpid( $procid, 0 ); 1414 | $rtn = $?; 1415 | 1416 | # Restore sigpipe handler for reader and writer processes 1417 | $SIG{PIPE} = 'DEFAULT'; 1418 | 1419 | # Interpret return code 1420 | interpret_return_code( $rtn ); 1421 | 1422 | return @out_from; 1423 | } 1424 | 1425 | 1426 | 1427 | # Still uses shell 1428 | sub get_cmd_output_win32 { 1429 | my ( @cmd ) = ( @_ ); 1430 | 1431 | # workaround to add quotes around the args because we are using a shell here 1432 | for ( @cmd ) { 1433 | s/^(.+)$/"$1"/g if ! m{^[\-\"]}; 1434 | } 1435 | 1436 | print $se "DEBUG: Command: ".( join ' ', @cmd )."\n"; 1437 | @cmd = map { encode_cl($_) } @cmd; 1438 | open( CMD, ( join ' ', @cmd ).'|' ) || print $se "ERROR: open failed: $!\n"; 1439 | binmode CMD, ':utf8'; 1440 | my @out; 1441 | my @out = ; 1442 | close CMD; 1443 | 1444 | # Interpret return code 1445 | interpret_return_code( $? ); 1446 | 1447 | return @out; 1448 | } 1449 | 1450 | 1451 | 1452 | sub interpret_return_code { 1453 | my $rtn = shift; 1454 | # Interpret return code and force return code 2 upon error 1455 | my $return = $rtn >> 8; 1456 | if ( $rtn == -1 && $IGNOREEXIT ) { 1457 | $return = 0; 1458 | } elsif ( $rtn == -1 ) { 1459 | print $se "ERROR: Command failed to execute: $!\n"; 1460 | $return = 2 if ! $return; 1461 | } elsif ( $rtn & 128 ) { 1462 | print $se "WARNING: Command executed but coredumped\n"; 1463 | $return = 2 if ! $return; 1464 | } elsif ( $rtn & 127 ) { 1465 | print $se sprintf "WARNING: Command executed but died with signal %d\n", $rtn & 127; 1466 | $return = 2 if ! $return; 1467 | } 1468 | print $se sprintf "INFO: Command exit code %d\n", $return if $return; 1469 | return $return; 1470 | } 1471 | 1472 | 1473 | 1474 | sub get_pvr_list { 1475 | my $pvrsearch; 1476 | my $out = join "\n", get_cmd_output( 1477 | @gip_cmd_base, 1478 | '--pvrlist', 1479 | ); 1480 | # Remove text before first pvrsearch entry 1481 | $out =~ s/^.+?(pvrsearch\s.+)$/$1/s; 1482 | # Parse all 'pvrsearch' elements 1483 | for ( split /pvrsearch\s+\=\s+/, $out ) { 1484 | next if /^get_iplayer/; 1485 | my $name; 1486 | $_ = "pvrsearch = $_"; 1487 | # Get each element 1488 | while ( /([\w\-]+?)\s+=\s+(.+?)\n/sg ) { 1489 | if ( $1 eq 'pvrsearch' ) { 1490 | $name = $2; 1491 | } 1492 | $pvrsearch->{$name}->{$1} = $2; 1493 | # Remove disabled entries 1494 | if ( $pvrsearch->{$name}->{disable} == 1 ) { 1495 | delete $pvrsearch->{$name}; 1496 | last; 1497 | } 1498 | } 1499 | } 1500 | return $pvrsearch; 1501 | } 1502 | 1503 | 1504 | 1505 | sub show_pvr_list { 1506 | my %fields; 1507 | my $pvrsearch = get_pvr_list(); 1508 | my $sort_field = $cgi->param( 'PVRSORT' ) || 'name'; 1509 | my $reverse = $cgi->param( 'PVRREVERSE' ) || '0'; 1510 | 1511 | # Sort data 1512 | my @pvrsearches = get_sorted( $pvrsearch, $sort_field, $reverse ); 1513 | 1514 | # Parse all 'pvrsearch' elements to get all fields used 1515 | for my $name ( @pvrsearches ) { 1516 | # Get each element 1517 | for ( keys %{ $pvrsearch->{$name} } ) { 1518 | $fields{$_} = 1; 1519 | } 1520 | } 1521 | 1522 | # Render options actions 1523 | my $buttons = div( { -class=>'action' }, 1524 | ul( { -class=>'action' }, 1525 | li( { -class=>'action' }, [ 1526 | a( 1527 | { 1528 | -class=>'action', 1529 | -title => 'Go Back', 1530 | -onClick => "history.back()", 1531 | }, 1532 | 'Back' 1533 | ), 1534 | a( 1535 | { 1536 | -class => 'action', 1537 | -title => 'Delete selected programmes from PVR search list', 1538 | -onClick => "if(! check_if_selected(document.form1, 'PVRSELECT')) { alert('No programmes were selected'); return false; } BackupFormVars(form1); form1.NEXTPAGE.value='pvr_del'; form1.submit(); RestoreFormVars(form1);", 1539 | }, 1540 | 'Delete' 1541 | ), 1542 | ]), 1543 | ), 1544 | ); 1545 | 1546 | my @html; 1547 | my @displaycols = ( 'pvrsearch', ( grep !/pvrsearch/, ( sort keys %fields ) ) ); 1548 | # Build header row 1549 | push @html, ""; 1550 | push @html, th( { -class => 'search' }, checkbox( -class=>'search', -title=>'Select/Unselect All PVR Searches', -onClick=>"check_toggle(document.form1, 'PVRSELECT')", -name=>'SELECTOR', -value=>'1', -label=>'' ) ); 1551 | # Display data in nested table 1552 | for my $heading (@displaycols) { 1553 | 1554 | # Sort by column click and change display class (colour) according to sort status 1555 | my ($title, $class, $onclick); 1556 | if ( $sort_field eq $heading && not $reverse ) { 1557 | ($title, $class, $onclick) = ("Sort by Reverse $fieldname{$heading}", 'sorted pointer', "BackupFormVars(form1); form1.NEXTPAGE.value='pvr_list'; form1.PVRSORT.value='$heading'; form1.PVRREVERSE.value=1; form1.submit(); RestoreFormVars(form1);"); 1558 | } else { 1559 | ($title, $class, $onclick) = ("Sort by $fieldname{$heading}", 'unsorted pointer', "BackupFormVars(form1); form1.NEXTPAGE.value='pvr_list'; form1.PVRSORT.value='$heading'; form1.submit(); RestoreFormVars(form1); "); 1560 | } 1561 | $class = 'sorted_reverse pointer' if $sort_field eq $heading && $reverse; 1562 | 1563 | push @html, th( { -class => 'search' }, 1564 | label( { 1565 | -title => $title, 1566 | -class => $class, 1567 | -onClick => $onclick, 1568 | }, 1569 | $fieldname{$heading} || $heading, 1570 | ) 1571 | ); 1572 | } 1573 | push @html, ""; 1574 | 1575 | # Build each row 1576 | for my $name ( @pvrsearches ) { 1577 | my @row; 1578 | push @row, td( {-class=>'search'}, 1579 | checkbox( 1580 | -class => 'search', 1581 | -name => 'PVRSELECT', 1582 | -label => '', 1583 | -value => "$name", 1584 | -checked => 0, 1585 | -override => 1, 1586 | ) 1587 | ); 1588 | for ( @displaycols ) { 1589 | push @row, td( {-class=>'search'}, 1590 | label( { 1591 | -title => "Click to Edit", 1592 | -class => 'search', 1593 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='pvr_edit'; form1.PVRSEARCH.value='$name'; form1.submit(); RestoreFormVars(form1);", 1594 | }, 1595 | $pvrsearch->{$name}->{$_}, 1596 | ) 1597 | ); 1598 | } 1599 | push @html, Tr( {-class=>'search'}, @row ); 1600 | } 1601 | 1602 | 1603 | # Search form 1604 | print $fh start_form( 1605 | -name => "form1", 1606 | -method => "POST", 1607 | ); 1608 | print $fh p("Click to Edit any PVR Search"); 1609 | # Render options actions 1610 | print $fh $buttons; 1611 | # Render table 1612 | print $fh table( {-class=>'search'} , @html ); 1613 | print $fh $buttons; 1614 | # Make sure we go to the correct nextpage for processing 1615 | print $fh hidden( 1616 | -name => "NEXTPAGE", 1617 | -value => "pvr_list", 1618 | -override => 1, 1619 | ); 1620 | # Reverse sort value 1621 | print $fh hidden( 1622 | -name => "PVRREVERSE", 1623 | -value => 0, 1624 | -override => 1, 1625 | ); 1626 | print $fh hidden( 1627 | -name => "PVRSORT", 1628 | -value => $sort_field, 1629 | -override => 1, 1630 | ); 1631 | print $fh hidden( 1632 | -name => "PVRSEARCH", 1633 | -value => '', 1634 | -override => 1, 1635 | ); 1636 | print $fh end_form(); 1637 | 1638 | return 0; 1639 | } 1640 | 1641 | 1642 | 1643 | # Edits a single record indicated by PVRSELECT 1644 | sub pvr_edit { 1645 | my %fields; 1646 | my $pvrsearch = get_pvr_list(); 1647 | my @html; 1648 | 1649 | my $pvrname = $cgi->param( 'PVRSEARCH' ); 1650 | 1651 | # Determine max field length 1652 | my $maxwidth = 30; 1653 | for ( values %{ $pvrsearch->{$pvrname} } ) { 1654 | $maxwidth = length($_) if length($_) > $maxwidth && $maxwidth < 200; 1655 | } 1656 | # Get each element 1657 | for my $key ( keys %{ $pvrsearch->{$pvrname} } ) { 1658 | my $val = $pvrsearch->{$pvrname}->{$key}; 1659 | # Put INPUT field here 1660 | my $element; 1661 | #if ( $key eq 'pvrsearch' ) { 1662 | # $element = $val; 1663 | #} else { 1664 | $element = hidden( 1665 | -name => "EDITKEYS", 1666 | -value => $key, 1667 | -override => 1, 1668 | ). 1669 | textfield( 1670 | -class => 'edit', 1671 | -name => "EDITVALUES", 1672 | -value => $val, 1673 | -size => $maxwidth + 20, 1674 | ); 1675 | #} 1676 | push @html, Tr( { -class => 'info' }, th( { -class => 'info' }, $key ).td( { -class => 'info' }, $element ) ); 1677 | } 1678 | 1679 | # Editing form 1680 | print $fh start_form( 1681 | -name => "form1", 1682 | -method => "POST", 1683 | ); 1684 | 1685 | print $fh table( { -class => 'info' }, @html ); 1686 | 1687 | # Render options actions 1688 | print $fh div( { -class=>'action' }, 1689 | ul( { -class=>'action' }, 1690 | li( { -class=>'action' }, [ 1691 | a( 1692 | { 1693 | -class=>'action', 1694 | -title => 'Go Back', 1695 | -onClick => "history.back()", 1696 | }, 1697 | 'Back' 1698 | ), 1699 | a( 1700 | { 1701 | -class => 'action', 1702 | -title => 'Save changes', 1703 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='pvr_save'; form1.submit(); RestoreFormVars(form1);", 1704 | }, 1705 | 'Save Changes' 1706 | ), 1707 | ]), 1708 | ), 1709 | ); 1710 | # Make sure we go to the correct nextpage for processing 1711 | print $fh hidden( 1712 | -name => "NEXTPAGE", 1713 | -value => "pvr_add", 1714 | -override => 1, 1715 | ); 1716 | print $fh hidden( 1717 | -name => "PVRSEARCH", 1718 | -value => $pvrname, 1719 | -override => 1, 1720 | ); 1721 | print $fh end_form(); 1722 | 1723 | return 0; 1724 | } 1725 | 1726 | 1727 | 1728 | # 1729 | # Will return a list of pids sorted by the requested Heading 1730 | # 1731 | sub get_sorted { 1732 | my @sorted; 1733 | my @unsorted; 1734 | my $data = shift; 1735 | my $sort_field = shift; 1736 | my $reverse = shift; 1737 | # Lookup table for nice field name headings 1738 | my %sorttype = ( 1739 | index => 'numeric', 1740 | duration => 'numeric', 1741 | timeadded => 'numeric', 1742 | seriesnum => 'numeric', 1743 | episodenum => 'numeric', 1744 | expires => 'numeric', 1745 | ); 1746 | 1747 | # Insert search '~~~' for each prog in hash 1748 | for my $key (keys %{ $data } ) { 1749 | # generate sort column 1750 | push @unsorted, $data->{$key}->{$sort_field}.'~~~'.$key; 1751 | } 1752 | 1753 | # If this a purely numerical field 1754 | if ( defined $sorttype{$sort_field} && $sorttype{$sort_field} eq 'numeric' ) { 1755 | if ($reverse) { 1756 | @sorted = reverse sort {$a <=> $b} @unsorted; 1757 | } else { 1758 | @sorted = sort {$a <=> $b} @unsorted; 1759 | } 1760 | # otherwise sort alphabetically 1761 | } else { 1762 | if ($reverse) { 1763 | @sorted = reverse sort { lc $a cmp lc $b } @unsorted; 1764 | } else { 1765 | @sorted = sort { lc $a cmp lc $b } @unsorted; 1766 | } 1767 | } 1768 | # Strip off search key at beginning of each line 1769 | s/^.*~~~// for @sorted; 1770 | 1771 | return @sorted; 1772 | } 1773 | 1774 | 1775 | 1776 | sub pvr_del { 1777 | my @record = ( $cgi->param( 'PVRSELECT' ) ); 1778 | my $out; 1779 | 1780 | # Queue all selected '|' entries in the PVR 1781 | for my $name (@record) { 1782 | chomp(); 1783 | my @cmd = ( 1784 | @gip_cmd_base, 1785 | '--webrequest', 1786 | get_iplayer_webrequest_args( "pvrdel=$name" ), 1787 | ); 1788 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 1789 | my $cmdout = join "", get_cmd_output( @cmd ); 1790 | return p("ERROR: ".$out) if $? && not $IGNOREEXIT; 1791 | print $fh p("Deleted: $name"); 1792 | $out .= $cmdout; 1793 | } 1794 | print $fh "
$out
"; 1795 | 1796 | # Show list below 1797 | show_pvr_list(); 1798 | 1799 | return $out; 1800 | } 1801 | 1802 | 1803 | 1804 | sub show_info { 1805 | my $progdata = ( $cgi->param( 'INFO' ) ); 1806 | my $out; 1807 | my @html; 1808 | my %prog; 1809 | my ( $type, $pid ) = split /\|/, $progdata; 1810 | 1811 | # Queue all selected '|' entries in the PVR 1812 | chomp(); 1813 | my @cmd = ( 1814 | @gip_cmd_base, 1815 | '--webrequest', 1816 | get_iplayer_webrequest_args( "type=$type", "future=$opt->{FUTURE}->{current}", "history=$opt->{HISTORY}->{current}", "skipdeleted=$opt->{HIDEDELETED}->{current}", 'info=1', 'fields=pid', "search=$pid" ), 1817 | ); 1818 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 1819 | my @cmdout = get_cmd_output( @cmd ); 1820 | return p("ERROR: ".@cmdout) if $? && not $IGNOREEXIT; 1821 | for ( grep !/^(Added|INFO):/, @cmdout ) { 1822 | my ( $key, $val ) = ( $1, $2 ) if m{^(\w+?):\s*(.+?)\s*$}; 1823 | next if $key =~ /(^$|^\d+$)/ || $val =~ /Matching Program/i; 1824 | $out .= "$key: $val\n"; 1825 | $prog{$pid}->{$key} = $val; 1826 | # Make into a link if this value is a URL 1827 | $val = a( { -class=>'info', -title=>'Open URL', -href=>$val, -target=>'_new' }, $val ) if $val =~ m{^https?://.+}; 1828 | push @html, Tr( { -class => 'info' }, th( { -class => 'info' }, $key ).td( { -class => 'info' }, $val ) ); 1829 | } 1830 | # Show thumb if one exists 1831 | $prog{$pid}->{thumbnail} ||= DEFAULT_THUMBNAIL; 1832 | print $fh img( { -height=>216, -class=>'action', -src=>$prog{$pid}->{thumbnail} } ) if $prog{$pid}->{thumbnail}; 1833 | # Set optional output dir for pvr queue if set 1834 | my $outdir; 1835 | $outdir = '&OUTPUT='.CGI::escape("$opt->{OUTPUT}->{current}") if $opt->{OUTPUT}->{current}; 1836 | # Render options actions 1837 | print $fh div( { -class=>'action' }, 1838 | ul( { -class=>'action' }, 1839 | li( { -class=>'action' }, [ 1840 | a( 1841 | { 1842 | -class=>'action', 1843 | -title => 'Close', 1844 | -onClick => "window.close()", 1845 | }, 1846 | 'Close' 1847 | ), 1848 | ]), 1849 | ), 1850 | ); 1851 | print $fh table( { -class => 'info' }, @html ); 1852 | return $out; 1853 | } 1854 | 1855 | 1856 | 1857 | # Get filename from history based on PID, MODE and TYPE 1858 | # If the PID is a filename then filename is still searched using PID and TYPE 1859 | sub get_direct_filename { 1860 | my ( $pid, $mode, $type ) = ( @_ ); 1861 | my $history = 1; 1862 | 1863 | print $se "DEBUG: Looking up filename for MODE=$mode TYPE=$type PID=$pid\n"; 1864 | 1865 | if ( ! ( $pid && $mode && $type ) ) { 1866 | print $se "ERROR: Cannot lookup filename unless PID, MODE and TYPE are set\n"; 1867 | return ''; 1868 | } 1869 | 1870 | # Get the 'filename' entry from --history --info for this pid 1871 | my @cmd = ( 1872 | @gip_cmd_base, 1873 | '--webrequest', 1874 | get_iplayer_webrequest_args( "history=$history", 'fields=pid', "search=$pid", "type=$type", 'listformat=filename: ||' ), 1875 | ); 1876 | print $se "Command: ".( join ' ', @cmd )."\n"; # if $opt_cmdline->{debug}; 1877 | my @cmdout = get_cmd_output( @cmd ); 1878 | return p("ERROR: ".@cmdout) if $? && not $IGNOREEXIT; 1879 | 1880 | # Extract the filename 1881 | my $match = ( grep /^filename:/, @cmdout )[0]; 1882 | my $filename; 1883 | $filename = $1 if $match =~ m{^filename: .+?\|\s*(.+?)\|$mode\s*$}; 1884 | return search_absolute_path( encode_fs($filename) ); 1885 | } 1886 | 1887 | 1888 | 1889 | # Hack to work around relative paths in recordings history 1890 | sub search_absolute_path { 1891 | my $filename = shift; 1892 | my $abs_path; 1893 | 1894 | # win32 doesn't seem to like abs_path 1895 | # abs_path croaks on cygwin if file not found 1896 | # rewrite win32 paths 1897 | if ( IS_WIN32 || $^O eq "cygwin" ) { 1898 | # add a hardcoded prefix for now if relative path (assume relative to local get_iplayer script) 1899 | if ( $filename !~ m{^[A-Za-z]:} && $filename =~ m{^(\.|\.\.|[A-Za-z_])} ) { 1900 | $filename = dirname( abs_path( $opt_cmdline->{getiplayer} ) ).'/'.$filename; 1901 | } 1902 | if ( IS_WIN32 ) { 1903 | # twiddle the / to \ 1904 | $filename =~ s!(\\/|/|\/)!\\!g; 1905 | } 1906 | return $filename; 1907 | } 1908 | 1909 | #print $se "FILENAME='$filename'"; 1910 | 1911 | # Try using CWD 1912 | if ( -f abs_path($filename) ) { 1913 | $abs_path = abs_path($filename); 1914 | 1915 | # else try dir of get_iplayer 1916 | } elsif ( -f dirname( abs_path( $opt_cmdline->{getiplayer} ) ).'/'.$filename ) { 1917 | $abs_path = dirname( abs_path( $opt_cmdline->{getiplayer} ) ).'/'.$filename; 1918 | 1919 | # else try dir current output dir option 1920 | } elsif ( $opt->{OUTPUT}->{current} && -f abs_path( $opt->{OUTPUT}->{current} ).'/'.$filename ) { 1921 | $abs_path = abs_path( encode_fs($opt->{OUTPUT}->{current}) ).'/'.$filename; 1922 | 1923 | # Else just return the relative path 1924 | } else { 1925 | $abs_path = $filename; 1926 | } 1927 | 1928 | #print $se " -> ABSPATH='$abs_path'\n"; 1929 | 1930 | return $abs_path; 1931 | } 1932 | 1933 | 1934 | 1935 | sub pvr_queue { 1936 | # Gets the multiple selections of progs to queue from PROGSELECT 1937 | my @record; 1938 | # The 'Record' action button uses SEARCH to pass it's pvr_queue data 1939 | if ( $cgi->param( 'SEARCH' ) ) { 1940 | push @record, $cgi->param( 'SEARCH' ); 1941 | } else { 1942 | @record = ( $cgi->param( 'PROGSELECT' ) ); 1943 | } 1944 | 1945 | my @params = get_search_params(); 1946 | my $out; 1947 | 1948 | # If a URL was specified by the User (assume auto mode list is OK): 1949 | if ( $opt->{URL}->{current} =~ m{^https?://} ) { 1950 | push @record, "$opt->{PROGTYPES}->{current}|$opt->{URL}->{current}|$opt->{URL}->{current}|-"; 1951 | } 1952 | 1953 | print $fh "

Queuing The Following Programmes in the PVR

    \n"; 1954 | for (@record) { 1955 | chomp(); 1956 | my ( $type, $pid, $name, $episode ) = (split /\|/)[0,1,2,3]; 1957 | next if ! ($type && $pid ); 1958 | print $fh "
  • $name - $episode ($pid)
  • \n"; 1959 | } 1960 | print $fh "

\n"; 1961 | # Queue all selected 'TYPE|PID|NAME|EPISODE|MODE|CHANNEL' entries in the PVR 1962 | for (@record) { 1963 | chomp(); 1964 | my ( $type, $pid, $name, $episode ) = (split /\|/)[0,1,2,3]; 1965 | next if ! ($type && $pid ); 1966 | my $comment = "$name - $episode"; 1967 | $comment =~ s/\'\"//g; 1968 | $comment =~ s/[^\s\w\d\-:\(\)]/_/g; 1969 | $comment =~ s/^_*//g; 1970 | $comment =~ s/_*$//g; 1971 | my @cmd = ( 1972 | @gip_cmd_base, 1973 | '--webrequest', 1974 | get_iplayer_webrequest_args( 1975 | 'pvrqueue=1', 1976 | "pid=$pid", 1977 | "comment=$comment (queued: ".localtime().')', 1978 | "type=$type", 1979 | build_cmd_options( grep !/^(HISTORY|SINCE|BEFORE|HIDEDELETED|FUTURE|SEARCH|SEARCHFIELDS|PROGTYPES|EXCLUDEC.+)$/, @params ) 1980 | ), 1981 | ); 1982 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 1983 | my $cmdout = join "", get_cmd_output( @cmd ); 1984 | return p("ERROR: ".$out) if $? && not $IGNOREEXIT; 1985 | print $fh p("Queued: $type: '$name - $episode' ($pid)"); 1986 | $out .= $cmdout; 1987 | } 1988 | print $fh "
$out
"; 1989 | 1990 | # Show list below 1991 | show_pvr_list(); 1992 | 1993 | return $out; 1994 | } 1995 | 1996 | 1997 | 1998 | sub recordings_delete { 1999 | # Gets the multiple selections of progs to queue from PROGSELECT 2000 | my @record; 2001 | # The 'Record' action button uses SEARCH to pass it's pvr_queue data 2002 | if ( $cgi->param( 'SEARCH' ) ) { 2003 | push @record, $cgi->param( 'SEARCH' ); 2004 | } else { 2005 | @record = ( $cgi->param( 'PROGSELECT' ) ); 2006 | } 2007 | 2008 | my @params = get_search_params(); 2009 | 2010 | # Render options actions 2011 | my $buttons = div( { -class=>'action' }, 2012 | ul( { -class=>'action' }, 2013 | li( { -class=>'action' }, [ 2014 | a( 2015 | { 2016 | -class=>'action', 2017 | -title => 'Go Back', 2018 | -onClick => "history.back()", 2019 | }, 2020 | 'Back' 2021 | ), 2022 | ]), 2023 | ), 2024 | ); 2025 | # Render options actions 2026 | print $fh $buttons; 2027 | print $fh "

Deleting the Following Programmes:

    \n"; 2028 | for (@record) { 2029 | chomp(); 2030 | my ( $type, $pid, $name, $episode ) = (split /\|/)[0,1,2,3]; 2031 | next if ! ($type && $pid ); 2032 | print $fh "
  • $name - $episode ($pid)
  • \n"; 2033 | } 2034 | print $fh "

\n"; 2035 | # Queue all selected 'TYPE|PID|NAME|EPISODE|MODE|CHANNEL' entries in the PVR 2036 | for (@record) { 2037 | chomp(); 2038 | my ( $type, $pid, $name, $episode, $mode ) = (split /\|/)[0,1,2,3,4]; 2039 | next if ! ($mode && $pid ); 2040 | my $filename = get_direct_filename( $pid, $mode, $type ); 2041 | my $dir = dirname( $filename ); 2042 | my $fileregex = basename( $filename ); 2043 | # get the filename less the ext 2044 | $fileregex =~ s/\.\w+$//g; 2045 | # escape regex metachars 2046 | $fileregex =~ s/([\\\^\$\.\|\?\*\+\(\)\[\]])/\\$1/g; 2047 | $fileregex .= '\.\w+$'; 2048 | # Find matching files .* 2049 | my $deleted; 2050 | if ( opendir DIR, $dir ) { 2051 | for my $file ( grep { /$fileregex/ } readdir(DIR) ) { 2052 | # Use absolute path 2053 | $file = "${dir}/${file}"; 2054 | if ( -f $file ) { 2055 | if ( ! unlink( $file ) ) { 2056 | print $fh p("ERROR: Failed to delete $file"); 2057 | } else { 2058 | $deleted = 1; 2059 | print $fh p("Successfully deleted: $type: '$name - $episode', MODE: $mode, PID: $pid"); 2060 | } 2061 | } else { 2062 | print $fh p("ERROR: File does not exist for: $type: '$name - $episode', MODE: $mode, PID: $pid, FILENAME: $filename"); 2063 | } 2064 | } 2065 | if ( ! $deleted ) { 2066 | print $fh p("No files deleted: $type: '$name - $episode', MODE: $mode, PID: $pid"); 2067 | } 2068 | closedir(DIR); 2069 | } else { 2070 | print $fh p("ERROR: Cannot open dir '$dir' for file deletion\n"); 2071 | } 2072 | } 2073 | # Render options actions 2074 | print $fh $buttons; 2075 | return ''; 2076 | } 2077 | 2078 | 2079 | 2080 | sub build_cmd_options { 2081 | my @options; 2082 | for ( @_ ) { 2083 | # skip non-options 2084 | next if $opt->{$_}->{optkey} eq '' || not defined $opt->{$_}->{optkey} || not $opt->{$_}->{optkey}; 2085 | my $value = $opt->{$_}->{current}; 2086 | push @options, "$opt->{$_}->{optkey}=$value" if $value ne ''; 2087 | } 2088 | return @options; 2089 | } 2090 | 2091 | 2092 | 2093 | sub get_search_params { 2094 | my @params; 2095 | for ( keys %{ $opt } ) { 2096 | # skip non-options 2097 | next if $opt->{$_}->{optkey} eq '' || not defined $opt->{$_}->{optkey} || not $opt->{$_}->{optkey}; 2098 | next if grep /^$_$/, @nosearch_params; 2099 | push @params, $_; 2100 | } 2101 | return @params; 2102 | } 2103 | 2104 | 2105 | 2106 | # Return get_iplayer command options when supplied an array of = options 2107 | sub get_iplayer_webrequest_args { 2108 | my @cmdopts; 2109 | print $se 'DEBUG: get_iplayer options: "'.join('" "', @_)."\"\n"; 2110 | for (@_) { 2111 | push @cmdopts, CGI::escape(encode_wr($_)); 2112 | } 2113 | my $cmdline = join('?', @cmdopts); 2114 | return $cmdline; 2115 | } 2116 | 2117 | 2118 | 2119 | sub pvr_add { 2120 | 2121 | my $out; 2122 | my @params = get_search_params(); 2123 | 2124 | # Only allow alphanumerics,_,-,. here for security reasons 2125 | my $searchname = "$opt->{SEARCH}->{current}_$opt->{SEARCHFIELDS}->{current}_$opt->{PROGTYPES}->{current}"; 2126 | $searchname =~ s/[^\w]+/_/g; 2127 | 2128 | # Remove a few options from leaking into a PVR search 2129 | my @cmd = ( 2130 | @gip_cmd_base, 2131 | '--webrequest', 2132 | get_iplayer_webrequest_args( "pvradd=$searchname", build_cmd_options( grep !/^(HISTORY|HIDEDELETED|SINCE|BEFORE|HIDE|FORCE|FUTURE)$/, @params ) ), 2133 | ); 2134 | print $se "DEBUG: Command: ".( join ' ', @cmd )."\n"; 2135 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 2136 | $out = join "", get_cmd_output( @cmd ); 2137 | return p("ERROR: ".$out) if $? && not $IGNOREEXIT; 2138 | print $fh p("Added PVR Search ($searchname):\n\tTypes: $opt->{PROGTYPES}->{current}\n\tSearch: $opt->{SEARCH}->{current}\n\tSearch Fields: $opt->{SEARCHFIELDS}->{current}\n"); 2139 | print $fh "
$out
"; 2140 | 2141 | # Show list below 2142 | show_pvr_list(); 2143 | 2144 | return $out; 2145 | } 2146 | 2147 | 2148 | 2149 | # Delete then add again - just in case user has edited name of pvr search 2150 | sub pvr_save { 2151 | my $out; 2152 | my @keys = $cgi->param( 'EDITKEYS' ); 2153 | my @values = $cgi->param( 'EDITVALUES' ); 2154 | my @params; 2155 | my @search_args; 2156 | my $newsearchname; 2157 | 2158 | # Convert the two keys and values arrays into a KEY=VALUE params array 2159 | for ( @keys ) { 2160 | my $val = shift @values; 2161 | if ( $_ eq 'pvrsearch' ) { 2162 | $newsearchname = $val; 2163 | # append search terms to cmdline 2164 | } elsif ( /^search\d+$/ && $val !~ /^\-/ ) { 2165 | push @search_args, $val; 2166 | } else { 2167 | push @params, $_.'='.$val; 2168 | } 2169 | } 2170 | 2171 | #print STDERR "ELEMENTS for save: ".(join ',', @params)."\n\n"; 2172 | 2173 | # Sanity check 2174 | if ( $newsearchname eq '' ) { 2175 | print $fh p("No PVR Search Name Specified - not updated"); 2176 | return; 2177 | } 2178 | 2179 | # Delete the original pvr entry 2180 | my $searchname = $cgi->param( 'PVRSEARCH' ); 2181 | my @cmd = ( 2182 | @gip_cmd_base, 2183 | '--webrequest', 2184 | get_iplayer_webrequest_args( "pvrdel=$searchname" ), 2185 | ); 2186 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 2187 | my $cmdout = join "", get_cmd_output( @cmd ); 2188 | return p("ERROR: ".$out) if $? && not $IGNOREEXIT; 2189 | print $fh p("Deleted: $searchname"); 2190 | $out .= $cmdout; 2191 | 2192 | # Add the new pvr entry 2193 | @cmd = ( 2194 | @gip_cmd_base, 2195 | '--webrequest', 2196 | get_iplayer_webrequest_args( "pvradd=$newsearchname", @params ), 2197 | '--', 2198 | @search_args, 2199 | ); 2200 | print $se "DEBUG: Command: ".( join ' ', @cmd )."\n"; 2201 | print $fh p("Command: ".( join ' ', @cmd ) ) if $opt_cmdline->{debug}; 2202 | $out = join "", get_cmd_output( @cmd ); 2203 | return p("ERROR: ".$out) if $? && not $IGNOREEXIT; 2204 | print $fh p("Added Updated PVR Search '$newsearchname'\n"); 2205 | print $fh "
$out
"; 2206 | 2207 | # Show list below 2208 | show_pvr_list(); 2209 | 2210 | return $out; 2211 | } 2212 | 2213 | 2214 | 2215 | # Build templated HTML for an option specified by passed hashref 2216 | sub build_option_html { 2217 | my $arg = shift; 2218 | 2219 | my $title = $arg->{title}; 2220 | my $tooltip = $arg->{tooltip}; 2221 | my $webvar = $arg->{webvar}; 2222 | my $option = $arg->{option}; 2223 | my $type = $arg->{type}; 2224 | my $label = $arg->{label}; 2225 | my $current = $arg->{current}; 2226 | my $value = $arg->{value}; 2227 | my $status = $arg->{status}; 2228 | my @html; 2229 | 2230 | # On/Off 2231 | if ( $type eq 'hidden' ) { 2232 | push @html, hidden( 2233 | -name => $webvar, 2234 | -id => "option_$webvar", 2235 | #-value => $arg->{default}, 2236 | -value => $current, 2237 | -override => 1, 2238 | ); 2239 | 2240 | # On/Off 2241 | } elsif ( $type eq 'boolean' ) { 2242 | push @html, th( { -class => 'options', -title => $tooltip, -id => "label_option_$webvar" }, $title ). 2243 | td( { -class => 'options', -title => $tooltip }, 2244 | checkbox( 2245 | -class => 'options', 2246 | -name => $webvar, 2247 | -id => "option_$webvar", 2248 | -label => '', 2249 | #-value => 1, 2250 | -checked => $current, 2251 | -override => 1, 2252 | "aria-labelledby" => "label_option_$webvar", 2253 | ) 2254 | ); 2255 | 2256 | # On/Off 2257 | } elsif ( $type eq 'radioboolean' ) { 2258 | push @html, th( { -class => 'options', -title => $tooltip }, $title ). 2259 | td( { -class => 'options', -title => $tooltip }, 2260 | radio_group( 2261 | -class => 'options', 2262 | -name => $webvar, 2263 | -values => [ 0 , 1 ], 2264 | -labels => { 0=>'Off' , 1=>'On' }, 2265 | -default => $current, 2266 | -override => 1, 2267 | ) 2268 | ); 2269 | 2270 | # Multi-On/Off 2271 | } elsif ( $type eq 'multiboolean' ) { 2272 | my $element; 2273 | # values in hash of $value->{} => value 2274 | # labels in hash of $label->{$value} 2275 | # selected status in $status->{$value} 2276 | my @keylist = sort { $a <=> $b } keys %{ $value }; 2277 | my $count = 0; 2278 | while ( @keylist ) { 2279 | my $val = $value->{shift @keylist}; 2280 | $element .= 2281 | td( { -class => 'options' }, 2282 | table ( { -class => 'options_embedded', -title => $tooltip, -role=>'presentation' }, Tr( { -class => 'options_embedded' }, td( { -class => 'options_embedded' }, [ 2283 | checkbox( 2284 | -class => 'options', 2285 | -name => $webvar, 2286 | -id => "option_${webvar}_$val", 2287 | -label => '', 2288 | -value => $val, 2289 | -checked => $status->{$val}, 2290 | -override => 1, 2291 | "aria-labelledby" => "label_option_${webvar}_$val", 2292 | ), 2293 | label( { -for => "option_${webvar}_$val"}, span({ -id=> "label_option_${webvar}_$val" }, $label->{$val} ) ) 2294 | ] ) ) ) 2295 | ); 2296 | # Spread over more rows if there are many elements 2297 | if ( not ( ($count+1) % 3 ) ) { 2298 | $element .= ''; 2299 | } 2300 | $count++; 2301 | } 2302 | my $inner_table = table ( { -class => 'options_embedded' }, Tr( { -class => 'options_embedded' }, 2303 | $element 2304 | ) ); 2305 | 2306 | push @html, th( { -class => 'options', -title => $tooltip }, $title ).td( { -class => 'options' }, $inner_table ); 2307 | # Popup type 2308 | } elsif ( $type eq 'popup' ) { 2309 | my @value = $arg->{value}; 2310 | push @html, th( { -class => 'options', -title => $tooltip, -id => "label_option_$webvar" }, $title ). 2311 | td( { -class => 'options', -title => $tooltip }, 2312 | popup_menu( 2313 | -class => 'options', 2314 | -name => $webvar, 2315 | -id => "option_$webvar", 2316 | -values => @value, 2317 | -labels => $label, 2318 | -default => $current, 2319 | -onChange => $arg->{onChange}, 2320 | "aria-labelledby" => "label_option_$webvar", 2321 | ) 2322 | ); 2323 | 2324 | # text field 2325 | } elsif ( $type eq 'text' ) { 2326 | push @html, th( { -class => 'options', -title => $tooltip, -id => "label_option_$webvar" }, $title ). 2327 | td( { -class => 'options', -title => $tooltip }, 2328 | textfield( 2329 | -class => 'options', 2330 | -name => $webvar, 2331 | -value => $current, 2332 | -size => $value, 2333 | -onKeyDown => 'return submitonEnter(event);', 2334 | "aria-labelledby" => "label_option_$webvar", 2335 | ) 2336 | ); 2337 | 2338 | } 2339 | 2340 | return @html; 2341 | } 2342 | 2343 | 2344 | 2345 | sub refresh { 2346 | my $typelist = join(",", $cgi->param( 'PROGTYPES' )) || 'tv'; 2347 | my $refreshfuture = $cgi->param( 'REFRESHFUTURE' ) || 0; 2348 | print $fh "

The cache will auto-refresh every $opt->{AUTOWEBREFRESH}->{current} hour(s) if you leave this page open

" if $opt->{AUTOWEBREFRESH}->{current}; 2349 | if ( IS_WIN32 ) { 2350 | print $fh "

Windows users: You may encounter errors if you perform other tasks in the Web PVR Manager while this page is reloading

" if $opt->{AUTOWEBREFRESH}->{current}; 2351 | print $fh "

Windows users: The Web PVR Manager may crash if you leave this window open for a long period of time

" if $opt->{AUTOWEBREFRESH}->{current}; 2352 | } 2353 | print $se "INFO: Refreshing\n"; 2354 | my @cmd = ( 2355 | @gip_cmd_refresh, 2356 | '--refresh', 2357 | '--webrequest', 2358 | get_iplayer_webrequest_args( "type=$typelist", "refreshfuture=$refreshfuture" ), 2359 | ); 2360 | print $fh '
';
2361 | 	run_cmd_autorefresh( $fh, $se, 1, @cmd );
2362 | 	print $fh '
'; 2363 | print $fh p("Flushed Programme Caches for Types: $typelist"); 2364 | 2365 | # Load the refresh tab if required 2366 | my $autorefresh = $cgi->cookie( 'AUTOWEBREFRESH' ) || $cgi->param( 'AUTOWEBREFRESH' ); 2367 | 2368 | # Render options actions 2369 | print $fh div( { -class=>'action' }, 2370 | ul( { -class=>'action' }, 2371 | li( { -class=>'action' }, [ 2372 | a( 2373 | { 2374 | -class=>'action', 2375 | -title => 'Refresh Cache Now', 2376 | -onClick => "RefreshTab( '?NEXTPAGE=refresh&PROGTYPES=$typelist&AUTOWEBREFRESH=$autorefresh', ".(1000*3600*$autorefresh).", 1 );", 2377 | }, 2378 | 'Force Refresh' 2379 | ), 2380 | a( 2381 | { 2382 | -class=>'action', 2383 | -title => 'Go Back', 2384 | -onClick => "window.close()", 2385 | }, 2386 | 'Close' 2387 | ), 2388 | ]), 2389 | ), 2390 | ); 2391 | 2392 | } 2393 | 2394 | 2395 | 2396 | # Just a wrapper to search_progs which defines history search settings for 'Recordings' tab 2397 | sub search_history { 2398 | $opt->{HISTORY}->{current} = 1; 2399 | $opt->{SORT}->{current} = 'timeadded'; 2400 | $opt->{REVERSE}->{current} = 1; 2401 | $opt->{SINCE}->{current} = ''; 2402 | $opt->{BEFORE}->{current} = ''; 2403 | $opt->{EXCLUDE}->{current} = ''; 2404 | $opt->{CATEGORY}->{current} = ''; 2405 | $opt->{EXCLUDECATEGORY}->{current} = ''; 2406 | $opt->{CHANNEL}->{current} = ''; 2407 | $opt->{EXCLUDECHANNEL}->{current} = ''; 2408 | search_progs(); 2409 | } 2410 | 2411 | 2412 | 2413 | sub search_progs { 2414 | # Set default status for progtypes 2415 | my %type; 2416 | $type{$_} = 1 for split /,/, $opt->{PROGTYPES}->{current}; 2417 | $opt->{PROGTYPES}->{status} = \%type; 2418 | 2419 | # Determine which cols to display and Set default status for cols 2420 | get_display_cols(); 2421 | 2422 | #for my $key (sort keys %ENV) { 2423 | # print $fh $key, " = ", $ENV{$key}, "\n
"; 2424 | #} 2425 | 2426 | # Get prog data 2427 | my @params = get_search_params(); 2428 | my ( $matchcount, $response ) = ( get_progs( @params ) ); 2429 | if ( $response ) { 2430 | print $fh p("ERROR: get_iplayer returned non-zero:").br().p( join '
', $response ); 2431 | return 1; 2432 | } 2433 | $matchcount ||= 0; 2434 | my ($first, $last, @pagetrail) = pagetrail( $opt->{PAGENO}->{current}, $opt->{PAGESIZE}->{current}, $matchcount, 7 ); 2435 | 2436 | # Default displaycols 2437 | my @html; 2438 | push @html, ""; 2439 | push @html, th( { -class => 'search' }, checkbox( -class=>'search', -title=>'Select/Unselect All Programmes', -onClick=>"check_toggle(document.form1, 'PROGSELECT')", -name=>'SELECTOR', -value=>'1', -label=>'' ) ); 2440 | 2441 | # Pad empty column for R/S 2442 | push @html, th( { -class => 'search' }, 'Actions' ); 2443 | 2444 | # Display data in nested table 2445 | for my $heading (@displaycols) { 2446 | 2447 | # Sort by column click and change display class (colour) according to sort status 2448 | my ($title, $class, $onclick); 2449 | 2450 | if ( $opt->{SORT}->{current} eq $heading && not $opt->{REVERSE}->{current} ) { 2451 | ($title, $class, $onclick) = ("Sort by Reverse $heading", 'sorted pointer', "form1.NEXTPAGE.value='search_progs'; form1.SORT.value='$heading'; form1.REVERSE[1].checked=true; form1.submit();"); 2452 | } else { 2453 | ($title, $class, $onclick) = ("Sort by $heading", 'unsorted pointer', "form1.NEXTPAGE.value='search_progs'; form1.SORT.value='$heading'; form1.REVERSE[0].checked=true; form1.submit();"); 2454 | } 2455 | $class = 'sorted_reverse pointer' if $opt->{SORT}->{current} eq $heading && $opt->{REVERSE}->{current}; 2456 | 2457 | push @html, 2458 | th( { -class => 'search' }, 2459 | table( { -class => 'searchhead', -role=>'presentation' }, 2460 | Tr( { -class => 'search' }, [ 2461 | th( { -class => 'search' }, 2462 | label( { 2463 | -title => $title, 2464 | -class => $class, 2465 | -onClick => $onclick, 2466 | }, 2467 | $fieldname{$heading}, 2468 | ) 2469 | ) 2470 | ] 2471 | ) 2472 | ) 2473 | ); 2474 | } 2475 | push @html, ""; 2476 | 2477 | # Set optional output dir for pvr queue if set 2478 | my $outdir; 2479 | $outdir = '&OUTPUT='.CGI::escape("$opt->{OUTPUT}->{current}") if $opt->{OUTPUT}->{current}; 2480 | # Build each prog row 2481 | my $time = time(); 2482 | for ( my $i = 0; $i <= $#pids; $i++ ) { 2483 | my $search_class = 'search'; 2484 | my $pid = $pids[$i]; 2485 | my @row; 2486 | 2487 | # Grey-out history lines which files have been deleted or where the history doesn't have a filename mentioned 2488 | if ( $opt->{HISTORY}->{current} && ! $opt->{HIDEDELETED}->{current} ) { 2489 | if ( ( ! $prog{$pid}->{filename} ) || ! -f $prog{$pid}->{filename} ) { 2490 | $search_class = 'search darker'; 2491 | } 2492 | } 2493 | 2494 | # Format of PROGSELECT: TYPE|PID|NAME|EPISODE|MODE|CHANNEL 2495 | if ( $opt->{HISTORY}->{current} && ! -f $prog{$pid}->{filename} ) { 2496 | push @row, td( {-class=>$search_class} ); 2497 | } else { 2498 | push @row, td( {-class=>$search_class}, 2499 | checkbox( 2500 | -class => $search_class, 2501 | -name => 'PROGSELECT', 2502 | -label => '', 2503 | -value => "$prog{$pid}->{type}|$pid|$prog{$pid}->{name}|$prog{$pid}->{episode}|$prog{$pid}->{mode}|$prog{$pid}->{channel}", 2504 | -checked => 0, 2505 | -override => 1, 2506 | ) 2507 | ); 2508 | } 2509 | # Record links 2510 | 2511 | my $links; 2512 | # History mode 2513 | if ( $opt->{HISTORY}->{current} ) { 2514 | if ( -f $prog{$pid}->{filename} ) { 2515 | # Play (Play Remote) 2516 | $links .= a( { -id=>'nowrap', -target=>'_blank', -class=>$search_class, -title=>"Stream from file on web server", -href=>build_url_playlist( '', 'playlistdirect', 'pid', $pid, $prog{$pid}->{mode}, $prog{$pid}->{type}, $opt->{STREAMTYPE}->{current}, $opt->{STREAMTYPE}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current}, $opt->{VERSIONLIST}->{current} ) }, 'Play' ).'
'; 2517 | # PlayFile 2518 | $links .= a( { -id=>'nowrap', -target=>'_blank', -class=>$search_class, -title=>"Play from local file", -href=>build_url_playlist( '', 'playlistfiles', 'pid', $pid, $prog{$pid}->{mode}, $prog{$pid}->{type}, undef ) }, 'Play File' ).'
'; 2519 | # PlayDirect - depends on browser support 2520 | if ( $prog{$pid}->{filename} =~ m{\.(m4a|mp4|mp3)$} ) { 2521 | $links .= a( { -id=>'nowrap', -target=>'_blank', -class=>$search_class, -title=>"Stream file into browser", -href=>build_url_direct( '', $prog{$pid}->{type}, $pid, $prog{$pid}->{mode}, $opt->{STREAMTYPE}->{current}, $opt->{STREAMTYPE}->{current}, $opt->{HISTORY}->{current}, $opt->{BITRATE}->{current}, $opt->{VSIZE}->{current}, $opt->{VFR}->{current}, $opt->{VERSIONLIST}->{current}, 'playdirect' ) }, 'Play Direct' ).'
'; 2522 | } 2523 | } 2524 | # Search mode 2525 | } else { 2526 | # Record 2527 | $links .= label( { -id=>'nowrap', -class=>$search_class, -title=>"Record '$prog{$pid}->{name} - $prog{$pid}->{episode}' Now", -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='record_now'; form1.SEARCH.value='".encode_entities("$prog{$pid}->{type}|$pid|$prog{$pid}->{name}|$prog{$pid}->{episode}|$prog{$pid}->{mode}")."'; form1.target='_newtab_$pid'; form1.submit(); RestoreFormVars(form1); form1.target='';" }, 'Record' ).'
'; 2528 | # Queue 2529 | $links .= label( { -id=>'nowrap', -class=>$search_class, -title=>"Queue '$prog{$pid}->{name} - $prog{$pid}->{episode}' for PVR Recording", -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='pvr_queue'; form1.SEARCH.value='".encode_entities("$prog{$pid}->{type}|$pid|$prog{$pid}->{name}|$prog{$pid}->{episode}|$prog{$pid}->{mode}")."'; form1.submit(); RestoreFormVars(form1);" }, 'Queue' ).'
'; 2530 | # Add Series 2531 | # escape regex metacharacters in programme name 2532 | (my $escaped_name = $prog{$pid}->{name}) =~ s/([\\\^\$\.\|\?\*\+\(\)\[\]])/\\\\$1/g; 2533 | $links .= label( { 2534 | -id=>'nowrap', 2535 | -class=>'search pointer_noul', 2536 | -title=>"Add Series '$prog{$pid}->{name}' to PVR", 2537 | -onClick=>"BackupFormVars(form1); form1.NEXTPAGE.value='pvr_add'; form1.SEARCH.value='".encode_entities("^$escaped_name\$")."'; form1.SEARCHFIELDS.value='name'; form1.PROGTYPES.value='$prog{$pid}->{type}'; form1.HISTORY.value='0'; form1.SINCE.value=''; form1.BEFORE.value=''; form1.submit(); RestoreFormVars(form1);" }, 'Add Series' ); 2538 | } 2539 | 2540 | # Add links to row 2541 | push @row, td( {-class=>$search_class}, $links ); 2542 | 2543 | # This builds each row in turn 2544 | for ( @displaycols ) { 2545 | # display thumb if defined (will have to use proxy to get file:// thumbs) 2546 | if ( /^thumbnail$/ ) { 2547 | if ( $prog{$pid}->{$_} !~ m{^https?://} ) { 2548 | $prog{$pid}->{$_} = DEFAULT_THUMBNAIL; 2549 | } 2550 | push @row, td( {-class=>$search_class}, a( { -title=>"Open original web URL", -class=>$search_class, -href=>$prog{$pid}->{web}, -target => "_blank" }, img( { -class=>$search_class, -height=>40, -src=>$prog{$pid}->{$_} } ) ) ); 2551 | } elsif ( /^web$/ ) { 2552 | push @row, td( {-class=>$search_class}, a( { -title=>"Open original web URL", -class=>$search_class, -href=>$prog{$pid}->{$_}, -target => "_blank" }, 'Open URL' ) ); 2553 | # Calculate the seconds difference between epoch_now and epoch_datestring and convert back into array_time 2554 | } elsif ( /^timeadded$/ ) { 2555 | my @t = gmtime( $time - $prog{$pid}->{$_} ); 2556 | my $years = ($t[5]-70)."y " if ($t[5]-70) > 0; 2557 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -title=>"Click for full info", -onClick=>"BackupFormVars(form1); form1.NEXTPAGE.value='show_info'; form1.INFO.value='".encode_entities("$prog{$pid}->{type}|$pid")."'; form1.target='_blank'; form1.submit(); RestoreFormVars(form1); form1.target='';" }, "${years}$t[7]d $t[2]h ago" ) ); 2558 | } elsif ( /^expires$/ ) { 2559 | my $expires; 2560 | if ( $prog{$pid}->{$_} && $prog{$pid}->{$_} > $time ) { 2561 | my @t = gmtime( $prog{$pid}->{$_} - $time ); 2562 | my $years = ($t[5]-70)."y " if ($t[5]-70) > 0; 2563 | $expires = "in ${years}$t[7]d $t[2]h"; 2564 | } 2565 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -title=>"Click for full info", -onClick=>"BackupFormVars(form1); form1.NEXTPAGE.value='show_info'; form1.INFO.value='".encode_entities("$prog{$pid}->{type}|$pid")."'; form1.target='_blank'; form1.submit(); RestoreFormVars(form1); form1.target='';" }, $expires ) ); 2566 | # truncate the description if it is too long 2567 | } elsif ( /^desc$/ ) { 2568 | my $text = $prog{$pid}->{$_}; 2569 | $text = substr($text, 0, 256).'...[more]' if length( $text ) > 256; 2570 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -title=>"Click for full info", -onClick=>"BackupFormVars(form1); form1.NEXTPAGE.value='show_info'; form1.INFO.value='".encode_entities("$prog{$pid}->{type}|$pid")."'; form1.target='_blank'; form1.submit(); RestoreFormVars(form1); form1.target='';" }, $text ) ); 2571 | # Name / Series link 2572 | } elsif ( /^name$/ ) { 2573 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -id=>'underline', -title=>"Click to list '$prog{$pid}->{$_}'", 2574 | -onClick=>" 2575 | BackupFormVars(form1); 2576 | form1.NEXTPAGE.value='search_progs'; 2577 | form1.SEARCHFIELDS.value='name'; 2578 | form1.SEARCH.value='".encode_entities('^'.$prog{$pid}->{$_}.'$')."'; 2579 | form1.PAGENO.value=1; 2580 | form1.submit(); 2581 | RestoreFormVars(form1); 2582 | "}, $prog{$pid}->{$_} ) 2583 | ); 2584 | # Channel link 2585 | } elsif ( /^channel$/ ) { 2586 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -id=>'underline', -title=>"Click to list '$prog{$pid}->{$_}'", 2587 | -onClick=>" 2588 | BackupFormVars(form1); 2589 | form1.NEXTPAGE.value='search_progs'; 2590 | form1.CHANNEL.value='".encode_entities('^'.$prog{$pid}->{$_}.'$')."'; 2591 | form1.EXCLUDECHANNEL.value=''; 2592 | form1.SEARCH.value='.*'; 2593 | form1.PAGENO.value=1; 2594 | form1.submit(); 2595 | RestoreFormVars(form1); 2596 | "}, $prog{$pid}->{$_} ) 2597 | ); 2598 | # Category links 2599 | } elsif ( /^categories$/ ) { 2600 | my @cats = split /,/, $prog{$pid}->{$_}; 2601 | for ( @cats ) { 2602 | my $category = $_; 2603 | $_ = label( { -class=>$search_class, -id=>'underline', -title=>"Click to list '$category'", 2604 | -onClick=>" 2605 | BackupFormVars(form1); 2606 | form1.NEXTPAGE.value='search_progs'; 2607 | form1.EXCLUDE.value=''; 2608 | form1.CATEGORY.value='".encode_entities($category)."'; 2609 | form1.EXCLUDECATEGORY.value=''; 2610 | form1.SEARCH.value='.*'; 2611 | form1.PAGENO.value=1; 2612 | form1.submit(); 2613 | RestoreFormVars(form1); 2614 | "}, 2615 | $category ); 2616 | } 2617 | push @row, td( {-class=>$search_class}, @cats ); 2618 | } elsif ( /^filename$/ ) { 2619 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -title=>"Click for full info", -onClick=>"BackupFormVars(form1); form1.NEXTPAGE.value='show_info'; form1.INFO.value='".encode_entities("$prog{$pid}->{type}|$pid")."'; form1.target='_blank'; form1.submit(); RestoreFormVars(form1); form1.target='';" }, decode_fs($prog{$pid}->{$_}) ) ); 2620 | # Every other column type 2621 | } else { 2622 | push @row, td( {-class=>$search_class}, label( { -class=>$search_class, -title=>"Click for full info", -onClick=>"BackupFormVars(form1); form1.NEXTPAGE.value='show_info'; form1.INFO.value='".encode_entities("$prog{$pid}->{type}|$pid")."'; form1.target='_blank'; form1.submit(); RestoreFormVars(form1); form1.target='';" }, $prog{$pid}->{$_} ) ); 2623 | } 2624 | } 2625 | push @html, Tr( {-class=>$search_class}, @row ); 2626 | } 2627 | 2628 | # Search form 2629 | print $fh start_form( 2630 | -name => "form1", 2631 | -method => "POST", 2632 | ); 2633 | 2634 | 2635 | # Create options tabs and buttons 2636 | 2637 | # Build tab 'buttons' (actually list labels) 2638 | # Add options buttons into the list 2639 | my @optrows_nav; 2640 | my @tablist = grep !/(BASICTAB|HIDDENTAB)/, @{ $layout->{taborder} }; 2641 | for my $tabname ( @tablist ) { 2642 | my $label = $layout->{$tabname}->{title}; 2643 | 2644 | # Set the colour to grey and change tab appearance if it is selected 2645 | my $class = 'options_tab'; 2646 | if ( defined $opt->{$tabname}->{current} && $opt->{$tabname}->{current} eq 'yes' ) { 2647 | $class = 'options_tab_sel'; 2648 | } 2649 | push @optrows_nav, li( { -class=>$class, -id=>"li_${tabname}" }, 2650 | label( { 2651 | -class => 'options_outer pointer_noul', 2652 | -id => 'button_'.$tabname, 2653 | -title => "Show $label tab", 2654 | -onClick => "show_options_tab( '$tabname', [ '".(join "', '", @tablist )."' ] );", 2655 | }, 2656 | $label ), 2657 | ) 2658 | } 2659 | 2660 | # add a save button on to end of list 2661 | my $options_buttons = ul( { -class=>'options_tab' }, 2662 | li( { -class=>'options_button' }, [ 2663 | # Apply button (same as 'Search') 2664 | label( { 2665 | -class => 'options_outer pointer_noul', 2666 | -title => 'Apply Current Options', 2667 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=1; form1.submit(); RestoreFormVars(form1);", 2668 | -role => "button", 2669 | }, 2670 | 'Apply Settings', 2671 | ), 2672 | # Save as Default button 2673 | label( { 2674 | -class => 'options_outer pointer_noul', 2675 | -title => 'Remember Current Options as Default', 2676 | -onClick => "BackupFormVars(form1); form1.SAVE.value=1; form1.submit(); RestoreFormVars(form1);", 2677 | -role => "button", 2678 | }, 2679 | 'Save As Default', 2680 | ), 2681 | ] ) 2682 | ); 2683 | 2684 | # Build each tab with it's contained options tables 2685 | my @opt_td; 2686 | my @opt_td_basic; 2687 | for my $tabname ( @{ $layout->{taborder} } ) { 2688 | my $tab = $layout->{$tabname}; 2689 | my @order = @{ $tab->{order} }; 2690 | my $heading = $tab->{heading}; 2691 | # Set displayed tab status (i.e. style) based on posted/cookie vars (always display basic tab) 2692 | $tab->{style} = "display: none; visibility: collapse;"; 2693 | $tab->{style} = "display: table-cell; visibility: visible;" if $tabname eq 'BASICTAB' || ( defined $opt->{$tabname}->{current} && $opt->{$tabname}->{current} eq 'yes' ); 2694 | 2695 | # Each option within the tab 2696 | my @optrows; 2697 | #push @optrows, td( { -class=>'options' }, label( { -class => 'options_heading' }, $heading ) ) if $heading; 2698 | for my $optname ( @order ) { 2699 | push @optrows, build_option_html( $opt->{$optname} ); 2700 | } 2701 | # Set the basic search tab to be rowspan=3 2702 | if ( $tabname eq 'BASICTAB' ) { 2703 | push @opt_td_basic, td( { -class=>'options_outer', -id=>"tab_${tabname}", -rowspan=>3, -style=>"$tab->{style}", -role=>'search' }, 2704 | table( { -class=>'options' }, Tr( { -class=>'options' }, [ @optrows ] ) ) 2705 | ); 2706 | } else { 2707 | push @opt_td, td( { -class=>'options_outer', -id=>"tab_${tabname}", -style=>"$tab->{style}" }, 2708 | table( { -class=>'options' }, Tr( { -class=>'options' }, [ @optrows ] ) ) 2709 | ); 2710 | } 2711 | } 2712 | 2713 | # Render outer options table frame (keeping some tabs hidden) 2714 | print $fh table( { -class=>'options_outer' }, 2715 | Tr( { -class=>'options_outer' }, (join '', @opt_td_basic). td( { -class=>'options_outer' }, ul( { -class=>'options_tab', -role=>'navigation', 'aria-label'=>'Settings' }, @optrows_nav ) ) ). 2716 | Tr( { -class=>'options_outer' }, (join '', @opt_td) ). 2717 | Tr( { -class=>'options_outer' }, td( { -class=>'options_outer' }, $options_buttons ) ) 2718 | ); 2719 | 2720 | # Grey-out 'Add Current Search to PVR' button if too many programme matches 2721 | my $add_search_class_suffix; 2722 | $add_search_class_suffix = ' darker' if $matchcount > 30; 2723 | my %action_button; 2724 | $action_button{'Search'} = a( 2725 | { 2726 | -class => 'action', 2727 | -title => 'Perform search based on search options', 2728 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=1; form1.submit(); RestoreFormVars(form1);", 2729 | }, 2730 | 'Search' 2731 | ); 2732 | $action_button{'Queue'} = a( 2733 | { 2734 | -class => 'action', 2735 | -title => 'Queue selected programmes (or Quick URL) for one-off recording', 2736 | -onClick => "if(! ( check_if_selected(document.form1, 'PROGSELECT') || form1.URL.value ) ) { alert('No Quick URL or programmes were selected'); return false; } BackupFormVars(form1); form1.SEARCH.value=''; form1.NEXTPAGE.value='pvr_queue'; form1.submit(); RestoreFormVars(form1); form1.URL.value=''; disable_selected_checkboxes(document.form1, 'PROGSELECT');", 2737 | }, 2738 | 'Queue' 2739 | ); 2740 | $action_button{'Record'} = a( 2741 | { 2742 | -class => 'action', 2743 | -title => 'Immediately Record selected programmes (or Quick URL) in a new tab', 2744 | -onClick => "if(! ( check_if_selected(document.form1, 'PROGSELECT') || form1.URL.value ) ) { alert('No Quick URL or programmes were selected'); return false; } BackupFormVars(form1); form1.SEARCH.value=''; form1.NEXTPAGE.value='record_now'; var random=Math.floor(Math.random()*99999); form1.target='_newtab_'+random; form1.submit(); RestoreFormVars(form1); form1.target=''; form1.URL.value=''; disable_selected_checkboxes(document.form1, 'PROGSELECT');", 2745 | }, 2746 | 'Record' 2747 | ); 2748 | $action_button{'Delete'} = a( 2749 | { 2750 | -class => 'action', 2751 | -title => 'Permanently delete selected recorded files', 2752 | -onClick => "if(! check_if_selected(document.form1, 'PROGSELECT')) { alert('No programmes were selected'); return false; } BackupFormVars(form1); form1.SEARCH.value=''; form1.NEXTPAGE.value='recordings_delete'; form1.submit(); RestoreFormVars(form1);", 2753 | }, 2754 | 'Delete' 2755 | ); 2756 | $action_button{'Play'} = a( 2757 | { 2758 | -class => 'action', 2759 | -title => 'Get a Playlist based on selected programmes for remote file streaming in your media player', 2760 | -onClick => "if(! check_if_selected(document.form1, 'PROGSELECT')) { alert('No programmes were selected'); return false; } BackupFormVars(form1); form1.SEARCH.value=''; form1.ACTION.value='genplaylistdirect'; form1.submit(); RestoreFormVars(form1);", 2761 | }, 2762 | 'Play' 2763 | ); 2764 | $action_button{'Play Files'} = a( 2765 | { 2766 | -class => 'action', 2767 | -title => 'Get a Playlist based on selected programmes for local file streaming in your media player', 2768 | -onClick => "if(! check_if_selected(document.form1, 'PROGSELECT')) { alert('No programmes were selected'); return false; } BackupFormVars(form1); form1.SEARCH.value=''; form1.ACTION.value='genplaylistfile'; form1.submit(); RestoreFormVars(form1);", 2769 | }, 2770 | 'Play Files' 2771 | ); 2772 | # check for an non-whitespace advanced search entries 2773 | # excluding Programme Version and Search Future Schedule 2774 | my $num_adv_srch = grep /\S/, ( 2775 | $opt->{EXCLUDE}->{current}, 2776 | $opt->{EXCLUDECATEGORY}->{current}, 2777 | $opt->{CATEGORY}->{current}, 2778 | $opt->{CHANNEL}->{current}, 2779 | $opt->{EXCLUDECHANNEL}->{current}, 2780 | $opt->{SINCE}->{current}, 2781 | $opt->{BEFORE}->{current} 2782 | ); 2783 | (my $escaped_search = $opt->{SEARCH}->{current}) =~ s/'/\\'/g; 2784 | $action_button{'Add Search to PVR'} = a( 2785 | { 2786 | -class => 'action'.$add_search_class_suffix, 2787 | -title => 'Create a persistent PVR search using the current search terms (i.e. all below programmes)', 2788 | -onClick => "if ('".$escaped_search."' == '.*' && $num_adv_srch == 0) { alert('Search = .* will download all available programmes. Please enter a more specific search term or additional advanced search criteria (excluding $opt->{VERSIONLIST}->{title} and $opt->{FUTURE}->{title}).'); return false; } if ('".$escaped_search."' == '' ) { alert('Please enter a search term. Use Search = .* to record all programmes matching advanced search criteria.'); return false; } if ( $matchcount > 30 ) { alert('Please limit your search to result in no more than 30 current programmes'); return false; } BackupFormVars(form1); form1.NEXTPAGE.value='pvr_add'; form1.submit(); RestoreFormVars(form1);", 2789 | }, 2790 | 'Add Search to PVR' 2791 | ); 2792 | #my $autorefresh = $cgi->cookie( 'AUTOWEBREFRESH' ) || $cgi->param( 'AUTOWEBREFRESH' ); 2793 | $action_button{'Refresh Cache'} = a( 2794 | { 2795 | -class => 'action', 2796 | -title => 'Refresh the list of programmes - can take a while', 2797 | -onClick => "BackupFormVars(form1); form1.target='_newtab_refresh'; form1.NEXTPAGE.value='refresh'; form1.submit(); RestoreFormVars(form1); form1.target=''; form1.NEXTPAGE.value=''; ", 2798 | #-onClick => "window.frames['dataframe'].window.location.replace('?NEXTPAGE=refresh&AUTOWEBREFRESH=$autorefresh')", 2799 | }, 2800 | 'Refresh Cache' 2801 | ); 2802 | 2803 | # Render action bar 2804 | my @actionbar; 2805 | if ( $opt->{HISTORY}->{current} ) { 2806 | push @actionbar, div( { -class=>'action', -role=>'navigation', 'aria-label'=>'Actions' }, 2807 | ul( { -class=>'action' }, 2808 | li( { -class=>'action' }, [ 2809 | $action_button{'Search'}, 2810 | $action_button{'Delete'}, 2811 | $action_button{'Play'}, 2812 | $action_button{'Play Files'}, 2813 | ]), 2814 | ), 2815 | ); 2816 | } else { 2817 | push @actionbar, div( { -class=>'action', -role=>'navigation', 'aria-label'=>'Actions' }, 2818 | ul( { -class=>'action' }, 2819 | li( { -class=>'action' }, [ 2820 | $action_button{'Search'}, 2821 | $action_button{'Record'}, 2822 | $action_button{'Queue'}, 2823 | $action_button{'Add Search to PVR'}, 2824 | $action_button{'Refresh Cache'}, 2825 | ]), 2826 | ), 2827 | ); 2828 | } 2829 | 2830 | print $fh @actionbar; 2831 | print $fh @pagetrail; 2832 | print $fh table( {-class=>'search', -role=>'main' }, @html ); 2833 | print $fh @pagetrail; 2834 | print $fh @actionbar; 2835 | 2836 | print $fh div( {id=>'status'} ); 2837 | 2838 | print $fh end_form(); 2839 | 2840 | return 0; 2841 | } 2842 | 2843 | 2844 | 2845 | # Build page trail 2846 | sub pagetrail { 2847 | my ( $page, $pagesize, $count, $trailsize ) = ( @_ ); 2848 | 2849 | # How many pages 2850 | my $pages = int( $count / $pagesize ); 2851 | $pages++ if $count % $pagesize; 2852 | # If we request a page that is too high 2853 | $page = $pages if $page > $pages; 2854 | # Calc first and last programme numbers 2855 | my $first = $pagesize * ($page - 1); 2856 | my $last = $first + $pagesize; 2857 | $last = $count if $last > $count; 2858 | 2859 | #print $se "PAGETRAIL: page=$page, first=$first, last=$first, pages=$pages, trailsize=$trailsize\n"; 2860 | # Page trail 2861 | my @pagetrail; 2862 | 2863 | push @pagetrail, td( { -class=>'pagetrail pointer' }, label( { 2864 | -title => "Previous Page", 2865 | -class => 'pagetrail pointer', 2866 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=$page-1; form1.submit(); RestoreFormVars(form1);",}, 2867 | "<<", 2868 | )) if $page > 1; 2869 | 2870 | push @pagetrail, td( { -class=>'pagetrail pointer' }, label( { 2871 | -title => "Page 1", 2872 | -class => 'pagetrail pointer', 2873 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=1; form1.submit(); RestoreFormVars(form1);",}, 2874 | "1", 2875 | )) if $page > 1; 2876 | 2877 | push @pagetrail, td( { -class=>'pagetrail' }, '...' ) if $page > $trailsize+2; 2878 | 2879 | for (my $pn=$page-$trailsize; $pn <= $page+$trailsize; $pn++) { 2880 | push @pagetrail, td( { -class=>'pagetrail pointer' }, label( { 2881 | -title => "Page $pn", 2882 | -class => 'pagetrail pointer', 2883 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value='$pn'; form1.submit(); RestoreFormVars(form1);",}, 2884 | "$pn", 2885 | )) if $pn > 1 && $pn != $page && $pn < $pages; 2886 | push @pagetrail, td( { -class=>'pagetrail' }, label( { 2887 | -title => "Current Page", 2888 | -class => 'pagetrail-current', }, 2889 | "$page", 2890 | )) if $pn == $page; 2891 | } 2892 | push @pagetrail, td( { -class=>'pagetrail' }, '...' ) if $page < $pages-$trailsize-1; 2893 | 2894 | push @pagetrail, td( { -class=>'pagetrail pointer' }, label( { 2895 | -title => "Page ".$pages, 2896 | -class => 'pagetrail pointer', 2897 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=$pages; form1.submit(); RestoreFormVars(form1);",}, 2898 | "$pages", 2899 | )) if $page < $pages; 2900 | 2901 | push @pagetrail, td( { -class=>'pagetrail pointer' }, label( { 2902 | -title => "Next Page", 2903 | -class => 'pagetrail pointer', 2904 | -onClick => "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=$page+1; form1.submit(); RestoreFormVars(form1);",}, 2905 | ">>", 2906 | )) if $page < $pages; 2907 | 2908 | push @pagetrail, td( { -class=>'pagetrail' }, label( { 2909 | -title => "Matches", 2910 | -class => 'pagetrail',}, 2911 | "($count programmes)", 2912 | )); 2913 | 2914 | my @html = table( { -id=>'centered', -class=>'pagetrail' }, Tr( { -class=>'pagetrail' }, @pagetrail )); 2915 | return ($first, $last, @html); 2916 | } 2917 | 2918 | 2919 | 2920 | sub get_progs { 2921 | my @params = @_; 2922 | my $options = ''; 2923 | 2924 | my $fields; 2925 | $fields .= "|<$_>" for @headings; 2926 | 2927 | my ( @webrequest_args ) = ( build_cmd_options( grep !/^(PVRHOLDOFF)$/, @params ), "listformat=ENTRY${fields}" ); 2928 | # Page params 2929 | if ( $opt->{PAGENO}->{current} && $opt->{PAGESIZE}->{current} ) { 2930 | push @webrequest_args, ( "page=$opt->{PAGENO}->{current}", "pagesize=$opt->{PAGESIZE}->{current}" ); 2931 | } 2932 | # Sort param 2933 | push @webrequest_args, "sortreverse=$opt->{PAGENO}->{current}" if $opt->{REVERSE}->{current}; 2934 | # sort reverse param 2935 | push @webrequest_args, "sortmatches=$opt->{SORT}->{current}" if $opt->{SORT}->{current} && $opt->{SORT}->{current} ne 'name'; 2936 | # Run command 2937 | my @list = get_cmd_output( 2938 | @gip_cmd_base, 2939 | '--webrequest', 2940 | get_iplayer_webrequest_args( @webrequest_args ), 2941 | ); 2942 | return ( '0', join("\n", @list) ) if $? && not $IGNOREEXIT; 2943 | # Get total matches count 2944 | my $matchcount = pop @list; 2945 | $matchcount = $1 if $matchcount =~ m{^INFO:\s*(\d+?)\s+}; 2946 | 2947 | for ( grep /^ENTRY/, @list ) { 2948 | chomp(); 2949 | # Strip white space 2950 | s/\|\s*$//; 2951 | 2952 | my $record; 2953 | my @element = split /\|/, $_; 2954 | shift @element; 2955 | 2956 | # Put data for this contact into temporary record hash for this user 2957 | for (my $i=0; $i <= $#headings; $i++) { 2958 | $record->{$headings[$i]} = $element[$i]; 2959 | } 2960 | 2961 | my $search_class = 'search'; 2962 | 2963 | # get the real path if file is defined 2964 | if ( $record->{filename} && $record->{filename} ne "" ) { 2965 | $record->{filename} = search_absolute_path( encode_fs($record->{filename}) ); 2966 | } 2967 | 2968 | # store record in the prog global hash (prog => pid) 2969 | $prog{ $record->{'pid'} } = $record; 2970 | push @pids, $record->{'pid'}; 2971 | } 2972 | return ( $matchcount, '' ); 2973 | } 2974 | 2975 | 2976 | 2977 | # 2978 | # Get the columns to display 2979 | # 2980 | sub get_display_cols { 2981 | 2982 | @displaycols = (); 2983 | # Set default status for columns options tab checkboxes 2984 | my %cols_status; 2985 | 2986 | # Add some default headings for history mode 2987 | push @headings_default, 'mode' if $opt->{HISTORY}->{current}; 2988 | 2989 | # Determine which columns to display (all if $cols not defined) 2990 | my $cols = join(",", $opt->{COLS}->{current} ) || join ',', @headings_default; 2991 | my @columns = split /,/, $cols; 2992 | 2993 | # Re-sort selected display columns into original header order 2994 | for my $heading (@headings) { 2995 | if ( grep /^$heading$/, @columns ) { 2996 | # Remove display of mode and filename if not history mode 2997 | if ( ( ! $opt->{HISTORY}->{current} ) && $heading =~ /^(mode|filename)$/ ) { 2998 | # skip 2999 | } else { 3000 | push @displaycols, $heading; 3001 | } 3002 | $cols_status{$heading} = 1; 3003 | } 3004 | } 3005 | 3006 | # Make sure we select all if no cols are specified 3007 | @displaycols = @headings_default if $#displaycols < 0; 3008 | 3009 | # Set defaults for checkboxes 3010 | $opt->{COLS}->{status} = \%cols_status; 3011 | 3012 | # Rebuild the hash for the checkboxes 3013 | %cols_order = (); 3014 | %cols_names = (); 3015 | for ( my $i = 0; $i <= $#headings; $i++ ) { 3016 | $cols_names{$headings[$i]} = $fieldname{$headings[$i]}; 3017 | $cols_order{$i} = $headings[$i]; 3018 | } 3019 | 3020 | return 0; 3021 | } 3022 | 3023 | 3024 | 3025 | ############################################# 3026 | # 3027 | # Form Header 3028 | # 3029 | ############################################# 3030 | sub form_header { 3031 | my $request_host = shift; 3032 | my $nextpage = shift || $cgi->param( 'NEXTPAGE' ); 3033 | 3034 | print $fh $cgi->start_form( 3035 | -name => "formheader", 3036 | -method => "POST", 3037 | ); 3038 | 3039 | # set $class for tab selection in nav bar 3040 | my $class = {}; 3041 | $class->{search} = 'nav_tab'; 3042 | $class->{recordings} = 'nav_tab'; 3043 | $class->{pvrlist} = 'nav_tab'; 3044 | $class->{pvrrun} = 'nav_tab'; 3045 | $class->{search} = 'nav_tab_sel' if ( $nextpage eq 'search_progs' || ! $nextpage ) && ! $opt->{HISTORY}->{current}; 3046 | $class->{recordings} = 'nav_tab_sel' if $nextpage eq 'search_history' || $opt->{HISTORY}->{current}; 3047 | $class->{pvrrun} = 'nav_tab_sel' if $nextpage eq 'pvr_run'; 3048 | $class->{pvrlist} = 'nav_tab_sel' if $nextpage =~ m{^(pvr_list|pvr_queue|pvr_del)$}; 3049 | 3050 | print $fh div( { -class=>'nav', -role=>'navigation' }, 3051 | ul( { -class=>'nav' }, 3052 | li( { -id=>'logo', -class=>'nav_tab' }, 3053 | span( { -class=>'logotext' }, 'get_iplayer' ) 3054 | ). 3055 | li( { -class=>$class->{search} }, a( { -class=>'nav', -title=>'Main search page', -onClick => "BackupFormVars(formheader); formheader.NEXTPAGE.value='search_progs'; formheader.submit(); RestoreFormVars(formheader);" }, 'Search' ) ). 3056 | li( { -class=>$class->{recordings} }, a( { -class=>'nav', -title=>'History search page', -onClick => "BackupFormVars(formheader); formheader.NEXTPAGE.value='search_history'; formheader.submit(); RestoreFormVars(formheader);" }, 'Recordings' ) ). 3057 | li( { -class=>$class->{pvrlist} }, a( { -class=>'nav', -title=>'List all saved PVR searches', -onClick => "BackupFormVars(formheader); formheader.NEXTPAGE.value='pvr_list'; formheader.submit(); RestoreFormVars(formheader);" }, 'PVR List' ) ). 3058 | li( { -class=>$class->{pvrrun} }, a( { -class=>'nav', -title=>'Run the PVR now - wait for the PVR to complete', -onClick => "BackupFormVars(formheader); formheader.NEXTPAGE.value='pvr_run'; formheader.target='_newtab_pvrrun'; formheader.submit(); RestoreFormVars(formheader); formheader.target='';" }, 'Run PVR' ) ). 3059 | li( { -class=>'nav_tab' }, a( { -class=>'nav', -title=>'Show help and instructions', -href => "https://github.com/get-iplayer/get_iplayer/wiki/webpvr", -target => "_newtab_help" }, 'Help' ) ) 3060 | ), 3061 | ); 3062 | print $fh hidden( -name => 'AUTOPVRRUN', -value => $opt->{AUTOPVRRUN}->{current}, -override => 1 ); 3063 | print $fh hidden( -name => 'NEXTPAGE', -value => 'search_progs', -override => 1 ); 3064 | print $fh $cgi->end_form(); 3065 | } 3066 | 3067 | 3068 | 3069 | # Form Footer 3070 | sub form_footer { 3071 | #print $fh ""; 3072 | #print $fh ""; 3073 | # 3074 | print $fh p( b({-class=>"footer"}, 3075 | "get_iplayer Web PVR Manager $VERSION_TEXT, ©2009-2010 Phil Lewis - Licensed under GPLv3" 3076 | )); 3077 | } 3078 | 3079 | 3080 | 3081 | # End HTML 3082 | sub html_end { 3083 | print $fh "\n"; 3084 | print $fh "\n\n"; 3085 | } 3086 | 3087 | 3088 | 3089 | # Gets and sets the CGI parameters (POST/Cookie) in the $opt hash - also sets $opt{VAR}->{current} from default or POST 3090 | sub process_params { 3091 | 3092 | # Store options definition here as hash of 'name' => [options] 3093 | $opt->{SEARCH} = { 3094 | title => 'Search', # Title 3095 | tooltip => 'Enter your partial text match (or regex expression)', # Tooltip 3096 | webvar => 'SEARCH', # webvar 3097 | optkey => 'search', # option key 3098 | type => 'text', # type 3099 | default => '.*', # default 3100 | value => 20, # width values 3101 | save => 0, 3102 | }; 3103 | 3104 | $opt->{URL} = { 3105 | title => 'Quick URL', # Title 3106 | tooltip => "Enter your URL for recording (then click 'Record' or 'Queue')", # Tooltip 3107 | webvar => 'URL', # webvar 3108 | type => 'text', # type 3109 | default => '', # default 3110 | value => 36, # width values 3111 | save => 0, 3112 | }; 3113 | 3114 | $opt->{SEARCHFIELDS} = { 3115 | title => 'Search in', # Title 3116 | tooltip => 'Select which column you wish to search', # Tooltip 3117 | webvar => 'SEARCHFIELDS', # webvar 3118 | optkey => 'fields', # option 3119 | type => 'popup', # type 3120 | label => \%fieldname, # labels 3121 | default => 'name', # default 3122 | value => [ (@headings,'name,episode','name,episode,desc') ], # values 3123 | save => 1, 3124 | }; 3125 | 3126 | $opt->{PAGESIZE} = { 3127 | title => 'Programmes per Page', # Title 3128 | tooltip => 'Select the number of search results displayed on each page', # Tooltip 3129 | webvar => 'PAGESIZE', # webvar 3130 | type => 'popup', # type 3131 | default => 10, # default 3132 | value => ['10','25','50','100','200','400'], # values 3133 | onChange=> "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.PAGENO.value=1; form1.submit(); RestoreFormVars(form1);", 3134 | save => 1, 3135 | }; 3136 | 3137 | $opt->{SORT} = { 3138 | title => 'Sort by', # Title 3139 | tooltip => 'Sort the results in this order', # Tooltip 3140 | webvar => 'SORT', # webvar 3141 | type => 'popup', # type 3142 | label => \%fieldname, # labels 3143 | default => 'index', # default 3144 | value => [@headings], # values 3145 | onChange=> "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.submit(); RestoreFormVars(form1);", 3146 | save => 1, 3147 | }; 3148 | 3149 | $opt->{REVERSE} = { 3150 | title => 'Reverse sort', # Title 3151 | tooltip => 'Reverse the sort order', # Tooltip 3152 | webvar => 'REVERSE', # webvar 3153 | type => 'radioboolean', # type 3154 | #onChange=> "BackupFormVars(form1); form1.NEXTPAGE.value='search_progs'; form1.submit(); RestoreFormVars(form1);", 3155 | default => '0', # value 3156 | save => 1, 3157 | }; 3158 | 3159 | $opt->{PROGTYPES} = { 3160 | title => 'Programme type', # Title 3161 | tooltip => 'Select the programme types you wish to search', # Tooltip 3162 | webvar => 'PROGTYPES', # webvar 3163 | optkey => 'type', # option 3164 | type => 'multiboolean', # type 3165 | label => \%prog_types, # labels 3166 | default => 'tv', 3167 | #status => \%type, # default status 3168 | value => \%prog_types_order, # order of values 3169 | save => 1, 3170 | }; 3171 | 3172 | $opt->{MODES} = { 3173 | title => 'Recording Quality', # Title 3174 | tooltip => 'Comma separated list of recording quality settings which should be tried in order. Must be one or more of: fhd,hd,sd,web,mobile,1080p,720p,540p,396p,288p,high,std,med,low,320k,128k,96k,48k,default', # Tooltip 3175 | webvar => 'MODES', # webvar 3176 | optkey => 'modes', # option 3177 | type => 'text', # type 3178 | default => '', # default 3179 | value => 30, # width values 3180 | save => 1, 3181 | }; 3182 | 3183 | $opt->{OUTPUT} = { 3184 | title => 'Override Recordings Folder', # Title 3185 | tooltip => 'Folder on the server where recordings should be saved', # Tooltip 3186 | webvar => 'OUTPUT', # webvar 3187 | optkey => 'output', # option 3188 | type => 'text', # type 3189 | default => '', # default 3190 | value => 30, # width values 3191 | save => 1, 3192 | }; 3193 | 3194 | $opt->{PROXY} = { 3195 | title => 'Web Proxy URL', # Title 3196 | tooltip => 'e.g. http://192.168.1.2:8080', # Tooltip 3197 | webvar => 'PROXY', # webvar 3198 | optkey => 'proxy', # option 3199 | type => 'text', # type 3200 | default => '', # default 3201 | value => 30, # width values 3202 | save => 1, 3203 | }; 3204 | 3205 | $opt->{VERSIONLIST} = { 3206 | title => 'Programme Version', # Title 3207 | tooltip => 'Comma separated list of versions to try to record in order (e.g., "signed,default" or "audiodescribed,default")', # Tooltip 3208 | webvar => 'VERSIONLIST', # webvar 3209 | optkey => 'versionlist', # option 3210 | type => 'text', # type 3211 | default => '', # default 3212 | value => 30, # width values 3213 | save => 1, 3214 | }; 3215 | 3216 | $opt->{EXCLUDE} = { 3217 | title => 'Exclude Programmes', # Title 3218 | tooltip => 'Comma separated list of programmes to exclude. Partial word matches and regular expressions are supported', # Tooltip 3219 | webvar => 'EXCLUDE', # webvar 3220 | optkey => 'exclude', # option 3221 | type => 'text', # type 3222 | default => '', # default 3223 | value => 30, # width values 3224 | save => 1, 3225 | }; 3226 | 3227 | $opt->{CATEGORY} = { 3228 | title => 'Categories Containing', # Title 3229 | tooltip => 'Comma separated list of categories to match. Partial word matches and regular expressions are supported. Only works in Recordings tab.', # Tooltip 3230 | webvar => 'CATEGORY', # webvar 3231 | optkey => 'category', # option 3232 | type => 'text', # type 3233 | default => '', # default 3234 | value => 30, # width values 3235 | save => 1, 3236 | }; 3237 | 3238 | $opt->{EXCLUDECATEGORY} = { 3239 | title => 'Exclude Categories Containing', # Title 3240 | tooltip => 'Comma separated list of categories to exclude. Partial word matches and regular expressions are supported. Only works in Recordings tab.', # Tooltip 3241 | webvar => 'EXCLUDECATEGORY', # webvar 3242 | optkey => 'excludecategory', # option 3243 | type => 'text', # type 3244 | default => '', # default 3245 | value => 30, # width values 3246 | save => 1, 3247 | }; 3248 | 3249 | $opt->{CHANNEL} = { 3250 | title => 'Channels Containing', # Title 3251 | tooltip => 'Comma separated list of channels to match. Partial word matches and regular expressions are supported', # Tooltip 3252 | webvar => 'CHANNEL', # webvar 3253 | optkey => 'channel', # option 3254 | type => 'text', # type 3255 | default => '', # default 3256 | value => 30, # width values 3257 | save => 1, 3258 | }; 3259 | 3260 | $opt->{EXCLUDECHANNEL} = { 3261 | title => 'Exclude Channels Containing', # Title 3262 | tooltip => 'Comma separated list of channels to exclude. Partial word matches and regular expressions are supported', # Tooltip 3263 | webvar => 'EXCLUDECHANNEL', # webvar 3264 | optkey => 'excludechannel', # option 3265 | type => 'text', # type 3266 | default => '', # default 3267 | value => 30, # width values 3268 | save => 1, 3269 | }; 3270 | 3271 | $opt->{HIDE} = { 3272 | title => 'Hide Recorded', # Title 3273 | tooltip => 'Whether to hide programmes that have already been successfully recorded', # Tooltip 3274 | webvar => 'HIDE', # webvar 3275 | optkey => 'hide', # option 3276 | type => 'radioboolean', # type 3277 | default => '0', # value 3278 | save => 1, 3279 | }; 3280 | 3281 | $opt->{FORCE} = { 3282 | title => 'Force Recording', # Title 3283 | tooltip => "Ignore the history and re-record a programme (Please delete the existing recording first). Doesn't apply to PVR Searches or 'Add Series'", # Tooltip 3284 | webvar => 'FORCE', # webvar 3285 | optkey => 'force', # option 3286 | type => 'radioboolean', # type 3287 | default => '0', # value 3288 | save => 1, 3289 | }; 3290 | 3291 | $opt->{REFRESHFUTURE} = { 3292 | title => 'Refresh Future Schedule', # Title 3293 | tooltip => "When Refresh is clicked also get the future programme schedule. This will take a longer time to index.", # Tooltip 3294 | webvar => 'REFRESHFUTURE', # webvar 3295 | optkey => 'refreshfuture', # option 3296 | type => 'radioboolean', # type 3297 | default => '0', # value 3298 | save => 1, 3299 | }; 3300 | 3301 | $opt->{FPS25} = { 3302 | title => 'Prefer lower-bitrate TV streams', 3303 | tooltip => "Prefer lower-bitrate TV streams", 3304 | webvar => 'FPS25', 3305 | optkey => 'fps25', 3306 | type => 'radioboolean', 3307 | default => '0', 3308 | save => 1, 3309 | }; 3310 | 3311 | my %metadata_labels = ( ''=>'Off', generic=>'Generic XML' ); 3312 | $opt->{METADATA} = { 3313 | title => 'Download Metadata', # Title 3314 | tooltip => 'Format of metadata file to create when recording', # Tooltip 3315 | webvar => 'METADATA', # webvar 3316 | optkey => 'metadata', # option 3317 | type => 'popup', # type 3318 | #label => \%fieldname, # labels 3319 | label => \%metadata_labels, # labels 3320 | default => '', # default 3321 | value => [ ( '', 'generic' ) ], # values 3322 | save => 1, 3323 | }; 3324 | 3325 | $opt->{SUBTITLES} = { 3326 | title => 'Download Subtitles', # Title 3327 | tooltip => 'Whether to download the subtitles when recording', # Tooltip 3328 | webvar => 'SUBTITLES', # webvar 3329 | optkey => 'subtitles', # option 3330 | type => 'radioboolean', # type 3331 | default => '0', # value 3332 | save => 1, 3333 | }; 3334 | 3335 | $opt->{THUMB} = { 3336 | title => 'Download Thumbnail', # Title 3337 | tooltip => 'Whether to download the thumbnail when recording', # Tooltip 3338 | webvar => 'THUMB', # webvar 3339 | optkey => 'thumb', # option 3340 | type => 'radioboolean', # type 3341 | default => '0', # value 3342 | save => 1, 3343 | }; 3344 | 3345 | $opt->{AUTOWEBREFRESH} = { 3346 | title => 'Auto-Refresh Cache Interval', # Title 3347 | tooltip => 'Automatically refresh the default caches in another browser tab (hours)', # Tooltip 3348 | webvar => 'AUTOWEBREFRESH', # webvar 3349 | type => 'text', # type 3350 | default => 4, # default 3351 | value => 3, # width values 3352 | save => 1, 3353 | }; 3354 | 3355 | $opt->{AUTOPVRRUN} = { 3356 | title => 'Auto-Run PVR Interval', # Title 3357 | tooltip => 'Automatically run the PVR in another browser tab (hours)', # Tooltip 3358 | webvar => 'AUTOPVRRUN', # webvar 3359 | type => 'text', # type 3360 | default => 4, # default 3361 | value => 3, # width values 3362 | save => 1, 3363 | }; 3364 | 3365 | $opt->{HISTORY} = { 3366 | title => 'Search History', # Title 3367 | tooltip => 'Whether to display and search programmes in the recordings history', # Tooltip 3368 | webvar => 'HISTORY', # webvar 3369 | optkey => 'history', # option 3370 | type => 'boolean', # type 3371 | default => '0', # value 3372 | save => 0, 3373 | }; 3374 | 3375 | $opt->{FUTURE} = { 3376 | title => 'Search Future Schedule', # Title 3377 | tooltip => 'Whether to additionally display and search programmes in the future programmes schedule (will only work if Refresh future schedule option is enable and refreshed)', # Tooltip 3378 | webvar => 'FUTURE', # webvar 3379 | optkey => 'future', # option 3380 | type => 'radioboolean', # type 3381 | default => '0', # value 3382 | save => 1, 3383 | }; 3384 | 3385 | $opt->{SINCE} = { 3386 | title => 'Added Since (hours)', # Title 3387 | tooltip => 'Only show programmes added to the local programmes cache in the past number of hours', # Tooltip 3388 | webvar => 'SINCE', # webvar 3389 | optkey => 'since', # option 3390 | type => 'text', # type 3391 | value => 3, # width values 3392 | default => '', 3393 | save => 1, 3394 | }; 3395 | 3396 | $opt->{BEFORE} = { 3397 | title => 'Added Before (hours)', # Title 3398 | tooltip => 'Only show programmes added to the local programmes cache over this number of hours ago', # Tooltip 3399 | webvar => 'BEFORE', # webvar 3400 | optkey => 'before', # option 3401 | type => 'text', # type 3402 | value => 3, # width values 3403 | default => '', 3404 | save => 1, 3405 | }; 3406 | 3407 | $opt->{PVRHOLDOFF} = { 3408 | title => 'PVR Hold off period (hours)', # Title 3409 | tooltip => 'Wait this number of hours before allowing the PVR to record a programme. This sometimes helps when the flashhd version is delayed in being made available.', # Tooltip 3410 | webvar => 'PVRHOLDOFF', # webvar 3411 | optkey => 'before', # option 3412 | type => 'text', # type 3413 | value => 3, # width values 3414 | default => '', 3415 | save => 1, 3416 | }; 3417 | 3418 | my %vsize_labels = ( ''=>'Native', '1920x1080'=>'1920x1080', '1280x720'=>'1280x720', '960x540'=>'960x540', '832x468'=>'832x468', '704x396'=>'704x396', '640x360'=>'640x360', '512x288'=>'512x288', '448x252'=>'448x252', '384x216'=>'384x216', '256x144'=>'256x144', '192x108'=>'192x108' ); 3419 | $opt->{VSIZE} = { 3420 | title => 'Remote Streaming Video Size', # Title 3421 | tooltip => "Video size 'x' to transcode remotely played files - specify 'Native' for native size", # Tooltip 3422 | webvar => 'VSIZE', # webvar 3423 | type => 'popup', # type 3424 | label => , \%vsize_labels, # labels 3425 | default => '', # default 3426 | value => [ (sort {$a <=> $b} keys %vsize_labels) ], # values 3427 | save => 1, 3428 | }; 3429 | 3430 | $opt->{BITRATE} = { 3431 | title => 'Remote Audio Bitrate', # Title 3432 | tooltip => 'Remote Audio Bitrate (in kbps) to transcode remotely played files - leave blank for native bitrate', # Tooltip 3433 | webvar => 'BITRATE', # webvar 3434 | type => 'text', # type 3435 | value => 3, # width values 3436 | default => '', 3437 | save => 1, 3438 | }; 3439 | 3440 | $opt->{VFR} = { 3441 | title => 'Remote Video Frame Rate', # Title 3442 | tooltip => 'Remote Video Frame Rate (in frames per second) to transcode remotely played files - leave blank for native framerate', # Tooltip 3443 | webvar => 'VFR', # webvar 3444 | type => 'text', # type 3445 | value => 2, # width values 3446 | default => '', 3447 | save => 1, 3448 | }; 3449 | my %streamtype_labels = ( ''=>'Auto', 'none'=>'Disable Transcoding', 'flv'=>'Flash Video (H.264/MP3)', 'mpegts'=>'MPEG Transport Stream (H.264/MP2)', 'matroska'=>'Matroska (H.264/Vorbis)', 'asf'=>'Advanced Systems Format (H.264/WMA)', 'mp3'=>'MP3 (Audio Only)', 'adts'=>'AAC (Audio Only)', 'oga'=>'Vorbis (Audio Only)', 'wav'=>'WAV (Audio Only)', 'flac'=>'FLAC (Audio Only)' ); 3450 | $opt->{STREAMTYPE} = { 3451 | title => "Remote Streaming type", # Title 3452 | tooltip => "Force the output to be this type when using 'Play' streaming. Specify 'Native' to disable transcoding/remuxing.", # Tooltip 3453 | webvar => 'STREAMTYPE', # webvar 3454 | type => 'popup', # type 3455 | label => , \%streamtype_labels, # labels 3456 | default => '', # default 3457 | value => [ '', 'none', 'flv', 'mpegts', 'matroska', 'asf', 'mp3', 'adts', 'oga', 'wav', 'flac' ], # values 3458 | onChange=> "form1.submit();", 3459 | save => 1, 3460 | }; 3461 | 3462 | # Whether to hide deleted programmes from the Recordings display. 3463 | $opt->{HIDEDELETED} = { 3464 | title => 'Hide Deleted Recordings', # Title 3465 | tooltip => 'Whether to hide deleted programmes from the recordings history list', # Tooltip 3466 | webvar => 'HIDEDELETED', # webvar 3467 | optkey => 'skipdeleted', # option 3468 | type => 'radioboolean', # type 3469 | default => 0, # value 3470 | save => 1, 3471 | }; 3472 | 3473 | # Which columns to display 3474 | $opt->{COLS} = { 3475 | title => 'Enable Columns', # Title 3476 | tooltip => 'Select the columns you wish to display', # Tooltip 3477 | webvar => 'COLS', # webvar 3478 | #optkey => 'type', # option 3479 | type => 'multiboolean', # type 3480 | label => \%cols_names, # labels 3481 | #status => \%cols_status, # default status 3482 | value => \%cols_order, # order of values 3483 | save => 1, 3484 | }; 3485 | 3486 | # Make sure we go to the correct nextpage for processing 3487 | $opt->{NEXTPAGE} = { 3488 | webvar => 'NEXTPAGE', 3489 | type => 'hidden', 3490 | default => 'search_progs', 3491 | save => 0, 3492 | }; 3493 | 3494 | # Make sure we go to the correct nextpage for processing 3495 | $opt->{ACTION} = { 3496 | webvar => 'ACTION', 3497 | type => 'hidden', 3498 | default => '', 3499 | save => 0, 3500 | }; 3501 | 3502 | # Make sure we go to the correct next page no. 3503 | $opt->{PAGENO} = { 3504 | webvar => 'PAGENO', 3505 | type => 'hidden', 3506 | default => 1, 3507 | save => 0, 3508 | }; 3509 | 3510 | # Remember the status of the tab options display 3511 | for my $tabname ( grep !/BASICTAB/, @{ $layout->{taborder} } ) { 3512 | my $default = 'no'; 3513 | # By default only show advanced search tab 3514 | $default = 'yes' if $tabname eq 'SEARCHTAB'; 3515 | $opt->{$tabname} = { 3516 | webvar => $tabname, # webvar 3517 | type => 'hidden', # type 3518 | default => $default, # value 3519 | save => 0, 3520 | }; 3521 | } 3522 | 3523 | # Save the status of the Advanced Search options and preferences settings 3524 | $opt->{SAVE} = { 3525 | webvar => 'SAVE', # webvar 3526 | type => 'hidden', # type 3527 | default => '0', # value 3528 | save => 0, 3529 | }; 3530 | 3531 | # INFO for page info if clicked 3532 | $opt->{INFO} = { 3533 | webvar => 'INFO', 3534 | type => 'hidden', 3535 | default => 0, 3536 | save => 0, 3537 | }; 3538 | 3539 | 3540 | # Go through each of the options defined above 3541 | for ( keys %{ $opt } ) { 3542 | # Ignore cookies if we are saving new ones 3543 | if ( not $cgi->param('SAVE') ) { 3544 | if ( defined $cgi->param($_) ) { 3545 | print $se "DEBUG: GOT Param $_ = ".$cgi->param($_)."\n" if $opt_cmdline->{debug}; 3546 | $opt->{$_}->{current} = join ",", $cgi->param($_); 3547 | } elsif ( defined $cgi->cookie($_) ) { 3548 | print $se "DEBUG: GOT Cookie $_ = ".$cgi->cookie($_)."\n" if $opt_cmdline->{debug}; 3549 | $opt->{$_}->{current} = join ",", $cgi->cookie($_); 3550 | } else { 3551 | $opt->{$_}->{current} = join ",", $opt->{$_}->{default}; 3552 | } 3553 | print $se "DEBUG: Using $_ = $opt->{$_}->{current}\n--\n" if $opt_cmdline->{debug}; 3554 | 3555 | } else { 3556 | $opt->{$_}->{current} = join(",", $cgi->param($_) ) || $opt->{$_}->{default} if not defined $opt->{$_}->{current}; 3557 | } 3558 | } 3559 | } 3560 | 3561 | 3562 | 3563 | ###################################################################### 3564 | # 3565 | # begin_html 3566 | # 3567 | # Send HTTP headers to browser 3568 | # Sets "title", Sends and flags 3569 | # 3570 | ###################################################################### 3571 | sub begin_html { 3572 | my $request_host = shift; 3573 | my $mimetype = 'text/html'; 3574 | 3575 | # Save settings if selected 3576 | my @cookies; 3577 | if ( $cgi->param('SAVE') ) { 3578 | print $se "DEBUG: Sending cookies\n"; 3579 | for ( %{ $opt } ) { 3580 | # skip if opt not allowed to be saved 3581 | next if not $opt->{$_}->{save}; 3582 | my $cookie = $cgi->cookie( -name=>$_, -value=>$opt->{$_}->{current}, -expires=>'+1y' ); 3583 | push @cookies, $cookie; 3584 | print $se "DEBUG: Sending cookie: $cookie\n" if $opt_cmdline->{debug}; 3585 | } 3586 | # Ensure SAVE state is reset to off 3587 | $opt->{SAVE}->{current} = 0; 3588 | } 3589 | 3590 | # Send the headers to the browser 3591 | my $headers = $cgi->header( 3592 | -type => $mimetype, 3593 | -charset => 'utf-8', 3594 | -cookie => [@cookies], 3595 | ); 3596 | print $se "\nHEADERS:\n$headers\n" if $opt_cmdline->{debug}; 3597 | 3598 | # Build body element and page title differently depending on the type of page 3599 | # Load the refresh tab if required 3600 | my $body_element; 3601 | my $title; 3602 | my $autorefresh = $cgi->cookie( 'AUTOWEBREFRESH' ) || $cgi->param( 'AUTOWEBREFRESH' ); 3603 | my $autopvrrun = $cgi->cookie( 'AUTOPVRRUN' ) || $cgi->param( 'AUTOPVRRUN' ); 3604 | if ( $autorefresh > 0 && $cgi->param( 'NEXTPAGE' ) eq 'refresh' ) { 3605 | $body_element = "{PROGTYPES}->{current}', ".(1000*3600*$autorefresh)." );\">"; 3606 | $title = 'Refreshing Cache: get_iplayer Web PVR Manager'; 3607 | } elsif ( $autopvrrun > 0 && $cgi->param( 'NEXTPAGE' ) eq 'pvr_run' ) { 3608 | $body_element = ""; 3609 | $title = 'Running PVR: get_iplayer Web PVR Manager'; 3610 | } else { 3611 | $body_element = "\n"; 3612 | $title = "get_iplayer Web PVR Manager $VERSION_TEXT"; 3613 | } 3614 | 3615 | # Write out the page http and html headers 3616 | print $fh $headers; 3617 | print $fh ''."\n"; 3618 | print $fh ""; 3619 | print $fh "$title\n"; 3620 | print $fh "{baseurl}\">\n" if $opt_cmdline->{baseurl}; 3621 | insert_stylesheet(); 3622 | print $fh "\n"; 3623 | insert_javascript(); 3624 | print $fh $body_element; 3625 | } 3626 | 3627 | 3628 | 3629 | ############################################# 3630 | # 3631 | # Javascript Functions here 3632 | # 3633 | ############################################# 3634 | sub insert_javascript { 3635 | 3636 | print $fh < 3639 | 3640 | function RefreshTab(url, time, force ) { 3641 | if ( force ) { 3642 | window.location.href = url; 3643 | } 3644 | if ( time <= 0 ) { 3645 | return; 3646 | } 3647 | setTimeout( "RefreshTab('" + url + "'," + time + ", 1 )", time ); 3648 | } 3649 | 3650 | 3651 | // global hash table for saving copy of form 3652 | var form_backup = {}; 3653 | 3654 | // 3655 | // Copy all non-grouped form values into a global hash 3656 | // 3657 | function BackupFormVars( f ) { 3658 | // empty out array 3659 | for(var key in form_backup) { 3660 | delete( form_backup[key] ); 3661 | } 3662 | 3663 | // copy forms elements 3664 | var elem = f.elements; 3665 | for(var i = 0; i < elem.length; i++) { 3666 | // exclude radio and checkbox types - can be duplicate names in groups... 3667 | if ( elem[i].type != "checkbox" && elem[i].type != "radio" ) { 3668 | form_backup[ elem[i].name ] = elem[i].value; 3669 | } 3670 | } 3671 | } 3672 | 3673 | // 3674 | // Copy all form values in the global hash into the specified form 3675 | // 3676 | function RestoreFormVars( f ) { 3677 | // copy form elements 3678 | for(var key in form_backup) { 3679 | f.elements[ key ].value = form_backup[key]; 3680 | // delete element 3681 | delete( form_backup[key] ); 3682 | } 3683 | } 3684 | 3685 | // 3686 | // Hide show an element (and modify the text of the button/label) 3687 | // e.g. document.getElementById('advanced_opts').style.display='table'; 3688 | // 3689 | // Usage: show_options_tab( SELECTEDID, [ 'TAB1', 'TAB2' ] ); 3690 | // Displays first tab in list or tab suffixes 3691 | // tab_TAB1 is the table element 3692 | // option_TAB1 is the form variable 3693 | // button_TAB1 is the label 3694 | // 3695 | function show_options_tab( selectedid, tabs ) { 3696 | 3697 | // selected tab element 3698 | var selected_tab = document.getElementById( 'tab_' + selectedid ); 3699 | 3700 | // Loop through the above tab elements 3701 | for(var i = 0; i < tabs.length; i++) { 3702 | var li = document.getElementById( 'li_' + tabs[i] ); 3703 | var tab = document.getElementById( 'tab_' + tabs[i] ); 3704 | var option = document.getElementById( 'option_' + tabs[i] ); 3705 | var button = document.getElementById( 'button_' + tabs[i] ); 3706 | if ( tab == selected_tab ) { 3707 | tab.style.display = 'table-cell'; 3708 | tab.style.visibility = 'visible'; 3709 | option.value = 'yes'; 3710 | //button.innerHTML = '- ' + button.innerHTML.substring(2); 3711 | //button.style.color = '#F54997'; 3712 | //li.style.borderBottom = '0px solid #666'; 3713 | li.className = 'options_tab_sel'; 3714 | } else { 3715 | tab.style.display = 'none'; 3716 | tab.style.visibility = 'collapse'; 3717 | option.value = 'no'; 3718 | //button.innerHTML = '+ ' + button.innerHTML.substring(2); 3719 | //button.style.color = '#ADADAD'; 3720 | //li.style.borderBottom = '1px solid #666'; 3721 | li.className = 'options_tab'; 3722 | } 3723 | } 3724 | return true; 3725 | } 3726 | 3727 | // 3728 | // Check/Uncheck all checkboxes named 3729 | // 3730 | function check_toggle(f, name) { 3731 | var empty_fields = ""; 3732 | var errors = ""; 3733 | var check; 3734 | 3735 | if (f.SELECTOR.checked == true) { 3736 | check = 1; 3737 | } else { 3738 | check = 0; 3739 | } 3740 | 3741 | // Loop through the elements of the form 3742 | for(var i = 0; i < f.length; i++) { 3743 | var e = f.elements[i]; 3744 | if (e.type == "checkbox" && e.name == name) { 3745 | if (check == 1) { 3746 | // First check if the box is checked (don't check a disabled box) 3747 | if(e.checked == false && e.disabled == false) { 3748 | e.checked = true; 3749 | } 3750 | } else { 3751 | // First check if the box is not checked 3752 | if(e.checked == true) { 3753 | e.checked = false; 3754 | } 3755 | } 3756 | } 3757 | } 3758 | return true; 3759 | } 3760 | 3761 | // 3762 | // Warn if none of the checkboxes named are selected 3763 | // 3764 | function check_if_selected(f, name) { 3765 | // Loop through the elements of the form 3766 | for(var i = 0; i < f.length; i++) { 3767 | var e = f.elements[i]; 3768 | if (e.type == "checkbox" && e.name == name && e.checked == true) { 3769 | return true; 3770 | } 3771 | } 3772 | return false; 3773 | } 3774 | 3775 | // 3776 | // Disable checkboxes named that are selected 3777 | // 3778 | function disable_selected_checkboxes(f, name) { 3779 | var empty_fields = ""; 3780 | var errors = ""; 3781 | var check; 3782 | 3783 | // Loop through the elements of the form 3784 | for(var i = 0; i < f.length; i++) { 3785 | var e = f.elements[i]; 3786 | if (e.type == "checkbox" && e.name == name) { 3787 | // First check if the box is checked 3788 | if(e.checked == true) { 3789 | e.checked = false; 3790 | e.disabled = true; 3791 | } 3792 | } 3793 | } 3794 | return true; 3795 | } 3796 | 3797 | // 3798 | // Submit Search only if enter is pressed from a textfield 3799 | // Called as: onKeyDown="return submitonEnter(event);" 3800 | // 3801 | function submitonEnter(evt){ 3802 | var charCode = (evt.which) ? evt.which : event.keyCode 3803 | if ( charCode == "13" ) { 3804 | document.form1.NEXTPAGE.value='search_progs'; 3805 | document.form1.PAGENO.value=1; 3806 | document.form1.submit(); 3807 | } 3808 | } 3809 | 3810 | 3811 | EOF 3812 | } 3813 | 3814 | 3815 | 3816 | ############################################# 3817 | # 3818 | # CSS1 Styles here 3819 | # 3820 | ############################################# 3821 | sub insert_stylesheet { 3822 | print $fh < 3825 | 3826 | body { 3827 | background: #000; 3828 | color: #fff; 3829 | font-family: Arial,Helvetica,sans-serif; 3830 | font-size: 100%; 3831 | } 3832 | 3833 | img { 3834 | border: 0; 3835 | } 3836 | 3837 | input, select { 3838 | background: #ddd; 3839 | border: 0; 3840 | } 3841 | 3842 | input { 3843 | font-size: 1em; 3844 | } 3845 | 3846 | a { 3847 | color: #fff; 3848 | text-decoration: none; 3849 | } 3850 | 3851 | a[href], a[onclick], label[onclick], :link, :visited { 3852 | cursor: pointer; 3853 | } 3854 | 3855 | ul.nav, 3856 | ul.options_tab, 3857 | ul.action { 3858 | list-style: none; 3859 | margin: 8px 0; 3860 | padding: 0; 3861 | } 3862 | 3863 | ul.nav, ul.action { 3864 | font-size: 1em; 3865 | } 3866 | 3867 | ul.nav { 3868 | border-bottom: 4px solid #888; 3869 | } 3870 | 3871 | ul.options_tab { 3872 | border-bottom: 2px solid #888; 3873 | } 3874 | 3875 | ul.nav > li, 3876 | ul.options_tab > li, 3877 | ul.action > li { 3878 | background: #444; 3879 | display: inline-block; 3880 | vertical-align: bottom; 3881 | margin: 0 4px; 3882 | } 3883 | 3884 | ul.nav > li, 3885 | ul.action > li { 3886 | padding: 4px 16px; 3887 | } 3888 | 3889 | ul.options_tab > li { 3890 | padding: 2px 8px; 3891 | } 3892 | 3893 | ul.nav > li:hover, 3894 | ul.options_tab > li:hover, 3895 | ul.action > li:hover { 3896 | background: #666; 3897 | } 3898 | 3899 | ul.nav > li.nav_tab_sel, 3900 | ul.options_tab > li.options_tab_sel { 3901 | background: #888; 3902 | } 3903 | 3904 | table.options_outer > tbody > tr { 3905 | font-size: 0.875em; 3906 | } 3907 | 3908 | table.options_outer td, 3909 | table.options_outer th, 3910 | table.info td, 3911 | table.info th { 3912 | vertical-align: top; 3913 | text-align: left; 3914 | } 3915 | 3916 | table.options, 3917 | table_options_embedded { 3918 | border-spacing: 1; 3919 | } 3920 | 3921 | table.pagetrail { 3922 | margin-left: auto; 3923 | margin-right: auto; 3924 | margin-top: 8px; 3925 | margin-bottom: 8px; 3926 | font-size: 1em; 3927 | font-weight: bold; 3928 | border-spacing: 10px 0; 3929 | padding: 0px; 3930 | } 3931 | 3932 | label.pagetrail-current { 3933 | color: #F54997; 3934 | } 3935 | 3936 | table.search, 3937 | table.info { 3938 | border: 2px solid #333; 3939 | border-collapse: collapse; 3940 | width: 100%; 3941 | } 3942 | 3943 | table.search > tbody > tr, 3944 | table.info > tbody > tr { 3945 | background: #444; 3946 | font-size: 0.875em; 3947 | } 3948 | 3949 | table.search > tbody > tr:hover, 3950 | table.info > tbody > tr:hover { 3951 | background: #666; 3952 | } 3953 | 3954 | table.search > tbody > tr > th, 3955 | table.info > tbody > tr > th { 3956 | background: #000; 3957 | text-align: center; 3958 | } 3959 | 3960 | table.search > tbody > tr > td, 3961 | table.search > tbody > tr > th, 3962 | table.info > tbody > tr > td, 3963 | table.info > tbody > tr > th { 3964 | border: 1px solid #333; 3965 | padding: 4px 8px; 3966 | } 3967 | 3968 | table.info > tbody > tr > td { 3969 | word-break: break-all 3970 | } 3971 | 3972 | table.searchhead { 3973 | width: 100%; 3974 | } 3975 | 3976 | label.sorted { 3977 | color: #CFC; 3978 | } 3979 | 3980 | label.sorted_reverse { 3981 | color: #FCC; 3982 | } 3983 | 3984 | b.footer { 3985 | color: #777; 3986 | font-size: 0.75em; 3987 | font-weight: normal; 3988 | } 3989 | 3990 | #nowrap { 3991 | white-space: nowrap; 3992 | } 3993 | 3994 | #logo { 3995 | background: none; 3996 | margin: 0; 3997 | } 3998 | 3999 | #logo .logotext { 4000 | color: #F54997; 4001 | font-family: "Courier New", monospace; 4002 | } 4003 | 4004 | .darker { 4005 | color: #7D7D7D; 4006 | } 4007 | 4008 | 4009 | EOF 4010 | 4011 | } 4012 | --------------------------------------------------------------------------------