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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 5
0
 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;
 }
 public function testDecode()
 {
     $test_data = array('0:0:' => false, 'ie' => false, 'i341foo382e' => false, 'i4e' => 4, 'i0e' => 0, 'i123456789e' => 123456789, 'i-10e' => -10, 'i-0e' => false, 'i123' => false, '' => false, 'i6easd' => false, '35208734823ljdahflajhdf' => false, '2:abfdjslhfld' => false, '0:' => '', '3:abc' => 'abc', '10:1234567890' => '1234567890', '02:xy' => false, 'l' => false, 'le' => array(), 'leanfdldjfh' => false, 'l0:0:0:e' => array('', '', ''), 'relwjhrlewjh' => false, 'li1ei2ei3ee' => array(1, 2, 3), 'l3:asd2:xye' => array('asd', 'xy'), 'll5:Alice3:Bobeli2ei3eee' => array(array('Alice', 'Bob'), array(2, 3)), 'd' => false, 'defoobar' => false, 'de' => array(), 'd1:a0:e' => array('a' => ''), 'd3:agei25e4:eyes4:bluee' => array('age' => 25, 'eyes' => 'blue'), 'd8:spam.mp3d6:author5:Alice6:lengthi100000eee' => array('spam.mp3' => array('author' => 'Alice', 'length' => 100000)), 'd3:fooe' => false, 'di1e0:e' => false, 'd1:b0:1:a0:e' => false, 'd1:a0:1:a0:e' => false, 'i03e' => false, 'l01:ae' => false, '9999:x' => false, 'l0:' => false, 'd0:0:' => false, 'd0:' => false, '00:' => false, 'l-3:e' => false, 'i-03e' => false, 'di0e0:e' => false, 'd8:announceldi0e0:eee' => false, 'd8:announcedi0e0:e18:azureus_propertiesi0ee' => false);
     // Thanks to IsoHunt.com for the last 3 testcases of bad data seen in their system.
     $File_Bittorrent2_Decode = new File_Bittorrent2_Decode();
     ini_set('mbstring.internal_encoding', 'ASCII');
     foreach ($test_data as $ti => $to) {
         if ($to === false) {
             try {
                 $File_Bittorrent2_Decode->decode($ti);
                 $this->fail('File_Bittorrent2 successfully decoded invalid data.');
             } catch (File_Bittorrent2_Exception $E) {
                 if ($E->getCode() != File_Bittorrent2_Exception::decode) {
                     throw $E;
                 }
             }
         } else {
             $this->assertEquals($to, $File_Bittorrent2_Decode->decode($ti));
         }
     }
 }
 public function testAnnounceList()
 {
     $MakeTorrent = new File_Bittorrent2_MakeTorrent(self::$torrent);
     // Set the announce URL
     $MakeTorrent->setAnnounce('http://www.example.org');
     // Set the comment
     $MakeTorrent->setComment('Hello World!');
     // Set the piece length (in KB)
     $MakeTorrent->setPieceLength(256);
     // Build the torrent
     $metainfo = $MakeTorrent->buildTorrent();
     $Decode = new File_Bittorrent2_Decode();
     $info = $Decode->decode($metainfo);
     $this->assertEquals(count($info['info']['files']), 3);
     $files = array();
     foreach ($info['info']['files'] as $k => $v) {
         $files[] = $v['path'][0];
     }
     sort($files);
     $expected = array('1.txt', '2.txt', '3.txt');
     $this->assertEquals($expected, $files);
 }
<?php

/**
 * Test case for Bug #3970
 *
 * @see http://pear.php.net/bugs/bug.php?id=3970
 *
 * @author Markus Tacker <*****@*****.**>
 * @version $Id$
 * @package File_Bittorrent2
 * @subpackage Bugs
 */
require_once '../File/Bittorrent2/Encode.php';
require_once '../File/Bittorrent2/Decode.php';
$Decoder = new File_Bittorrent2_Decode();
$Encoder = new File_Bittorrent2_Encode();
$torrent = $Decoder->decode(file_get_contents('../freebsd.torrent'));
$info_encoded = $Encoder->encode($torrent);
$decoded_info_encoded = $Decoder->decode($info_encoded);
var_dump($torrent['info']['piece length']);
var_dump($decoded_info_encoded['info']['piece length']);
Esempio n. 9
0
 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']);
 }
Esempio n. 10
0
 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;
 }
Esempio n. 11
0
<?php

/**
 * Test case for Bug #4570
 *
 * @see http://pear.php.net/bugs/bug.php?id=4570
 *
 * @author Justin "nagash" Jones <j dot nagash at gmail dot com>
 * @version $Id$
 * @package File_Bittorrent2
 * @subpackage Bugs
 */
require_once '../File/Bittorrent2/Encode.php';
require_once '../File/Bittorrent2/Decode.php';
$decoder = new File_Bittorrent2_Decode();
$encoder = new File_Bittorrent2_Encode();
error_reporting(E_ALL);
$data = array('broken' => null, 'bit' => 'torrent');
echo '<pre>';
echo 'The data array:' . "\n";
print_r($data);
$encode1 = $encoder->encode_array($data);
$decode1 = $decoder->decode($encode1);
echo "\n" . 'First decode:' . "\n";
print_r($decode1);
// Works fine!
// If you add and remove and change these things, your results will vary.
// Sometimes I just got an empty Array, other times I got data in the wrong keys.
// And for the worst times, it looped indefinately, but I couldn't reproduce that
// with this data - see below for an example.'
$decode1['bit'] = 'testing';
Esempio n. 12
0
 *
 * 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";
}
Esempio n. 13
0
 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']);
 }
Esempio n. 14
0
// | License along with this library; if not, write to the                |
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA               |
// +----------------------------------------------------------------------+
/**
* Example usage of File_Bittorrent2
*
* @author Markus Tacker <*****@*****.**>
* @version $Id$
*/
/**
* Include class
*/
require_once 'File/Bittorrent2/Encode.php';
require_once 'File/Bittorrent2/Decode.php';
$File_Bittorrent2_Decode = new File_Bittorrent2_Decode();
$File_Bittorrent2_Encode = new File_Bittorrent2_Encode();
// Encoding vars
echo "Encoding integers\n";
$encodedInt = $File_Bittorrent2_Encode->encode(10);
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";
 */
// 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;
}
$File_Bittorrent2_Decode = new File_Bittorrent2_Decode();
$info = $File_Bittorrent2_Decode->decodeFile($torrent);
foreach ($info as $key => $val) {
    echo str_pad($key . ': ', 20, ' ', STR_PAD_LEFT);
    switch ($key) {
        case 'files':
            $n = 1;
            $files_n = count($val);
            $n_length = strlen($files_n);
            echo '(' . $files_n . ")\n";
            foreach ($val as $file) {
                echo str_repeat(' ', 20) . '' . str_pad($n, $n_length, ' ', PAD_LEFT) . ': ' . $file['filename'] . "\n";
                $n++;
            }
            break;
        case 'announce_list':
Esempio n. 16
0
 * Info-Hash Test
 * Compares the info_hash compution of this package to the original program implementation
 *
 * Usage:
 *   # php infohash.php -t file.torrent
 *
 * @author Markus Tacker <*****@*****.**>
 * @version $Id$
 */
error_reporting(E_ALL);
// 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;
}
$File_Bittorrent2_Decode = new File_Bittorrent2_Decode();
$File_Bittorrent2_Decode->decodeFile($torrent);
echo "\nInfo Hash\n";
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
echo "This:                " . $File_Bittorrent2_Decode->getInfoHash() . "\n";
exec('torrentinfo-console ' . escapeshellarg($torrent), $bt);
echo "torrentinfo-console: " . substr($bt[3], strpos($bt[3], ':') + 2) . "\n";