Migliorie a videoteca e segna come già visto

This commit is contained in:
Alhaziel01
2021-01-25 18:52:39 +01:00
parent b9c059f84e
commit 30bde135b2
3 changed files with 52 additions and 6 deletions

View File

@@ -351,6 +351,38 @@ def mark_season_as_watched_on_kodi(item, value=1):
execute_sql_kodi(sql)
def set_watched_on_kod(data):
from specials import videolibrary
from core import videolibrarytools
logger.debug('TYPE',type(data))
data = jsontools.load(data)
logger.debug('TYPE',type(data))
Type = data['item']['type']
ID = data['item']['id']
playcount = data['playcount']
for Type in ['movie', 'episode']:
sql = 'select strFileName, strPath, uniqueid_value from %s_view where (id%s like "%s")' % (Type, Type.capitalize(), ID)
n, records = execute_sql_kodi(sql)
if records:
for filename, path, uniqueid_value in records:
if Type in ['movie']:
title = filename.replace('.strm', ' [' + uniqueid_value + ']')
filename = title +'.nfo'
else:
title = filename.replace('.strm', '')
filename = 'tvshow.nfo'
path = filetools.join(path, filename)
head_nfo, item = videolibrarytools.read_nfo(path)
item.library_playcounts.update({title: playcount})
filetools.write(path, head_nfo + item.tojson())
if item.infoLabels['mediatype'] == "tvshow":
for season in item.library_playcounts:
if "season" in season:
season_num = int(scrapertools.find_single_match(season, r'season (\d+)'))
item = videolibrary.check_season_playcount(item, season_num)
filetools.write(path, head_nfo + item.tojson())
def mark_content_as_watched_on_kod(path):
from specials import videolibrary
@@ -384,6 +416,7 @@ def mark_content_as_watched_on_kod(path):
if "\\" in path:
path = path.replace("/", "\\")
head_nfo, item = videolibrarytools.read_nfo(path) # I read the content .nfo
old = item.clone()
if not item:
logger.error('.NFO not found: ' + path)
return
@@ -437,8 +470,9 @@ def mark_content_as_watched_on_kod(path):
if "season" in season: # we look for the tags "season" inside playCounts
season_num = int(scrapertools.find_single_match(season, r'season (\d+)')) # we save the season number
item = videolibrary.check_season_playcount(item, season_num) # We call the method that updates Temps. and series
filetools.write(path, head_nfo + item.tojson())
if item.library_playcounts != old.library_playcounts:
logger.debug('scrivo')
filetools.write(path, head_nfo + item.tojson())
#logger.debug(item)

View File

@@ -24,7 +24,7 @@ sys.path.insert(0, librerias)
from core import videolibrarytools, filetools, channeltools, httptools, scrapertools
from lib import schedule
from platformcode import logger, platformtools, updater
from platformcode import logger, platformtools, updater, xbmc_videolibrary
from specials import videolibrary
from servers import torrent
@@ -398,6 +398,11 @@ class AddonMonitor(xbmc.Monitor):
xbmc.executebuiltin('Action(reloadkeymaps)')
self.settings_pre = settings_post
def onNotification(self, sender, method, data):
if method == 'VideoLibrary.OnUpdate':
xbmc_videolibrary.set_watched_on_kod(data)
logger.debug('AGGIORNO')
def onScreensaverActivated(self):
logger.debug('screensaver activated, un-scheduling screen-on jobs')
schedule.clear('screenOn')

View File

@@ -67,6 +67,8 @@ def list_tvshows(item):
lista = []
root = videolibrarytools.TVSHOWS_PATH
from time import time
start = time()
with futures.ThreadPoolExecutor() as executor:
itlist = [executor.submit(get_results, filetools.join(root, folder, "tvshow.nfo"), root, 'tvshow') for folder in filetools.listdir(root)]
for res in futures.as_completed(itlist):
@@ -75,7 +77,7 @@ def list_tvshows(item):
if item_tvshow.library_urls and len(item_tvshow.library_urls) > 0:
itemlist += [item_tvshow]
lista += [{'title':item_tvshow.contentTitle,'thumbnail':item_tvshow.thumbnail,'fanart':item_tvshow.fanart, 'active': value, 'nfo':item_tvshow.nfo}]
logger.debug('load list',time() - start)
if itemlist:
itemlist = sorted(itemlist, key=lambda it: it.title.lower())
@@ -94,7 +96,10 @@ def get_results(nfo_path, root, Type, local=False):
if filetools.exists(nfo_path):
# We synchronize the episodes seen from the Kodi video library with that of KoD
from platformcode import xbmc_videolibrary
xbmc_videolibrary.mark_content_as_watched_on_kod(nfo_path)
from time import time
start = time()
# xbmc_videolibrary.mark_content_as_watched_on_kod(nfo_path)
logger.debug('execution time =',time()-start)
head_nfo, item = videolibrarytools.read_nfo(nfo_path)
# If you have not read the .nfo well, we will proceed to the next
@@ -907,7 +912,9 @@ def mark_season_as_watched(item):
# logger.debug("item:\n" + item.tostring('\n'))
# Get dictionary of marked episodes
f = filetools.join(item.path, 'tvshow.nfo')
if not item.path: f = item.nfo
else: f = filetools.join(item.path, 'tvshow.nfo')
head_nfo, it = videolibrarytools.read_nfo(f)
if not hasattr(it, 'library_playcounts'):
it.library_playcounts = {}