Skip to content

Instantly share code, notes, and snippets.

@skyway22
Forked from josefnpat/trans_to_deluge.php
Last active February 20, 2017 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyway22/8777c91222afe922c32204334158f014 to your computer and use it in GitHub Desktop.
Save skyway22/8777c91222afe922c32204334158f014 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
/* Transmission to Deluge export script
*
* Transmission - transmission-gtk 2.77 (14031)
* Deluge - deluge: 1.3.6
* Script - PHP 5.4.14 (cli)
*
* How to use this script;
* 1) Run `php trans_to_deluge.php` and make sure there aren't any errors.
* 2) Save the output (`php trans_to_deluge.php > out.temp`)
* 3) Copy the out.temp to your copy-paste buffer
* 4) Run `deluge-console`, ensure you are connected, and simply paste the data
* into the console. It should simply add all the torrents sequentially and
* if the data is availible, it should link it up properly.
*
* Ways the script can die:
* - "RegEx cannot find destination for [...]"
* Something is wrong with the regular expression for the resume file.
* - "Not a torrent: [...]"
* The resume file does not have a corresponding torrent file.
*
*/
define("CLI_RED", "\033[31;40m\033[1m[%s]\033[0m");
chdir($_SERVER['HOME']."/.config/transmission-daemon/resume/");
$torrent_dir = $_SERVER['HOME']."/.config/transmission-daemon/torrents";
foreach(glob("*.resume") as $resume){
$raw = file_get_contents($resume);
$dest = get_dest($raw,$resume);
$name = get_name($resume);
$console = "add -p \"$dest\" \"$torrent_dir/$name\"\n";
echo $console;
//echo "$name\n";
//echo "$dest\n";
}
function get_dest($raw,$resume){
if(preg_match("@destination(\d){1,2}:(\/(.)+?)3:@",$raw,$matches)){
return $matches[2];
} else {
error("RegEx cannot find destination for $resume");
}
}
function get_name($resume){
$data = explode(".",$resume);
array_pop($data);
$torrent = implode(".",$data).".torrent";
if(!is_file("../torrents/$torrent")){
error("Not a torrent: $torrent");
}
return $torrent;
}
function error($msg){
echo sprintf(CLI_RED," ERROR: $msg \n");
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment