Ejemplo n.º 1
0
function transmission_add_torrent($tor, $dest, $title, $seedRatio)
{
    global $config_values;
    // transmission dies with bad folder if it doesn't end in a /
    if (substr($dest, strlen($dest) - 1, 1) != '/') {
        $dest .= '/';
    }
    if (preg_match('/^magnet:/', $tor)) {
        $request = array('method' => 'torrent-add', 'arguments' => array('download-dir' => $dest, 'filename' => $tor));
    } else {
        $request = array('method' => 'torrent-add', 'arguments' => array('download-dir' => $dest, 'metainfo' => base64_encode($tor)));
    }
    $response = transmission_rpc($request);
    $torHash = $response['arguments']['torrent-added']['hashString'];
    if (isset($response['result']) and $response['result'] == 'success') {
        $cache = $config_values['Settings']['Cache Dir'] . "/rss_dl_" . filename_encode($title);
        if ($torHash) {
            $handle = fopen("{$cache}", "w");
            fwrite($handle, $torHash);
            fclose($handle);
        }
        if ($seedRatio >= 0 && $torHash) {
            $request = array('method' => 'torrent-set', 'arguments' => array('ids' => $torHash, 'seedRatioLimit' => $seedRatio, 'seedRatioMode' => 1));
            $response = transmission_rpc($request);
            if ($response['result'] != 'success') {
                _debug("Failed setting ratio limit for {$title}\n");
            }
        }
        return 0;
    } else {
        if ($response['result'] == 'duplicate torrent') {
            return "Duplicate Torrent";
        } else {
            if (!isset($response['result'])) {
                return "Failure connecting to Transmission";
            } else {
                return "Transmission RPC Error: " . print_r($response, TRUE);
            }
        }
    }
}
Ejemplo n.º 2
0
function moveTorrent($location, $torHash, $batch = false)
{
    global $config_values;
    if ($batch) {
        $torHash = explode(',', $torHash);
    }
    switch ($config_values['Settings']['Client']) {
        case 'Transmission':
            $torInfo = torInfo($torHash);
            if ($torInfo['bytesDone'] > 0) {
                $move = true;
            } else {
                $move = false;
            }
            $request = array('arguments' => array('location' => $location, 'move' => $move, 'ids' => $torHash), 'method' => 'torrent-set-location');
            $response = transmission_rpc($request);
            return json_encode($response);
            break;
    }
}