TMDB Selezione Gruppo Numerazione (Test)

This commit is contained in:
Alhaziel01
2021-02-01 20:37:12 +01:00
parent d0f022070f
commit 058b3ed507
5 changed files with 73 additions and 12 deletions

View File

@@ -187,7 +187,7 @@ def callback_cuadro_completar(item, dict_values):
return False
def get_nfo(item):
def get_nfo(item, search_groups=False):
"""
Returns the information necessary for the result to be scraped into the kodi video library,
@@ -229,7 +229,7 @@ def get_nfo(item):
if item.contentType == "movie": scraper_actual = ['tmdb'][config.get_setting("scraper_movies", "videolibrary")]
else: scraper_actual = ['tmdb', 'tvdb'][config.get_setting("scraper_tvshows", "videolibrary")]
scraper = __import__('core.%s' % scraper_actual, fromlist=["core.%s" % scraper_actual])
return scraper.get_nfo(item)
return scraper.get_nfo(item, search_groups)
def sort_episode_list(episodelist):

View File

@@ -526,7 +526,7 @@ def find_and_set_infoLabels(item):
return False
def get_nfo(item):
def get_nfo(item, search_groups=False):
"""
Returns the information necessary for the result to be scraped into the kodi video library, for tmdb it works only by passing it the url.
@param item: element that contains the data necessary to generate the info
@@ -534,6 +534,22 @@ def get_nfo(item):
@rtype: str
@return:
"""
if search_groups:
from platformcode.autorenumber import RENUMBER, GROUP
path = filetools.join(config.get_data_path(), "settings_channels", item.channel + "_data.json")
if filetools.exists(path):
g = jsontools.load(filetools.read(path)).get(RENUMBER,{}).get(item.fulltitle.strip(),{}).get(GROUP,'')
if g: return g
groups = get_groups(item)
if groups:
Id = select_group(groups)
if Id:
info_nfo = 'https://www.themoviedb.org/tv/{}/episode_group/{}'.format(item.infoLabels['tmdb_id'], Id)
return info_nfo
if "season" in item.infoLabels and "episode" in item.infoLabels:
info_nfo = "https://www.themoviedb.org/tv/%s/season/%s/episode/%s\n" % (item.infoLabels['tmdb_id'], item.contentSeason, item.contentEpisodeNumber)
else:
@@ -541,6 +557,34 @@ def get_nfo(item):
return info_nfo
def get_groups(item):
url = 'https://api.themoviedb.org/3/tv/{}/episode_groups?api_key=a1ab8b8669da03637a4b98fa39c39228&language={}'.format(item.infoLabels['tmdb_id'], def_lang)
groups = requests.get(url).json().get('results',[])
return groups
def select_group(groups):
selected = -1
selections = []
ids = []
for group in groups:
name = '[B]{}[/B] Seasons: {} Episodes: {}'.format(group.get('name',''), group.get('group_count',''), group.get('episode_count',''))
description = group.get('description','')
if description:
name = '{}\n{}'.format(name, description)
ID = group.get('id','')
if ID:
selections.append(name)
ids.append(ID)
if selections and ids:
selected = platformtools.dialog_select('Seleziona', selections)
if selected > -1:
return ids[selected]
return ''
def get_group(Id):
url = 'https://api.themoviedb.org/3/tv/episode_group/{}?api_key=a1ab8b8669da03637a4b98fa39c39228&language={}'.format(Id, def_lang)
group = requests.get(url).json().get('groups',[])
return group
def completar_codigos(item):
"""
@@ -1407,11 +1451,9 @@ class Tmdb(object):
return ret_dic
def get_list_episodes(self):
# from core.support import dbg;dbg()
url = 'https://api.themoviedb.org/3/tv/{id}?api_key=a1ab8b8669da03637a4b98fa39c39228&language={lang}'.format(id=self.busqueda_id, lang=self.busqueda_idioma)
# url = 'https://api.themoviedb.org/3/tv/{id}/episode_groups?api_key=a1ab8b8669da03637a4b98fa39c39228&language={lang}'.format(id=_id, lang=self.busqueda_idioma)
results = requests.get(url).json()['seasons']
return results if 'Error' not in results else {}
results = requests.get(url).json().get('seasons', [])
return results if 'Error' not in results else []
def get_videos(self):
"""

View File

@@ -298,7 +298,7 @@ def set_infoLabels_item(item):
return len(item.infoLabels)
def get_nfo(item):
def get_nfo(item, search_groups=False):
"""
Returns the information necessary for the result to be scraped into the kodi video library,

View File

@@ -499,7 +499,7 @@ def save_tvshow(item, episodelist, silent=False):
if not filetools.exists(tvshow_path):
# We create tvshow.nfo, if it does not exist, with the head_nfo, series info and watched episode marks
logger.debug("Creating tvshow.nfo: " + tvshow_path)
head_nfo = scraper.get_nfo(item)
head_nfo = scraper.get_nfo(item, search_groups=True)
item.infoLabels['mediatype'] = "tvshow"
item.infoLabels['title'] = item.contentSerieName
item_tvshow = Item(title=item.contentSerieName, channel="videolibrary", action="get_seasons",
@@ -867,7 +867,8 @@ def save_episodes(path, episodelist, serie, silent=False, overwrite=True):
if max_sea == high_sea and max_epi == high_epi and (tvshow_item.infoLabels["status"] == "Ended" or tvshow_item.infoLabels["status"] == "Canceled") and insertados == 0 and fallidos == 0 and not tvshow_item.local_episodes_path:
tvshow_item.active = 0 # ... nor we will update it more
logger.debug("%s [%s]: 'Finished' or 'Canceled' series. Periodic update is disabled" % (serie.contentSerieName, serie.channel))
else:
tvshow_item.active = 1
update_last = datetime.date.today()
tvshow_item.update_last = update_last.strftime('%Y-%m-%d')
update_next = datetime.date.today() + datetime.timedelta(days=int(tvshow_item.active))

View File

@@ -20,6 +20,7 @@ EPISODE = 'episode'
EPISODES = 'episodes'
SPECIALEPISODES = 'specials'
MANUALMODE = 'manual'
GROUP = 'info'
# helper Functions
def check(item):
@@ -178,6 +179,7 @@ class autorenumber():
def makelist(self):
self.epdict = {}
self.group = self.renumberdict[self.title].get(GROUP, None)
busy(True)
itemlist = find_episodes(self.item)
busy(False)
@@ -192,7 +194,22 @@ class autorenumber():
self.episodes = Manual
else:
seasons = tmdb.Tmdb(id_Tmdb=self.id).get_list_episodes()
if self.group:
Id = self.group.split('/')[-1]
else:
Id = None
groups = tmdb.get_groups(self.item)
if groups:
Id = tmdb.select_group(groups)
if Id:
self.group = 'https://www.themoviedb.org/tv/{}/episode_group/{}'.format(self.item.infoLabels['tmdb_id'], Id)
seasons = []
groupedSeasons = tmdb.get_group(Id)
for groupedSeason in groupedSeasons:
seasons.append({'season_number':groupedSeason['order'], 'episode_count':len(groupedSeason['episodes'])})
else:
seasons = tmdb.Tmdb(id_Tmdb=self.id).get_list_episodes()
count = 0
for season in seasons:
s = season['season_number']
@@ -202,7 +219,7 @@ class autorenumber():
for e in range(1, c + 1):
count += 1
self.epdict[count] = '{}x{:02d}'.format(s,e)
# dbg()
firstep = 0
if self.season > 1:
for c in range(1, self.season):
@@ -228,6 +245,7 @@ class autorenumber():
count += 1
if self.episodes: self.renumberdict[self.title][EPISODES] = self.episodes
if self.group: self.renumberdict[self.title][GROUP] = self.group
self.renumberdict[self.title][MANUALMODE] = self.manual
self.renumberdict[self.title][SEASON] = self.season
self.renumberdict[self.title][EPISODE] = self.episode