From cc6168afd200ede9eb86c96efb5b825f1816818f Mon Sep 17 00:00:00 2001 From: Alhaziel Date: Mon, 8 Jul 2019 18:51:51 +0200 Subject: [PATCH] Fix Numerazione Automatica --- resources/language/English/strings.po | 12 ++ resources/language/Italian/strings.po | 15 +- specials/autorenumber.py | 255 +++++++++++++++----------- 3 files changed, 176 insertions(+), 106 deletions(-) diff --git a/resources/language/English/strings.po b/resources/language/English/strings.po index ab616c85..36d067f9 100644 --- a/resources/language/English/strings.po +++ b/resources/language/English/strings.po @@ -5571,4 +5571,16 @@ msgstr "" msgctxt "#70716" msgid "Choose menus you wanna in homepage" +msgstr "" + +msgctxt "#70717" +msgid "Are all the special episodes present?" +msgstr "" + +msgctxt "#70718" +msgid "Ep. No (Empty for OK) " +msgstr "" + +msgctxt "#70719" +msgid "I can't automatically find the special episode number, please enter it manually" msgstr "" \ No newline at end of file diff --git a/resources/language/Italian/strings.po b/resources/language/Italian/strings.po index dc397050..315e9a74 100644 --- a/resources/language/Italian/strings.po +++ b/resources/language/Italian/strings.po @@ -5160,6 +5160,7 @@ msgstr "" "[CR]- Puoi scaricare una lista se ti inviano un codice di tinyupload o un url dove esso è ospitato." "[CR]- Se vuoi farlo manualmente, puoi copiare una lista KODvorites-*.json che hai inserito nella cartella userdata dell’addon. E puoi caricare questi json su qualche server e inviare i loro url ai tuoi amici per condividerli." "[CR]- Il servizio tinyupload.com è utilizzato per condividere le liste degli addon perché è gratuito, privato e relativamente veloce. I file rimangono salvati per 100 giorni se nessuno li scarica, sono privati perché richiedono un codice per accedervi e il limite di 50MB è sufficiente per le liste." + msgctxt "#70612" msgid "Name of the list" msgstr "Nome della lista" @@ -5570,4 +5571,16 @@ msgstr "Personalizza Homepage" msgctxt "#70716" msgid "Choose menus you wanna in homepage" -msgstr "Seleziona gli elementi che vuoi visualizzare nella homepage" \ No newline at end of file +msgstr "Seleziona gli elementi che vuoi visualizzare nella homepage" + +msgctxt "#70717" +msgid "Are all the special episodes present?" +msgstr "Sono presenti tutti gli episodi spaciali?" + +msgctxt "#70718" +msgid "Ep. No (Empty for OK) " +msgstr "N° Ep. (vuoto per OK) " + +msgctxt "#70719" +msgid "I can't automatically find the special episode number, please enter it manually" +msgstr "Non riesco a trovare automaticamente il numero dell'episodio speciale, per favore inseriscilo manualmente" \ No newline at end of file diff --git a/specials/autorenumber.py b/specials/autorenumber.py index 0a679b4c..1bdc5339 100644 --- a/specials/autorenumber.py +++ b/specials/autorenumber.py @@ -12,7 +12,7 @@ USO: { "id": "autorenumber", "type": "bool", - "label": "Abilita Rinumerazione Automatica", + "label": "@70712", "default": false, "enabled": true, "visible": true @@ -20,23 +20,29 @@ USO: { "id": "autorenumber_mode", "type": "bool", - "label": "Sono presenti episodi speciali nella serie (Episodio 0 Escluso)?", + "label": "@70688", "default": false, "enabled": true, "visible": "eq(-1,true)" } ''' -import re, base64, json +try: + import xbmcgui +except: + xbmcgui = None + +import re, base64, json, os from core import jsontools, tvdb, scrapertoolsV2 from core.support import typo, log -from platformcode import config, platformtools +from platformcode import config, platformtools, logger from platformcode.config import get_setting TAG_TVSHOW_RENUMERATE = "TVSHOW_AUTORENUMBER" TAG_ID = "ID" TAG_SEASON = "Season" TAG_EPISODE = "Episode" +TAG_SPECIAL = "Special" TAG_MODE = "Mode" __channel__ = "autorenumber" @@ -49,21 +55,19 @@ def access(): return allow - def context(exist): if access(): modify = config.get_localized_string(70714) if exist else '' _context = [{"title": typo(modify + config.get_localized_string(70585), 'bold'), - "action": "manual_config_item", + "action": "semiautomatic_config_item", "channel": "autorenumber"}] return _context - -def manual_config_item(item): +def semiautomatic_config_item(item): + log() # Configurazione Semi Automatica, utile in caso la numerazione automatica fallisca - log(item) tvdb.find_and_set_infoLabels(item) item.channel = item.from_channel dict_series = jsontools.get_node_from_file(item.channel, TAG_TVSHOW_RENUMERATE) @@ -72,11 +76,12 @@ def manual_config_item(item): # Trova l'ID dellla serie while not item.infoLabels['tvdb_id']: try: - item.show = platformtools.dialog_input(default=item.show, heading=config.get_localized_string(30112)) + item.show = platformtools.dialog_input(default=item.show, heading=config.get_localized_string(30112)) # <- Enter title to search tvdb.find_and_set_infoLabels(item) except: - heading = config.get_localized_string(70704) - item.infoLabels['tvdb_id'] = platformtools.dialog_numeric(0, heading) + heading = config.get_localized_string(70704) # <- TMDB ID (0 to cancel) + info = platformtools.dialog_numeric(0, heading) + item.infoLabels['tvdb_id'] = '0' if info == '' else info if item.infoLabels['tvdb_id']: @@ -85,23 +90,55 @@ def manual_config_item(item): dict_series[title] = dict_renumerate # Trova la Stagione if any( word in title.lower() for word in ['specials', 'speciali'] ): - heading = config.get_localized_string(70686) + heading = config.get_localized_string(70686) # <- Enter the number of the starting season (for specials) season = platformtools.dialog_numeric(0, heading, '0') dict_renumerate[TAG_SEASON] = season elif RepresentsInt(title.split()[-1]): - heading = config.get_localized_string(70686) + heading = config.get_localized_string(70686) # <- Enter the number of the starting season (for season > 1) season = platformtools.dialog_numeric(0, heading, title.split()[-1]) dict_renumerate[TAG_SEASON] = season else: - heading = config.get_localized_string(70686) + heading = config.get_localized_string(70686) # <- Enter the number of the starting season (for season 1) season = platformtools.dialog_numeric(0, heading, '1') dict_renumerate[TAG_SEASON] = season - # Richede se ci sono speciali nella stagione + + ########### PROVVISORIO ################### mode = platformtools.dialog_yesno(config.get_localized_string(70687), config.get_localized_string(70688), nolabel=config.get_localized_string(30023), yeslabel=config.get_localized_string(30022)) - if mode == 0: dict_renumerate[TAG_MODE] = False - else: dict_renumerate[TAG_MODE] = True + if mode == 1: + dict_renumerate[TAG_MODE] = False + specials = [] + stop = False + while not stop: + heading = config.get_localized_string(70718) + str(specials) + special = platformtools.dialog_numeric(0, heading, '') + if special: + specials.append(int(special)) + dict_renumerate[TAG_SPECIAL] = specials + else: stop = True + dict_renumerate[TAG_MODE] = False + # Richede se ci sono speciali nella stagione + # mode = platformtools.dialog_yesno(config.get_localized_string(70687), config.get_localized_string(70688), nolabel=config.get_localized_string(30023), yeslabel=config.get_localized_string(30022)) + # if mode == 0: dict_renumerate[TAG_MODE] = False + # else: + # select = platformtools.dialog_yesno(config.get_localized_string(70687), config.get_localized_string(70717), nolabel=config.get_localized_string(30023), yeslabel=config.get_localized_string(30022)) + # if select == 0: + # dict_renumerate[TAG_MODE] = False + # specials = [] + # stop = False + # while not stop: + # heading = config.get_localized_string(70718) + str(specials) + # special = platformtools.dialog_numeric(0, heading, '') + # if special: + # specials.append(int(special)) + # dict_renumerate[TAG_SPECIAL] = specials + # else: stop = True + # else: + # dict_renumerate[TAG_MODE] = True + ########### PROVVISORIO ################### + + # Imposta la voce Episode - dict_renumerate[TAG_EPISODE] = [] + dict_renumerate[TAG_EPISODE] = '' # Scrive nel json jsontools.update_node(dict_series, item.channel, TAG_TVSHOW_RENUMERATE)[0] @@ -113,16 +150,14 @@ def manual_config_item(item): def config_item(item, itemlist=[], typography='', active=False): - # Configurazione Automatica, Tenta la numerazione Automatica degli episodi log() + # Configurazione Automatica, Tenta la numerazione Automatica degli episodi title = item.fulltitle dict_series = jsontools.get_node_from_file(item.channel, TAG_TVSHOW_RENUMERATE) - try: - ID = dict_series[item.show.rstrip()][TAG_ID] - except: - ID = '' - + try: ID = dict_series[item.show.rstrip()][TAG_ID] + except: ID = '' + # Pulizia del Titolo if any( word in title.lower() for word in ['specials', 'speciali']): item.show = re.sub(r'\sspecials|\sspeciali', '', item.show.lower()) @@ -143,7 +178,7 @@ def config_item(item, itemlist=[], typography='', active=False): elif RepresentsInt(title.split()[-1]): dict_renumerate[TAG_SEASON] = title.split()[-1] else: dict_renumerate[TAG_SEASON] = '1' - dict_renumerate[TAG_EPISODE] = [] + dict_renumerate[TAG_EPISODE] = '' settings_node = jsontools.get_node_from_file(item.channel, 'settings') dict_renumerate[TAG_MODE] = settings_node['autorenumber_mode'] jsontools.update_node(dict_series, item.channel, TAG_TVSHOW_RENUMERATE)[0] @@ -156,8 +191,8 @@ def config_item(item, itemlist=[], typography='', active=False): def renumber(itemlist, item='', typography=''): + log() # Seleziona la funzione Adatta, Menu Contestuale o Rinumerazione - # import web_pdb; web_pdb.set_trace() if item: settings_node = jsontools.get_node_from_file(item.channel, 'settings') # Controlla se la Serie è già stata rinumerata @@ -176,7 +211,7 @@ def renumber(itemlist, item='', typography=''): SEASON = dict_series[TITLE][TAG_SEASON] EPISODE = dict_series[TITLE][TAG_EPISODE] MODE = dict_series[TITLE][TAG_MODE] - return renumeration(itemlist, item, typography, dict_series, ID, SEASON, EPISODE, MODE, TITLE) + renumeration(itemlist, item, typography, dict_series, ID, SEASON, EPISODE, MODE, TITLE) else: # se non è stata rinumerata controlla se è attiva la rinumerazione automatica if 'autorenumber' not in settings_node: return itemlist @@ -194,12 +229,14 @@ def renumber(itemlist, item='', typography=''): if item.contentType != 'movie': if item.context: context2 = item.context + item.show = TITLE item.context = context(exist) + context2 else: + item.show = TITLE item.context = context(exist) def renumeration (itemlist, item, typography, dict_series, ID, SEASON, EPISODE, MODE, TITLE): - # import web_pdb; web_pdb.set_trace() + log() # Se ID è 0 salta la rinumerazione if ID == '0': return itemlist @@ -210,18 +247,17 @@ def renumeration (itemlist, item, typography, dict_series, ID, SEASON, EPISODE, for item in itemlist: number = scrapertoolsV2.find_single_match(item.title, r'\d+') item.title = typo('0x' + number + ' - ', typography) + item.title + # Usa la lista degli Episodi se esiste nel Json elif EPISODE: - log('EPISODE') EpisodeDict = json.loads(base64.b64decode(EPISODE)) + # Controlla che la lista egli Episodi sia della stessa lunghezza di Itemlist if EpisodeDict == 'none': return error(itemlist) - log(len(EpisodeDict)) - log(len(itemlist)) - if len(EpisodeDict) == len(itemlist): + if len(EpisodeDict) >= len(itemlist): for item in itemlist: number = scrapertoolsV2.find_single_match(item.title, r'\d+') item.title = typo(EpisodeDict[str(number)] + ' - ', typography) + item.title @@ -232,77 +268,104 @@ def renumeration (itemlist, item, typography, dict_series, ID, SEASON, EPISODE, make_list(itemlist, item, typography, dict_series, ID, SEASON, EPISODE, MODE, TITLE) def make_list(itemlist, item, typography, dict_series, ID, SEASON, EPISODE, MODE, TITLE): - log('RINUMERAZIONE') + log() page = 1 - EpDict = {} - EpDateList = [] EpList = [] EpisodeDict = {} exist = True item.infoLabels['tvdb_id'] = ID tvdb.set_infoLabels_item(item) - ABS = 0 - ep = 1 + FirstOfSeason= 0 + try: SPECIAL = dict_series[TITLE][TAG_SPECIAL] + except: SPECIAL = [] # Ricava Informazioni da TVDB while exist: data = tvdb.otvdb_global.get_list_episodes(ID,page) - log('DATA= ',data) if data: page = page + 1 else: exist = False - + if data: for episodes in data['data']: - log(episodes) - try: ABS = int(episodes['absoluteNumber']) - except: ABS = ep - EpDict[str(ABS)] = [str(episodes['airedSeason']) + 'x' + str(episodes['airedEpisodeNumber']), episodes['firstAired']] - EpDateList.append(episodes['firstAired']) - if ABS != 0: - EpList.append([ABS, episodes['airedSeason'], episodes['airedEpisodeNumber']]) - ep = ep + 1 - EpDateList.sort() - EpList.sort() - log(EpDateList) - log(EpDict) - log(EpList) - - # seleziona l'Episodio di partenza - if int(SEASON) > 1: - for name, episode in EpDict.items(): - if episode[0] == SEASON + 'x1': - ep = int(name) - 1 - else: - ep = 0 + EpList.append([episodes['firstAired'], episodes['airedSeason'], episodes['airedEpisodeNumber']]) + EpList.sort() + log(EpList) - log('SEASON= ', SEASON) - log(ep) - - # rinumera gli episodi - for item in itemlist: - number = int(scrapertoolsV2.find_single_match(item.title, r'\d+')) - episode = ep + number - 1 - - if len(EpList) < episode: return error(itemlist) - # Crea una lista di Episodi in base alla modalità di rinumerazione - if MODE == False and number != 0: - # import web_pdb; web_pdb.set_trace() - while EpList[episode][1] == 0 and len(EpList) > episode + 1: - episode = episode + 1 + # Crea Dizionari per la numerazione + if EpList: + specials = [] + regular = {} + complete = {} + allep = 1 + ep = 1 + specialep = 0 + for episode in EpList: + complete[allep] = [str(episode[1]) + 'x' + str(episode[2]), episode[0]] + if episode[1] == 0: + specials.append(allep) + specialep = specialep + 1 + else: + regular[ep] = [str(episode[1]) + 'x' + str(episode[2]), str(episode[0]), allep - 1] ep = ep + 1 - elif number == 0: - episode = previous(EpDateList, EpDict, ep + 1) - - if config.get_localized_string(30161) not in item.title: - EpisodeDict[str(number)] = (str(EpList[episode][1]) + 'x' + str(EpList[episode][2])) - item.title = typo(str(EpList[episode][1]) + 'x' + str(EpList[episode][2]) + ' - ', typography) + item.title + allep = allep + 1 + + # seleziona l'Episodio di partenza + if int(SEASON) > 1: + for numbers, data in regular.items(): + if data[0] == SEASON + 'x1': + FirstOfSeason = numbers - 1 - # Scrive sul json - EpisodeDict = base64.b64encode(json.dumps(EpisodeDict)) - dict_series[TITLE][TAG_EPISODE] = EpisodeDict - jsontools.update_node(dict_series, item.channel, TAG_TVSHOW_RENUMERATE)[0] + if MODE == True: SPECIAL = specials + log(SPECIAL) + log(complete) + log(regular) - return itemlist + addiction = 0 + for item in itemlist: + # Otiene Numerazione Episodi + episode = int(scrapertoolsV2.find_single_match(item.title, r'\d+')) + number = episode + FirstOfSeason - addiction + count = number + addiction + # find = episode + FirstOfSeason + # log('FIND= ',find, ' ',str(episode) + ' ' + str(FirstOfSeason)) + # Crea Dizionario Episodi + + # log(episode, ' ', number, ' ', count) + if episode == 0: + EpisodeDict[str(episode)] = str(complete[regular[FirstOfSeason+1][2]][0]) + elif addiction < len(SPECIAL): + if episode in SPECIAL: + season = complete[regular[count][2]][0] + EpisodeDict[str(episode)] = str(complete[regular[count][2]][0]) if season.startswith( '0' ) else '0x' + platformtools.dialog_numeric(0, item.title + '?', '') + addiction = addiction + 1 + else: + EpisodeDict[str(episode)] = str(regular[number][0]) + elif number <= len(regular): + EpisodeDict[str(episode)] = str(regular[number][0]) + else: + try: EpisodeDict[str(episode)] = str(complete[regular[number+2][2]][0]) + except: EpisodeDict[str(episode)] = '0x0' + + # Aggiunge numerazione agli Episodi + + item.title = typo(EpisodeDict[str(episode)] + ' - ', typography) + item.title + + # Scrive Dizionario Episodi sul json + EpisodeDict = base64.b64encode(json.dumps(EpisodeDict)) + dict_series[TITLE][TAG_EPISODE] = EpisodeDict + jsontools.update_node(dict_series, item.channel, TAG_TVSHOW_RENUMERATE)[0] + + else: + heading = config.get_localized_string(70704) + ID = platformtools.dialog_numeric(0, heading) + dict_series[TITLE][TAG_ID] = ID + jsontools.update_node(dict_series, item.channel, TAG_TVSHOW_RENUMERATE)[0] + if ID == '0': + return itemlist + else: + return make_list(itemlist, item, typography, dict_series, ID, SEASON, EPISODE, MODE, TITLE) + + # return itemlist @@ -315,26 +378,8 @@ def RepresentsInt(s): except ValueError: return False -def previous(date_list, Dict, search): - # Seleziona Eventuale Episodio 0 - log() - P = None - result = 0 - for ep, variants in Dict.items(): - if variants[1] == Dict[str(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 = int(name)-1 - return result - def error(itemlist): message = config.get_localized_string(70713) heading = itemlist[0].fulltitle.strip() platformtools.dialog_notification(heading, message) - return itemlist \ No newline at end of file + return itemlist