标签:
People that are interested in using our service for automated caching of their newly created .torrent files or caching massive amounts of older files, can do so by using one our APIs.
This page contains some documentation on the APIs but also some example code in different languages. If you have some code for any additional language we do not cover, please give us some working example code over e-mail.
All files will be cached at http://torcache.net/torrent/<infoHash>.torrent
Note: HEX values A-F must be in uppercase in torrent URL‘s
The SOAP API is probably the most easy to use in a modern scripting/programming language. The WSDL offers one simply function; cacheTorrent(). The function returns the info hash of the torrent on success, or a three digit error code if there was an error.
The SOAP WSDL is located at http://torcache.net/torcache.wsdl.
Below is example code in PHP to cache "my.torrent". You would need to compile PHP --with-soap.
$client = new SoapClient( ‘http://torcache.net/torcache.wsdl‘ ); $infoHash = $client->cacheTorrent( base64_encode( file_get_contents( ‘my.torrent‘ ) ) );
Perl code to cache "my.torrent". Requires SOAP::Lite (libsoap-lite-perl in debian)
#!/usr/bin/perl use MIME::Base64 (); use SOAP::Lite (); open( FILE, ‘my.torrent‘ ) or die "$!"; while( read( FILE, $buf, 60*57 ) ) { $tor .= MIME::Base64::encode( $buf ); } close( FILE ); $infoHash = SOAP::Lite->service( ‘http://torcache.net/torcache.wsdl‘ )->cacheTorrent( $tor ); print $infoHash;
If you don‘t have support for SOAP there is a normal HTTP POST interface. Here we show some example code for that as well.
Below is example code to cache "my.torrent". This feature requires the pecl_http extension.
$files = array( array( ‘name‘ => ‘torrent‘, // Don‘t change ‘type‘ => ‘application/x-bittorrent‘, ‘file‘ => ‘my.torrent‘ // Full path for file to upload ) ); $http_resp = http_post_fields( ‘http://torcache.net/autoupload.php‘, array(), $files ); $tmp = explode( "\r\n", $http_resp ); $infoHash = substr( $tmp[count( $tmp ) - 1], 0, 40 ); unset( $tmp, $http_resp, $files );
标签:
原文地址:http://www.cnblogs.com/imsb/p/4818163.html