From 26cbb07ce412d5ca51be7db3fb85035056f6fe89 Mon Sep 17 00:00:00 2001 From: Alhaziel Date: Mon, 17 Jun 2019 19:54:05 +0200 Subject: [PATCH] Nuovo Autorenumber --- specials/autorenumber.py | 127 ++++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 47 deletions(-) diff --git a/specials/autorenumber.py b/specials/autorenumber.py index 35b00022..13774901 100644 --- a/specials/autorenumber.py +++ b/specials/autorenumber.py @@ -8,16 +8,17 @@ try: except: xbmcgui = None -from core import jsontools, tvdb +from core import jsontools, tvdb, scrapertoolsV2 from core.support import typo, log from platformcode import config from platformcode import platformtools +# from datetime import datetime TAG_TVSHOW_RENUMERATE = "TVSHOW_AUTORENUMBER" -TAG_SEASON_EPISODE = "season_episode" +TAG_ID = "ID" +TAG_SEASON = "Season" __channel__ = "autorenumber" - def access(): allow = False @@ -39,8 +40,7 @@ def context(): def config_item(item): log(item) tvdb.find_and_set_infoLabels(item) - data = '' - data = add_season(data) + data = [] title = item.show count = 0 @@ -53,8 +53,8 @@ def config_item(item): heading = config.get_localized_string(70704) item.infoLabels['tvdb_id'] = platformtools.dialog_numeric(0, heading) data.append(item.infoLabels['tvdb_id']) - if item.infoLabels['tvdb_id'] != 0: - write_data(item.from_channel, title, data) + if item.infoLabels['tvdb_id'] != '': + write_data(item.from_channel, title, item.infoLabels['tvdb_id']) else: message = config.get_localized_string(60444) heading = item.show.strip() @@ -62,39 +62,35 @@ def config_item(item): -def add_season(data=None): - log("data= ", data) - heading = config.get_localized_string(70686) - season = platformtools.dialog_numeric(0, heading) - - if season != "": - heading = config.get_localized_string(70687) - episode = platformtools.dialog_numeric(0, heading) - - if episode == "0": - heading = config.get_localized_string(70688) - special = platformtools.dialog_numeric(0, heading) - return [int(season), int(episode), int(special)] - elif episode != '': - return [int(season), int(episode), ''] -def write_data(channel, show, data): +def write_data(channel, show, ID): log() dict_series = jsontools.get_node_from_file(channel, TAG_TVSHOW_RENUMERATE) tvshow = show.strip() - # list_season_episode = dict_series.get(tvshow, {}).get(TAG_SEASON_EPISODE, []) - if data: - dict_renumerate = {TAG_SEASON_EPISODE: data} + if ID: + dict_renumerate = {TAG_ID: ID} dict_series[tvshow] = dict_renumerate else: dict_series.pop(tvshow, None) + # Cerca di individuare la serie dal titolo + if any( word in show.lower() for word in ['special', 'specials', 'speciali', 'speciale'] ): + heading = config.get_localized_string(70686) + season = platformtools.dialog_numeric(0, heading, '0') + dict_renumerate[TAG_SEASON] = season + elif RepresentsInt(show.split()[-1]): + heading = config.get_localized_string(70686) + season = platformtools.dialog_numeric(0, heading, show.split()[-1]) + dict_renumerate[TAG_SEASON] = season + else: dict_renumerate[TAG_SEASON] = '1' + + result = jsontools.update_node(dict_series, channel, TAG_TVSHOW_RENUMERATE)[0] if result: - if data: + if ID: message = config.get_localized_string(60446) else: message = config.get_localized_string(60444) @@ -108,43 +104,58 @@ def write_data(channel, show, data): def renumber(itemlist, item='', typography=''): log() + if item: - try: + try: dict_series = jsontools.get_node_from_file(item.channel, TAG_TVSHOW_RENUMERATE) - SERIES = dict_series[item.show.rstrip()]['season_episode'] - S = SERIES[0] - E = SERIES[1] - SP = SERIES[2] - ID = SERIES[3] + ID = dict_series[item.show.rstrip()]['ID'] + SEASON = dict_series[item.show.rstrip()]['Season'] page = 1 + epDict = {} epList = [] exist = True item.infoLabels['tvdb_id'] = ID tvdb.set_infoLabels_item(item) - + ep = 1 + while exist: data = tvdb.otvdb_global.get_list_episodes(ID,page) + log(data) if data: for episodes in data['data']: - if episodes['airedSeason'] >= S: - if E == 0: - epList.append([0, SP]) - E = 1 - if episodes['airedEpisodeNumber'] >= E or episodes['airedSeason'] > S: - epList.append([episodes['airedSeason'], episodes['airedEpisodeNumber']]) + log(episodes) + if hasattr(episodes,'absoluteNumber'): ABS = episodes['absoluteNumber'] + else: ABS = str(ep) + epDict[str(ABS)] = [str(episodes['airedSeason']) + 'x' + str(episodes['airedEpisodeNumber']), episodes['firstAired']] + epList.append(episodes['firstAired']) + ep = ep + 1 + page = page + 1 else: exist = False - + log(epDict) epList.sort() - ep = 0 + log(epList) - for item in itemlist: - s = str(epList[ep][0]) - e = str(epList[ep][1]) - item.title = typo(s + 'x'+ e + ' - ', typography) + item.title - ep = ep + 1 + if SEASON: + for name, episode in epDict.items(): + if episode[0] == SEASON + 'x1': + ep = int(name)-1 + else: + ep = 0 + + if SEASON != '0': + for item in itemlist: + number = int(scrapertoolsV2.find_single_match(item.title, r'\d+')) + episode = str(ep + number) + if number == 0: + episode = previous(epList, epDict, str(ep + 1)) + item.title = typo(epDict[episode][0] + ' - ', typography) + item.title + else: + for item in itemlist: + number = scrapertoolsV2.find_single_match(item.title, r'\d+') + item.title = typo('0x' + number + ' - ', typography) + item.title except: return itemlist @@ -160,4 +171,26 @@ def renumber(itemlist, item='', typography=''): return itemlist +def RepresentsInt(s): + try: + int(s) + return True + except ValueError: + return False +def previous(date_list, Dict, search): + log('Start') + P = None + for ep, variants in Dict.items(): + if variants[1] == Dict[search][1]: + date = variants[1] + for index, obj in enumerate(date_list): + if obj == date: + if index > 0: + P = date_list[index - 1] + for name, variants in Dict.items(): + log(variants[1], ' = ', P) + if variants[1] == P: + result = name + log(result) + return result \ No newline at end of file