Torrage - Torrent Storage Cache

API

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://torrage.com/torrent/<infoHash>.torrent

Note: HEX values A-F must be in uppercase in torrent URL's

SOAP API

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://torrage.com/api/torrage.wsdl.

PHP

Below is example code in PHP to cache "my.torrent". You would need to compile PHP --with-soap.

<?php
        $client = new SoapClient( 'http://torrage.com/api/torrage.wsdl' );
        $infoHash = $client->cacheTorrent( base64_encode( file_get_contents( 'my.torrent' ) ) );
?>

PERL

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://torrage.com/api/torrage.wsdl' )->cacheTorrent( $tor );

print $infoHash;

HTTP POST

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.

PHP

Below is example code to cache "my.torrent". This feature requires the pecl_http extension.

<?php
	$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://torrage.com/autoupload.php', array(), $files );
	$tmp = explode( "\r\n", $http_resp );
	$infoHash = substr( $tmp[count( $tmp ) - 1], 0, 40 );
	unset( $tmp, $http_resp, $files );
?>

libTorrage

We've also made a small client in C that you can build if you want to script on command line or use the code in your own C project.
The file is available to download here: libtorrage-0.1.1.tar.gz.

Sample usage

./torragecache http://torrage.com/autoupload.php my.torrent
BTC: 1Ehd61TD4Uazy7n7Wbp7YhoMGQ5MhKRLTv