From c63401533c5c5ba3edaa12e408586ddce46eec6f Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Tue, 4 Aug 2015 20:47:39 +0300 Subject: [PATCH] playSTRM choose file --- Core.py | 85 ++++++--------------------------------------------- Libtorrent.py | 40 +++++++++++++----------- changelog.txt | 4 +-- 3 files changed, 34 insertions(+), 95 deletions(-) diff --git a/Core.py b/Core.py index d260c98..a191c75 100644 --- a/Core.py +++ b/Core.py @@ -42,23 +42,6 @@ class Core: history_bool = __settings__.getSetting('history') == 'true' open_option = int(__settings__.getSetting('open_option')) language = {0: 'en', 1: 'ru', 2: 'ru'}.get(int(__settings__.getSetting("language"))) - htmlCodes = ( - ('&', '&'), - ('<', '<'), - ('>', '>'), - ('"', '"'), - ("'", '''), - ) - stripPairs = ( - ('

', '\n'), - ('

  • ', '\n'), - ('
    ', '\n'), - ('<.+?>', ' '), - ('', ' '), - (' ', ' '), - ('«', '"'), - ('»', '"'), - ) scrapperDB_ver = {'en':'1.1', 'ru':'1.3'} print 'SYS ARGV: ' + str(sys.argv) @@ -1044,16 +1027,6 @@ class Core: commands[name] = value return commands - def unescape(self, string): - for (symbol, code) in self.htmlCodes: - string = re.sub(code, symbol, string) - return string - - def stripHtml(self, string): - for (html, replacement) in self.stripPairs: - string = re.sub(html, replacement, string) - return string - def executeAction(self, params={}): get = params.get if hasattr(self, get("action")): @@ -1230,9 +1203,9 @@ class Core: showMessage(self.localize('Error'), self.localize('Not a magnet-link!')) return elif keyboard.isConfirmed(): - params["url"] = urllib.quote_plus(self.unescape(urllib.unquote_plus(query))) + params["url"] = urllib.quote_plus(unescape(urllib.unquote_plus(query))) else: - params["url"] = urllib.quote_plus(self.unescape(urllib.unquote_plus(defaultKeyword))) + params["url"] = urllib.quote_plus(unescape(urllib.unquote_plus(defaultKeyword))) #print str(params) self.torrentPlayer(params) @@ -1258,7 +1231,7 @@ class Core: fileTitle = filedict.get('title') if filedict.get('size'): fileTitle += ' [%d MB]' % (filedict.get('size') / 1024 / 1024) - contentList.append((self.unescape(fileTitle), str(filedict.get('ind')))) + contentList.append((unescape(fileTitle), str(filedict.get('ind')))) contentList = sorted(contentList, key=lambda x: x[0]) #print str(contentList) @@ -1375,16 +1348,9 @@ class Core: self.__settings__.setSetting("lastTorrentUrl", url) torrent = Downloader.Torrent(self.userStorageDirectory, torrentFilesDirectory=self.torrentFilesDirectory) self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url)) - contentList = [] - for filedict in torrent.getContentList(): - fileTitle = filedict.get('title') - if filedict.get('size'): - fileTitle += ' [%d MB]' % (filedict.get('size') / 1024 / 1024) - contentList.append((filedict.get('size'), self.unescape(fileTitle), str(filedict.get('ind')))) - if len(contentList)>0: - contentList = sorted(contentList, key=lambda x: x[0], reverse=True) - #self.playTorrent({'url':contentList[0][2]}) - xbmc.executebuiltin('xbmc.RunPlugin("plugin://plugin.video.torrenter/?action=playTorrent&url='+contentList[0][2]+'")') + fileIndex = chooseFile(torrent.getContentList()) + if fileIndex: + xbmc.executebuiltin('xbmc.RunPlugin("plugin://plugin.video.torrenter/?action=playTorrent&url='+fileIndex+'")') def openTorrent(self, params={}): get = params.get @@ -1413,47 +1379,16 @@ class Core: self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url)) if silent != 'true': if external: - myshows_items, myshows_files, contentList, myshows_sizes = [], [], [], {} - for filedict in torrent.getContentList(): - fileTitle = '' - if filedict.get('size'): - myshows_sizes[str(filedict.get('ind'))]='[%d MB] ' % (filedict.get('size') / 1024 / 1024) - title = filedict.get('title') - fileTitle = fileTitle + '[%s]%s' % (title[len(title) - 3:], title) - contentList.append((self.unescape(fileTitle), str(filedict.get('ind')))) - contentList = sorted(contentList, key=lambda x: x[0]) - for title, identifier in contentList: - try: - if title.split('.')[-1].lower() in ['avi','mp4','mkv','flv','mov','vob','wmv','ogm','asx','mpg','mpeg','avc','vp3','fli','flc','m4v','iso','mp3']: - myshows_items.append(title) - myshows_files.append(identifier) - except: - pass - if len(myshows_items) > 1: - if len(myshows_sizes)==0: - myshows_items = cutFileNames(myshows_items) - else: - myshows_cut = cutFileNames(myshows_items) - myshows_items=[] - x=-1 - for i in myshows_files: - x=x+1 - fileTitle=myshows_sizes[str(i)]+myshows_cut[x] - myshows_items.append(fileTitle) - dialog = xbmcgui.Dialog() - if len(myshows_items) == 1: - ret = 0 - else: - ret = dialog.select(self.localize('Search results:'), myshows_items) - if ret > -1: - xbmc.executebuiltin('xbmc.RunPlugin("plugin://plugin.video.torrenter/?action=playTorrent&url=' + myshows_files[ret] + '")') + fileIndex = chooseFile(torrent.getContentList()) + if fileIndex: + xbmc.executebuiltin('xbmc.RunPlugin("plugin://plugin.video.torrenter/?action=playTorrent&url=' + fileIndex + '")') else: contentList = [] for filedict in torrent.getContentList(): fileTitle = filedict.get('title') if filedict.get('size'): fileTitle += ' [%d MB]' % (filedict.get('size') / 1024 / 1024) - contentList.append((self.unescape(fileTitle), str(filedict.get('ind')))) + contentList.append((unescape(fileTitle), str(filedict.get('ind')))) contentList = sorted(contentList, key=lambda x: x[0]) dirList, contentListNew = cutFolder(contentList, tdir) diff --git a/Libtorrent.py b/Libtorrent.py index 2f8bb00..267f633 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -154,8 +154,8 @@ class Libtorrent: 'save_path': self.storageDirectory, 'storage_mode': self.lt.storage_mode_t(0), 'paused': True, - 'auto_managed': True, - 'duplicate_is_error': True + #'auto_managed': True, + #'duplicate_is_error': True } progressBar = xbmcgui.DialogProgress() progressBar.create(Localization.localize('Please Wait'), Localization.localize('Magnet-link is converting')) @@ -180,21 +180,25 @@ class Libtorrent: self.magnetLink = magnet self.initSession() torrentInfo = self.getMagnetInfo() - try: - torrentFile = self.lt.create_torrent(torrentInfo) - baseName = os.path.basename(self.storageDirectory + os.sep + torrentInfo.files()[0].path) - if not xbmcvfs.exists(self.torrentFilesPath): - xbmcvfs.mkdirs(self.torrentFilesPath) - self.torrentFile = self.torrentFilesPath + self.md5(baseName) + '.torrent' - torentFileHandler = xbmcvfs.File(self.torrentFile, "w+b") - torentFileHandler.write(self.lt.bencode(torrentFile.generate())) - torentFileHandler.close() - e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read()) - self.torrentFileInfo = self.lt.torrent_info(e) - except: - xbmc.executebuiltin("Notification(%s, %s, 7500)" % (Localization.localize('Error'), Localization.localize( - 'Can\'t download torrent, probably no seeds available.'))) - self.torrentFileInfo = torrentInfo + if torrentInfo: + try: + torrentFile = self.lt.create_torrent(torrentInfo) + baseName = os.path.basename(self.storageDirectory + os.sep + torrentInfo.files()[0].path) + if not xbmcvfs.exists(self.torrentFilesPath): + xbmcvfs.mkdirs(self.torrentFilesPath) + self.torrentFile = self.torrentFilesPath + self.md5(baseName) + '.torrent' + torentFileHandler = xbmcvfs.File(self.torrentFile, "w+b") + torentFileHandler.write(self.lt.bencode(torrentFile.generate())) + torentFileHandler.close() + e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read()) + self.torrentFileInfo = self.lt.torrent_info(e) + except: + xbmc.executebuiltin("Notification(%s, %s, 7500)" % (Localization.localize('Error'), Localization.localize( + 'Can\'t download torrent, probably no seeds available.'))) + self.torrentFileInfo = torrentInfo + finally: + self.session.remove_torrent(self.torrentHandle) + self.torrentHandle = None def getUploadRate(self): if None == self.torrentHandle: @@ -538,7 +542,7 @@ class Libtorrent: try: nodes=self.session.dht_state().get('nodes') except: - nodes=None + nodes=self.session.status().get('nodes_num') nodes=len(nodes) if nodes else 0 result='DHT: %s (%d)' % (is_dht_running, nodes) return result diff --git a/changelog.txt b/changelog.txt index 9d16225..0e7989d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,8 +1,8 @@ English changelog at http://bit.ly/1MfSVUP [B]Version 2.3.6[/B] -[+] Оптимизация импорта -[+] Новый Проигрыватель BTclient (https://github.com/izderadicka/btclient) в тестовом режиме. +[+] Оптимизация импорта, ускорена работа меню +[+] Новый Проигрыватель [url=https://github.com/izderadicka/btclient]BTclient[/url] в тестовом режиме, требует python-libtorrent >=1.0.4. [B]Version 2.3.5[/B] [+] Проигрыватель: Уменьшена просадка после загрузки буфера