history update

pull/1/head
DiMartinoXBMC 2016-02-25 22:29:18 +03:00
parent 16cc3c5aa2
commit c41d55ef1c
10 changed files with 537 additions and 508 deletions

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ import sys
from contextlib import contextmanager, closing, nested 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 from torrent2http import State, Engine, MediaType
@ -282,7 +282,7 @@ class AnteoPlayer(xbmc.Player):
if self.setup_play(): if self.setup_play():
self.setup_subs() self.setup_subs()
self.loop() 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: else:
log('[AnteoPlayer]: ************************************* break') log('[AnteoPlayer]: ************************************* break')
break break
@ -635,6 +635,14 @@ class AnteoPlayer(xbmc.Player):
contentList = sorted(contentList, key=lambda x: x[0]) contentList = sorted(contentList, key=lambda x: x[0])
return get_ids_video(contentList) 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): class OverlayText(object):
def __init__(self, w, h, *args, **kwargs): def __init__(self, w, h, *args, **kwargs):
self.window = xbmcgui.Window(WINDOW_FULLSCREEN_VIDEO) self.window = xbmcgui.Window(WINDOW_FULLSCREEN_VIDEO)

10
Core.py
View File

@ -572,7 +572,7 @@ class Core:
showMessage(self.localize('Watched History'), self.localize('Deleted!')) showMessage(self.localize('Watched History'), self.localize('Deleted!'))
if action2 == 'open': 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): if os.path.exists(path):
self.__settings__.setSetting("lastTorrent", path) self.__settings__.setSetting("lastTorrent", path)
else: else:
@ -609,11 +609,15 @@ class Core:
if items: if items:
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')
#for favbool, bbstring in favlist: #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 seek = int(seek) if int(seek) > 3*60 else 0
watchedPercent = int((float(seek) / float(length)) * 100) watchedPercent = int((float(seek) / float(length)) * 100)
duration = '%02d:%02d:%02d' % ((length / (60*60)), (length / 60) % 60, length % 60) 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: if self.torrent_player == '2' and seek > 0:
seek_text = '%02d:%02d:%02d' % ((seek / (60*60)), (seek / 60) % 60, seek % 60) 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))), contextMenu = [(self.localize('Play (from %s)') % seek_text, ListString % ('WatchedHistory', 'playwithseek', 'addtime', str(addtime))),

View File

@ -430,6 +430,9 @@ class Libtorrent:
#'auto_managed': False, #'auto_managed': False,
#'duplicate_is_error': True #'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 = self.session.add_torrent(torrent_info)
self.torrentHandle.set_sequential_download(True) self.torrentHandle.set_sequential_download(True)
@ -475,6 +478,19 @@ class Libtorrent:
self.session.stop_lsd() self.session.stop_lsd()
self.session.stop_dht() 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): def debug(self):
#try: #try:
if 1==1: if 1==1:

View File

@ -30,7 +30,7 @@ import Downloader
import xbmcgui import xbmcgui
import xbmcvfs import xbmcvfs
import Localization 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__ ROOT = sys.modules["__main__"].__root__
RESOURCES_PATH = os.path.join(ROOT, 'resources') RESOURCES_PATH = os.path.join(ROOT, 'resources')
@ -165,7 +165,7 @@ class TorrentPlayer(xbmc.Player):
self.torrent.startSession() self.torrent.startSession()
self.torrent.continueSession(self.contentId) self.torrent.continueSession(self.contentId)
self.loop() 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: else:
break break
debug('************************************* GO NEXT?') debug('************************************* GO NEXT?')
@ -226,11 +226,12 @@ class TorrentPlayer(xbmc.Player):
int(download_limit) * 1024 * 1024 / 8) # MBits/second int(download_limit) * 1024 * 1024 / 8) # MBits/second
self.torrent.status = False self.torrent.status = False
self.fullSize = self.torrent.getFileSize(self.contentId) self.fullSize = self.torrent.getFileSize(self.contentId)
self.path = self.torrent.getFilePath(self.contentId)
Offset = calculate(self.fullSize) Offset = calculate(self.fullSize)
debug('Offset: '+str(Offset)) debug('Offset: '+str(Offset))
# mp4 fix # mp4 fix
label = os.path.basename(self.torrent.getFilePath(self.contentId)) label = os.path.basename(self.path)
isMP4 = False isMP4 = False
if '.' in label and str(label.split('.')[-1]).lower() == 'mp4': if '.' in label and str(label.split('.')[-1]).lower() == 'mp4':
isMP4 = True isMP4 = True
@ -243,7 +244,7 @@ class TorrentPlayer(xbmc.Player):
progressBar.create(self.localize('Please Wait') + str(' [%s]' % str(self.torrent.lt.version)), progressBar.create(self.localize('Please Wait') + str(' [%s]' % str(self.torrent.lt.version)),
self.localize('Seeds searching.')) self.localize('Seeds searching.'))
if self.subs_dl: 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: if len(subs) > 0:
for ind, title in subs: for ind, title in subs:
self.torrent.continueSession(ind) self.torrent.continueSession(ind)
@ -284,6 +285,8 @@ class TorrentPlayer(xbmc.Player):
xbmc.sleep(1000) xbmc.sleep(1000)
#self.torrent.torrentHandle.flush_cache() #self.torrent.torrentHandle.flush_cache()
#self.torrent.session.remove_torrent(self.torrent.torrentHandle) #self.torrent.session.remove_torrent(self.torrent.torrentHandle)
self.torrent.resume_data()
self.torrent.session.remove_torrent(self.torrent.torrentHandle)
progressBar.update(0) progressBar.update(0)
progressBar.close() progressBar.close()
return True return True

View File

@ -1,5 +1,9 @@
English changelog at http://bit.ly/1MfSVUP English changelog at http://bit.ly/1MfSVUP
[B]Version 2.4.6[/B]
[+] Проигрыватель: Уменьшена просадка после загрузки буфера (спасибо srg70 и RussakHH)
[+] История Просмотров: Добавлено имя раздачи, тонкая настройка добавления по проценту просмотра
[B]Version 2.4.5[/B] [B]Version 2.4.5[/B]
[+] Дополнительна секция настроек со специфическими опциями [+] Дополнительна секция настроек со специфическими опциями
[+] Минимальный размер хранилища при очищении [+] Минимальный размер хранилища при очищении

View File

@ -1005,14 +1005,14 @@ class HistoryDB:
class WatchedHistoryDB: class WatchedHistoryDB:
def __init__(self, version=1.2): def __init__(self, version=1.3):
self.name = 'watched_history.db3' self.name = 'watched_history.db3'
self.version = version self.version = version
self.history_bool = __settings__.getSetting('history') == 'true' self.history_bool = __settings__.getSetting('history') == 'true'
def get_all(self): def get_all(self):
self._connect() 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() x = self.cur.fetchall()
self._close() self._close()
return x if x else None return x if x else None
@ -1024,14 +1024,18 @@ class WatchedHistoryDB:
self._close() self._close()
return x if x else None return x if x else None
def add(self, filename, seek = 0, length = 1, ind = 0, size = 0): def add(self, filename, foldername = None, seek = 0, length = 1, ind = 0, size = 0):
if self.history_bool: 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() self._connect()
url = __settings__.getSetting("lastTorrentUrl") url = __settings__.getSetting("lastTorrentUrl")
path = __settings__.getSetting("lastTorrent") path = __settings__.getSetting("lastTorrent")
if not foldername:
foldername = ''
self.cur.execute('delete from history where filename="' + decode(filename) + '"') self.cur.execute('delete from history where filename="' + decode(filename) + '"')
self.cur.execute('insert into history(addtime,filename,path,url,seek,length,ind,size)' self.cur.execute('insert into history(addtime,filename,foldername,path,url,seek,length,ind,size)'
' values(?,?,?,?,?,?,?,?)', (int(time.time()), decode(filename), decode(path), ' values(?,?,?,?,?,?,?,?,?)', (int(time.time()), decode(filename), decode(foldername), decode(path),
decode(url), str(int(seek)), str(int(length)), str(ind), str(size))) decode(url), str(int(seek)), str(int(length)), str(ind), str(size)))
self.db.commit() self.db.commit()
self._close() self._close()
@ -1090,7 +1094,7 @@ class WatchedHistoryDB:
cur.execute('pragma auto_vacuum=1') cur.execute('pragma auto_vacuum=1')
cur.execute('create table db_ver(version real)') cur.execute('create table db_ver(version real)')
cur.execute( 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,)) cur.execute('insert into db_ver(version) values(?)', (self.version,))
self.db.commit() self.db.commit()
cur.close() cur.close()
@ -2012,4 +2016,11 @@ def getDirectorySizeInBytes(directory):
def getDirectorySizeInGB(directory): def getDirectorySizeInGB(directory):
dir_size = int(getDirectorySizeInBytes(directory)/1024/1024/1024) dir_size = int(getDirectorySizeInBytes(directory)/1024/1024/1024)
return dir_size return dir_size
def foldername(path):
if '\\' in path:
foldername = path.split('\\')[0]
else:
foldername = ''
return foldername

View File

@ -62,6 +62,7 @@
<string id="30062">by Seeds</string> <string id="30062">by Seeds</string>
<string id="30063">Do not sort</string> <string id="30063">Do not sort</string>
<string id="30064">by Name</string> <string id="30064">by Name</string>
<string id="30065">Do not add to Watched History if played more (%)</string>
<string id="30101">Interface</string> <string id="30101">Interface</string>
<string id="30102">P2P Network</string> <string id="30102">P2P Network</string>
<string id="30103">Advanced</string> <string id="30103">Advanced</string>

View File

@ -62,6 +62,7 @@
<string id="30062">по Количеству раздающих</string> <string id="30062">по Количеству раздающих</string>
<string id="30063">Не сортировать</string> <string id="30063">Не сортировать</string>
<string id="30064">по Имени</string> <string id="30064">по Имени</string>
<string id="30065">Не добавлять в История Просмотров если больше (%)</string>
<string id="30101">Интерфейс</string> <string id="30101">Интерфейс</string>
<string id="30102">P2P Сеть</string> <string id="30102">P2P Сеть</string>
<string id="30103">Дополнительные</string> <string id="30103">Дополнительные</string>

View File

@ -68,5 +68,6 @@
<setting id="listen_port" type="number" label="30053" default="6881" visible="!eq(-4,1)"/> <setting id="listen_port" type="number" label="30053" default="6881" visible="!eq(-4,1)"/>
<setting id="min_storage_size" type="slider" label="30059" default="0" visible="!eq(-5,1)" range="0,2,100" option="int"/> <setting id="min_storage_size" type="slider" label="30059" default="0" visible="!eq(-5,1)" range="0,2,100" option="int"/>
<setting id="pause_onplay" type="bool" label="30060" default="false" visible="!eq(-6,1)"/> <setting id="pause_onplay" type="bool" label="30060" default="false" visible="!eq(-6,1)"/>
<setting id="max_history_add" type="slider" label="30065" default="100" visible="!eq(-7,1)" range="0,2,100" option="int"/>
</category> </category>
</settings> </settings>