From 30bde135b2a3c55bb6feebd2574ef8223052c3d0 Mon Sep 17 00:00:00 2001 From: Alhaziel01 Date: Mon, 25 Jan 2021 18:52:39 +0100 Subject: [PATCH] =?UTF-8?q?Migliorie=20a=20videoteca=20e=20segna=20come=20?= =?UTF-8?q?gi=C3=A0=20visto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformcode/xbmc_videolibrary.py | 38 +++++++++++++++++++++++++++++-- service.py | 7 +++++- specials/videolibrary.py | 13 ++++++++--- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/platformcode/xbmc_videolibrary.py b/platformcode/xbmc_videolibrary.py index 2e231fe4..fdd56595 100644 --- a/platformcode/xbmc_videolibrary.py +++ b/platformcode/xbmc_videolibrary.py @@ -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) diff --git a/service.py b/service.py index d85bbf81..9cf9adfd 100644 --- a/service.py +++ b/service.py @@ -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') diff --git a/specials/videolibrary.py b/specials/videolibrary.py index 21ff24eb..b3722e4d 100644 --- a/specials/videolibrary.py +++ b/specials/videolibrary.py @@ -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 = {}