From 90ea77513c7f11db4c6adac6ad59cf6387ec926e Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 7 Mar 2016 20:58:43 +0300 Subject: [PATCH] fixes --- .idea/workspace.xml | 1012 ++++++++++++------------ Anteoloader.py | 34 +- Core.py | 8 +- Downloader.py | 2 +- Libtorrent.py | 36 +- Localization.py | 2 +- Player.py | 6 +- addon.xml | 2 +- changelog.txt | 4 + functions.py | 16 +- resources/language/English/strings.xml | 1 + resources/language/Russian/strings.xml | 1 + resources/settings.xml | 4 +- 13 files changed, 574 insertions(+), 554 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 84188cc..7cbf0b0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,20 @@ - + + + + + + + + + + @@ -94,12 +103,16 @@ - + - + + + + + @@ -118,16 +131,19 @@ + + + + - @@ -135,16 +151,22 @@ + + + + + + @@ -153,23 +175,33 @@ + + + + + + + + + + + + - - @@ -179,10 +211,11 @@ - + + + - @@ -194,17 +227,28 @@ - + + - - - - - - + + + + + + + + + + + + + + + + @@ -213,44 +257,34 @@ - - + + - + - - + + - - - - - - - - + + + + + + + + - - - - - - - - - - @@ -328,23 +362,21 @@ - + - - + + - - - - - - - - - - + + + + + + + + @@ -354,14 +386,13 @@ - + - - + + - @@ -370,16 +401,22 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -399,98 +436,63 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + - - + + - - - - - - - - - - - - - - - - - - - - - - - @@ -500,7 +502,7 @@ - + @@ -510,7 +512,7 @@ - + @@ -520,7 +522,7 @@ - + @@ -573,11 +575,9 @@ @@ -633,8 +635,6 @@ - - @@ -731,6 +731,8 @@ + + @@ -912,18 +914,6 @@ - + - + - + @@ -1230,7 +1232,7 @@ - + @@ -1247,7 +1249,6 @@ - @@ -1267,12 +1268,13 @@ - - @@ -1520,14 +1522,6 @@ - - - - - - - - @@ -1535,43 +1529,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1625,6 +1582,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1700,294 +1935,73 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/Anteoloader.py b/Anteoloader.py index 1eab055..f00d385 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -39,8 +39,12 @@ from contextlib import contextmanager, closing, nested from functions import foldername, showMessage, clearStorage, WatchedHistoryDB, get_ids_video, log, debug, ensure_str -from torrent2http import State, Engine, MediaType -#from pyrrent2http import State, Engine, MediaType +if sys.modules["__main__"].__settings__.getSetting("torrent_player") == '2': + from torrent2http import State, Engine, MediaType + author = 'Anteo' +elif sys.modules["__main__"].__settings__.getSetting("torrent_player") == '3': + from pyrrent2http import State, Engine, MediaType + author = 'Inpos' ROOT = sys.modules["__main__"].__root__ RESOURCES_PATH = os.path.join(ROOT, 'resources') @@ -210,8 +214,8 @@ class AnteoLoader: localFile.write(content) localFile.close() except Exception, e: - print 'Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str( - e) + log('Unable to rename torrent file from %s to %s in AnteoLoader::saveTorrent. Exception: %s' % + (torrentUrl, torrentFile, str(e))) return else: torrentFile = torrentUrl @@ -239,7 +243,7 @@ class AnteoLoader: self.torrentFile = torrent.torrentFile except: self.torrentFile = magnet - log('[AnteoLoader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile)) + log('['+author+'Loader][magnetToTorrent]: self.torrentFile '+str(self.torrentFile)) class AnteoPlayer(xbmc.Player): __plugin__ = sys.modules["__main__"].__plugin__ @@ -278,15 +282,15 @@ class AnteoPlayer(xbmc.Player): self.setup_nextep() while True: if self.buffer(): - log('[AnteoPlayer]: ************************************* GOING LOOP') + log('['+author+'Player]: ************************************* GOING LOOP') if self.setup_play(): self.setup_subs() self.loop() WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize) else: - log('[AnteoPlayer]: ************************************* break') + log('['+author+'Player]: ************************************* break') break - log('[AnteoPlayer]: ************************************* GO NEXT?') + log('['+author+'Player]: ************************************* GO NEXT?') if self.next_dl and self.next_contentId != False and isinstance(self.next_contentId, int) and self.iterator == 100: if not self.next_play: xbmc.sleep(3000) @@ -296,7 +300,7 @@ class AnteoPlayer(xbmc.Player): break self.contentId = self.next_contentId continue - log('[AnteoPlayer]: ************************************* NO! break') + log('['+author+'Player]: ************************************* NO! break') break xbmc.Player().stop() @@ -455,7 +459,7 @@ class AnteoPlayer(xbmc.Player): else: self.next_dl = False self.next_play = self.__settings__.getSetting('next_play') == 'true' - log('[AnteoPlayer]: next_dl - %s, next_play - %s, ids_video - %s' % (str(self.next_dl), str(self.next_play), str(self.ids_video))) + log('['+author+'Player]: next_dl - %s, next_play - %s, ids_video - %s' % (str(self.next_dl), str(self.next_play), str(self.ids_video))) def setup_play(self): file_status = self.engine.file_status(self.contentId) @@ -474,7 +478,7 @@ class AnteoPlayer(xbmc.Player): self.next_contentId = int(self.ids_video[next_contentId_index]) else: self.next_contentId = False - log('[AnteoPlayer][setup_play]: next_contentId: '+str(self.next_contentId)) + log('['+author+'Player][setup_play]: next_contentId: '+str(self.next_contentId)) try: seasonId = self.get("seasonId") self.episodeId = self.get("episodeId") if not self.episodeId else int(self.episodeId) + 1 @@ -494,7 +498,7 @@ class AnteoPlayer(xbmc.Player): 'season': int(seasonId), 'tvshowtitle': title}) except: - log('[AnteoPlayer]: Operation INFO failed!') + log('['+author+'Player]: Operation INFO failed!') thumbnail = self.get("thumbnail") if thumbnail: @@ -510,12 +514,12 @@ class AnteoPlayer(xbmc.Player): xbmc.sleep(200) i += 1 - log('[AnteoPlayer]: self.isPlaying() = %s, i = %d, xbmc.abortRequested - %s' % (str(self.isPlaying()), i, str(xbmc.abortRequested))) + log('['+author+'Player]: self.isPlaying() = %s, i = %d, xbmc.abortRequested - %s' % (str(self.isPlaying()), i, str(xbmc.abortRequested))) if not self.isPlaying() or xbmc.abortRequested: return False if self.seek > 0: - log('[AnteoPlayer]: seekTime - '+str(self.seek)) + log('['+author+'Player]: seekTime - '+str(self.seek)) self.seekTime(self.seek) return True @@ -622,7 +626,7 @@ class AnteoPlayer(xbmc.Player): if not status: status = self.engine.status() self.engine.check_torrent_error(status) - log('[AnteoPlayer]: %.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % \ + log('['+author+'Player]: %.2f%% complete (down: %.1f kb/s up: %.1f kb/s peers: %d) %s' % \ (status.progress * 100, status.download_rate, status.upload_rate, status.num_peers, status.state_str)) diff --git a/Core.py b/Core.py index 52e08fe..c0a2277 100644 --- a/Core.py +++ b/Core.py @@ -35,7 +35,7 @@ class Core: userStorageDirectory = file_encode(__settings__.getSetting("storage")) torrentFilesDirectory = 'torrents' debug = __settings__.getSetting('debug') == 'true' - torrent_player=__settings__.getSetting("torrent_player") + torrent_player = __settings__.getSetting("torrent_player") history_bool = __settings__.getSetting('history') == 'true' open_option = int(__settings__.getSetting('open_option')) language = {0: 'en', 1: 'ru', 2: 'uk', 3: 'he'}.get(int(__settings__.getSetting("language"))) @@ -54,7 +54,7 @@ class Core: def sectionMenu(self): if self.__settings__.getSetting('plugin_name') != self.__plugin__: #Every update run - first_run_242() + first_run_250() self.__settings__.setSetting('plugin_name', self.__plugin__) #check_network_advancedsettings() check_download_dir() @@ -100,7 +100,7 @@ class Core: image=self.ROOT + '/icons/torrentPlayer.png') self.drawItem('< %s >' % self.localize('Search Control Window'), 'controlCenter', image=self.ROOT + '/icons/settings.png', isFolder=False) - self.drawItem('< %s >' % self.localize('Magnet-link Player'), 'magentPlayer',#if self.torrent_player!='1': + self.drawItem('< %s >' % self.localize('Magnet-link Player'), 'magentPlayer', image=self.ROOT + '/icons/magnet.png') if self.debug: self.drawItem('full_download', 'full_download', image=self.ROOT + '/icons/magnet.png') @@ -1413,7 +1413,7 @@ class Core: self.Player = TorrentPlayer(userStorageDirectory=self.userStorageDirectory, torrentUrl=torrentUrl, params=params) else: log(self.__plugin__ + " Unexpected access to method playTorrent() without torrent content") - elif self.torrent_player == '2': + elif self.torrent_player == '2' or self.torrent_player == '3': from Anteoloader import AnteoPlayer if 0 != len(torrentUrl): self.Player = AnteoPlayer(userStorageDirectory=self.userStorageDirectory, torrentUrl=torrentUrl, params=params) diff --git a/Downloader.py b/Downloader.py index 3d326f3..bde7252 100644 --- a/Downloader.py +++ b/Downloader.py @@ -49,7 +49,7 @@ class Torrent(): self.player = 'libtorrent' elif player == '1': self.player = 'acestream' - elif player == '2': + elif player == '2' or player == '3': self.player = 'anteo' def play_url_ind(self, ind, label, icon): diff --git a/Libtorrent.py b/Libtorrent.py index 1ee5c3d..1e25088 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -138,8 +138,8 @@ class Libtorrent: try: xbmcvfs.rename(torrentFile, newFile) except Exception, e: - print 'Unable to rename torrent file from "' + torrentFile + '" to "' + newFile + '" in Torrent::renameTorrent' + '. Exception: ' + str( - e) + log('Unable to rename torrent file from %s to %s in Torrent::renameTorrent. Exception: %s' % + (torrentFile, newFile, str(e))) return self.torrentFile = newFile if not self.torrentFileInfo: @@ -436,7 +436,7 @@ class Libtorrent: else: resume_file=self.resume_data_path() if xbmcvfs.exists(resume_file): - log('loading resume data from file'+resume_file) + log('loading resume data from file '+resume_file) try: resumDataFile=xbmcvfs.File(resume_file,'rb') self.save_resume_data=resumDataFile.read() @@ -444,7 +444,7 @@ class Libtorrent: torrent_info['resume_data']=self.save_resume_data except: - log(' Failed to load resume data from file'+ resume_file) + log('Failed to load resume data from file '+ resume_file) self.torrentHandle = self.session.add_torrent(torrent_info) self.torrentHandle.set_sequential_download(True) self.torrentHandle.set_max_connections(60) @@ -454,7 +454,6 @@ class Libtorrent: def stopSession(self): for i in range(self.torrentFileInfo.num_pieces()): self.torrentHandle.piece_priority(i, 0) - self.resume_data() def continueSession(self, contentId=0, Offset=0, seeding=False, isMP4=False): self.piece_length = self.torrentFileInfo.piece_length() @@ -462,10 +461,8 @@ class Libtorrent: if not Offset: Offset = selectedFileInfo['size'] / (1024 * 1024) self.partOffset = (Offset * 1024 * 1024 / self.piece_length) + 1 - # print 'partOffset ' + str(self.partOffset)+str(' ') self.startPart = selectedFileInfo['offset'] / self.piece_length self.endPart = int((selectedFileInfo['offset'] + selectedFileInfo['size']) / self.piece_length) - # print 'part ' + str(self.startPart)+ str(' ')+ str(self.endPart) multiplier = self.partOffset / 5 log('continueSession: multiplier ' + str(multiplier)) for i in range(self.startPart, self.startPart + self.partOffset): @@ -473,13 +470,12 @@ class Libtorrent: self.torrentHandle.piece_priority(i, 7) if isMP4 and i % multiplier == 0: self.torrentHandle.piece_priority(self.endPart - i / multiplier, 7) - # print str(i) if multiplier >= i: self.torrentHandle.piece_priority(self.endPart - i, 7) - # print str(i) def checkThread(self): if self.threadComplete == True: + self.resume_data() log('checkThread KIIIIIIIIIIILLLLLLLLLLLLLLL') try: self.session.remove_torrent(self.torrentHandle) @@ -491,6 +487,7 @@ class Libtorrent: self.session.stop_dht() def resume_data(self): + wasPaused=self.session.is_paused() self.session.pause() self.save_resume_data=None @@ -504,7 +501,7 @@ class Libtorrent: return log('[save_resume_data]: waiting for alert...') - self.torrentHandle.save_resume_data() + self.torrentHandle.save_resume_data(self.lt.save_resume_flags_t.flush_disk_cache) received=False while not received: self.session.wait_for_alert(1000) @@ -528,19 +525,20 @@ class Libtorrent: log('[save_resume_data]: done.') finally: - self.session.resume() + if not wasPaused: + self.session.resume() def debug(self): #try: if 1==1: - # print str(self.getFilePath(0)) + # log(str(self.getFilePath(0))) s = self.torrentHandle.status() #get_cache_status=self.session.get_cache_status() #log('get_cache_status - %s/%s' % (str(get_cache_status.blocks_written), str(get_cache_status.blocks_read))) # get_settings=self.torrentHandle.status - # print s.num_pieces + # log(s.num_pieces) #priorities = self.torrentHandle.piece_priorities() - #print str(priorities) + #log(str(priorities)) state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume'] @@ -562,11 +560,11 @@ class Libtorrent: #i = 0 # for t in s.pieces: # if t: i=i+1 - #print str(self.session.pop_alert()) - # print str(s.pieces[self.startPart:self.endPart]) - # print 'True pieces: %d' % i - # print s.current_tracker - # print str(s.pieces) + #log(str(self.session.pop_alert()) + # log(str(s.pieces[self.startPart:self.endPart])) + # log('True pieces: %d' % i) + # log(s.current_tracker) + # log(str(s.pieces)) #except: else: log('debug error') diff --git a/Localization.py b/Localization.py index f6d47a0..80f0800 100644 --- a/Localization.py +++ b/Localization.py @@ -539,7 +539,7 @@ def localize(text): 'Please, restart Kodi now!':'Теперь перезагрузите Коди, пожалуйста!', './ (Root folder)':'./ (Корневой каталог)', 'Opening torrent file':'Открытие torrent-файла', - 'New player to Torrenter v2 - Torrent2HTTP! It should be faster, stable and better with Android, also seeking works in it.':'В Torrenter новый плеер - Torrent2HTTP! Он стабильнее, быстрее и отлично ладит с Android, в нем работает перемотка.', + 'New player to Torrenter v2 - pyrrent2http! Advantages of Torrent2HTTP but with python-libtorrent library instead of libtorrent-go!':'В Torrenter новый плеер - pyrrent2http! Преимущества Torrent2HTTP, но на библиотеке python-libtorrent вместо libtorrent-go!', 'Would you like to try it?':'Хотите его попробовать?', 'Torrent2HTTP enabled! Can be changed in Settings.':'Torrent2HTTP включен! Можно изменить в Настройках.', 'Seeking':'Перемотка', diff --git a/Player.py b/Player.py index bc6ed87..39f4c66 100644 --- a/Player.py +++ b/Player.py @@ -259,7 +259,7 @@ class TorrentPlayer(xbmc.Player): downloadedSize = self.torrent.torrentHandle.file_progress()[self.contentId] status = self.torrent.torrentHandle.status() iterator = int(status.progress * 100) - if status.state == 0 or (status.progress == 0 and status.num_pieces > 0): + if status.state in [0, 1] or (status.progress == 0 and status.num_pieces > 0): iterator = int(status.num_pieces * 100 / num_pieces) if iterator > 99: iterator = 99 progressBar.update(iterator, self.localize('Checking preloaded files...'), ' ', ' ') @@ -286,10 +286,8 @@ class TorrentPlayer(xbmc.Player): self.torrent.checkThread() return xbmc.sleep(1000) - #self.torrent.torrentHandle.flush_cache() - #self.torrent.session.remove_torrent(self.torrent.torrentHandle) self.torrent.resume_data() - self.torrent.session.remove_torrent(self.torrent.torrentHandle) + #self.torrent.session.remove_torrent(self.torrent.torrentHandle) progressBar.update(0) progressBar.close() return True diff --git a/addon.xml b/addon.xml index c39c21a..938d89d 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@  - + diff --git a/changelog.txt b/changelog.txt index edb5c2b..91811fb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ English changelog at http://bit.ly/1MfSVUP +[B]Version 2.5.0[/B] +[+] НОВЫЙ проигрыватель pyrrent2http от inpos! Аналог torrent2http написаный на python, а не на GO. +[+] Проигрыватель: Ускорена повторная работа с торрентом - resume data (спасибо srg70 и RussakHH) + [B]Version 2.4.6[/B] [+] Проигрыватель: Уменьшена просадка после загрузки буфера (спасибо srg70 и RussakHH) [+] История Просмотров: Добавлено имя раздачи, тонкая настройка добавления по проценту просмотра diff --git a/functions.py b/functions.py index 4228fbe..8026f0d 100644 --- a/functions.py +++ b/functions.py @@ -1749,15 +1749,15 @@ def first_run_231(): xbmc.executebuiltin('Dialog.Close(all,true)') xbmc.executebuiltin('XBMC.ActivateWindow(Addonbrowser,addons://search/%s)' % ('Torrenter Searcher')) -def first_run_242(): - if __settings__.getSetting('torrent_player')=='2': - __settings__.setSetting('first_run_242','True') +def first_run_250(): + if __settings__.getSetting('torrent_player')=='3': + __settings__.setSetting('first_run_250','True') - if not __settings__.getSetting('first_run_242')=='True': - __settings__.setSetting('first_run_242','True') - yes=xbmcgui.Dialog().yesno('< %s >' % (Localization.localize('Torrenter Update ') + '2.4.2'), - Localization.localize('New player to Torrenter v2 - Torrent2HTTP! It should be faster, ' - 'stable and better with Android, also seeking works in it.'), + if not __settings__.getSetting('first_run_250')=='True': + __settings__.setSetting('first_run_250','True') + yes=xbmcgui.Dialog().yesno('< %s >' % (Localization.localize('Torrenter Update ') + '2.5.0'), + Localization.localize('New player to Torrenter v2 - pyrrent2http! Advantages of Torrent2HTTP ' + 'but with python-libtorrent library instead of libtorrent-go!'), Localization.localize('Would you like to try it?'),) if yes: __settings__.openSettings() diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index c4dc59f..da2da48 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -65,6 +65,7 @@ Do not add to Watched History if played more (%) Confluence (by safonov_ivan) Aeon Nox (by joyrider) + pyrrent2http (python-libtorrent via http) Interface P2P Network Advanced diff --git a/resources/language/Russian/strings.xml b/resources/language/Russian/strings.xml index 0055e9c..3bd940f 100644 --- a/resources/language/Russian/strings.xml +++ b/resources/language/Russian/strings.xml @@ -65,6 +65,7 @@ Не добавлять в История Просмотров если больше (%) Confluence (от safonov_ivan) Aeon Nox (от joyrider) + pyrrent2http (python-libtorrent по http) Интерфейс P2P Сеть Дополнительные diff --git a/resources/settings.xml b/resources/settings.xml index 1e8df80..1dc796b 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -15,7 +15,7 @@ - + @@ -61,7 +61,7 @@ - +