From c41d55ef1c47f03340d05d20e318830d58eb710e Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Thu, 25 Feb 2016 22:29:18 +0300 Subject: [PATCH] history update --- .idea/workspace.xml | 962 ++++++++++++------------- Anteoloader.py | 12 +- Core.py | 10 +- Libtorrent.py | 16 + Player.py | 11 +- changelog.txt | 4 + functions.py | 27 +- resources/language/English/strings.xml | 1 + resources/language/Russian/strings.xml | 1 + resources/settings.xml | 1 + 10 files changed, 537 insertions(+), 508 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bce384e..b687182 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,11 +3,14 @@ + - + + + + - @@ -41,8 +44,8 @@ - - + + @@ -101,59 +104,58 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -162,46 +164,44 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -211,7 +211,7 @@ - + @@ -223,7 +223,6 @@ - @@ -231,13 +230,9 @@ - - - - - - - + + + @@ -247,7 +242,7 @@ - + @@ -256,8 +251,8 @@ - - + + @@ -266,8 +261,8 @@ - - + + @@ -280,30 +275,29 @@ - - + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -322,8 +316,8 @@ - - + + @@ -332,36 +326,38 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -370,8 +366,8 @@ - - + + @@ -380,8 +376,8 @@ - - + + @@ -409,7 +405,6 @@ @@ -494,7 +490,7 @@ - + @@ -529,7 +525,7 @@ - + @@ -711,12 +707,6 @@ - + - + - + + + @@ -1027,11 +1025,9 @@ - - @@ -1068,10 +1064,10 @@ - - @@ -1080,13 +1076,6 @@ - - - - - - - @@ -1266,15 +1255,6 @@ - - - - - - - - - @@ -1311,7 +1291,6 @@ - @@ -1323,10 +1302,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1338,7 +1542,6 @@ - @@ -1346,193 +1549,17 @@ - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -1591,105 +1618,58 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Anteoloader.py b/Anteoloader.py index 8eca8ec..252ab99 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -38,7 +38,7 @@ import sys from contextlib import contextmanager, closing, nested -from functions import calculate, showMessage, clearStorage, WatchedHistoryDB, get_ids_video, log, debug, ensure_str +from functions import foldername, showMessage, clearStorage, WatchedHistoryDB, get_ids_video, log, debug, ensure_str from torrent2http import State, Engine, MediaType @@ -282,7 +282,7 @@ class AnteoPlayer(xbmc.Player): if self.setup_play(): self.setup_subs() self.loop() - WatchedHistoryDB().add(self.basename, self.watchedTime, self.totalTime, self.contentId, self.fullSize) + WatchedHistoryDB().add(self.basename, foldername(self.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize) else: log('[AnteoPlayer]: ************************************* break') break @@ -635,6 +635,14 @@ class AnteoPlayer(xbmc.Player): contentList = sorted(contentList, key=lambda x: x[0]) return get_ids_video(contentList) + def getContentList(self): + filelist = [] + for fs in self.engine.list(): + stringdata = {"title": ensure_str(fs.name), "size": fs.size, "ind": fs.index, + 'offset': fs.offset} + filelist.append(stringdata) + return filelist + class OverlayText(object): def __init__(self, w, h, *args, **kwargs): self.window = xbmcgui.Window(WINDOW_FULLSCREEN_VIDEO) diff --git a/Core.py b/Core.py index cdc74ec..b1c562c 100644 --- a/Core.py +++ b/Core.py @@ -572,7 +572,7 @@ class Core: showMessage(self.localize('Watched History'), self.localize('Deleted!')) if action2 == 'open': - filename, path, url, seek, length, ind = db.get('filename, path, url, seek, length, ind', 'addtime', str(addtime)) + filename, foldername, path, url, seek, length, ind = db.get('filename, foldername, path, url, seek, length, ind', 'addtime', str(addtime)) if os.path.exists(path): self.__settings__.setSetting("lastTorrent", path) else: @@ -609,11 +609,15 @@ class Core: if items: ListString = 'XBMC.RunPlugin(%s)' % (sys.argv[0] + '?action=%s&action2=%s&%s=%s') #for favbool, bbstring in favlist: - for addtime, filename, path, url, seek, length, ind, size in items: + for addtime, filename, foldername, path, url, seek, length, ind, size in items: seek = int(seek) if int(seek) > 3*60 else 0 watchedPercent = int((float(seek) / float(length)) * 100) duration = '%02d:%02d:%02d' % ((length / (60*60)), (length / 60) % 60, length % 60) - title = '[%d%%][%s] %s [%d MB]' % (watchedPercent, duration, filename.encode('utf-8'), int(size)) + title = '[%d%%][%s] %s [%d MB]' %\ + (watchedPercent, duration, filename.encode('utf-8'), int(size)) + clDimgray = '[COLOR FF696969]%s[/COLOR]' + + title = title + chr(10) + clDimgray % '(%s)' % foldername.encode('utf-8') if self.torrent_player == '2' and seek > 0: seek_text = '%02d:%02d:%02d' % ((seek / (60*60)), (seek / 60) % 60, seek % 60) contextMenu = [(self.localize('Play (from %s)') % seek_text, ListString % ('WatchedHistory', 'playwithseek', 'addtime', str(addtime))), diff --git a/Libtorrent.py b/Libtorrent.py index c7b9aef..cef814d 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -430,6 +430,9 @@ class Libtorrent: #'auto_managed': False, #'duplicate_is_error': True } + if self.save_resume_data: + log('loading resume data') + torrent_info['resume_data']=self.save_resume_data self.torrentHandle = self.session.add_torrent(torrent_info) self.torrentHandle.set_sequential_download(True) @@ -475,6 +478,19 @@ class Libtorrent: self.session.stop_lsd() self.session.stop_dht() + def resume_data(self): + self.torrentHandle.save_resume_data() + received=False + while not received: + self.session.wait_for_alert(1000) + a = self.session.pop_alert() + log('[save_resume_data]: ['+str(type(a))+'] the alert '+str(a)+' is received') + if type(a) == self.lt.save_resume_data_alert: + received = True + debug('[save_resume_data]: '+str(dir(a))) + self.save_resume_data=self.lt.bencode(a.resume_data) + log('[save_resume_data]: the torrent resume data are saved') + def debug(self): #try: if 1==1: diff --git a/Player.py b/Player.py index 20aa2b5..0634b3b 100644 --- a/Player.py +++ b/Player.py @@ -30,7 +30,7 @@ import Downloader import xbmcgui import xbmcvfs import Localization -from functions import calculate, showMessage, clearStorage, WatchedHistoryDB, DownloadDB, get_ids_video, log, debug +from functions import calculate, showMessage, clearStorage, WatchedHistoryDB, DownloadDB, get_ids_video, log, debug, foldername ROOT = sys.modules["__main__"].__root__ RESOURCES_PATH = os.path.join(ROOT, 'resources') @@ -165,7 +165,7 @@ class TorrentPlayer(xbmc.Player): self.torrent.startSession() self.torrent.continueSession(self.contentId) self.loop() - WatchedHistoryDB().add(self.basename, self.watchedTime, self.totalTime, self.contentId, self.fullSize / 1024 / 1024) + WatchedHistoryDB().add(self.basename, foldername(self.torrent.getContentList()[self.contentId]['title']), self.watchedTime, self.totalTime, self.contentId, self.fullSize / 1024 / 1024) else: break debug('************************************* GO NEXT?') @@ -226,11 +226,12 @@ class TorrentPlayer(xbmc.Player): int(download_limit) * 1024 * 1024 / 8) # MBits/second self.torrent.status = False self.fullSize = self.torrent.getFileSize(self.contentId) + self.path = self.torrent.getFilePath(self.contentId) Offset = calculate(self.fullSize) debug('Offset: '+str(Offset)) # mp4 fix - label = os.path.basename(self.torrent.getFilePath(self.contentId)) + label = os.path.basename(self.path) isMP4 = False if '.' in label and str(label.split('.')[-1]).lower() == 'mp4': isMP4 = True @@ -243,7 +244,7 @@ class TorrentPlayer(xbmc.Player): progressBar.create(self.localize('Please Wait') + str(' [%s]' % str(self.torrent.lt.version)), self.localize('Seeds searching.')) if self.subs_dl: - subs = self.torrent.getSubsIds(os.path.basename(self.torrent.getFilePath(self.contentId))) + subs = self.torrent.getSubsIds(os.path.basename(self.path)) if len(subs) > 0: for ind, title in subs: self.torrent.continueSession(ind) @@ -284,6 +285,8 @@ class TorrentPlayer(xbmc.Player): 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) progressBar.update(0) progressBar.close() return True diff --git a/changelog.txt b/changelog.txt index 3123ca3..021ee0a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,9 @@ English changelog at http://bit.ly/1MfSVUP +[B]Version 2.4.6[/B] +[+] Проигрыватель: Уменьшена просадка после загрузки буфера (спасибо srg70 и RussakHH) +[+] История Просмотров: Добавлено имя раздачи, тонкая настройка добавления по проценту просмотра + [B]Version 2.4.5[/B] [+] Дополнительна секция настроек со специфическими опциями [+] Минимальный размер хранилища при очищении diff --git a/functions.py b/functions.py index e1d4c75..6909029 100644 --- a/functions.py +++ b/functions.py @@ -1005,14 +1005,14 @@ class HistoryDB: class WatchedHistoryDB: - def __init__(self, version=1.2): + def __init__(self, version=1.3): self.name = 'watched_history.db3' self.version = version self.history_bool = __settings__.getSetting('history') == 'true' def get_all(self): self._connect() - self.cur.execute('select addtime,filename,path,url,seek,length,ind,size from history order by addtime DESC') + self.cur.execute('select addtime,filename,foldername,path,url,seek,length,ind,size from history order by addtime DESC') x = self.cur.fetchall() self._close() return x if x else None @@ -1024,14 +1024,18 @@ class WatchedHistoryDB: self._close() return x if x else None - def add(self, filename, seek = 0, length = 1, ind = 0, size = 0): - if self.history_bool: + def add(self, filename, foldername = None, seek = 0, length = 1, ind = 0, size = 0): + watchedPercent = int((float(seek) / float(length)) * 100) + max_history_add = int(__settings__.getSetting('max_history_add')) + if self.history_bool and watchedPercent <= max_history_add: self._connect() url = __settings__.getSetting("lastTorrentUrl") path = __settings__.getSetting("lastTorrent") + if not foldername: + foldername = '' self.cur.execute('delete from history where filename="' + decode(filename) + '"') - self.cur.execute('insert into history(addtime,filename,path,url,seek,length,ind,size)' - ' values(?,?,?,?,?,?,?,?)', (int(time.time()), decode(filename), decode(path), + self.cur.execute('insert into history(addtime,filename,foldername,path,url,seek,length,ind,size)' + ' values(?,?,?,?,?,?,?,?,?)', (int(time.time()), decode(filename), decode(foldername), decode(path), decode(url), str(int(seek)), str(int(length)), str(ind), str(size))) self.db.commit() self._close() @@ -1090,7 +1094,7 @@ class WatchedHistoryDB: cur.execute('pragma auto_vacuum=1') cur.execute('create table db_ver(version real)') cur.execute( - 'create table history(addtime integer PRIMARY KEY, filename varchar(32), path varchar(32), url varchar(32), seek integer, length integer, ind integer, size integer)') + 'create table history(addtime integer PRIMARY KEY, filename varchar(32), foldername varchar(32), path varchar(32), url varchar(32), seek integer, length integer, ind integer, size integer)') cur.execute('insert into db_ver(version) values(?)', (self.version,)) self.db.commit() cur.close() @@ -2012,4 +2016,11 @@ def getDirectorySizeInBytes(directory): def getDirectorySizeInGB(directory): dir_size = int(getDirectorySizeInBytes(directory)/1024/1024/1024) - return dir_size \ No newline at end of file + return dir_size + +def foldername(path): + if '\\' in path: + foldername = path.split('\\')[0] + else: + foldername = '' + return foldername \ No newline at end of file diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 0ca5dd8..e8c0a45 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -62,6 +62,7 @@ by Seeds Do not sort by Name + Do not add to Watched History if played more (%) Interface P2P Network Advanced diff --git a/resources/language/Russian/strings.xml b/resources/language/Russian/strings.xml index 8d97d14..b8d272c 100644 --- a/resources/language/Russian/strings.xml +++ b/resources/language/Russian/strings.xml @@ -62,6 +62,7 @@ по Количеству раздающих Не сортировать по Имени + Не добавлять в История Просмотров если больше (%) Интерфейс P2P Сеть Дополнительные diff --git a/resources/settings.xml b/resources/settings.xml index c6dd8d3..42a1d8c 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -68,5 +68,6 @@ +