added support for direct torrent streaming

This commit is contained in:
JohnDoee
2015-11-21 19:05:01 +01:00
parent 342b9f77a4
commit 634219f0f8
3 changed files with 68 additions and 19 deletions

View File

@@ -317,6 +317,7 @@ class Torrent(object):
else:
if f.size > biggest_file_size:
best_file = f
biggest_file_size = f.size
return best_file
@@ -472,6 +473,10 @@ class Torrent(object):
logger.debug('Scheduling based on current piece %s' % tfr.current_piece)
all_heads_done &= self.do_pieces_schedule(f, currently_downloading, tfr.current_piece)
if all(self.torrent.status.pieces):
logger.debug('All pieces complete, no need to loop')
return
if all_heads_done and not self.torrent_released:
logger.debug('We are already done with all heads, figuring out what to do next')

View File

@@ -150,6 +150,28 @@ StreamingPlugin = Ext.extend(Deluge.Plugin, {
deluge.preferences.addPage(this.prefsPage);
console.log('Streaming plugin loaded');
var doStream = function (tid, fileIndex) {
deluge.client.streaming.stream_torrent(tid, null, null, fileIndex, {
success: function (result) {
console.log('Got result', result);
if (result.status == 'success') {
var url = result.url;
if (result.use_stream_urls) {
url = 'stream+' + url;
if (result.auto_open_stream_urls) {
window.location.assign(url);
return;
}
}
Ext.Msg.alert('Stream ready', 'URL for stream: <a target="_blank" href="' + url + '">' + url + '</a>');
} else {
Ext.Msg.alert('Stream failed', 'Error message: ' + result.message);
}
}
})
}
deluge.menus.filePriorities.addMenuItem({
id: 'streamthis',
text: 'Stream this file',
@@ -162,29 +184,26 @@ StreamingPlugin = Ext.extend(Deluge.Plugin, {
var fileIndex = nodes[0].attributes.fileIndex;
var tid = files.torrentId;
if (fileIndex >= 0) {
deluge.client.streaming.stream_torrent(tid, null, null, fileIndex, {
success: function (result) {
console.log('Got result', result);
if (result.status == 'success') {
var url = result.url;
if (result.use_stream_urls) {
url = 'stream+' + url;
if (result.auto_open_stream_urls) {
window.location.assign(url);
return;
}
}
Ext.Msg.alert('Stream ready', 'URL for stream: <a target="_blank" href="' + url + '">' + url + '</a>');
} else {
Ext.Msg.alert('Stream failed', 'Error message: ' + result.message);
}
}
})
doStream(tid, fileIndex);
}
}
return false;
}
});
deluge.menus.torrent.addMenuItem({
id: 'streamthistorrent',
text: 'Stream this torrent',
iconCls: 'icon-down',
handler: function (item, event) {
deluge.menus.torrent.hide();
var ids = deluge.torrents.getSelectedIds();
if (ids) {
doStream(ids[0]);
}
return false;
}
});
}
});
Deluge.registerPlugin('Streaming', StreamingPlugin);

View File

@@ -75,7 +75,11 @@ class LocalAddResource(resource.Resource):
if torrent_file:
torrent_file = torrent_file[0]
client.streaming.stream_torrent(url=torrent_url[0], filepath_or_index=torrent_file).addCallback(self.gtkui.stream_ready)
infohash = request.args.get('infohash', None)
if infohash:
infohash = infohash[0]
client.streaming.stream_torrent(url=torrent_url[0], infohash=infohash, filepath_or_index=torrent_file).addCallback(self.gtkui.stream_ready)
return json.dumps({'status': 'ok', 'message': 'queued'})
@@ -99,6 +103,18 @@ class GtkUI(GtkPluginBase):
self.sep.show()
self.item.show()
torrentmenu = component.get("MenuBar").torrentmenu
self.sep_torrentmenu = gtk.SeparatorMenuItem()
self.item_torrentmenu = gtk.MenuItem(_("_Stream this torrent"))
self.item_torrentmenu.connect("activate", self.on_torrentmenu_menuitem_stream)
torrentmenu.append(self.sep_torrentmenu)
torrentmenu.append(self.item_torrentmenu)
self.sep_torrentmenu.show()
self.item_torrentmenu.show()
self.resource = LocalAddResource(self)
self.site = server.Site(self.resource)
self.listening = reactor.listenTCP(40747, self.site, interface='127.0.0.1')
@@ -114,6 +130,11 @@ class GtkUI(GtkPluginBase):
file_menu.remove(self.item)
file_menu.remove(self.sep)
torrentmenu = component.get("MenuBar").torrentmenu
file_menu.remove(self.item_torrentmenu)
file_menu.remove(self.sep_torrentmenu)
self.site.stopFactory()
yield self.listening.stopListening()
@@ -173,3 +194,7 @@ class GtkUI(GtkPluginBase):
path = ft.get_file_path(select)
client.streaming.stream_torrent(infohash=torrent_id, filepath_or_index=path).addCallback(self.stream_ready)
break
def on_torrentmenu_menuitem_stream(self, data=None):
torrent_id = component.get("TorrentView").get_selected_torrents()[0]
client.streaming.stream_torrent(infohash=torrent_id).addCallback(self.stream_ready)