public function testInfoHash() { $File_Bittorrent2_Decode = new File_Bittorrent2_Decode(); $File_Bittorrent2_Decode->decodeFile(self::$torrent); exec('torrentinfo-console ' . escapeshellarg(self::$torrent), $bt); $this->assertEquals($File_Bittorrent2_Decode->getInfoHash(), substr($bt[3], strpos($bt[3], ':') + 2)); }
public function testAnnounceList() { $Decode = new File_Bittorrent2_Decode(); $info = $Decode->decodeFile(self::$torrent); $expected = array(array('http://tracker.gotwoot.net:6968/announce'), array('http://www.point-blank.cc:6969/announce', 'http://www.point-blank.cc:7000/announce', 'http://www.point-blank.cc:7001/announce')); $this->assertEquals($expected, $info['announce_list']); unset($Decode); }
function setFile($file, $store_original_file = true) { if (!$file instanceof sfValidatedFile) { if (is_string($file)) { return parent::setFile($file); } } $filename = $this->formatFilename($file->getOriginalName()) . $file->getOriginalExtension(); $extension = $file->getOriginalExtension(); parent::setFile($filename); // fixme this isn't setting the whole path $this->setSize($file->getSize()); $this->setMimeType($file->getType()); $sha1 = method_exists($file, 'getFileSha1') ? $file->getFileSha1() : sha1_file($file->getTempName()); $this->setFileSha1($sha1); $torrent_file = $this->getTorrentPath(); if (file_exists($torrent_file)) { $this->cleanupFiles(); throw new limeException('torrent', "{$torrent_file} already exists"); parent::setFile(null); } if ($store_original_file) { $file->save($this->getOriginalFilePath(), 0644); } else { } // NB: formatFilename should probably put the real filename on the file // but we've factored this out $MakeTorrent = new File_Bittorrent2_MakeTorrent($file->isSaved() ? $file->getSavedName() : $file->getTempName()); $MakeTorrent->setAnnounce(url_for('client/announce', true)); $MakeTorrent->setComment('TODO'); $MakeTorrent->setPieceLength(256); // KiBw $info = array(); if ($file instanceof sfValidatedFileFromUrl) { $info['url-list'] = array($file->getUrl()); } $meta = $MakeTorrent->buildTorrent($info); if ($meta && file_put_contents($torrent_file, $meta)) { $File_Bittorrent2_Decode = new File_Bittorrent2_Decode(); $info = $File_Bittorrent2_Decode->decodeFile($torrent_file); $this->setInfoHash($info['info_hash']); if (!file_exists($torrent_file)) { $this->cleanupFiles(); throw new limeException('torrent', "{$torrent_file} not written"); } } else { $this->cleanupFiles(); throw new limeException('torrent', 'Unable to generate torrent'); } if ($file instanceof sfValidatedFileFromUrl) { $this->setWebUrl($file->getUrl()); } else { $this->setWebUrl(_compute_public_path($this->getFile(), 'uploads', '', true)); } }
public function testScrape() { if (!(bool) ini_get('allow_url_fopen')) { $this->markTestSkipped(); } // Decode the torrent $File_Bittorrent2_Decode = new File_Bittorrent2_Decode(); $temp = tempnam(sys_get_temp_dir(), __CLASS__); file_put_contents($temp, file_get_contents('http://torrents.thepiratebay.org/4442311/Brothers.and .Sisters.S03E03.HDTV.XviD-NoTV.avi.4442311.TPB.torrent')); $File_Bittorrent2_Decode->decodeFile($temp); $stats = $File_Bittorrent2_Decode->getStats(); unlink($temp); }
public function testMakePrivateTorrent() { $Torrent = new File_Bittorrent2_MakeTorrent(__FILE__); $Torrent->setAnnounce('http://example.com/'); $Torrent->setIsPrivate(true); $tfile = tempnam('./', __CLASS__); $bemetainfo = $Torrent->buildTorrent(); file_put_contents($tfile, $bemetainfo); $Decode = new File_Bittorrent2_Decode(); $Decode->decodeFile($tfile); $metainfo = $Decode->decode($bemetainfo); unlink($tfile); $this->assertTrue($Decode->isPrivate()); $this->assertTrue($metainfo['info']['private'] === 1); }
function torrent_files_array($filepath) { $files_arr = array(); $final = array(); $temp = array(); require_once './plugins/bittorrent/Decode.php'; $Torrent_Decode = new File_Bittorrent2_Decode(); //$filepath = './data/torrent/1420772477/Stonehearst_Asylum_2014_720p.torrent'; //$info = $Torrent_Decode->decodeFile($filepath); try { $info = $Torrent_Decode->decodeFile($filepath); } catch (Exception $e) { return false; } $files = $info['files']; for ($i = 0; $i < count($files); $i++) { $files_arr = array_merge($files_arr, array($i => $files[$i]['filename'] . ':' . $this->file_size_format($files[$i]['size']) . ';')); } $temp = $this->parse_file_arr($files_arr); return $temp; }
function torrent_file_size($filepath) { // //$filepath = './data/torrent/1420772477/Stonehearst_Asylum_2014__720p.torrent'; require_once './plugins/bittorrent/Decode.php'; $Torrent_Decode = new File_Bittorrent2_Decode(); $info = $Torrent_Decode->decodeFile($filepath); // './data/torrent/1420772477/Stonehearst_Asylum_2014__720p.torrent' return $this->file_size_format($info['size']); }
function unique_for($params = array('user' => null)) { $original_payload = new File_Bittorrent2_Decode(); $original_payload->decodeFile(TORRENT_BASE_PATH . '/' . $this->fid . '.torrent'); $original_payload = $original_payload->decoded; $user = $params['user']; $original_payload['announce'] = $user->url_announce; $unique_payload = new File_Bittorrent2_Encode(); $unique_payload = $unique_payload->encode($original_payload); return $unique_payload; }
* * Usage: * # php scrape.php -t file * * @author Markus Tacker <*****@*****.**> * @version $Id$ */ // Includes require_once 'File/Bittorrent2/Decode.php'; require_once 'Console/Getargs.php'; // Get filename from command line $args_config = array('torrent' => array('short' => 't', 'min' => 1, 'max' => 1, 'desc' => 'Filename of the torrent')); $args =& Console_Getargs::factory($args_config); if (PEAR::isError($args) or !($torrent = $args->getValue('torrent'))) { echo Console_Getargs::getHelp($args_config) . "\n"; exit; } if (!is_readable($torrent)) { echo 'ERROR: "' . $torrent . "\" is not readable.\n"; exit; } // Decode the torrent $File_Bittorrent2_Decode = new File_Bittorrent2_Decode(); $File_Bittorrent2_Decode->decodeFile($torrent); echo "\nStatistics\n"; echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"; echo 'Tracker: ' . $File_Bittorrent2_Decode->getAnnounce() . "\n"; echo 'info hash: ' . $File_Bittorrent2_Decode->getInfoHash() . "\n"; foreach ($File_Bittorrent2_Decode->getStats() as $key => $val) { echo str_pad($key . ':', 20) . $val . "\n"; }
function torrent_file_info() { // require_once './plugins/bittorrent/Decode.php'; $Torrent_Decode = new File_Bittorrent2_Decode(); $info = $Torrent_Decode->decodeFile('./data/torrent/1420772477/Stonehearst_Asylum_2014__720p.torrent'); echo '<pre>'; print_r($info); echo '</pre>'; echo $this->size_format($info['size']); }
var_dump($encodedInt); var_dump($File_Bittorrent2_Decode->decode($encodedInt)); echo "Encoding strings\n"; $encodedStr = $File_Bittorrent2_Encode->encode('This is a string.'); var_dump($encodedStr); var_dump($File_Bittorrent2_Decode->decode($encodedStr)); echo "Encoding arrays as lists\n"; $encodedList = $File_Bittorrent2_Encode->encode(array('Banana', 'Apple', 'Cherry')); var_dump($encodedList); var_dump($File_Bittorrent2_Decode->decode($encodedList)); echo "Encoding arrays as dictionaries\n"; $encodedDict = $File_Bittorrent2_Encode->encode(array('fruits' => array('Banana', 'Apple', 'Cherry', 'subarray' => array(1, 2, 3)), 'ints' => array(1, 2, 3), 'count' => 3)); var_dump($encodedDict); print_r($File_Bittorrent2_Decode->decode($encodedDict)); // Decode a file print_r($File_Bittorrent2_Decode->decodeFile('install-x86-universal-2005.0.iso.torrent')); /* Output of decode Array ( [count] => 3 [fruits] => Array ( [0] => Banana [1] => Apple [2] => Cherry [subarray] => Array ( [0] => 1 [1] => 2 [2] => 3