Created by Luis Porras / @lporras16 Software Developer at Selfie Inc
Btapp.js has hard dependencies on jQuery, Backbone, Json2 and jStorage
- <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
- <script src="http://underscorejs.org/underscore-min.js"></script>
- <script src="http://backbonejs.org/backbone-min.js"></script>
- <script src="https://raw.github.com/andris9/jStorage/master/jstorage.js"></script>
Backbrace is also heavily recommended, to alleviate some of the trouble you might have using deep trees of Backbone models and collections.
- <script src="https://raw.github.com/bittorrenttorque/backbrace/master/backbrace.js"></script>
- <script src="http://torque.bittorrent.com/btapp/btapp.min.js"></script>
or... Download Btapp.js source
By default, the api will try to use Torque
which means, it facilitates the installation of a browser plugin, and the underlying torrent client if it isn't already available.
//Connecting with Torque (by default)
var btapp = new Btapp;
btapp.connect();
Or...
//Using plugin sintax
var btapp = new Btapp;
btapp.connect({
product: 'Torque'
plugin: true
});
var btapp = new Btapp;
btapp.connect({
product: 'uTorrent',
plugin: false,
pairing_type: 'native'
});
var btapp = new Btapp;
btapp.connect({
product: 'BitTorrent',
plugin: false,
pairing_type: 'native'
});
Don't
var btapp = new Btapp();
btapp.connect();
btapp.get('torrent').each(function(torrent) {
torrent.remove();
});
Do
var btapp = new Btapp();
btapp.connect();
// This code will wait for the traditional backbone add event to be thrown.
// We can listen to a specific attribute (in this case torrent) by adding :attribute
btapp.on('add:torrent', function(torrents) {
torrents.each(function(torrent) {
torrent.remove();
});
});
var magnet = 'magnet:?xt=urn:btih:f0d665f264393a7dafd7d05d739e1097df652e80&dn=The.Yes.Men.Fix.The.World';
//var url = 'http://vodo.net/media/torrents/Deadside.Pilot.2012.720p.x264-VODO.torrent';
var callback = function() {
alert('added the torrent');
};
btapp.get('add').torrent({
url: magnet,
callback: callback
});
// To add a torrent and stop after the torrent file has been added (or the magnet link has resolved to a torrent file), try the following:
var url = 'http://vodo.net/media/torrents/Deadside.Pilot.2012.720p.x264-VODO.torrent';
btapp.get('add').torrent({
url: url,
priority: Btapp.TORRENT.PRIORITY.METADATA_ONLY
});
var files = btapp.get('torrent').get('D9C70109CB05C181F9EC9373BE876A0D40C4D7B0').get('file');
> files.pluck('id');
["Deadside.2012.720p.x264-VODO.mkv", "Want.to.see.what.happens.next.url", "vodo.nfo"]
var btapp = new Btapp;
btapp.connect();
var url = 'http://vodo.net/media/torrents/Deadside.Pilot.2012.720p.x264-VODO.torrent';
btapp.live('add', function(add) {
add.torrent(url);
});
btapp.live('torrent * properties download_url', function(download_url, properties) {
// Only interested in the torrent that has a download_url that matches the location we provided
if(download_url == url) {
var name = properties.get('name');
// We found our torrent!
// Now lets listen for progress changes
properties.on('change:progress', function(progress) {
// We have an update!
alert('Download progress for ' + name + ': ' + progress);
});
}
});
Live Coding: DHT App using btapp.js from Patrick Williams on Vimeo.