Beispiel #1
0
        die("ERROR: Failed to download torrent from torcache.net\n");
    }
    if ($torrentData[0] !== 'd') {
        $torrentData = gzdecode($torrentData);
    }
} else {
    if (!file_exists($torrentFile)) {
        die("ERROR: Unable to open torrent file '{$torrentFile}'\n");
    }
    $torrentData = file_get_contents($torrentFile);
    if (strlen($torrentData) <= 0) {
        die("ERROR: Failed to read torrent '{$torrentFile}'\n");
    }
}
try {
    $torrent = Torrent::read($torrentData);
} catch (Exception $e) {
    trigger_error($e);
    die("ERROR: Failed to parse torrent\n");
}
echo " Info Hash: {$torrent->getInfoHashHex()}\n";
echo " Piece Size: " . Util::formatSize($torrent->getPieceSize()) . "\n";
echo " Total Size: " . Util::formatSize($torrent->getTotalSize()) . "\n";
$download = new Download($torrent, $dir);
$download->on('allocate', function ($finished, $total) {
    $p = (int) ($finished / $total * 100.0);
    echo "Allocating Files ... ({$p}%)         \r";
});
$download->on('check', function ($finished, $total) {
    $p = (int) ($finished / $total * 100.0);
    echo "Checking Files ... ({$p}%)           \r";