From 92b56ca51ff4ac46a04e561794116876fd352f2d Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Thu, 6 Aug 2015 00:38:19 +0300 Subject: [PATCH] advancedsettings.xml --- BTClientPlayer.py | 25 ++++++++-- Core.py | 13 ++---- Localization.py | 5 +- functions.py | 73 +++++++++++++++++++++++++++++- resources/btclient/btclient.py | 7 +-- resources/btclient/common.py | 38 +++++++++++++++- resources/btclient/opensubtitle.py | 3 +- 7 files changed, 142 insertions(+), 22 deletions(-) diff --git a/BTClientPlayer.py b/BTClientPlayer.py index 84fa12f..64ff25b 100644 --- a/BTClientPlayer.py +++ b/BTClientPlayer.py @@ -232,10 +232,10 @@ class BTClientPlayer(xbmc.Player): iterator = 0 ready_list=[] status = self.c.get_normalized_status() - conditions=[status['state'] in ['downloading', 'finished', 'seeding'], status['desired_rate'] > 0, + conditions=[status['state'] in ['downloading', 'finished', 'seeding'], status['desired_rate'] > 0 or status['progress'] > 0.02, status['progress'] > 0, - status['desired_rate'] > 0 and (status['download_rate'] > status['desired_rate'] or - status['download_rate'] * status['progress'] * 100 > status['desired_rate'])] + status['desired_rate'] > 0 or status['progress'] > 0.02 and (status['download_rate'] > status['desired_rate'] or + status['download_rate'] * status['progress'] * 100 > status['desired_rate'])] for cond in conditions: if cond: ready_list.append(True) @@ -341,11 +341,13 @@ class BTClientPlayer(xbmc.Player): while not response: xbmc.sleep(100) if response: + xbmc.sleep(3000) + #if 1==1: playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear() playlist.add(url, listitem) - xbmc.Player().play(playlist) - print "\nServing file on %s" % url + xbmc.Player().play(playlist, listitem) + log("Serving file on %s" % url) return True def onPlayBackStarted(self): @@ -368,6 +370,19 @@ class BTClientPlayer(xbmc.Player): f() log('[onPlayBackStopped]: '+(str(("video", "stop", self.display_name)))) + + def onPlayBackSeek(self): + log('[onPlayBackSeek]: '+(str(("video", "seek", self.display_name)))) + self.pause() + self.buffer() + self.play() + + def onPlayBackSeekChapter(self): + log('[onPlayBackSeek]: '+(str(("video", "seek", self.display_name)))) + self.pause() + self.buffer() + self.play() + @contextmanager def attach(self, callback, *events): for event in events: diff --git a/Core.py b/Core.py index d8253b7..9d0bbce 100644 --- a/Core.py +++ b/Core.py @@ -71,16 +71,9 @@ class Core: def sectionMenu(self): if self.__settings__.getSetting('plugin_name')!=self.__plugin__: - if self.__plugin__ == 'Torrenter v.2.3.2': - #first_run_230(self.__settings__.getSetting('delete_russian')=='true') - first_run_231() - if self.__settings__.getSetting('delete_russian')!='false': - not_russian=delete_russian(ok=self.__settings__.getSetting('delete_russian')=='true', action='delete') - if not_russian: - self.__settings__.setSetting('delete_russian', 'true') - self.__settings__.setSetting('language', '0') - else: - self.__settings__.setSetting('delete_russian', 'false') + if self.__plugin__ == 'Torrenter v.2.3.7': + #first_run_231() + check_network_advancedsettings() self.__settings__.setSetting('plugin_name',self.__plugin__) ListString = 'XBMC.RunPlugin(%s)' % (sys.argv[0] + '?action=%s&action2=%s&%s=%s') diff --git a/Localization.py b/Localization.py index 389a88f..64d72cf 100644 --- a/Localization.py +++ b/Localization.py @@ -267,7 +267,10 @@ def localize(text): 'Ask to save':'Спросить о сохранении', 'Would you like to save this file?':'Хотите сохранить данный файл?', 'Your storage path is not writable or not local! Please change it in settings!':'Ваше хранилище не доступно для записи или не локально! Измените в настройках!', - + 'Upgrade advancedsettings.xml':'Обновление advancedsettings.xml', + 'We would like to set some advanced settings for you!':'Нам нужно обновить продвинутые настройки для работы!', + 'Do it!':'Скажите "ДА"!', + 'Please, restart Kodi now!':'Теперь перезагрузите Коди, пожалуйста!', }, 'uk': { 'Seeds searching.': 'Йде пошук сідів.', diff --git a/functions.py b/functions.py index 22a6560..165ee0e 100644 --- a/functions.py +++ b/functions.py @@ -1747,4 +1747,75 @@ def chooseFile(filelist): ret = xbmcgui.Dialog().select(Localization.localize('Search results:'), myshows_items) if ret > -1: - return myshows_files[ret] \ No newline at end of file + return myshows_files[ret] + +def check_network_advancedsettings(): + path=xbmc.translatePath('special://profile/advancedsettings.xml') + updated=False + #path='''C:\\Users\\Admin\\AppData\\Roaming\\Kodi\\userdata\\advancedsettings.xml''' + settings={'buffermode':2, 'curlclienttimeout':100, 'cachemembuffersize':252420, 'readbufferfactor':5} + add, update = {}, {} + + if not os.path.exists(path): + updated=True + file_cont=''' + + 2 + 100 + 252420 + 5 + +''' + else: + with open(path) as f: + file_cont=f.read() + + print str(file_cont) + + if not updated and not re.search('.+?', file_cont, re.DOTALL): + updated=True + file_cont=file_cont.replace('', +''' + + 2 + 100 + 252420 + 5 + +''') + elif not updated: + for key in settings.keys(): + search=re.search('<'+key+'>(.+?)', file_cont, re.DOTALL) + if not search: + add[key]=settings[key] + elif int(search.group(1))0 or len(update)>0: + updated=True + for key in add.keys(): + file_cont=file_cont.replace('','\r\n <'+key+'>'+str(add[key])+'') + for key in update.keys(): + file_cont=re.sub(r'<'+key+'>\d+', '<'+key+'>'+str(update[key])+'', file_cont) + print str(file_cont) + + if updated: + dialog=xbmcgui.Dialog() + ok=dialog.yesno(Localization.localize('Upgrade advancedsettings.xml'), + Localization.localize('We would like to set some advanced settings for you!'), + Localization.localize('Do it!')) + if ok: + print 'OUTPUT: ' + print str(file_cont) + + f=open(path, mode='w') + f.write(file_cont) + f.close() + dialog.ok(Localization.localize('Upgrade advancedsettings.xml'), + Localization.localize('Please, restart Kodi now!')) + print 'Restart Kodi' + else: + print 'UPDATE advancedsettings.xml disabled by user!' + sys.exit(1) \ No newline at end of file diff --git a/resources/btclient/btclient.py b/resources/btclient/btclient.py index d0d6e0a..7caecaa 100644 --- a/resources/btclient/btclient.py +++ b/resources/btclient/btclient.py @@ -203,7 +203,7 @@ class BTClient(BaseClient): self.lt=lt self._cache = CacheBT(path_to_store, self.lt) self._torrent_params = {'save_path': path_to_store, - 'storage_mode': self.lt.storage_mode_t.storage_mode_sparse + #'storage_mode': self.lt.storage_mode_t.storage_mode_sparse } if not state_file: state_file=os.path.join(path_to_store,'.btclient_state') @@ -249,6 +249,7 @@ class BTClient(BaseClient): if s.state in [3, 4, 5] and not self._file and s.progress > 0: self._meta_ready(self._th.torrent_file()) logger.debug('Got torrent metadata and start download') + self.hash = True self.hash = Hasher(self._file, self._on_file_ready) def _choose_file(self, files, i): @@ -425,6 +426,7 @@ class BTClient(BaseClient): def close(self): self.remove_all_dispatcher_listeners() self._monitor.stop() + self._cache.close() if self._ses: self._ses.pause() if self._th: @@ -435,7 +437,7 @@ class BTClient(BaseClient): self._ses.remove_torrent(self._th) except: print 'RuntimeError: invalid torrent handle used' - #BaseClient.close(self) + BaseClient.close(self) @property def status(self): @@ -505,7 +507,6 @@ class BTClient(BaseClient): (self.lt.version, s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state])) - def get_normalized_status(self): s = self.status if self._file: diff --git a/resources/btclient/common.py b/resources/btclient/common.py index 8cea8c2..a770b0c 100644 --- a/resources/btclient/common.py +++ b/resources/btclient/common.py @@ -18,7 +18,7 @@ from hachoir_metadata import extractMetadata from hachoir_parser import guessParser import hachoir_core.config as hachoir_config from hachoir_core.stream.input import InputIOStream -from opensubtitle import OpenSubtitles +#from opensubtitle import OpenSubtitles logger = logging.getLogger('common') hachoir_config.quiet = True @@ -64,12 +64,48 @@ class Hasher(Thread): self.start() def run(self): + pass with self._btfile.create_cursor() as c: filehash = OpenSubtitles.hash_file(c, self._btfile.size) self.hash = filehash self._hash_cb(filehash) +class OpenSubtitles(object): + USER_AGENT = 'BTClient' + + def __init__(self, lang, user='', pwd=''): + self._lang = lang + self._token = None + self._user = user + self._pwd = pwd + + @staticmethod + def hash_file(f, filesize): + import struct + + longlongformat = '