From c807d5ffc2a9d10b29933aa6b102b585ca374447 Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Thu, 23 Jul 2015 18:23:22 +0300 Subject: [PATCH] 1.0.5 fix --- Core.py | 12 ++--------- Libtorrent.py | 59 ++++++++++++++++++++------------------------------- Player.py | 10 +++++---- functions.py | 1 - 4 files changed, 31 insertions(+), 51 deletions(-) diff --git a/Core.py b/Core.py index b6dc3e6..208defc 100644 --- a/Core.py +++ b/Core.py @@ -1247,8 +1247,6 @@ class Core: if url: self.__settings__.setSetting("lastTorrentUrl", url) torrent = Downloader.Torrent(self.userStorageDirectory, torrentFilesDirectory=self.torrentFilesDirectory) - if not torrent: torrent = Downloader.Torrent(self.userStorageDirectory, - torrentFilesDirectory=self.torrentFilesDirectory) self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url)) contentList = [] for filedict in torrent.getContentList(): @@ -1330,11 +1328,7 @@ class Core: ind = get("url") icon = get("thumbnail") if get("thumbnail") else '' path = torrent.getFilePath(int(ind)) - label = os.path.basename(path) - try: - label = urllib.unquote_plus(get("label")) - except: - print 'except' + label = unquote(get("label"), os.path.basename(path)) torrent.play_url_ind(int(ind), label, icon) torrent.__exit__() __ASsettings__.setSetting("folder", folder) @@ -1364,12 +1358,10 @@ class Core: def playSTRM(self, params={}): get = params.get xbmc.executebuiltin('xbmc.Playlist.Clear') - url = unquote(get("url"),None) + url = unquote(get("url"), None) if url: self.__settings__.setSetting("lastTorrentUrl", url) torrent = Downloader.Torrent(self.userStorageDirectory, torrentFilesDirectory=self.torrentFilesDirectory) - if not torrent: torrent = Downloader.Torrent(self.userStorageDirectory, - torrentFilesDirectory=self.torrentFilesDirectory) self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url)) contentList = [] for filedict in torrent.getContentList(): diff --git a/Libtorrent.py b/Libtorrent.py index 6446f6c..7ba7a74 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -123,7 +123,7 @@ class Libtorrent: xbmcvfs.mkdirs(self.torrentFilesPath) newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5( torrentUrl) + '.torrent' # + '.'+ baseName - if not xbmcvfs.exists(newFile): + if xbmcvfs.exists(newFile): xbmcvfs.delete(newFile) if not xbmcvfs.exists(newFile): try: @@ -328,33 +328,17 @@ class Libtorrent: #self.session.add_extension("smart_ban") # Session settings - session_settings = self.session.settings() - - session_settings.announce_to_all_tiers = True - session_settings.announce_to_all_trackers = True - session_settings.connection_speed = 100 - session_settings.peer_connect_timeout = 2 - session_settings.rate_limit_ip_overhead = True - session_settings.request_timeout = 5 - session_settings.torrent_connect_boost = 100 - - #libtorrent 0.15 compability - #session_settings = self.session.get_settings() - #session_settings['announce_to_all_tiers'] = True - #session_settings['announce_to_all_trackers'] = True - #session_settings['connection_speed'] = 100 - #session_settings['peer_connect_timeout'] = 2 - #session_settings['rate_limit_ip_overhead'] = True - #session_settings['request_timeout'] = 5 - #session_settings['torrent_connect_boost'] = 100 - - #tribler example never tested - #session_settings['user_agent'] = 'python_client/' + self.lt.version - #session_settings['auto_manage_startup'] = 30 - #session_settings['auto_manage_interval'] = 30 - #session_settings['dht_announce_interval'] = 60 - - self.session.set_settings(session_settings) + #session_settings = self.session.settings() + # + #session_settings.announce_to_all_tiers = True + #session_settings.announce_to_all_trackers = True + #session_settings.connection_speed = 100 + #session_settings.peer_connect_timeout = 2 + #session_settings.rate_limit_ip_overhead = True + #session_settings.request_timeout = 5 + #session_settings.torrent_connect_boost = 100 + # + #self.session.set_settings(session_settings) def encryptSession(self): # Encryption settings @@ -375,14 +359,16 @@ class Libtorrent: if None == self.magnetLink: self.torrentHandle = self.session.add_torrent({'ti': self.torrentFileInfo, 'save_path': self.storageDirectory, - 'flags': 0x300, - # 'storage_mode': self.lt.storage_mode_t.storage_mode_allocate, + #'flags': 0x300, + 'paused': False, + 'auto_managed': False, + 'storage_mode': self.lt.storage_mode_t.storage_mode_allocate, }) else: self.torrentFileInfo = self.getMagnetInfo() self.torrentHandle.set_sequential_download(True) - #self.torrentHandle.set_max_connections(60) - #self.torrentHandle.set_max_uploads(-1) + self.torrentHandle.set_max_connections(60) + self.torrentHandle.set_max_uploads(-1) self.stopSession() def stopSession(self): @@ -400,7 +386,7 @@ class Libtorrent: self.endPart = int((selectedFileInfo['offset'] + selectedFileInfo['size']) / self.piece_length) # print 'part ' + str(self.startPart)+ str(' ')+ str(self.endPart) multiplier = self.partOffset / 5 - print 'continueSession: multiplier ' + str(multiplier) + log('continueSession: multiplier ' + str(multiplier)) for i in range(self.startPart, self.startPart + self.partOffset): if i <= self.endPart: self.torrentHandle.piece_priority(i, 7) @@ -446,11 +432,12 @@ class Libtorrent: state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating'] - print '[%s] %.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ + log('[%s] %.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ (self.lt.version, s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, - s.num_peers, state_str[s.state]) - i = 0 + s.num_peers, state_str[s.state])) + debug('TRACKERS:' +str(self.torrentHandle.trackers())) + #i = 0 # for t in s.pieces: # if t: i=i+1 # print str(self.session.pop_alert()) diff --git a/Player.py b/Player.py index b713b13..f954b33 100644 --- a/Player.py +++ b/Player.py @@ -134,6 +134,7 @@ class TorrentPlayer(xbmc.Player): seeding_run = False ids_video = None episodeId = None + basename = '' def __init__(self, userStorageDirectory, torrentUrl, params={}): self.userStorageDirectory = userStorageDirectory @@ -425,10 +426,11 @@ class TorrentPlayer(xbmc.Player): ] def db_delete(self): - db = DownloadDB() - get = db.get(self.basename) - if get: - db.delete(get[0]) + if self.basename: + db = DownloadDB() + get = db.get(self.basename) + if get: + db.delete(get[0]) def seed(self, contentId): self.db_delete() diff --git a/functions.py b/functions.py index 40e3876..2b1163b 100644 --- a/functions.py +++ b/functions.py @@ -55,7 +55,6 @@ userStorageDirectory = __settings__.getSetting("storage") USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0" __addonpath__ = __settings__.getAddonInfo('path') icon = __addonpath__ + '/icon.png' -debug = __settings__.getSetting("debug") __version__ = __settings__.getAddonInfo('version') __plugin__ = __settings__.getAddonInfo('name') + " v." + __version__