advancedsettings.xml

pull/1/head
DiMartinoXBMC 2015-08-06 00:38:19 +03:00
parent e35dc7a06d
commit 92b56ca51f
7 changed files with 142 additions and 22 deletions

View File

@ -232,10 +232,10 @@ class BTClientPlayer(xbmc.Player):
iterator = 0 iterator = 0
ready_list=[] ready_list=[]
status = self.c.get_normalized_status() 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['progress'] > 0,
status['desired_rate'] > 0 and (status['download_rate'] > status['desired_rate'] or 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'])] status['download_rate'] * status['progress'] * 100 > status['desired_rate'])]
for cond in conditions: for cond in conditions:
if cond: if cond:
ready_list.append(True) ready_list.append(True)
@ -341,11 +341,13 @@ class BTClientPlayer(xbmc.Player):
while not response: while not response:
xbmc.sleep(100) xbmc.sleep(100)
if response: if response:
xbmc.sleep(3000)
#if 1==1:
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear() playlist.clear()
playlist.add(url, listitem) playlist.add(url, listitem)
xbmc.Player().play(playlist) xbmc.Player().play(playlist, listitem)
print "\nServing file on %s" % url log("Serving file on %s" % url)
return True return True
def onPlayBackStarted(self): def onPlayBackStarted(self):
@ -368,6 +370,19 @@ class BTClientPlayer(xbmc.Player):
f() f()
log('[onPlayBackStopped]: '+(str(("video", "stop", self.display_name)))) 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 @contextmanager
def attach(self, callback, *events): def attach(self, callback, *events):
for event in events: for event in events:

13
Core.py
View File

@ -71,16 +71,9 @@ class Core:
def sectionMenu(self): def sectionMenu(self):
if self.__settings__.getSetting('plugin_name')!=self.__plugin__: if self.__settings__.getSetting('plugin_name')!=self.__plugin__:
if self.__plugin__ == 'Torrenter v.2.3.2': if self.__plugin__ == 'Torrenter v.2.3.7':
#first_run_230(self.__settings__.getSetting('delete_russian')=='true') #first_run_231()
first_run_231() check_network_advancedsettings()
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')
self.__settings__.setSetting('plugin_name',self.__plugin__) self.__settings__.setSetting('plugin_name',self.__plugin__)
ListString = 'XBMC.RunPlugin(%s)' % (sys.argv[0] + '?action=%s&action2=%s&%s=%s') ListString = 'XBMC.RunPlugin(%s)' % (sys.argv[0] + '?action=%s&action2=%s&%s=%s')

View File

@ -267,7 +267,10 @@ def localize(text):
'Ask to save':'Спросить о сохранении', 'Ask to save':'Спросить о сохранении',
'Would you like to save this file?':'Хотите сохранить данный файл?', 'Would you like to save this file?':'Хотите сохранить данный файл?',
'Your storage path is not writable or not local! Please change it in settings!':'Ваше хранилище не доступно для записи или не локально! Измените в настройках!', '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': { 'uk': {
'Seeds searching.': 'Йде пошук сідів.', 'Seeds searching.': 'Йде пошук сідів.',

View File

@ -1748,3 +1748,74 @@ def chooseFile(filelist):
if ret > -1: if ret > -1:
return myshows_files[ret] 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='''<advancedsettings>
<network>
<buffermode>2</buffermode>
<curlclienttimeout>100</curlclienttimeout>
<cachemembuffersize>252420</cachemembuffersize>
<readbufferfactor>5</readbufferfactor>
</network>
</advancedsettings>'''
else:
with open(path) as f:
file_cont=f.read()
print str(file_cont)
if not updated and not re.search('<network>.+?</network>', file_cont, re.DOTALL):
updated=True
file_cont=file_cont.replace('<advancedsettings>',
'''<advancedsettings>
<network>
<buffermode>2</buffermode>
<curlclienttimeout>100</curlclienttimeout>
<cachemembuffersize>252420</cachemembuffersize>
<readbufferfactor>5</readbufferfactor>
</network>
</advancedsettings>''')
elif not updated:
for key in settings.keys():
search=re.search('<'+key+'>(.+?)</'+key+'>', file_cont, re.DOTALL)
if not search:
add[key]=settings[key]
elif int(search.group(1))<int(settings[key]):
print str(int(search.group(1)))
update[key]=settings[key]
print str(add)
print str(update)
if len(add)>0 or len(update)>0:
updated=True
for key in add.keys():
file_cont=file_cont.replace('<network>','<network>\r\n <'+key+'>'+str(add[key])+'</'+key+'>')
for key in update.keys():
file_cont=re.sub(r'<'+key+'>\d+</'+key+'>', '<'+key+'>'+str(update[key])+'</'+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)

View File

@ -203,7 +203,7 @@ class BTClient(BaseClient):
self.lt=lt self.lt=lt
self._cache = CacheBT(path_to_store, self.lt) self._cache = CacheBT(path_to_store, self.lt)
self._torrent_params = {'save_path': path_to_store, 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: if not state_file:
state_file=os.path.join(path_to_store,'.btclient_state') 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: if s.state in [3, 4, 5] and not self._file and s.progress > 0:
self._meta_ready(self._th.torrent_file()) self._meta_ready(self._th.torrent_file())
logger.debug('Got torrent metadata and start download') logger.debug('Got torrent metadata and start download')
self.hash = True
self.hash = Hasher(self._file, self._on_file_ready) self.hash = Hasher(self._file, self._on_file_ready)
def _choose_file(self, files, i): def _choose_file(self, files, i):
@ -425,6 +426,7 @@ class BTClient(BaseClient):
def close(self): def close(self):
self.remove_all_dispatcher_listeners() self.remove_all_dispatcher_listeners()
self._monitor.stop() self._monitor.stop()
self._cache.close()
if self._ses: if self._ses:
self._ses.pause() self._ses.pause()
if self._th: if self._th:
@ -435,7 +437,7 @@ class BTClient(BaseClient):
self._ses.remove_torrent(self._th) self._ses.remove_torrent(self._th)
except: except:
print 'RuntimeError: invalid torrent handle used' print 'RuntimeError: invalid torrent handle used'
#BaseClient.close(self) BaseClient.close(self)
@property @property
def status(self): def status(self):
@ -505,7 +507,6 @@ class BTClient(BaseClient):
(self.lt.version, s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, (self.lt.version, s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000,
s.num_peers, state_str[s.state])) s.num_peers, state_str[s.state]))
def get_normalized_status(self): def get_normalized_status(self):
s = self.status s = self.status
if self._file: if self._file:

View File

@ -18,7 +18,7 @@ from hachoir_metadata import extractMetadata
from hachoir_parser import guessParser from hachoir_parser import guessParser
import hachoir_core.config as hachoir_config import hachoir_core.config as hachoir_config
from hachoir_core.stream.input import InputIOStream from hachoir_core.stream.input import InputIOStream
from opensubtitle import OpenSubtitles #from opensubtitle import OpenSubtitles
logger = logging.getLogger('common') logger = logging.getLogger('common')
hachoir_config.quiet = True hachoir_config.quiet = True
@ -64,12 +64,48 @@ class Hasher(Thread):
self.start() self.start()
def run(self): def run(self):
pass
with self._btfile.create_cursor() as c: with self._btfile.create_cursor() as c:
filehash = OpenSubtitles.hash_file(c, self._btfile.size) filehash = OpenSubtitles.hash_file(c, self._btfile.size)
self.hash = filehash self.hash = filehash
self._hash_cb(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 = '<q' # little-endian long long
bytesize = struct.calcsize(longlongformat)
hash = filesize # @ReservedAssignment
if filesize < 65536 * 2:
raise ValueError("SizeError")
for _x in range(65536 / bytesize):
buffer = f.read(bytesize) # @ReservedAssignment
(l_value,) = struct.unpack(longlongformat, buffer)
hash += l_value
hash = hash & 0xFFFFFFFFFFFFFFFF # to remain as 64bit number @ReservedAssignment
f.seek(max(0, filesize - 65536))
for _x in range(65536 / bytesize):
buffer = f.read(bytesize) # @ReservedAssignment
(l_value,) = struct.unpack(longlongformat, buffer)
hash += l_value
hash = hash & 0xFFFFFFFFFFFFFFFF # @ReservedAssignment
returnedhash = "%016x" % hash
return returnedhash
class BaseMonitor(Thread): class BaseMonitor(Thread):
def __init__(self, client, name): def __init__(self, client, name):
Thread.__init__(self, name=name) Thread.__init__(self, name=name)

View File

@ -2,7 +2,7 @@
Created on Apr 2, 2015 Created on Apr 2, 2015
@author: ivan @author: ivan
'''
import xmlrpclib import xmlrpclib
import urllib2 import urllib2
import os.path import os.path
@ -259,3 +259,4 @@ if __name__ == '__main__':
down(args.video_file, args.lang, args.overwrite) down(args.video_file, args.lang, args.overwrite)
else: else:
list_subs(args.video_file, args.lang) list_subs(args.video_file, args.lang)
'''