📜 ⬆️ ⬇️

Rtorrent + PHP + MySQL

After my first acquaintance with the console torrent client rtorrent, I did not abandon the idea of ​​automating my work with torrents.
There are many articles on working with torrents, but I did not find what I need.

In this article I will tell and show by example how to work with torrents using php + mysql + rtorrent.

It is necessary:




Put the torrent file on download

In this example, the form with the upload torrent file, but it does not matter. No one bothers you to parse the tracker and transfer the finished torrent file to the script.
<?php .......... $torrent = new Torrent($_FILES['file']['tmp_name']); if ($hash = $torrent->hash_info()) { move_uploaded_file($_FILES['file']['tmp_name'], "torrent/new/" . microtime(true) . rand(1000, 9999) . ".torrent"); mysql_query("INSERT INTO video SET `show` = '" . mysql_real_escape_string($show) . "', hash = '" . mysql_real_escape_string($hash) . "'}'"); $error = " "; } else { $error = "  torrent-"; } .......... ?> 

')
Connect to rtorrent:

 <?php ...... $xrc = XML_RPC2_Client::create("http://127.0.0.1/RPC2", array("encoding" => "utf-8")); ..... 

and work with the list of downloaded torrents:

 ..... foreach ($xrc->download_list("complete") as $hash) { $episode = mysql_fetch_assoc(mysql_query("SELECT * FROM video WHERE hash = '" . mysql_real_escape_string($hash) . "'")); if (!$episode) { //    continue; } $base_path = $xrc->{"d.get_base_path"}($hash); if (is_file($base_path)) { //  ,          mysql_query("UPDATE video SET filename = '" . mysql_real_escape_string($base_path) . "', hash = '' WHERE hash = '" . mysql_real_escape_string($hash) . "'"); $xrc->{"d.erase"}($hash); } else { printf("$base_path does not exist!\n"); } } ?> 

List of all commands to rtorrent: RTorrentCommands

What do we have in the end?


After we connected rtorrent with php + mysql there are a lot of ideas for further automation. Personally for myself, I made an automatic download of a new series of serials and SMS notification of successful download.
Integrating such a method into any CMS and organizing the downloading of new films / series / software and uploading them to file sharing services is easy.

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


All Articles