Created
April 25, 2013 13:14
-
-
Save josefnpat/5459595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/resume/"); | |
$torrent_dir = $_SERVER['HOME']."/.config/transmission/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(); | |
} |
nice! super helpful.
I did have some issues just pasting the list into Deluge console though. I had a large list of 1000+ torrents. Deluge only took ~200 of them before it cut off the paste.
I wrote this script to import them slowly into the console one by one which worked better for me.
usage is: ./<script name> <output file from trans_to_deluge.php>
#!/usr/bin/env bash
# copy all output to a log file
logname="deluge_import.log"
# delay in seconds between adding torrents
time="60"
# port for deluge-console connection
deluge_port="58846"
# log all output to file
exec > >(tee -ia `dirname "$0"`/$logname)
exec 2> >(tee -ia `dirname "$0"`/$logname >&2)
if [[ -z $1 ]]; then
read -p "Path to input file: " 1
fi
# deluge-console syntax example:
# deluge-console "connect 127.0.0.1:58846 ; <line from trans_to_deluge.php output> ; exit"
while read i; do
deluge-console "connect 127.0.0.1:$deluge_port ; \
$i; \
exit"
sleep $time
echo
done < $1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You saved my life with this, thanks.