From 14c23065b578675ca1c27fb7bf07d469580fed90 Mon Sep 17 00:00:00 2001 From: Anders Jensen Date: Fri, 17 Aug 2018 19:02:58 +0200 Subject: [PATCH] fixed compatibility issues and resume --- streaming/core.py | 27 ++++++++++++++++++++++++--- streaming/data/streaming.js | 13 ++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/streaming/core.py b/streaming/core.py index dca20e4..66deac2 100644 --- a/streaming/core.py +++ b/streaming/core.py @@ -48,6 +48,7 @@ import deluge.configmanager from copy import copy from datetime import datetime, timedelta +from types import MethodType from deluge import component, configmanager from deluge._libtorrent import lt @@ -88,6 +89,24 @@ DEFAULT_PREFS = { logger = logging.getLogger(__name__) +def get_torrent(infohash): + def get_file_priorities(self): + """Return the file priorities""" + if not self.handle.has_metadata(): + return [] + + if not self.options["file_priorities"]: + # Ensure file_priorities option is populated. + self.set_file_priorities([]) + + return self.options["file_priorities"] + + torrent = component.get("TorrentManager").torrents.get(infohash, None) + if torrent and not hasattr(torrent, 'get_file_priorities'): + torrent.get_file_priorities = MethodType(get_file_priorities, torrent) + + return torrent + class Torrent(object): def __init__(self, torrent_handler, infohash): @@ -99,7 +118,7 @@ class Torrent(object): self.cycle_lock = defer.DeferredLock() self.last_activity = datetime.now() - self.torrent = component.get("TorrentManager").torrents.get(infohash, None) + self.torrent = get_torrent(infohash) status = self.torrent.get_status(['piece_length']) self.piece_length = status['piece_length'] self.torrent.handle.set_sequential_download(True) @@ -194,6 +213,8 @@ class Torrent(object): first_files.add(fileset['files'][0]) if found_not_started: + self.torrent.resume() + logger.debug('We had a fileset not started, must_whitelist:%r first_files:%r cannot_blacklist:%r' % (must_whitelist, first_files, cannot_blacklist)) status = self.torrent.get_status(['files', 'file_progress']) @@ -354,7 +375,7 @@ class TorrentHandler(object): self.cleanup_looping_call.stop() def get_filesystem(self, infohash): - torrent = component.get("TorrentManager").torrents.get(infohash, None) + torrent = get_torrent(infohash) status = torrent.get_status(['piece_length', 'files', 'file_progress', 'save_path']) self.piece_length = status['piece_length'] save_path = status['save_path'] @@ -666,7 +687,7 @@ class Core(CorePluginBase): @defer.inlineCallbacks def stream_torrent(self, infohash=None, url=None, filedump=None, filepath_or_index=None, includes_name=False, wait_for_end_pieces=False): logger.debug('Trying to stream infohash:%s, url:%s, filepath_or_index:%s' % (infohash, url, filepath_or_index)) - torrent = component.get("TorrentManager").torrents.get(infohash, None) + torrent = get_torrent(infohash) if torrent is None: logger.info('Did not find torrent, must add it') diff --git a/streaming/data/streaming.js b/streaming/data/streaming.js index 5546602..aed9aaf 100644 --- a/streaming/data/streaming.js +++ b/streaming/data/streaming.js @@ -204,15 +204,14 @@ PreferencePage = Ext.extend(Ext.Panel, { } }); - om.bind('remote_username', fieldset.add({ - xtype: 'textfield', - name: 'remote_username', - fieldLabel: 'Remote control username' - })); + // om.bind('remote_username', fieldset.add({ + // xtype: 'textfield', + // name: 'remote_username', + // fieldLabel: 'Remote control username' + // })); om.bind('remote_password', fieldset.add({ xtype: 'textfield', - inputType: 'password', name: 'remote_password', fieldLabel: 'Remote control password' })); @@ -308,7 +307,7 @@ PreferencePage = Ext.extend(Ext.Panel, { var apiUrl = 'http'; if (optionsManager.get('use_ssl')) apiUrl += 's'; - apiUrl += '://' + optionsManager.get('ip') + ':' + optionsManager.get('port') + '/streaming/stream'; + apiUrl += '://' + optionsManager.get('remote_username') + ':' + optionsManager.get('remote_password') + '@' + optionsManager.get('ip') + ':' + optionsManager.get('port') + '/streaming/stream'; Ext.getCmp('remote_url').setValue(apiUrl); } });