├── .editorconfig ├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── Dockerfile ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── transmission-add-file └── transmission-rss ├── contrib ├── transmission-rss.init.sh └── transmission-rss.service ├── lib ├── transmission-rss.rb └── transmission-rss │ ├── aggregator.rb │ ├── callback.rb │ ├── client.rb │ ├── config.rb │ ├── core_ext │ ├── Array.rb │ ├── Hash.rb │ ├── Object.rb │ └── URI.rb │ ├── feed.rb │ ├── log.rb │ ├── seen_file.rb │ └── version.rb ├── log └── .gitkeep ├── spec ├── aggregator_spec.rb ├── callback_spec.rb ├── client_spec.rb ├── config_spec.rb ├── feed_spec.rb ├── seen_file_spec.rb ├── spec_helper.rb └── vcr │ ├── add_torrent.yml │ ├── add_torrent_alt_port.yml │ ├── add_torrent_download_dir.yml │ ├── add_torrent_paused.yml │ ├── add_torrent_too_many_requests.yml │ ├── add_torrent_via_http_with_special_chars.yml │ ├── add_torrent_with_ratio.yml │ ├── feed_fetch.yml │ ├── session_id.yml │ └── set_torrent.yml ├── transmission-rss.conf.example └── transmission-rss.gemspec /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | tab_width = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please include the following information in new issues: 2 | 3 | - `ruby -v` 4 | - `transmission-rss -v` 5 | - The content for your configuration file. You can anonymize URLs if the 6 | issue is independent of the feed contents. 7 | - Relevant lines from log output. 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /coverage 2 | /log 3 | /*.gem 4 | /Gemfile.lock 5 | 6 | /transmission-rss.conf 7 | /.seen 8 | 9 | /pkg 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | os: 4 | - linux 5 | - osx 6 | 7 | rvm: 8 | - 2.7 # Current stable 9 | - 2.6 # Alpine 3.11 10 | - 2.5 # Debian stable (buster), Ubuntu 11 | - 2.1 # Minimum supported version (Debian oldoldstable (jessie)) 12 | 13 | matrix: 14 | fast_finish: true 15 | allow_failures: 16 | - os: osx 17 | - rvm: ruby-head 18 | exclude: 19 | - os: osx 20 | rvm: ruby-head 21 | - os: osx 22 | rvm: 2.1 23 | 24 | notifications: 25 | email: false 26 | 27 | install: 28 | - gem install bundler -v '< 2' 29 | - bundle install --jobs=3 --retry=3 30 | 31 | script: 32 | - bundle exec gem build transmission-rss.gemspec 33 | - bundle exec rake 34 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # docker build -t transmission-rss . 2 | # docker build -t transmission-rss --build-arg UID=1337 --build-arg GID=1337 . 3 | # docker run -it -v $(pwd)/transmission-rss.conf:/etc/transmission-rss.conf transmission-rss 4 | # 5 | # docker build -t nning2/transmission-rss:v1.2.3 . 6 | # docker tag nning2/transmission-rss:v1.2.3 nning2/transmission-rss:latest 7 | # docker push nning2/transmission-rss:v1.2.3 8 | 9 | FROM alpine:3 as builder 10 | RUN apk add gcc libc-dev make ruby-dev 11 | COPY . /tmp 12 | WORKDIR /tmp 13 | RUN gem build transmission-rss.gemspec 14 | RUN gem install -N --build-root /build transmission-rss-*.gem 15 | 16 | FROM alpine:3 17 | ARG UID=1000 18 | ARG GID=1000 19 | RUN \ 20 | addgroup -g $GID ruby && \ 21 | adduser -u $UID -G ruby -D ruby && \ 22 | apk add --no-cache ruby ruby-etc ruby-json 23 | USER ruby 24 | COPY --from=builder /build / 25 | CMD ["transmission-rss"] 26 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :test do 6 | gem 'coveralls', require: false 7 | gem 'rake' 8 | gem 'rspec' 9 | gem 'vcr' 10 | gem 'webmock' 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | transmission-rss 2 | ================ 3 | 4 | [![Gem Version](https://img.shields.io/gem/v/transmission-rss.svg)](http://badge.fury.io/rb/transmission-rss) 5 | [![Build Status](https://img.shields.io/travis/nning/transmission-rss/master.svg)](https://travis-ci.org/nning/transmission-rss) 6 | [![Coverage Status](https://img.shields.io/coveralls/nning/transmission-rss/master.svg)](https://coveralls.io/r/nning/transmission-rss) 7 | [![Code Climate](https://img.shields.io/codeclimate/maintainability/nning/transmission-rss.svg)](https://codeclimate.com/github/nning/transmission-rss) 8 | [![Docker Hub Build Status](https://img.shields.io/docker/build/nning2/transmission-rss.svg)](https://hub.docker.com/r/nning2/transmission-rss/) 9 | 10 | transmission-rss is basically a workaround for transmission's lack of the 11 | ability to monitor RSS feeds and automatically add enclosed torrent links. 12 | 13 | It works with transmission-daemon and transmission-gtk (if the web frontend 14 | is enabled in the settings dialog). Sites like showrss.karmorra.info and 15 | ezrss.it or self-hosted seriesly instances are suited well as feed sources. 16 | 17 | A tool called transmission-add-file is also included for mass adding of 18 | torrent files. 19 | 20 | As it's done with poems, I devote this very artful and romantic piece of 21 | code to the single most delightful human being: Ann. 22 | 23 | The minimum supported Ruby version is 2.1. (You will need `rbenv` if your 24 | os does not support Ruby >= 2.1, e.g. on Debian wheezy.) 25 | 26 | **Note, that this README is for the current development branch!** You can find 27 | a link to a suitable README for your version 28 | [on the releases page](https://github.com/nning/transmission-rss/releases). 29 | 30 | Installation 31 | ------------ 32 | 33 | ### Latest stable version from rubygems.org 34 | 35 | ```sh 36 | gem install transmission-rss 37 | ``` 38 | 39 | ### From source 40 | 41 | ```sh 42 | git clone https://github.com/nning/transmission-rss 43 | cd transmission-rss 44 | bundle 45 | gem build transmission-rss.gemspec 46 | gem install transmission-rss-*.gem 47 | ``` 48 | 49 | ### Via Docker 50 | 51 | ```sh 52 | docker run -t \ 53 | -v $(pwd)/transmission-rss.conf:/etc/transmission-rss.conf \ 54 | nning2/transmission-rss:v1.2.1 55 | ``` 56 | 57 | Configuration 58 | ------------- 59 | 60 | A yaml formatted config file is expected at `/etc/transmission-rss.conf`. Users 61 | can override some options for their transmission-rss instances by providing a 62 | config at `~/.config/transmission-rss/config.yml` (or in `$XDG_CONFIG_HOME` 63 | instead of `~/.config`). 64 | 65 | **WARNING:** If you want to override a nested option like `log.target` you also 66 | have to explicitly specify the others like `log.level`. (True for categories 67 | `server`, `login`, `log`, `privileges`, and `client`.) 68 | 69 | ### Minimal example 70 | 71 | It should at least contain a list of feeds: 72 | 73 | ```yaml 74 | feeds: 75 | - url: http://example.com/feed1 76 | - url: http://example.com/feed2 77 | ``` 78 | 79 | Feed item titles can be filtered by a regular expression: 80 | 81 | ```yaml 82 | feeds: 83 | - url: http://example.com/feed1 84 | regexp: foo 85 | - url: http://example.com/feed2 86 | regexp: (foo|bar) 87 | ``` 88 | 89 | Feeds can also be configured to download files to specific directory: 90 | 91 | 92 | ```yaml 93 | feeds: 94 | - url: http://example.com/feed1 95 | download_path: /home/user/Downloads 96 | ``` 97 | 98 | Setting the seed ratio limit is supported per feed: 99 | 100 | 101 | ```yaml 102 | feeds: 103 | - url: http://example.com/feed1 104 | seed_ratio_limit: 0 105 | ``` 106 | 107 | Configurable certificate validation, good for self-signed certificates. Default 108 | is true: 109 | 110 | 111 | ```yaml 112 | feeds: 113 | - url: http://example.com/feed1 114 | validate_cert: false 115 | ``` 116 | 117 | Using the GUID instead of the link for tracking seen torrents is also available, 118 | useful for changing URLs such as Prowlarr's proxy links. Default is false: 119 | 120 | ```yaml 121 | feeds: 122 | - url: http://example.com/feed1 123 | seen_by_guid: true 124 | ``` 125 | 126 | ### All available options 127 | 128 | The following configuration file example contains every existing option 129 | (although `update_interval`, `add_paused`, `server`, `log`, `fork`, `single`, and 130 | `pid_file` are default values and could be omitted). The default `log.target` is 131 | STDERR. `privileges` is not defined by default, so the script runs as current 132 | user/group. `login` is also not defined by default. It has to be defined, if 133 | transmission is configured for HTTP basic authentication. 134 | 135 | See `./transmission-rss.conf.example` for more documentation. 136 | 137 | 138 | ```yaml 139 | feeds: 140 | - url: http://example.com/feed1 141 | - url: http://example.com/feed2 142 | - url: http://example.com/feed3 143 | regexp: match1 144 | - url: http://example.com/feed4 145 | regexp: (match1|match2) 146 | - url: http://example.com/feed5 147 | download_path: /home/user/Downloads 148 | delay_time: 2 149 | - url: http://example.com/feed6 150 | seed_ratio_limit: 1 151 | - url: http://example.com/feed7 152 | regexp: 153 | - match1 154 | - match2 155 | - url: http://example.com/feed8 156 | regexp: 157 | - matcher: match1 158 | download_path: /home/user/match1 159 | - matcher: match2 160 | download_path: /home/user/match2 161 | - url: http://example.com/feed9 162 | validate_cert: false 163 | seen_by_guid: true 164 | 165 | update_interval: 600 166 | 167 | add_paused: false 168 | 169 | server: 170 | host: localhost 171 | port: 9091 172 | tls: false 173 | rpc_path: /transmission/rpc 174 | 175 | login: 176 | username: transmission 177 | password: transmission 178 | 179 | log: 180 | target: /var/log/transmissiond-rss.log 181 | level: debug 182 | 183 | privileges: 184 | user: nobody 185 | group: nobody 186 | 187 | client: 188 | timeout: 5 189 | 190 | fork: false 191 | 192 | single: false 193 | 194 | pid_file: false 195 | 196 | seen_file: ~/.config/transmission/seen 197 | ``` 198 | 199 | Daemonized Startup 200 | ------------------ 201 | 202 | ### As a systemd service 203 | 204 | The following content can be saved into 205 | `/etc/systemd/system/transmission-rss.service` to create a systemd unit. 206 | Remember checking the path in `ExecStart`. 207 | 208 | ```ini 209 | [Unit] 210 | Description=Transmission RSS daemon. 211 | After=network.target transmission-daemon.service 212 | 213 | [Service] 214 | Type=forking 215 | ExecStart=/usr/local/bin/transmission-rss -f 216 | ExecReload=/bin/kill -s HUP $MAINPID 217 | 218 | [Install] 219 | WantedBy=multi-user.target 220 | ``` 221 | 222 | The unit files are reloaded by `systemctl daemon-reload`. You can then start 223 | transmission-rss by running `systemctl start transmission-rss`. Starting on 224 | boot, can be enabled `systemctl enable transmission-rss`. 225 | 226 | ### As a cronjob 227 | 228 | `transmission-rss` can also be started in a single run mode, in which it runs a single loop and then exits. To do so, `transmission-rss` needs to be started with the `-s` flag. An example crontab line for running every 10 minutes can be: 229 | 230 | `*/10 * * * * /usr/local/bin/transmission-rss -s` 231 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | 3 | require 'rspec/core/rake_task' 4 | RSpec::Core::RakeTask.new(:spec) 5 | task default: :spec 6 | 7 | namespace :docker do 8 | desc 'Build docker image' 9 | task :build do 10 | sh 'docker build -t transmission-rss .' 11 | end 12 | 13 | desc 'Run docker image' 14 | task :run do 15 | sh ' 16 | touch \ 17 | $(pwd)/transmission-rss.conf \ 18 | $(pwd)/.seen 19 | 20 | docker run \ 21 | -it \ 22 | --net host \ 23 | -v $(pwd)/transmission-rss.conf:/etc/transmission-rss.conf \ 24 | -v $(pwd)/.seen:/home/ruby/.config/transmission/seen \ 25 | transmission-rss 26 | ' 27 | end 28 | 29 | desc 'Publish docker image' 30 | task :publish do 31 | sh " 32 | set -e 33 | docker build -t nning2/transmission-rss:#{TransmissionRSS::VERSION} . 34 | docker tag nning2/transmission-rss:#{TransmissionRSS::VERSION} nning2/transmission-rss:latest 35 | docker push nning2/transmission-rss:#{TransmissionRSS::VERSION} 36 | docker push nning2/transmission-rss:latest 37 | " 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /bin/transmission-add-file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'getoptlong' 4 | 5 | $:.unshift(File.dirname(__FILE__) + '/../lib') 6 | require 'transmission-rss' 7 | 8 | include TransmissionRSS 9 | 10 | # Default config file path. 11 | config_file = '/etc/transmission-rss.conf' 12 | 13 | # Shows a summary of the command line options. 14 | def usage_message( config_file ) 15 | $stderr << "#{File.basename($0)} [option].. [file].. 16 | Adds torrent files to transmission web frontend. 17 | 18 | -c Custom config file path. Default: #{config_file} 19 | -h This help. 20 | 21 | " 22 | exit(1) 23 | end 24 | 25 | # Define command-line options. 26 | options = GetoptLong.new( 27 | [ '-c', GetoptLong::REQUIRED_ARGUMENT ], 28 | [ '-h', GetoptLong::NO_ARGUMENT ] 29 | ) 30 | 31 | # Parse given options. 32 | options.each do |option, argument| 33 | case(option) 34 | when '-c' 35 | config_file = argument 36 | when '-h' 37 | usage_message(config_file) 38 | end 39 | end 40 | 41 | usage_message(config_file) if ARGV.empty? 42 | 43 | # Seems to be necessary when called from gem installation. 44 | # Otherwise Config is somehow mixed up with RbConfig. 45 | config = TransmissionRSS::Config.instance 46 | 47 | # Initialize a log instance and configure it. 48 | log = Log.instance 49 | 50 | # Load config file (default or given by argument). 51 | begin 52 | config.load(config_file) 53 | log.target = config.log.target 54 | log.level = config.log.level 55 | rescue Errno::ENOENT 56 | log.error(config_file + ' not found') 57 | end 58 | log.debug(config) 59 | 60 | # Initialize communication to transmission. 61 | client = Client.new(config.server, config.login) 62 | 63 | ARGV.each do |torrent_file| 64 | client.add_torrent(torrent_file, :file, paused: config.add_paused) 65 | end 66 | 67 | log.close 68 | -------------------------------------------------------------------------------- /bin/transmission-rss: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'getoptlong' 4 | require 'etc' 5 | 6 | $:.unshift(File.dirname(__FILE__) + '/../lib') 7 | require 'transmission-rss' 8 | 9 | include TransmissionRSS 10 | 11 | # Default config file path. 12 | config_file = '/etc/transmission-rss.conf' 13 | custom_config = false 14 | 15 | # Change default config file path on BSD. 16 | if bsd? 17 | config_file = '/usr/local' + config_file 18 | end 19 | 20 | # Do not fork by default. 21 | dofork = false 22 | 23 | # Do not run single time by default. 24 | dosingle = false 25 | 26 | # No PID file by default. 27 | pid_file = false 28 | 29 | # Seen file not reset by default. 30 | reset_seen_file = false 31 | 32 | # Shows a summary of the command line options. 33 | def usage_message(config_file) 34 | $stderr << "#{File.basename $0} [options] 35 | Adds torrents from rss feeds to transmission web frontend. 36 | 37 | -c Custom config file path. Default: #{config_file} 38 | -f Fork into background after startup. 39 | -s Single run mode. 40 | -h This help. 41 | -p Write PID to file. 42 | -r Reset seenfile on startup. 43 | -v Show program version and exit. 44 | 45 | " 46 | exit(1) 47 | end 48 | 49 | # Define command-line options. 50 | options = GetoptLong.new \ 51 | ['-c', GetoptLong::REQUIRED_ARGUMENT], 52 | ['-f', GetoptLong::NO_ARGUMENT], 53 | ['-s', GetoptLong::NO_ARGUMENT], 54 | ['-h', GetoptLong::NO_ARGUMENT], 55 | ['-p', GetoptLong::REQUIRED_ARGUMENT], 56 | ['-r', GetoptLong::NO_ARGUMENT], 57 | ['-v', GetoptLong::NO_ARGUMENT] 58 | 59 | # Parse given options. 60 | options.each do |option, argument| 61 | case option 62 | when '-c' 63 | config_file = argument 64 | custom_config = true 65 | when '-f' 66 | dofork = true 67 | when '-s' 68 | dosingle = true 69 | when '-h' 70 | usage_message(config_file) 71 | when '-p' 72 | pid_file = argument 73 | when '-r' 74 | reset_seen_file = true 75 | when '-v' 76 | puts TransmissionRSS::VERSION 77 | exit 78 | end 79 | end 80 | 81 | # Module prefix seems to be necessary when called from gem installation. 82 | # Otherwise Config is somehow mixed up with RbConfig. 83 | config = TransmissionRSS::Config.instance 84 | 85 | # Initialize a log instance and configure it. 86 | log = Log.instance 87 | 88 | # Load config file (default or given by argument). 89 | begin 90 | config.load(config_file) 91 | log.target = config.log.target 92 | log.level = config.log.level 93 | rescue Errno::ENOENT 94 | log.error(config_file + ' not found') 95 | end 96 | 97 | # Unless a custom config is given as an argument from command line or HOME is 98 | # unset, check for user configuration and load if existing. 99 | if !(custom_config || ENV['HOME'].nil?) 100 | prefix = ENV['XDG_CONFIG_HOME'] || File.expand_path('~/.config') 101 | path = File.join(prefix, 'transmission-rss', 'config.yml') 102 | 103 | if File.exist?(path) 104 | log.debug('loading user config ' + path) 105 | config.load(path) 106 | end 107 | end 108 | 109 | # Print current config. 110 | log.info('transmission-rss ' + VERSION) 111 | log.debug(config) 112 | 113 | # Fork value from command line. 114 | config.fork = dofork if dofork 115 | 116 | # Run a single time. 117 | config.single = dosingle if dosingle 118 | 119 | # PID file path from command line. 120 | config.pid_file = pid_file if pid_file 121 | 122 | # Drop privileges, if section is given in config file. 123 | unless config.privileges.empty? 124 | Process::Sys.setgid \ 125 | Etc.getgrnam(config.privileges.group).gid 126 | 127 | Process::Sys.setuid \ 128 | Etc.getpwnam(config.privileges.user).uid 129 | 130 | log.debug \ 131 | 'dropped privileges ' + 132 | config.privileges.user + 133 | ':' + 134 | config.privileges.group 135 | else 136 | user = Etc.getpwuid(Process.euid).name 137 | log.debug('no privilege dropping, running as user ' + user) 138 | end 139 | 140 | # Warn if no feeds are given. 141 | log.warn('no feeds given') if config.feeds.empty? 142 | 143 | # Connect reload of config file to SIGHUP. 144 | trap 'HUP' do 145 | config.load(config_file) rescue nil 146 | end 147 | 148 | # Initialize feed aggregator. 149 | aggregator = Aggregator.new(config.feeds, seen_file: config.seen_file) 150 | 151 | if reset_seen_file 152 | aggregator.seen.clear! 153 | log.debug('seenfile reset') 154 | end 155 | 156 | # Initialize communication to transmission. 157 | client = Client.new(config.server, config.login, config.client) 158 | 159 | # Callback for a new item on one of the feeds. 160 | aggregator.on_new_item do |torrent_file, feed, download_path| 161 | client.add_torrent(torrent_file, :url, 162 | paused: config.add_paused, 163 | download_dir: download_path, 164 | seed_ratio_limit: feed.config.seed_ratio_limit) 165 | end 166 | 167 | # Callback for changes to the config. 168 | config.on_change do 169 | aggregator.reinitialize!(config.feeds, seen_file: config.seen_file) 170 | 171 | if reset_seen_file 172 | aggregator.seen.clear! 173 | log.debug('seenfile reset after config change') 174 | end 175 | end 176 | 177 | # Start the aggregation process. 178 | begin 179 | if config.fork 180 | pid = fork { aggregator.run(config.update_interval) } 181 | log.debug('forked ' + pid.to_s) 182 | 183 | # Save PID. 184 | if config.pid_file 185 | log.debug('wrote pid to ' + config.pid_file) 186 | File.write(config.pid_file, pid) 187 | end 188 | elsif config.single 189 | aggregator.run(-1) 190 | else 191 | log.debug('pid ' + Process.pid.to_s) 192 | 193 | # Save PID. 194 | if config.pid_file 195 | log.debug('wrote pid to ' + config.pid_file) 196 | File.write(config.pid_file, Process.pid) 197 | end 198 | 199 | aggregator.run(config.update_interval) 200 | end 201 | rescue Interrupt 202 | log.info('interrupt caught') 203 | end 204 | 205 | log.close 206 | -------------------------------------------------------------------------------- /contrib/transmission-rss.init.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: transmission-rss 4 | # Required-Start: $remote_fs $syslog 5 | # Required-Stop: $remote_fs $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Description: init.d script for transmission-rss 9 | ### END INIT INFO 10 | 11 | PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin 12 | DESC="transmission-rss daemon" 13 | NAME=transmission-rss 14 | DAEMON=/usr/local/bin/$NAME 15 | RUBY=$(which ruby) 16 | PIDFILE=/var/run/$NAME.pid 17 | SCRIPTNAME=/etc/init.d/$NAME 18 | 19 | [ -x "$DAEMON" ] || exit 0 20 | 21 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME 22 | 23 | . /lib/init/vars.sh 24 | 25 | . /lib/lsb/init-functions 26 | 27 | do_start() 28 | { 29 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ 30 | || return 1 31 | start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ 32 | || return 2 33 | } 34 | 35 | do_stop() 36 | { 37 | start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --exec $RUBY 38 | RETVAL="$?" 39 | [ "$RETVAL" = 2 ] && return 2 40 | start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $RUBY 41 | [ "$?" = 2 ] && return 2 42 | rm -f $PIDFILE 43 | return "$RETVAL" 44 | } 45 | 46 | case "$1" in 47 | start) 48 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" 49 | do_start 50 | case "$?" in 51 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 52 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 53 | esac 54 | ;; 55 | stop) 56 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" 57 | do_stop 58 | case "$?" in 59 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 60 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; 61 | esac 62 | ;; 63 | status) 64 | status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? 65 | ;; 66 | restart|force-reload) 67 | log_daemon_msg "Restarting $DESC" "$NAME" 68 | do_stop 69 | case "$?" in 70 | 0|1) 71 | do_start 72 | case "$?" in 73 | 0) log_end_msg 0 ;; 74 | 1) log_end_msg 1 ;; # Old process is still running 75 | *) log_end_msg 1 ;; # Failed to start 76 | esac 77 | ;; 78 | *) 79 | # Failed to stop 80 | log_end_msg 1 81 | ;; 82 | esac 83 | ;; 84 | *) 85 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 86 | exit 3 87 | ;; 88 | esac 89 | 90 | : 91 | -------------------------------------------------------------------------------- /contrib/transmission-rss.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Transmission RSS daemon. 3 | #After=transmission-daemon.service 4 | Wants=network-online.target 5 | 6 | [Service] 7 | Type=forking 8 | ExecStart=/usr/bin/transmission-rss -f 9 | ExecReload=/bin/kill -s HUP $MAINPID 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /lib/transmission-rss.rb: -------------------------------------------------------------------------------- 1 | $:.unshift(File.dirname(__FILE__)) 2 | 3 | module TransmissionRSS 4 | end 5 | 6 | require 'transmission-rss/core_ext/Array' 7 | require 'transmission-rss/core_ext/Object' 8 | require 'transmission-rss/core_ext/URI' 9 | 10 | Dir.glob($:.first + '/**/*.rb').each do |lib| 11 | require lib 12 | end 13 | -------------------------------------------------------------------------------- /lib/transmission-rss/aggregator.rb: -------------------------------------------------------------------------------- 1 | require 'open-uri' 2 | require 'open_uri_redirections' 3 | require 'rss' 4 | require 'openssl' 5 | 6 | libdir = File.dirname(__FILE__) 7 | require File.join(libdir, 'log') 8 | require File.join(libdir, 'callback') 9 | 10 | module TransmissionRSS 11 | # Class for aggregating torrent files through RSS feeds. 12 | class Aggregator 13 | extend Callback 14 | callback(:on_new_item) # Declare callback for new items. 15 | 16 | attr_reader :seen 17 | 18 | def initialize(feeds = [], options = {}) 19 | reinitialize!(feeds, options) 20 | end 21 | 22 | def reinitialize!(feeds = [], options = {}) 23 | seen_file = options[:seen_file] 24 | 25 | # Prepare Array of feeds URLs. 26 | @feeds = feeds.map { |config| TransmissionRSS::Feed.new(config) } 27 | 28 | # Nothing seen, yet. 29 | @seen = SeenFile.new(seen_file) 30 | 31 | # Initialize log instance. 32 | @log = Log.instance 33 | 34 | # Log number of +@seen+ URIs. 35 | @log.debug(@seen.size.to_s + ' uris from seenfile') 36 | end 37 | 38 | # Get file enclosures from all feeds items and call on_new_item callback 39 | # with torrent file URL as argument. 40 | def run(interval = 600) 41 | @log.debug('aggregator start') 42 | 43 | loop do 44 | @feeds.each do |feed| 45 | @log.debug('aggregate ' + feed.url) 46 | 47 | begin 48 | content = fetch(feed) 49 | rescue StandardError => e 50 | @log.debug("retrieval error (#{e.class}: #{e.message})") 51 | next 52 | end 53 | 54 | # gzip HTTP Content-Encoding is not automatically decompressed in 55 | # Ruby 1.9.3. 56 | content = decompress(content) if RUBY_VERSION == '1.9.3' 57 | begin 58 | items = parse(content) 59 | rescue StandardError => e 60 | @log.debug("parse error (#{e.class}: #{e.message})") 61 | next 62 | end 63 | 64 | items.each do |item| 65 | result = process_link(feed, item) 66 | next if result.nil? 67 | end 68 | end 69 | 70 | if interval == -1 71 | @log.debug('single run mode, exiting') 72 | break 73 | end 74 | 75 | sleep(interval) 76 | end 77 | end 78 | 79 | private 80 | 81 | def fetch(feed) 82 | options = { 83 | allow_redirections: :safe, 84 | 'User-Agent' => 'transmission-rss' 85 | } 86 | 87 | unless feed.validate_cert 88 | @log.debug('aggregate certificate validation: false') 89 | options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE 90 | end 91 | 92 | # open for URIs is obsolete, URI.open does not work in 2.4 93 | URI.send(:open, feed.url, options).read 94 | end 95 | 96 | def parse(content) 97 | RSS::Parser.parse(content, false).items 98 | end 99 | 100 | def decompress(string) 101 | Zlib::GzipReader.new(StringIO.new(string)).read 102 | rescue Zlib::GzipFile::Error, Zlib::Error 103 | string 104 | end 105 | 106 | def process_link(feed, item) 107 | link = item.enclosure.url rescue item.link 108 | 109 | # Item contains no link. 110 | return if link.nil? 111 | 112 | # Link is not a String directly. 113 | link = link.href if link.class != String 114 | 115 | # Determine whether to use guid or link as seen hash 116 | seen_value = feed.seen_by_guid ? (item.guid.content rescue item.guid || link).to_s : link 117 | 118 | # The link is not in +@seen+ Array. 119 | unless @seen.include?(seen_value) 120 | # Skip if filter defined and not matching. 121 | unless feed.matches_regexp?(item.title) && !feed.exclude?(item.title) 122 | @seen.add(seen_value) 123 | return 124 | end 125 | 126 | @log.debug('on_new_item event ' + link) 127 | 128 | download_path = feed.download_path(item.title) 129 | 130 | begin 131 | if feed.delay_time > 0 132 | @log.debug("sleeping for #{feed.delay_time} seconds...") 133 | sleep(feed.delay_time) 134 | end 135 | on_new_item(link, feed, download_path) 136 | rescue Client::TooManyRequests 137 | @log.debug('TooManyRequests: Consider adding delay_time to this feed.') 138 | rescue Client::Unauthorized, Errno::ECONNREFUSED, Timeout::Error 139 | @log.debug('not added to seen file ' + link) 140 | else 141 | @seen.add(seen_value) 142 | end 143 | end 144 | 145 | return link 146 | end 147 | end 148 | end 149 | -------------------------------------------------------------------------------- /lib/transmission-rss/callback.rb: -------------------------------------------------------------------------------- 1 | module TransmissionRSS 2 | module Callback 3 | # Define callback method. 4 | def callback(*names) 5 | names.each do |name| 6 | self.class_eval do 7 | define_method name, ->(*args, &block) do 8 | @callbacks ||= {} 9 | if block 10 | @callbacks[name] = block 11 | elsif @callbacks[name] 12 | @callbacks[name].call(*args) 13 | end 14 | end 15 | end 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/transmission-rss/client.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'json' 3 | require 'base64' 4 | 5 | require File.join(File.dirname(__FILE__), 'log') 6 | 7 | module TransmissionRSS 8 | # Class for communication with transmission utilizing the RPC web interface. 9 | class Client 10 | OPTIONS = [:paused, :download_dir] 11 | 12 | class Unauthorized < StandardError 13 | end 14 | 15 | class TooManyRequests < StandardError 16 | end 17 | 18 | def initialize(server = {}, login = nil, options = {}) 19 | options ||= {} 20 | 21 | @host = server.host || 'localhost' 22 | @port = server.port || 9091 23 | @tls = !!server.tls 24 | @rpc_path = server.rpc_path || '/transmission/rpc' 25 | @login = login 26 | 27 | @timeout = options.timeout || 5 28 | @log = TransmissionRSS::Log.instance 29 | end 30 | 31 | def rpc(method, arguments) 32 | sid = get_session_id 33 | raise Unauthorized unless sid 34 | 35 | post = Net::HTTP::Post.new \ 36 | @rpc_path, 37 | { 38 | 'Content-Type' => 'application/json', 39 | 'X-Transmission-Session-Id' => sid 40 | } 41 | 42 | add_basic_auth(post) 43 | post.body = {method: method, arguments: arguments}.to_json 44 | 45 | response = JSON.parse(request(post).body) 46 | 47 | if response.result.include? "(429)" 48 | raise TooManyRequests 49 | end 50 | 51 | response 52 | end 53 | 54 | # POST json packed torrent add command. 55 | def add_torrent(file, type = :url, options = {}) 56 | arguments = set_arguments_from_options(options) 57 | 58 | case type 59 | when :url 60 | file = URI.escape(file) if URI.unescape(file) == file 61 | arguments.filename = file 62 | when :file 63 | arguments.metainfo = Base64.encode64(File.read(file)) 64 | else 65 | raise ArgumentError.new('type has to be :url or :file.') 66 | end 67 | 68 | response = rpc('torrent-add', arguments) 69 | id = get_id_from_response(response) 70 | 71 | log_message = 'torrent-add result: ' + response.result 72 | log_message << ' (id ' + id.to_s + ')' if id 73 | @log.debug(log_message) 74 | 75 | if id && options[:seed_ratio_limit] 76 | if options[:seed_ratio_limit].to_f < 0 77 | set_torrent(id, { 78 | 'seedRatioMode' => 2 79 | }) 80 | else 81 | set_torrent(id, { 82 | 'seedRatioLimit' => options[:seed_ratio_limit].to_f, 83 | 'seedRatioMode' => 1 84 | }) 85 | end 86 | end 87 | 88 | response 89 | end 90 | 91 | def set_torrent(id, arguments = {}) 92 | arguments.ids = [id] 93 | response = rpc('torrent-set', arguments) 94 | @log.debug('torrent-set result: ' + response.result) 95 | 96 | response 97 | end 98 | 99 | # Get transmission session id. 100 | def get_session_id 101 | get = Net::HTTP::Get.new(@rpc_path) 102 | 103 | add_basic_auth(get) 104 | 105 | response = request(get) 106 | 107 | id = response.header['x-transmission-session-id'] 108 | 109 | if id.nil? 110 | @log.debug("could not obtain session id (#{response.code}, " + 111 | "#{response.class})") 112 | else 113 | @log.debug('got session id ' + id) 114 | end 115 | 116 | id 117 | end 118 | 119 | private 120 | 121 | def add_basic_auth(request) 122 | return if @login.nil? 123 | request.basic_auth(@login['username'], @login['password']) 124 | end 125 | 126 | def get_id_from_response(response) 127 | response.arguments.first.last.id 128 | rescue 129 | end 130 | 131 | def http_request(data) 132 | Net::HTTP.start(@host, @port, use_ssl: @tls) do |http| 133 | http.request(data) 134 | end 135 | end 136 | 137 | def request(data) 138 | c ||= 0 139 | 140 | Timeout.timeout(@timeout) do 141 | @log.debug("request #@host:#@port") 142 | http_request(data) 143 | end 144 | rescue Errno::ECONNREFUSED 145 | @log.debug('connection refused') 146 | raise 147 | rescue Timeout::Error 148 | s = 'connection timeout' 149 | s << " (retry #{c})" if c > 0 150 | @log.debug(s) 151 | 152 | c += 1 153 | retry unless c > 2 154 | 155 | raise 156 | end 157 | 158 | def set_arguments_from_options(options) 159 | arguments = {} 160 | 161 | OPTIONS.each do |o| 162 | unless options[o].nil? 163 | arguments[o.to_s.sub('_', '-')] = options[o] 164 | end 165 | end 166 | 167 | arguments 168 | end 169 | end 170 | end 171 | -------------------------------------------------------------------------------- /lib/transmission-rss/config.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | require 'rb-inotify' if linux? 3 | require 'singleton' 4 | require 'yaml' 5 | 6 | libdir = File.dirname(__FILE__) 7 | require File.join(libdir, 'log') 8 | require File.join(libdir, 'callback') 9 | 10 | module TransmissionRSS 11 | DEPRECATED = { 12 | log_target: 'log.target' 13 | } 14 | 15 | # Class handles configuration parameters. 16 | class Config < Hash 17 | # This is a singleton class. 18 | include Singleton 19 | 20 | extend Callback 21 | callback(:on_change) # Declare callback for changed config. 22 | 23 | def initialize(file = nil) 24 | self.merge_defaults! 25 | self.load(file) unless file.nil? 26 | 27 | @log = Log.instance 28 | end 29 | 30 | # Merges a Hash or YAML file (containing a Hash) with itself. 31 | def load(config, watch: true) 32 | case config.class.to_s 33 | when 'Hash' 34 | self.merge!(config) 35 | when 'String' 36 | self.merge_yaml!(config, watch) 37 | else 38 | raise ArgumentError.new('Could not load config.') 39 | end 40 | 41 | check_deprecated 42 | check_warnings 43 | 44 | self 45 | end 46 | 47 | def merge_defaults! 48 | self.merge!({ 49 | 'feeds' => [], 50 | 'update_interval' => 600, 51 | 'add_paused' => false, 52 | 'server' => { 53 | 'host' => 'localhost', 54 | 'port' => 9091, 55 | 'tls' => false, 56 | 'rpc_path' => '/transmission/rpc' 57 | }, 58 | 'login' => nil, 59 | 'log' => { 60 | 'target' => $stderr, 61 | 'level' => :debug 62 | }, 63 | 'fork' => false, 64 | 'single' => false, 65 | 'pid_file' => false, 66 | 'privileges' => {}, 67 | 'seen_file' => nil 68 | }) 69 | end 70 | 71 | # Merge Config Hash with Hash from YAML file. 72 | def merge_yaml!(path, watch = true) 73 | self.merge!(YAML.load_file(path)) 74 | rescue TypeError 75 | # If YAML loading fails, .load_file returns `false`. 76 | else 77 | watch_file(path) if watch && linux? 78 | end 79 | 80 | def reset! 81 | self.clear 82 | self.merge_defaults! 83 | end 84 | 85 | def watch_file(path) 86 | path = Pathname.new(path).realpath.to_s 87 | 88 | @notifier ||= INotify::Notifier.new 89 | @notifier.watch(path, :close_write) do |e| 90 | self.reset! 91 | self.merge_yaml!(path, false) 92 | 93 | @log.debug('reloaded config file ' + path) 94 | @log.debug(self) 95 | 96 | on_change 97 | end 98 | 99 | @notifier_thread ||= Thread.start do 100 | @notifier.run 101 | end 102 | end 103 | 104 | private 105 | 106 | def check_deprecated 107 | warnings = false 108 | 109 | DEPRECATED.each do |key, value| 110 | if self[key.to_s] 111 | @log.warn('[DEPRECATED] option %s, use %s' % [key, value]) 112 | warnings = true 113 | end 114 | end 115 | 116 | warnings 117 | end 118 | 119 | def check_warnings 120 | return false unless self['feeds'] 121 | 122 | warnings = false 123 | 124 | urls = self['feeds'].map { |feed| feed['url'] } 125 | urls.duplicates.each do |duplicate| 126 | @log.warn('Duplicate URL definition: %s' % duplicate) 127 | warnings = true 128 | end 129 | 130 | warnings 131 | end 132 | end 133 | end 134 | -------------------------------------------------------------------------------- /lib/transmission-rss/core_ext/Array.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | def duplicates 3 | self.group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/transmission-rss/core_ext/Hash.rb: -------------------------------------------------------------------------------- 1 | class Hash 2 | # If a method is missing it is interpreted as the key of the hash. If the 3 | # method has an argument (for example by "method="), the key called "method" 4 | # is set to the respective argument. 5 | def method_missing(symbol, *args) 6 | if args.size == 0 7 | self[symbol.to_s] 8 | else 9 | self[symbol.to_s.slice 0..-2] = args.first 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/transmission-rss/core_ext/Object.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | def bsd? 3 | RUBY_PLATFORM.include?('bsd') 4 | end 5 | 6 | def linux? 7 | RUBY_PLATFORM.downcase.include?('linux') 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/transmission-rss/core_ext/URI.rb: -------------------------------------------------------------------------------- 1 | module URI 2 | def self.escape(*arg) 3 | URI::DEFAULT_PARSER.escape(*arg) 4 | end 5 | 6 | def self.unescape(*arg) 7 | URI::DEFAULT_PARSER.unescape(*arg) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/transmission-rss/feed.rb: -------------------------------------------------------------------------------- 1 | module TransmissionRSS 2 | class Feed 3 | attr_reader :url, :regexp, :config, :validate_cert, :seen_by_guid, :delay_time 4 | 5 | def initialize(config = {}) 6 | @download_paths = {} 7 | @excludes = {} 8 | 9 | case config 10 | when Hash 11 | @config = config 12 | 13 | @url = URI.escape(URI.unescape(config['url'] || config.keys.first)) 14 | 15 | @download_path = config['download_path'] 16 | 17 | matchers = Array(config['regexp']).map do |e| 18 | e.is_a?(String) ? e : e['matcher'] 19 | end 20 | 21 | @regexp = build_regexp(matchers) 22 | 23 | initialize_download_paths_and_excludes(config['regexp']) 24 | else 25 | @config = {} 26 | @url = config.to_s 27 | end 28 | 29 | @validate_cert = @config['validate_cert'].nil? || !!@config['validate_cert'] 30 | @seen_by_guid = !!@config['seen_by_guid'] 31 | @delay_time = 0 32 | if !@config['delay_time'].nil? 33 | @delay_time = @config['delay_time'] 34 | end 35 | end 36 | 37 | def download_path(title = nil) 38 | return @download_path if title.nil? 39 | 40 | @download_paths.each do |regexp, path| 41 | return path if title =~ to_regexp(regexp) 42 | end 43 | 44 | @download_path 45 | end 46 | 47 | def matches_regexp?(title) 48 | @regexp.nil? || !(title =~ @regexp).nil? 49 | end 50 | 51 | def exclude?(title) 52 | @excludes.each do |regexp, exclude| 53 | return true if title =~ to_regexp(exclude) 54 | end 55 | 56 | return false 57 | end 58 | 59 | private 60 | 61 | def build_regexp(matchers) 62 | matchers = Array(matchers).map { |m| to_regexp(m) } 63 | matchers.empty? ? nil : Regexp.union(matchers) 64 | end 65 | 66 | def initialize_download_paths_and_excludes(regexps) 67 | return unless regexps.is_a?(Array) 68 | 69 | regexps.each do |regexp| 70 | matcher = regexp['matcher'] 71 | path = regexp['download_path'] 72 | exclude = regexp['exclude'] 73 | 74 | @download_paths[matcher] = path if matcher && path 75 | @excludes[matcher] = exclude if matcher && exclude 76 | end 77 | end 78 | 79 | def to_regexp(s) 80 | Regexp.new(s, Regexp::IGNORECASE) 81 | end 82 | end 83 | end 84 | -------------------------------------------------------------------------------- /lib/transmission-rss/log.rb: -------------------------------------------------------------------------------- 1 | require 'logger' 2 | require 'singleton' 3 | 4 | module TransmissionRSS 5 | # Encapsulates Logger as a singleton class. 6 | class Log 7 | include Singleton 8 | 9 | def initialize(target = $stderr, level = :debug) 10 | @target = target 11 | @level = level 12 | 13 | @logger = Logger.new(target) 14 | @logger.level = to_level_const(level) 15 | @logger.formatter = proc do |sev, time, _, msg| 16 | time = time.strftime('%Y-%m-%d %H:%M:%S') 17 | "#{time} (#{sev.downcase}) #{msg}\n" 18 | end 19 | end 20 | 21 | # Change log target (IO, path to a file as String, or Symbol for IO 22 | # constant). 23 | def target=(target) 24 | if target.is_a? Symbol 25 | target = Object.const_get(target.to_s.upcase) 26 | end 27 | 28 | initialize(target, @level) 29 | end 30 | 31 | # Change log level (String or Symbol) 32 | def level=(level) 33 | initialize(@target, level) 34 | end 35 | 36 | # If this class misses a method, call it on the encapsulated Logger class. 37 | def method_missing(sym, *args) 38 | @logger.send(sym, *args) 39 | end 40 | 41 | private 42 | 43 | def to_level_const(level) 44 | Object.const_get('Logger::' + level.to_s.upcase) 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/transmission-rss/seen_file.rb: -------------------------------------------------------------------------------- 1 | require 'digest' 2 | require 'etc' 3 | require 'fileutils' 4 | require 'forwardable' 5 | 6 | module TransmissionRSS 7 | # Persist seen torrent URLs 8 | class SeenFile 9 | extend ::Forwardable 10 | 11 | def_delegators :@seen, :size, :to_a 12 | 13 | def initialize(path = nil) 14 | @path = path || default_path 15 | initialize_path!(@path) 16 | 17 | @seen = Set.new(file_to_array(@path)) 18 | end 19 | 20 | def add(url) 21 | hash = digest(url) 22 | 23 | return if @seen.include?(hash) 24 | 25 | @seen << hash 26 | 27 | open(@path, 'a') do |f| 28 | f.write(hash + "\n") 29 | end 30 | end 31 | 32 | def clear! 33 | @seen.clear 34 | open(@path, 'w') {} 35 | end 36 | 37 | def include?(url) 38 | @seen.include?(digest(url)) 39 | end 40 | 41 | private 42 | 43 | def default_path 44 | File.join(Etc.getpwuid.dir, '.config/transmission/seen') 45 | end 46 | 47 | def digest(s) 48 | Digest::SHA256.hexdigest(s) 49 | end 50 | 51 | def file_to_array(path) 52 | open(path, 'r').readlines.map(&:chomp) 53 | end 54 | 55 | def initialize_path!(path) 56 | return if File.exist?(path) 57 | 58 | FileUtils.mkdir_p(File.dirname(path)) 59 | FileUtils.touch(path) 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /lib/transmission-rss/version.rb: -------------------------------------------------------------------------------- 1 | module TransmissionRSS 2 | VERSION = '1.3.0.pre' 3 | end 4 | -------------------------------------------------------------------------------- /log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nning/transmission-rss/7082d51c4577d4e96e7e09314d00f7bb9a936fd4/log/.gitkeep -------------------------------------------------------------------------------- /spec/aggregator_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Aggregator do 4 | SEEN_FILE = tmp_path(:seen_file) 5 | FEEDS = [ 6 | Feed.new('https://www.archlinux.org/feeds/releases/') 7 | ] 8 | 9 | subject do 10 | Aggregator.new(FEEDS, seen_file: SEEN_FILE) 11 | end 12 | 13 | after(:all) do 14 | FileUtils.rm_f(SEEN_FILE) 15 | end 16 | 17 | describe '#fetch' do 18 | it 'returns content' do 19 | VCR.use_cassette('feed_fetch', MATCH_REQUESTS_ON) do 20 | content = subject.send(:fetch, FEEDS.first) 21 | 22 | expect(content).not_to be_empty 23 | expect(content.size).to eq(1725) 24 | end 25 | end 26 | end 27 | 28 | describe '#parse' do 29 | it 'returns content' do 30 | VCR.use_cassette('feed_fetch', MATCH_REQUESTS_ON) do 31 | content = subject.send(:parse, subject.send(:fetch, FEEDS.first)) 32 | 33 | expect(content.size).to eq(3) 34 | 35 | description_matches = content 36 | .map(&:title) 37 | .map { |x| x =~ /^[0-9]{4}\.[0-9]{2}\.[0-9]{2}/ } 38 | .uniq 39 | 40 | expect(description_matches).to eq([0]) 41 | 42 | urls = content.map(&:enclosure).map(&:url) 43 | 44 | urls.each do |url| 45 | url = URI.parse(url) 46 | 47 | expect(url.scheme).to eq('https') 48 | expect(url.host).to eq('www.archlinux.org') 49 | expect(File.basename(url.path)).to match(/\.iso\.torrent$/) 50 | end 51 | end 52 | end 53 | end 54 | 55 | describe '#process_link' do 56 | before(:each) do 57 | VCR.use_cassette('feed_fetch', MATCH_REQUESTS_ON) do 58 | @item = subject.send(:parse, subject.send(:fetch, FEEDS.first)).first 59 | subject.seen.clear! 60 | end 61 | end 62 | 63 | it 'returns enclosure url and adds url to seen' do 64 | content = subject.send(:process_link, FEEDS.first, @item) 65 | 66 | url = URI.parse(content) 67 | 68 | expect(url.scheme).to eq('https') 69 | expect(url.host).to eq('www.archlinux.org') 70 | expect(File.basename(url.path)).to match(/\.iso\.torrent$/) 71 | 72 | expect(subject.seen.size).to eq(1) 73 | expect(subject.seen.include?(@item.enclosure.url)).to be true 74 | end 75 | 76 | it 'returns link and adds link to seen if no enclosure url' do 77 | @item.enclosure = nil 78 | 79 | content = subject.send(:process_link, FEEDS.first, @item) 80 | 81 | url = URI.parse(content) 82 | expect(url.scheme).to eq('https') 83 | expect(url.host).to eq('www.archlinux.org') 84 | expect(File.basename(url.path)).to match(/2020\.01\.01$/) 85 | 86 | expect(subject.seen.size).to eq(1) 87 | expect(subject.seen.include?(@item.link)).to be true 88 | end 89 | 90 | it 'returns nil if no link or enclosure url' do 91 | @item.enclosure = nil 92 | @item.link = nil 93 | 94 | content = subject.send(:process_link, FEEDS.first, @item) 95 | 96 | expect(content).to be_nil 97 | 98 | expect(subject.seen.size).to eq(0) 99 | end 100 | 101 | it 'returns nil but adds url to seen if unseen but no regexp match' do 102 | feed = Feed.new({ 103 | 'url' => FEEDS.first.url, 104 | 'regexp' => 'WILL_NOT_MATCH$' 105 | }) 106 | 107 | content = subject.send(:process_link, feed, @item) 108 | 109 | expect(content).to be_nil 110 | 111 | expect(subject.seen.size).to eq(1) 112 | expect(subject.seen.include?(@item.enclosure.url)).to be true 113 | end 114 | 115 | it 'returns enclosure url and adds guid to seen if seen_by_guid' do 116 | feed = Feed.new({ 117 | 'url' => FEEDS.first.url, 118 | 'seen_by_guid' => true 119 | }) 120 | 121 | content = subject.send(:process_link, feed, @item) 122 | 123 | url = URI.parse(content) 124 | expect(url.scheme).to eq('https') 125 | expect(url.host).to eq('www.archlinux.org') 126 | expect(File.basename(url.path)).to match(/\.iso\.torrent$/) 127 | 128 | expect(subject.seen.size).to eq(1) 129 | expect(subject.seen.include?(@item.guid.content.to_s)).to be true 130 | end 131 | 132 | it 'returns link and adds guid to seen if seen_by_guid but no enclosure url' do 133 | feed = Feed.new({ 134 | 'url' => FEEDS.first.url, 135 | 'seen_by_guid' => true 136 | }) 137 | @item.enclosure = nil 138 | 139 | content = subject.send(:process_link, feed, @item) 140 | 141 | url = URI.parse(content) 142 | expect(url.scheme).to eq('https') 143 | expect(url.host).to eq('www.archlinux.org') 144 | expect(File.basename(url.path)).to match(/2020\.01\.01$/) 145 | 146 | expect(subject.seen.size).to eq(1) 147 | expect(subject.seen.include?(@item.guid.content.to_s)).to be true 148 | end 149 | 150 | it 'returns enclosure url and adds url to seen if seen_by_guid but no guid' do 151 | feed = Feed.new({ 152 | 'url' => FEEDS.first.url, 153 | 'seen_by_guid' => true 154 | }) 155 | @item.guid = nil 156 | 157 | content = subject.send(:process_link, feed, @item) 158 | 159 | expect(content).not_to be_empty 160 | 161 | expect(subject.seen.size).to eq(1) 162 | expect(subject.seen.include?(@item.enclosure.url)).to be true 163 | end 164 | 165 | it 'returns link and adds link to seen if seen_by_guid but no guid' do 166 | feed = Feed.new({ 167 | 'url' => FEEDS.first.url, 168 | 'seen_by_guid' => true 169 | }) 170 | @item.enclosure = nil 171 | @item.guid = nil 172 | 173 | content = subject.send(:process_link, feed, @item) 174 | 175 | expect(content).not_to be_empty 176 | 177 | expect(subject.seen.size).to eq(1) 178 | expect(subject.seen.include?(@item.link)).to be true 179 | end 180 | 181 | it 'returns enclosure url and adds guid to seen if seen_by_guid but guid has no attributes' do 182 | feed = Feed.new({ 183 | 'url' => FEEDS.first.url, 184 | 'seen_by_guid' => true 185 | }) 186 | @item.guid = @item.guid.content 187 | 188 | content = subject.send(:process_link, feed, @item) 189 | 190 | expect(content).not_to be_empty 191 | 192 | expect(subject.seen.size).to eq(1) 193 | expect(subject.seen.include?(@item.guid)).to be true 194 | end 195 | 196 | it 'returns link and adds guid to seen if seen_by_guid but no enclosure link and guid has no attributes' do 197 | feed = Feed.new({ 198 | 'url' => FEEDS.first.url, 199 | 'seen_by_guid' => true 200 | }) 201 | @item.enclosure = nil 202 | @item.guid = @item.guid.content 203 | 204 | content = subject.send(:process_link, feed, @item) 205 | 206 | expect(content).not_to be_empty 207 | 208 | expect(subject.seen.size).to eq(1) 209 | expect(subject.seen.include?(@item.guid)).to be true 210 | end 211 | 212 | it 'returns nil but adds to seen if seen_by_guid and unseen but no regexp match' do 213 | feed = Feed.new({ 214 | 'url' => FEEDS.first.url, 215 | 'regexp' => 'WILL_NOT_MATCH$', 216 | 'seen_by_guid' => true 217 | }) 218 | 219 | content = subject.send(:process_link, feed, @item) 220 | 221 | expect(content).to be_nil 222 | 223 | expect(subject.seen.size).to eq(1) 224 | expect(subject.seen.include?(@item.guid.content)).to be true 225 | end 226 | 227 | it 'calls on_new_item when returning link and adding to seen' do 228 | on_new_item_args = nil 229 | subject.on_new_item do | arg1, arg2, arg3 | 230 | on_new_item_args = Hash[binding.local_variables.map{|x| [x, binding.local_variable_get(x)]}] 231 | end 232 | 233 | content = subject.send(:process_link, FEEDS.first, @item) 234 | 235 | expect(on_new_item_args).not_to be_nil 236 | expect(on_new_item_args[:arg1]).to eq(@item.enclosure.url) 237 | expect(on_new_item_args[:arg2]).to be(FEEDS.first) 238 | expect(on_new_item_args[:arg3]).to be_nil 239 | 240 | expect(subject.seen.size).to eq(1) 241 | expect(subject.seen.include?(@item.enclosure.url)).to be true 242 | end 243 | 244 | it 'calls on_new_item with download_path when download_path set on feed' do 245 | on_new_item_args = nil 246 | subject.on_new_item do | arg1, arg2, arg3 | 247 | on_new_item_args = Hash[binding.local_variables.map{|x| [x, binding.local_variable_get(x)]}] 248 | end 249 | feed = Feed.new({ 250 | 'url' => FEEDS.first.url, 251 | 'download_path' => '/tmp' 252 | }) 253 | 254 | content = subject.send(:process_link, feed, @item) 255 | 256 | expect(on_new_item_args).not_to be_nil 257 | expect(on_new_item_args[:arg1]).to eq(@item.enclosure.url) 258 | expect(on_new_item_args[:arg2]).to be(feed) 259 | expect(on_new_item_args[:arg3]).to eq('/tmp') 260 | 261 | expect(subject.seen.size).to eq(1) 262 | expect(subject.seen.include?(@item.enclosure.url)).to be true 263 | end 264 | 265 | it 'calls on_new_item with download_path from regexp when matching' do 266 | on_new_item_args = nil 267 | subject.on_new_item do | arg1, arg2, arg3 | 268 | on_new_item_args = Hash[binding.local_variables.map{|x| [x, binding.local_variable_get(x)]}] 269 | end 270 | feed = Feed.new({ 271 | 'url' => FEEDS.first.url, 272 | 'regexp' => [{'matcher' => '.+', 'download_path' => '/tmp/foo'}] 273 | }) 274 | 275 | content = subject.send(:process_link, feed, @item) 276 | 277 | expect(on_new_item_args).not_to be_nil 278 | expect(on_new_item_args[:arg1]).to eq(@item.enclosure.url) 279 | expect(on_new_item_args[:arg2]).to be(feed) 280 | expect(on_new_item_args[:arg3]).to eq('/tmp/foo') 281 | 282 | expect(subject.seen.size).to eq(1) 283 | expect(subject.seen.include?(@item.enclosure.url)).to be true 284 | end 285 | 286 | [Client::Unauthorized, Errno::ECONNREFUSED, Timeout::Error].each { | err | 287 | it "does not add to seen when on_new_item throws #{err}" do 288 | subject.on_new_item do 289 | raise err.new "Test #{err}" 290 | end 291 | 292 | content = subject.send(:process_link, FEEDS.first, @item) 293 | 294 | expect(subject.seen.size).to eq(0) 295 | end 296 | } 297 | end 298 | end 299 | -------------------------------------------------------------------------------- /spec/callback_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Callback do 4 | before do 5 | class TestDummy 6 | extend Callback 7 | callback :test_callback 8 | 9 | attr_accessor :state 10 | 11 | def go! 12 | test_callback 13 | end 14 | end 15 | end 16 | 17 | describe '#callback' do 18 | before do 19 | @dummy = TestDummy.new 20 | @dummy.test_callback do 21 | @dummy.state = 1 22 | end 23 | @dummy.go! 24 | end 25 | 26 | it 'should be called' do 27 | expect(@dummy.state).to eq(1) 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /spec/client_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Client do 4 | let!(:magnet_link) { 'magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce' } 5 | let!(:http_url) { 'https://nning.io/Sin Tel.torrent' } 6 | 7 | describe '#session_id' do 8 | it 'returns valid session id' do 9 | VCR.use_cassette('session_id', MATCH_REQUESTS_ON) do 10 | id = Client.new.get_session_id 11 | expect(id.class).to eq(String) 12 | expect(id.size).to eq(48) 13 | end 14 | end 15 | 16 | [[Errno::ECONNREFUSED, 1], [Timeout::Error, 3]].each do |error, n| 17 | it 'should raise ' + error.to_s do 18 | c = Client.new 19 | expect(c).to receive(:http_request).exactly(n).times.and_raise(error) 20 | expect { c.get_session_id }.to raise_exception(error) 21 | end 22 | end 23 | end 24 | 25 | describe '#add_torrent' do 26 | it 'adds magnet link' do 27 | VCR.use_cassette('add_torrent', MATCH_REQUESTS_ON) do 28 | response = Client.new.add_torrent(magnet_link) 29 | expect(response.result).to eq('success') 30 | end 31 | end 32 | 33 | it 'adds magnet link with download dir option' do 34 | VCR.use_cassette('add_torrent_download_dir', MATCH_REQUESTS_ON) do 35 | response = Client.new.add_torrent(magnet_link, :url, download_dir: '/tmp') 36 | expect(response.result).to eq('success') 37 | end 38 | end 39 | 40 | it 'adds magnet link with paused option' do 41 | VCR.use_cassette('add_torrent_paused', MATCH_REQUESTS_ON) do 42 | response = Client.new.add_torrent(magnet_link, :url, paused: true) 43 | expect(response.result).to eq('success') 44 | end 45 | end 46 | 47 | it 'adds magnet link using alternative port' do 48 | VCR.use_cassette('add_torrent_alt_port', MATCH_REQUESTS_ON) do 49 | response = Client.new({'port' => 8081}).add_torrent(magnet_link) 50 | expect(response.result).to eq('success') 51 | end 52 | end 53 | 54 | it 'adds magnet link with seed ratio' do 55 | VCR.use_cassette('add_torrent_with_ratio', MATCH_REQUESTS_ON) do 56 | response = Client.new.add_torrent(magnet_link, :url, seed_ratio_limit: 1) 57 | expect(response.result).to eq('success') 58 | end 59 | end 60 | 61 | it 'adds http URL with special characters' do 62 | VCR.use_cassette('add_torrent_via_http_with_special_chars', MATCH_REQUESTS_ON) do 63 | response = Client.new.add_torrent(http_url, :url) 64 | expect(response.result).to eq('success') 65 | end 66 | 67 | VCR.use_cassette('add_torrent_via_http_with_special_chars', MATCH_REQUESTS_ON) do 68 | response = Client.new.add_torrent(URI.escape(http_url), :url) 69 | expect(response.result).to eq('success') 70 | end 71 | end 72 | 73 | it 'should raise TooManyRequests' do 74 | VCR.use_cassette('add_torrent_too_many_requests', MATCH_REQUESTS_ON) do 75 | expect { Client.new.add_torrent(magnet_link) }.to raise_exception(Client::TooManyRequests) 76 | end 77 | end 78 | end 79 | 80 | describe '#set_torrent' do 81 | it 'sets ratio limit' do 82 | VCR.use_cassette('set_torrent', MATCH_REQUESTS_ON) do 83 | response = Client.new.set_torrent(18, { 84 | 'seedRatioLimit' => 1, 85 | 'seedRatioMode' => 1 86 | }) 87 | 88 | expect(response.result).to eq('success') 89 | end 90 | end 91 | end 92 | end 93 | -------------------------------------------------------------------------------- /spec/config_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe TransmissionRSS::Config do 4 | describe '#load' do 5 | before do 6 | @config = TransmissionRSS::Config.instance 7 | @config.clear # Remove defaults for now. 8 | @hash = {'a' => 1, 'b' => [2, 3], 'c' => {'d' => 4}} 9 | end 10 | 11 | it 'should raise on wrong argument' do 12 | [nil, 1, []].each do |item| 13 | expect { @config.load(item) }.to raise_exception(ArgumentError) 14 | end 15 | end 16 | 17 | it 'should warn on deprecated options' do 18 | expect(@config.send(:check_deprecated)).to be false 19 | 20 | @config.load(YAML.load("log_target: 1")) 21 | expect(@config.send(:check_deprecated)).to be true 22 | end 23 | 24 | it 'should warn on duplicate urls' do 25 | expect(@config.send(:check_warnings)).to be false 26 | 27 | @config.load(YAML.load(" 28 | feeds: 29 | - url: http://example.com 30 | - url: http://example.com 31 | ")) 32 | 33 | expect(@config.send(:check_warnings)).to be true 34 | end 35 | 36 | describe 'hash' do 37 | before do 38 | @config.load(@hash) 39 | end 40 | 41 | it 'should merge' do 42 | expect(@config).to eq(@hash) 43 | end 44 | 45 | it 'should get values' do 46 | @hash.keys.each do |x| 47 | expect(@config.send(x.to_sym)).to eq(@hash[x]) 48 | end 49 | end 50 | 51 | it 'should set value' do 52 | @config.a = 2 53 | expect(@config.a).to eq(2) 54 | end 55 | 56 | it 'should clear' do 57 | @config.clear 58 | expect(@config).to eq({}) 59 | end 60 | end 61 | 62 | describe 'yaml' do 63 | before do 64 | @path = '/tmp/transmission-rss-config-test.yml' 65 | File.write(@path, @hash.to_yaml) 66 | @config.load(@path, watch: false) 67 | end 68 | 69 | it 'should merge' do 70 | expect(@config).to eq(@hash) 71 | end 72 | 73 | after do 74 | File.delete(@path) 75 | end 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /spec/feed_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Feed do 4 | before do 5 | @url = 'http://site.com/rss' 6 | @encoded_url = { 'url' => 'http://site.com/rss?name=name%20with%20empty%20space' } 7 | @download_path = '~/files' 8 | @matcher = '.*\\.pdf' 9 | @regexp = /.*\.pdf/i 10 | end 11 | 12 | it 'should be parse simple array format' do 13 | feed = Feed.new(@url) 14 | expect(feed.url).to eq(@url) 15 | expect(feed.config).not_to be_nil 16 | expect(feed.download_path).to be_nil 17 | expect(feed.regexp).to be_nil 18 | expect(feed.validate_cert).to eq(true) 19 | expect(feed.seen_by_guid).to eq(false) 20 | end 21 | 22 | it 'should be able to parse encoded url' do 23 | feed = Feed.new(@encoded_url) 24 | expect(feed.url).to eq(@encoded_url['url']) 25 | end 26 | 27 | it 'should be able to parse old style hash with no options' do 28 | feed = Feed.new({@url => nil}) 29 | expect(feed.url).to eq(@url) 30 | expect(feed.download_path).to be_nil 31 | expect(feed.regexp).to be_nil 32 | expect(feed.validate_cert).to eq(true) 33 | expect(feed.seen_by_guid).to eq(false) 34 | end 35 | 36 | it 'should be able to parse old style with all options' do 37 | feed = Feed.new({@url => nil, 'download_path' => @download_path, 'regexp' => @matcher, 'validate_cert' => true, 'seen_by_guid' => false}) 38 | expect(feed.url).to eq(@url) 39 | expect(feed.download_path).to eq(@download_path) 40 | expect(feed.regexp).to eq(@regexp) 41 | expect(feed.validate_cert).to eq(true) 42 | expect(feed.seen_by_guid).to eq(false) 43 | end 44 | 45 | it 'should be able to use new style config with no options' do 46 | feed = Feed.new({'url' => @url}) 47 | expect(feed.url).to eq(@url) 48 | expect(feed.download_path).to be_nil 49 | expect(feed.regexp).to be_nil 50 | end 51 | 52 | it 'should be able to use new style config with all options' do 53 | feed = Feed.new({'url' => @url, 'download_path' => @download_path, 'regexp' => @matcher, 'validate_cert' => false, 'seen_by_guid' => true}) 54 | expect(feed.url).to eq(@url) 55 | expect(feed.download_path).to eq(@download_path) 56 | expect(feed.regexp).to eq(@regexp) 57 | expect(feed.validate_cert).to eq(false) 58 | expect(feed.seen_by_guid).to eq(true) 59 | end 60 | 61 | it 'should have a functioning matcher' do 62 | feed = Feed.new({'url' => @url, 'download_path' => @download_path, 'regexp' => @matcher}) 63 | expect(feed.matches_regexp?('myfile.pdf')).to eq(true) 64 | expect(feed.matches_regexp?('myfile.doc')).to eq(false) 65 | expect(feed.matches_regexp?('MYFILE.PDF')).to eq(true) 66 | end 67 | 68 | it 'should union array of regexes' do 69 | feed = Feed.new('regexp' => ['foo', 'bar']) 70 | expect(feed.matches_regexp?('foo')).to be 71 | expect(feed.matches_regexp?('bar')).to be 72 | expect(feed.matches_regexp?('daz')).not_to be 73 | end 74 | 75 | it 'should return download_path per regexp' do 76 | feed = Feed.new('download_path' => '/tmp', 'regexp' => [{'matcher' => 'foo', 'download_path' => '/tmp/foo'}, {'matcher' => 'bar'}]) 77 | expect(feed.download_path).to eq('/tmp') 78 | expect(feed.download_path('foo')).to eq('/tmp/foo') 79 | expect(feed.download_path('bar')).to eq('/tmp') 80 | end 81 | 82 | it 'should return download_path per regexp if feed download_path is nil' do 83 | feed = Feed.new('regexp' => [{'matcher' => 'foo', 'download_path' => '/tmp/foo'}, {'matcher' => 'bar'}]) 84 | expect(feed.download_path).to eq(nil) 85 | expect(feed.download_path('foo')).to eq('/tmp/foo') 86 | expect(feed.download_path('bar')).to eq(nil) 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /spec/seen_file_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe SeenFile do 4 | A = tmp_path(:a) 5 | 6 | before(:each, :init) do 7 | @seen_file = SeenFile.new(A) 8 | @url = 'http://example.com/foo' 9 | 10 | @seen_file.clear! 11 | @seen_file.add(@url) 12 | end 13 | 14 | after(:all) do 15 | FileUtils.rm_rf(File.dirname(A)) 16 | end 17 | 18 | describe '#add', :init do 19 | it 'saves entry in instance' do 20 | expect(@seen_file.include?(@url)).to be true 21 | end 22 | 23 | it 'saves entry over instances' do 24 | expect(SeenFile.new(A).include?(@url)).to be true 25 | end 26 | end 27 | 28 | describe '#clear', :init do 29 | it 'removes all entries' do 30 | @seen_file.clear! 31 | 32 | expect(@seen_file.size).to eq(0) 33 | expect(@seen_file.include?(@url)).to be false 34 | end 35 | end 36 | 37 | describe '#size', :init do 38 | it 'returns size' do 39 | expect(@seen_file.size).to eq(1) 40 | end 41 | end 42 | 43 | describe '#file_to_array', :init do 44 | subject { @seen_file.send(:file_to_array, A) } 45 | let(:hash) { @seen_file.send(:digest, @url) } 46 | 47 | it 'returns array' do 48 | expect(subject).to be_a Array 49 | end 50 | 51 | it 'has correct size' do 52 | expect(subject.empty?).to be false 53 | expect(subject.size).to eq(1) 54 | end 55 | 56 | it 'has correct content' do 57 | expect(subject.include?(hash)).to be true 58 | end 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'coveralls' 2 | require 'vcr' 3 | 4 | basedir = File.join(File.dirname(__FILE__), '..') 5 | require File.join(basedir, 'lib', 'transmission-rss') 6 | 7 | include TransmissionRSS 8 | 9 | def tmp_path(file) 10 | File.join(Dir.tmpdir, 'rspec', file.to_s) 11 | end 12 | 13 | Coveralls.wear! 14 | 15 | VCR.configure do |config| 16 | config.cassette_library_dir = 'spec/vcr' 17 | config.hook_into :webmock 18 | config.allow_http_connections_when_no_cassette = true 19 | end 20 | 21 | MATCH_REQUESTS_ON = { match_requests_on: [:method, :uri, :headers, :body] } 22 | 23 | RSpec.configure do |config| 24 | config.filter_run focus: true 25 | config.run_all_when_everything_filtered = true 26 | end -------------------------------------------------------------------------------- /spec/vcr/add_torrent.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 25 | Date: 26 | - Tue, 27 Dec 2016 13:57:26 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 39 | http_version: 40 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"filename":"magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Tue, 27 Dec 2016 13:57:26 GMT 69 | Content-Length: 70 | - '149' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{"torrent-added":{"hashString":"a31bf5dacae5b6f7bbe42d916549c8c4f34489de","id":18,"name":"archlinux-2016.12.01-dual.iso"}},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 78 | recorded_with: VCR 3.0.3 79 | -------------------------------------------------------------------------------- /spec/vcr/add_torrent_alt_port.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:8081/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - ordUcMBZp0CQVjPgYPljUFqrKbu8sQPh4grRowAsRMBE4B6T 25 | Date: 26 | - Sat, 18 Feb 2017 14:05:58 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: ordUcMBZp0CQVjPgYPljUFqrKbu8sQPh4grRowAsRMBE4B6T

' 39 | http_version: 40 | recorded_at: Sat, 18 Feb 2017 14:08:43 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:8081/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"filename":"magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - ordUcMBZp0CQVjPgYPljUFqrKbu8sQPh4grRowAsRMBE4B6T 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Sat, 18 Feb 2017 14:05:58 GMT 69 | Content-Length: 70 | - '149' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{"torrent-added":{"hashString":"a31bf5dacae5b6f7bbe42d916549c8c4f34489de","id":132,"name":"archlinux-2016.12.01-dual.iso"}},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Sat, 18 Feb 2017 14:08:43 GMT 78 | recorded_with: VCR 3.0.3 79 | -------------------------------------------------------------------------------- /spec/vcr/add_torrent_download_dir.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 25 | Date: 26 | - Tue, 27 Dec 2016 13:57:26 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 39 | http_version: 40 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"download-dir":"/tmp","filename":"magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Tue, 27 Dec 2016 13:57:26 GMT 69 | Content-Length: 70 | - '149' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{"torrent-added":{"hashString":"a31bf5dacae5b6f7bbe42d916549c8c4f34489de","id":18,"name":"archlinux-2016.12.01-dual.iso"}},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 78 | recorded_with: VCR 3.0.3 79 | -------------------------------------------------------------------------------- /spec/vcr/add_torrent_paused.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 25 | Date: 26 | - Tue, 27 Dec 2016 13:57:26 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 39 | http_version: 40 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"paused":true,"filename":"magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Tue, 27 Dec 2016 13:57:26 GMT 69 | Content-Length: 70 | - '149' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{"torrent-added":{"hashString":"a31bf5dacae5b6f7bbe42d916549c8c4f34489de","id":18,"name":"archlinux-2016.12.01-dual.iso"}},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 78 | recorded_with: VCR 3.0.3 79 | -------------------------------------------------------------------------------- /spec/vcr/add_torrent_too_many_requests.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 25 | Date: 26 | - Tue, 27 Dec 2016 13:57:26 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 39 | http_version: 40 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"filename":"magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Tue, 27 Dec 2016 13:57:26 GMT 69 | Content-Length: 70 | - '149' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{},"result":"Couldn''t fetch torrent: Unknown Error (429)"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Tue, 27 Dec 2016 13:58:47 GMT 78 | recorded_with: VCR 3.0.3 79 | -------------------------------------------------------------------------------- /spec/vcr/add_torrent_via_http_with_special_chars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - NQZGyjmLI9krJxK1Mch4KdvsPWGPuYNw2kEEnGfwXcL8C02t 25 | Date: 26 | - Mon, 17 Sep 2018 07:30:44 GMT 27 | Content-Length: 28 | - '581' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: NQZGyjmLI9krJxK1Mch4KdvsPWGPuYNw2kEEnGfwXcL8C02t

' 39 | http_version: 40 | recorded_at: Mon, 17 Sep 2018 07:30:44 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"filename":"https://nning.io/Sin%20Tel.torrent"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - NQZGyjmLI9krJxK1Mch4KdvsPWGPuYNw2kEEnGfwXcL8C02t 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Mon, 17 Sep 2018 07:30:44 GMT 69 | Content-Length: 70 | - '137' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{"torrent-duplicate":{"hashString":"08ada5a7a6183aae1e09d831df6748d566095a10","id":149,"name":"Sintel"}},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Mon, 17 Sep 2018 07:30:44 GMT 78 | recorded_with: VCR 4.0.0 79 | -------------------------------------------------------------------------------- /spec/vcr/add_torrent_with_ratio.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 25 | Date: 26 | - Tue, 27 Dec 2016 14:06:57 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 39 | http_version: 40 | recorded_at: Tue, 27 Dec 2016 14:08:17 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-add","arguments":{"filename":"magnet:?xt=urn:btih:a31bf5dacae5b6f7bbe42d916549c8c4f34489de&dn=archlinux-2016.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Tue, 27 Dec 2016 14:06:57 GMT 69 | Content-Length: 70 | - '154' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{"torrent-duplicate":{"hashString":"a31bf5dacae5b6f7bbe42d916549c8c4f34489de","id":18,"name":"archlinux-2016.12.01-dual.iso"}},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Tue, 27 Dec 2016 14:08:18 GMT 78 | - request: 79 | method: get 80 | uri: http://localhost:9091/transmission/rpc 81 | body: 82 | encoding: US-ASCII 83 | string: '' 84 | headers: 85 | Accept-Encoding: 86 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 87 | Accept: 88 | - "*/*" 89 | User-Agent: 90 | - Ruby 91 | response: 92 | status: 93 | code: 409 94 | message: Conflict 95 | headers: 96 | Server: 97 | - Transmission 98 | X-Transmission-Session-Id: 99 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 100 | Date: 101 | - Tue, 27 Dec 2016 14:06:57 GMT 102 | Content-Length: 103 | - '580' 104 | Content-Type: 105 | - text/html; charset=ISO-8859-1 106 | body: 107 | encoding: UTF-8 108 | string: '

409: Conflict

Your request had an invalid session-id header.

To 109 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 110 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 111 | When you get this 409 error message, resend your request with the updated 112 | header

This requirement has been added to help prevent CSRF 113 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 114 | http_version: 115 | recorded_at: Tue, 27 Dec 2016 14:08:18 GMT 116 | - request: 117 | method: post 118 | uri: http://localhost:9091/transmission/rpc 119 | body: 120 | encoding: UTF-8 121 | string: '{"method":"torrent-set","arguments":{"seedRatioLimit":1.0,"seedRatioMode":1,"ids":[18]}}' 122 | headers: 123 | Content-Type: 124 | - application/json 125 | X-Transmission-Session-Id: 126 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 127 | Accept-Encoding: 128 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 129 | Accept: 130 | - "*/*" 131 | User-Agent: 132 | - Ruby 133 | response: 134 | status: 135 | code: 200 136 | message: OK 137 | headers: 138 | Server: 139 | - Transmission 140 | Content-Type: 141 | - application/json; charset=UTF-8 142 | Date: 143 | - Tue, 27 Dec 2016 14:06:57 GMT 144 | Content-Length: 145 | - '56' 146 | body: 147 | encoding: ASCII-8BIT 148 | string: '{"arguments":{},"result":"success"} 149 | 150 | ' 151 | http_version: 152 | recorded_at: Tue, 27 Dec 2016 14:08:18 GMT 153 | recorded_with: VCR 3.0.3 154 | -------------------------------------------------------------------------------- /spec/vcr/feed_fetch.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://www.archlinux.org/feeds/releases/ 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | User-Agent: 11 | - transmission-rss 12 | Accept-Encoding: 13 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 14 | Accept: 15 | - "*/*" 16 | response: 17 | status: 18 | code: 200 19 | message: OK 20 | headers: 21 | Server: 22 | - nginx/1.16.1 23 | Date: 24 | - Wed, 22 Jan 2020 09:40:03 GMT 25 | Content-Type: 26 | - application/rss+xml; charset=utf-8 27 | Content-Length: 28 | - '1725' 29 | Connection: 30 | - keep-alive 31 | Last-Modified: 32 | - Wed, 01 Jan 2020 05:38:20 GMT 33 | Expires: 34 | - Wed, 22 Jan 2020 09:40:21 GMT 35 | Cache-Control: 36 | - max-age=317 37 | Content-Security-Policy: 38 | - img-src 'self' data:; frame-ancestors 'none'; script-src 'self'; default-src 39 | 'self'; base-uri 'none'; form-action 'self' 40 | Etag: 41 | - '"745d5b30f26f9fd8681800dc571a5d30"' 42 | X-Content-Type-Options: 43 | - nosniff 44 | X-Xss-Protection: 45 | - 1; mode=block 46 | X-Frame-Options: 47 | - DENY 48 | Strict-Transport-Security: 49 | - max-age=31536000; includeSubdomains; preload 50 | body: 51 | encoding: UTF-8 52 | string: |- 53 | 54 | Arch Linux: Releaseshttps://www.archlinux.org/download/Release ISOsen-usWed, 01 Jan 2020 05:38:20 +00002020.01.01https://www.archlinux.org/releng/releases/2020.01.01/Wed, 01 Jan 2020 00:00:00 +0000tag:www.archlinux.org,2020-01-01:/releng/releases/2020.01.01/2019.12.01https://www.archlinux.org/releng/releases/2019.12.01/Sun, 01 Dec 2019 00:00:00 +0000tag:www.archlinux.org,2019-12-01:/releng/releases/2019.12.01/2019.11.01https://www.archlinux.org/releng/releases/2019.11.01/Fri, 01 Nov 2019 00:00:00 +0000tag:www.archlinux.org,2019-11-01:/releng/releases/2019.11.01/ 55 | http_version: 56 | recorded_at: Wed, 22 Jan 2020 09:40:03 GMT 57 | recorded_with: VCR 5.0.0 58 | -------------------------------------------------------------------------------- /spec/vcr/session_id.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - ytWw47rvAhPKKK5bzpAjHnnELK4HCLbWGVhA3medTtJAWN9B 25 | Date: 26 | - Thu, 07 Apr 2016 18:18:33 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: ytWw47rvAhPKKK5bzpAjHnnELK4HCLbWGVhA3medTtJAWN9B

' 39 | http_version: 40 | recorded_at: Thu, 07 Apr 2016 18:19:09 GMT 41 | recorded_with: VCR 3.0.1 42 | -------------------------------------------------------------------------------- /spec/vcr/set_torrent.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: http://localhost:9091/transmission/rpc 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept-Encoding: 11 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 12 | Accept: 13 | - "*/*" 14 | User-Agent: 15 | - Ruby 16 | response: 17 | status: 18 | code: 409 19 | message: Conflict 20 | headers: 21 | Server: 22 | - Transmission 23 | X-Transmission-Session-Id: 24 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 25 | Date: 26 | - Tue, 27 Dec 2016 14:11:58 GMT 27 | Content-Length: 28 | - '580' 29 | Content-Type: 30 | - text/html; charset=ISO-8859-1 31 | body: 32 | encoding: UTF-8 33 | string: '

409: Conflict

Your request had an invalid session-id header.

To 34 | fix this, follow these steps:

  1. When reading a response, get its X-Transmission-Session-Id 35 | header and remember it
  2. Add the updated header to your outgoing requests
  3. 36 | When you get this 409 error message, resend your request with the updated 37 | header

This requirement has been added to help prevent CSRF 38 | attacks.

X-Transmission-Session-Id: XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp

' 39 | http_version: 40 | recorded_at: Tue, 27 Dec 2016 14:13:19 GMT 41 | - request: 42 | method: post 43 | uri: http://localhost:9091/transmission/rpc 44 | body: 45 | encoding: UTF-8 46 | string: '{"method":"torrent-set","arguments":{"seedRatioLimit":1,"seedRatioMode":1,"ids":[18]}}' 47 | headers: 48 | Content-Type: 49 | - application/json 50 | X-Transmission-Session-Id: 51 | - XDD7zLE1f8S0lJHdow9Jjpavvvt6WzrS8dWJEIq6obO3ITRp 52 | Accept-Encoding: 53 | - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 54 | Accept: 55 | - "*/*" 56 | User-Agent: 57 | - Ruby 58 | response: 59 | status: 60 | code: 200 61 | message: OK 62 | headers: 63 | Server: 64 | - Transmission 65 | Content-Type: 66 | - application/json; charset=UTF-8 67 | Date: 68 | - Tue, 27 Dec 2016 14:11:58 GMT 69 | Content-Length: 70 | - '56' 71 | body: 72 | encoding: ASCII-8BIT 73 | string: '{"arguments":{},"result":"success"} 74 | 75 | ' 76 | http_version: 77 | recorded_at: Tue, 27 Dec 2016 14:13:19 GMT 78 | recorded_with: VCR 3.0.3 79 | -------------------------------------------------------------------------------- /transmission-rss.conf.example: -------------------------------------------------------------------------------- 1 | # 2 | # Indent consistently with spaces! 3 | # Format documentation on http://www.yaml.org/. 4 | # 5 | # WARNING: 6 | # If you want to override a nested option like `log.target` you also have to 7 | # explicitly specify the others like `log.level`. (True for categories 8 | # `server`, `login`, `log`, `privileges`, and `client`.) 9 | # 10 | 11 | # List of feeds to watch. 12 | 13 | feeds: 14 | - url: http://example.com/feed1 15 | - url: http://example.com/feed2 16 | - url: http://example.com/feed3 17 | regexp: match1 18 | - url: http://example.com/feed4 19 | regexp: (match1|match2) 20 | - url: http://example.com/feed5 21 | download_path: /home/user/Downloads 22 | delay_time: 2 # Delay between adding each torrent in seconds 23 | - url: http://example.com/feed6 24 | regexp: 25 | - match1 26 | - match2 27 | - url: http://example.com/feed7 28 | regexp: 29 | - matcher: match1 30 | download_path: /home/user/match1 31 | exclude: dontmatch 32 | - matcher: match2 33 | download_path: /home/user/match2 34 | - url: http://example.com/feed8 35 | validate_cert: false 36 | seen_by_guid: true 37 | 38 | # Feed probing interval in seconds. Default is 600. 39 | 40 | #update_interval: 600 41 | 42 | # Whether to add torrents paused. Default is false. 43 | 44 | #add_paused: false 45 | 46 | # The transmission server to connect to. Default is localhost:9091. 47 | 48 | #server: 49 | # host: localhost 50 | # port: 9091 51 | # rpc_path: /transmission/rpc 52 | 53 | # Uncomment if transmission server requires login. 54 | 55 | #login: 56 | # username: transmission 57 | # password: transmission 58 | 59 | # Where to log. Default target is stderr, level debug. Target can be IO symbol 60 | # (e.g. ":stderr", ":stdout") or file path (e.g. 61 | # "/var/log/transmission-rss.log"). Level can be "error", "warn", "info", 62 | # "debug". 63 | 64 | #log: 65 | # target: :stderr 66 | # level: debug 67 | 68 | # Drop privileges. If omitted, privileges are not dropped. 69 | 70 | #privileges: 71 | # user: nobody 72 | # group: nobody 73 | 74 | # Other Transmission client options 75 | 76 | #client: 77 | # timeout: 5 78 | 79 | # Fork? 80 | 81 | #fork: false 82 | 83 | # Single run mode? 84 | 85 | # single: false 86 | 87 | # Save PID. 88 | 89 | #pid_file: false 90 | -------------------------------------------------------------------------------- /transmission-rss.gemspec: -------------------------------------------------------------------------------- 1 | $: << File.dirname(__FILE__) 2 | require 'lib/transmission-rss/version' 3 | 4 | Gem::Specification.new do |s| 5 | s.name = 'transmission-rss' 6 | 7 | s.summary = 'Adds torrents from rss feeds to transmission web frontend.' 8 | s.description = "transmission-rss is basically a workaround for 9 | transmission's lack of the ability to monitor RSS feeds and 10 | automatically add enclosed torrent links. Devoted to Ann." 11 | 12 | s.homepage = 'https://rubygems.org/gems/transmission-rss' 13 | s.version = TransmissionRSS::VERSION 14 | s.licenses = ['GPL-3.0'] 15 | s.author = 'henning mueller' 16 | s.email = 'henning@orgizm.net' 17 | s.files = Dir.glob('{bin,lib}/**/*').push 'README.md', 'transmission-rss.conf.example' 18 | s.executables = Dir.glob('bin/**').map { |x| x[4..-1] } 19 | 20 | s.required_ruby_version = '>= 2.1' 21 | 22 | s.add_dependency 'rss', '~> 0.2', '>= 0.2.9' 23 | s.add_dependency 'open_uri_redirections', '~> 0.2', '>= 0.2.1' 24 | s.add_dependency 'rb-inotify', '~> 0.9', '>= 0.9.10' 25 | end 26 | --------------------------------------------------------------------------------