📜 ⬆️ ⬇️

Automatically download .torrent files from trackers

Sofrus and I are big fans of TV shows. Not those who are "Slave Izaura" or "BTP", and the modern type of "Escape" or "House". Once, on the way from the office to the metro, we talked about new series and sofrus suggested that it would be very nice to parse RSS from popular Russian serial trackers like lostfilm or novafilm, and then download automatically. I really liked this thought, but I put it off until better times.



And now the time came when Webcam needed the CURL module. Making a wrapper for it under our framework, I suggested that the best way to test the module would be to write a script to automatically download .torrent files from trackers. For me, this script is very useful, since I really appreciate what the release teams of the aforementioned trackers do and want to support them in every way, if you understand me.
')
In general, let's start:

Since the wrapper module for CURL of our framework is written in PHP, I will use its CLI varinat.

On my home special system sistemnik worth rTorrent. And, if you do not know, then it has the function of auto-scanning a specific folder for the appearance of new torrent files there. So the task is to simply download the files from the trackers and put them in this very folder.

Both trackers have RSS with distributions, which means I will download them, parse, download torrents and put them in a folder. Simply? Not really. The fact is that before you download a torrent from the tracker you need to log in to it. Well that for CURL is not a problem. I will simulate the behavior of a regular browser, say FireFox and the trick is done.

It would also be nice to make filters for torrent files so that the script does not download everything, but only what interests me. Fortunately, the names of the files on the trackers are intelligible and the problems to apply regular programs to them are not.

Next, you need to make a configuration file so that you can customize the script for yourself and add any trackers (experimentally). This is also not very difficult, the main thing is to think out the structure of the config correctly.

After several hours of work there is a result .

Just unpack the archive where you like, correct the config.php (instruction inside the file) and put the torrents.php file on the crontab. like this:

* / 30 * * * * php /path/to/script/torrents.php

and once every 30 minutes he will go to the tracker and see if there are new distributions of interest to you, if there is, then download them to the folder you specified in the config. The result of the work is written to the file /var/log/torrents.log.

The bonus comes with the file get_torrent.php, which takes the paths to the torrent files by parameters and, based on the same config file, downloads them and puts them in the same folder.

In general, I give this script to all those to whom it will help, in no way do I pretend either to know how or to the genius of an idea or implementation. :) If you have any questions / suggestions, I will be happy to answer in the comments.

Source: https://habr.com/ru/post/47263/


All Articles