Coder Social home page Coder Social logo

torrent-rw's Introduction

Torrent RW

PHP version 5.2+

  1. Features:
  • Decode torrent file or data
  • Build torrent from source folder/file(s)
  • Silent Exception error system
  1. Usage example
require_once 'Torrent.php';

// get torrent infos
$torrent = new Torrent( './test.torrent' );
echo '<br>private: ', $torrent->is_private() ? 'yes' : 'no', 
	 '<br>annonce: ', $torrent->announce(), 
	 '<br>name: ', $torrent->name(), 
	 '<br>comment: ', $torrent->comment(), 
	 '<br>piece_length: ', $torrent->piece_length(), 
	 '<br>size: ', $torrent->size( 2 ),
	 '<br>hash info: ', $torrent->hash_info(),
	 '<br>stats: ';
var_dump( $torrent->scrape() );
echo '<br>content: ';
var_dump( $torrent->content() );
echo '<br>source: ',
	 $torrent;

// get magnet link
$torrent->magnet(); // use $torrent->magnet( false ); to get non html encoded ampersand

// create torrent
$torrent = new Torrent( array( 'test.mp3', 'test.jpg' ), 'http://torrent.tracker/annonce' );
$torrent->save('test.torrent'); // save to disk

// modify torrent
$torrent->announce('http://alternate-torrent.tracker/annonce'); // add a tracker
$torrent->announce(false); // reset announce trackers
$torrent->announce(array('http://torrent.tracker/annonce', 'http://alternate-torrent.tracker/annonce')); // set tracker(s), it also works with a 'one tracker' array...
$torrent->announce(array(array('http://torrent.tracker/annonce', 'http://alternate-torrent.tracker/annonce'), 'http://another-torrent.tracker/annonce')); // set tiered trackers
$torrent->comment('hello world');
$torrent->name('test torrent');
$torrent->is_private(true);
$torrent->httpseeds('http://file-hosting.domain/path/'); // Bittornado implementation
$torrent->url_list(array('http://file-hosting.domain/path/','http://another-file-hosting.domain/path/')); // GetRight implementation

// print errors
if ( $errors = $torrent->errors() )
	var_dump( $errors );

// send to user
$torrent->send();

torrent-rw's People

Contributors

aberaud avatar adriengibrat avatar darkalchemy avatar dimak08 avatar drsdavidsoft avatar rudde avatar sparanoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torrent-rw's Issues

Another PHP 5.4.0 Warning

Hey,

Getting a lot of these in my log:

Accessing static property Torrent::$errors as non static in torrent_inc.php on line 113

line 113 is:

$this->{$key} = $value;

extraire la "key" d'un torrent

Bonjour,

Est-il possible d'extraire l'attribut key à l'aide de cette librairie?
En effet de nombreux .torrent embarque une clef unique pour pouvoir identifier le client, ce serait très utile de pouvoir extraire cette clef.

send() gives "Invalid torrent file!"

Hi!

First things first; I just love this class! Many thanks!

Now to the problem. When I set the new information about the torrent-file and choose $torrent->send() to download the torrent with the new information, I can't open the file! I only get "Invalid torrent file!". Please help?

Thanks in advance.

Modify torrent doesn't work

Hi there,

I'm not able to modify torrents at all.

require_once 'Torrent.php';

$torrent = new Torrent('test.torrent');

// modify torrent
$torrent->announce('http://alternate-torrent.tracker/announce'); // add a tracker
$torrent->comment('hello world');

This should modify the tracker and comment, but it does not work.
I'm running PHP 5.5, with cURL enabled.

Any ideas?

Problem with some torrents

Hi,
I have a problem with some torrents - I received error "Non-digit characters in integer" on line 535
If commented lines 530 and 534 - all works correct (in other words if system see i-1e it throws exception)

UDP Tracker Scrape

Hi,

This is more of a feature request. Could you please consider making it possible to scrape a UDP tracker for numbers, as a lot of trackers seem to be switching to UDP only model (openbittorrent being the biggest one). Since you now use CURL this should be no problem.

Cheers.

Unable to retrive contents of torrent containing many files

Hello,

First of all, Thank You for this amazing Library/Package!

I am facing some issue getting the list of torrents containing almost 40-50 files. Let's say I have a torrent file containing more than 50 files in this manner

  • Directory - 1
    • -- File 1
  • Directory - 2
    • -- File 2

The content() function return an empty Array in this case.

Can you please look into it once?

Thanks,

Call to a member function magnet() on a non-object

Salut,

J'ai cette erreur avec la nouvelle fonction magnet()

J'appelle : $torrent->magnet();

et ça me renvoie : Call to a member function magnet() on a non-object
^^

Et sinon faudrai penser à mettre à jours la doc :P

merci

Modify comment and creator

Hi,

This is really great tool. I just started using this tool.

I need to modify only comment and create by from .torrent file. Can you help me with that?

Maximum execution time of exceeded when reading torrent file

Hi
I'm getting the errors
PHP Fatal error: Maximum execution time of 55 seconds exceeded in /home/mojtaba/.rapidpich/lib/Torrent.class.php on line 531
it's not always the same lines however I get repeated error around same lines. I also don't know where the 55seconds come from as I'm running the script in cli mode.
The lines are mostly 539 - 543 but sometimes 520,511,476
(It's the same torrent but everytime it terminates at different line
The script does hog one CPU core at 100%.

error.zip

The torrents are rather large so this might be the same problem as
#38
but since the OP of that issue didn't provide more details I opened a new issue.

Warning: array_intersect_assoc(): at least 2 parameters are required, 1 given in ....../Torrent.php on line 710

Warning: array_intersect_assoc(): at least 2 parameters are required, 1 given in /storage/ssd2/491/3580491/public_html/files/Torrent.php on line 710

Warning: array_diff_assoc(): Argument #2 is not an array in /storage/ssd2/491/3580491/public_html/files/Torrent.php on line 720

Warning: end() expects parameter 1 to be array, null given in /storage/ssd2/491/3580491/public_html/files/Torrent.php on line 725

Only variables should be passed by reference

Salut,

Tiens une nouvelle erreur :

Strict Standards: Only variables should be passed by reference in /home/admin/domains/.com/public_html/cfg/torrent.php on line 334

Il me semble que c'est à cause de PHP 5.4 donc ligne 334 :

$stats = self::decode_data( curl_multi_getcontent( $done['handle'] ) );

en

$stats = curl_multi_getcontent( $done['handle'] );
$stats = self::decode_data( $stats );

;)

Ajouter la date de création du torrent

Bonjour Adrien,

Je me doute que tu ne maintiens plus trop cette class, mais peux-tu, à l'occasion, ajouter les informations concernant la date de création du torrent.

Ca ressemble à :

creation datei1483384502

Cordialement

Encode

Hello thanks for the script:) is there a way we can bencode back to .torrent file from decoded data. Like for example I have metadata stored in mysql and I would like to create torrents from it. Is this possible with this script.

Kind regards

is_torrent function works bad

Hi Adrien,

It's about is_torrent function.
Do you know better way of torrent meta-file format validation?
I downloaded torrent file from http://torrent.ubuntu.com:6969/ , first link. The file has d8:announce at the begin, but mTorrent said the format is invalid, and your Torrent.php library returns hash=NULL.

What do you think?
Btw, thx for great library.

Max.

New torrents from certain directory structures are accidentally flattened and files are discarded

When a root directory that contains more than one descendant directory who, themselves, both share a common parent directory but whose parent has no files, the Torrent::files method incorrectly identifies the root directory as one of the descendant directories rather than their shared parent directory.

Specifically, given a directory structure like this:

$ tree
.
└── child-directory
    ├── descendant-dir1
    │   └── file1.txt
    └── descendant-dir2
        └── file2.txt

creating a new torrent from either . or ./child-directory like so:

<?php
require_once 'Torrent-RW/Torrent.php';
$torrent = new Torrent('/path/to/child-directory', 'udp://tracker.publicbt.com:80');
$torrent->save('test.torrent');

will create a torrent file whose info dictionary only lists the contents of descendant-dir2:

$ lstor --raw test.torrent 
{'announce': 'http://tracker.openbt.com/',
 'created by': 'Torrent RW PHP Class - http://github.com/************/**********',
 'creation date': 1421322276,
 'info': {'files': [{'length': 0, 'path': ['file2.txt']}],
          'name': 'descendant-dir2',
          'piece length': 262144,
          'pieces': '<0 piece hashes>'}}
INFO:pyrocore.scripts.lstor.MetafileLister:Total time: 0.047 seconds.

This is unexpected behavior. Instead, both the contents of descendant-dir1 and the contents of descendant-dir2 should have been included, with child-directory (their common root) being correctly identified as the torrent root.

However, if we then add a file inside of child-directory, so that our directory tree looks like this:

$ tree
.
└── child-directory
    ├── descendant-dir1
    │   └── file1.txt
    ├── descendant-dir2
    │   └── file2.txt
    └── fileX.txt

Then the correct root (child-directory) is identified:

MacBookPro:torrent-test meitar$ php ./test.php 
MacBookPro:torrent-test meitar$ lstor --raw test.torrent 
{'announce': 'http://tracker.openbt.com/',
 'created by': 'Torrent RW PHP Class - http://github.com/************/**********',
 'creation date': 1421322693,
 'info': {'files': [{'length': 0, 'path': ['fileX.txt']},
                    {'length': 0, 'path': ['descendant-dir2', 'file2.txt']},
                    {'length': 0, 'path': ['descendant-dir1', 'file1.txt']}],
          'name': 'child-directory',
          'piece length': 262144,
          'pieces': '<0 piece hashes>'}}
INFO:pyrocore.scripts.lstor.MetafileLister:Total time: 0.029 seconds.

hi,how to clean the torrent file?

hi,how to clean the torrent file?
if i have download a torrent file ,but in the torrent comment or the file name exist some forbidden word ,such as sexy,porn,so it's not for user to read it,i want to transfer the bad word to other format,that the user can't read it clear,for example,the bad word is " sex porn" after tranfer it by md5 function,it's md5('sex porn') = 276df15cc7611d1ec34914de60d24611,so nobody can read the bad word anymore.

but if i have transfer the bad word and save the torrent file again,the torrent client can't download the file anymore. do u know how to resulte this problem?

add to composer

Hello,
Would u mind adding this to composer , it'll be a lot easier to follow

Problem with torrents makes with ruTorrent

User story:

  • make torrent with ruTorrent
  • open torrent edit and save with your script - torrent is ok
  • open torrent but pieces is broken :(

UPD: Problem with var "errors" in torrent; for avoid this is error please use $mixed = get_object_vars($mixed); at 383 line

PHP 5.4.0 Support

Just a heads up..

PHP Fatal error: 'continue' operator with non-constant operand is no longer supported

Sorry

sorry, my bad, please delete this post

Problem with torrents detector

Problem with function "is_torrent" - its not detects torrents without announce urls (somebody of users really lazy)

static public function is_torrent ( $file, $timeout = self::timeout ) {
        return self::file_get_contents( $file, $timeout, 0, 11 ) === 'd8:announce'
            or self::file_get_contents( $file, $timeout, 0, 14 ) === 'd10:created by';
}

P.S. Ofc, it's workaround

Error while reading some torrent file

Hello
When I try to read this torrent file:
https://pirateiro.com/download-t64/download
I get the following error:

PHP Fatal error: Cannot access property started with '\0' in Torrent.class.php on line 113

I temporarily solved the issue by changing the following lines:

        foreach( $meta as $key => $value )
        {
            $key = trim($key);
            $this->{$key} = $value;
        }

but I don't know if I might be breaking something or not!
This might be useful:
https://cweiske.de/tagebuch/php-property-started-nul.htm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.