0

So deluge doesn't natively support adding a torrent with a different label or download directory than the global set one. So the browser addons available dont either. So i worked out a way to get around this for adding torrents to the webui without writing a custom plugin.

0

How it works is by directing the output of the browser addon to the below php script instead of deluge itself. The scrip then saves the torrent or magnet to a specific watch directory specified by a paramater in the addon url. From here the "AutoAdd" plugin for deluge will be set up to monitor the various watch directories you want and load torrents from each with a chosen label, and download directory (orany other setting available by that addon) specific to that watch directory.

    <?php

    //specify hostname in addon as server.com/thisScript.php?label=labelName
    //tested with these addons:
    //https://addons.mozilla.org/en-US/firefox/addon/bittorrent-webui-120685/
    //https://chrome.google.com/webstore/detail/remote-torrent-adder/oabphaconndgibllomdcjbfdghcmenci?hl=en
    //in deluge mode, others may work.
    //specify server address as server.com/path/storeTorrent.php?label=labelname
    //label folder must first be created
    //use with AutoAdd plugin, to watch directories, and add with individual labels and locations
    //http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd (configure with pc client)
    //edit $watchDir to your base watch dir yours

    $watchDir = '/media/sdf1/home/private/deluge/watch/';

    $label = str_replace(array("json",":"),"",$_REQUEST['label']);

    //file_put_contents('debug.txt', json_encode($_REQUEST).'--'.file_get_contents('php://input'));//debug full
    //file_put_contents('debug.txt', $label;//debug just label param

    if($label && is_dir($watchDir.$label)){
                $json = file_get_contents('php://input');
                $array = json_decode($json,true);

                if($array['method'] == 'core.add_torrent_magnet'){
                    preg_match('#magnet:\?xt=urn:btih:(?<hash>.*?)&dn=(?<filename>.*?)&tr=(?<trackers>.*?)$#', $array['params'][0], $magnet_link);
                    file_put_contents($watchDir.$label.$magnet_link['hash'].'.magnet', $array['params'][0]);
                }else if($array['method'] == 'core.add_torrent_file'){              
                    file_put_contents( $watchDir.$label.md5($array['params'][1]).'.torrent' , base64_decode($array['params'][1]));
                }


    }
    else header(':', true, 401);


    header('Content-Type: application/json');
    echo '{"id": 0, "result": true, "error": null}';
    ?>

http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.