Miglioprie tmdb e autorenumber
This commit is contained in:
+67
-23
@@ -18,7 +18,7 @@ from future.builtins import object
|
|||||||
|
|
||||||
import ast, copy, re, time
|
import ast, copy, re, time
|
||||||
|
|
||||||
from core import filetools, httptools, jsontools, scrapertools
|
from core import filetools, httptools, jsontools, scrapertools, support
|
||||||
from core.item import InfoLabels
|
from core.item import InfoLabels
|
||||||
from platformcode import config, logger, platformtools
|
from platformcode import config, logger, platformtools
|
||||||
|
|
||||||
@@ -527,6 +527,7 @@ def get_nfo(item, search_groups=False):
|
|||||||
@rtype: str
|
@rtype: str
|
||||||
@return:
|
@return:
|
||||||
"""
|
"""
|
||||||
|
# from core.support import dbg;dbg()
|
||||||
|
|
||||||
if search_groups:
|
if search_groups:
|
||||||
from platformcode.autorenumber import RENUMBER, GROUP
|
from platformcode.autorenumber import RENUMBER, GROUP
|
||||||
@@ -542,24 +543,42 @@ def get_nfo(item, search_groups=False):
|
|||||||
if groups:
|
if groups:
|
||||||
Id = select_group(groups, item)
|
Id = select_group(groups, item)
|
||||||
if Id == 'original':
|
if Id == 'original':
|
||||||
info_nfo = ', '.join(item.infoLabels['url_scraper']) + "\n"
|
info_nfo = ', '.join(item.infoLabels['url_scraper'])
|
||||||
return info_nfo
|
return info_nfo + '\n'
|
||||||
elif Id :
|
elif Id :
|
||||||
info_nfo = 'https://www.themoviedb.org/tv/{}/episode_group/{}\n'.format(item.infoLabels['tmdb_id'], Id)
|
info_nfo = 'https://www.themoviedb.org/tv/{}/episode_group/{}'.format(item.infoLabels['tmdb_id'], Id)
|
||||||
return info_nfo
|
return info_nfo + '\n'
|
||||||
else: return
|
else: return
|
||||||
|
|
||||||
if "season" in item.infoLabels and "episode" in item.infoLabels:
|
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)
|
info_nfo = "https://www.themoviedb.org/tv/%s/season/%s/episode/%s" % (item.infoLabels['tmdb_id'], item.contentSeason, item.contentEpisodeNumber)
|
||||||
else:
|
else:
|
||||||
info_nfo = ', '.join(item.infoLabels['url_scraper']) + "\n"
|
info_nfo = ', '.join(item.infoLabels['url_scraper'])
|
||||||
|
|
||||||
return info_nfo
|
return info_nfo + '\n'
|
||||||
|
|
||||||
def get_groups(item):
|
def get_groups(item):
|
||||||
|
valid_groups = []
|
||||||
|
|
||||||
url = 'https://api.themoviedb.org/3/tv/{}/episode_groups?api_key=a1ab8b8669da03637a4b98fa39c39228&language={}'.format(item.infoLabels['tmdb_id'], def_lang)
|
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',[])
|
groups = requests.get(url).json().get('results',[])
|
||||||
return groups
|
|
||||||
|
for g in groups:
|
||||||
|
seasons = []
|
||||||
|
add = False
|
||||||
|
Id = g.get('id','')
|
||||||
|
group = get_group(Id)
|
||||||
|
for gr in group:
|
||||||
|
if gr['episodes']:
|
||||||
|
season = gr['episodes'][0]['season_number']
|
||||||
|
if season not in seasons:
|
||||||
|
seasons.append(season)
|
||||||
|
add = True
|
||||||
|
else:
|
||||||
|
add = False
|
||||||
|
break
|
||||||
|
if add: valid_groups.append(g)
|
||||||
|
return valid_groups
|
||||||
|
|
||||||
def select_group(groups, item):
|
def select_group(groups, item):
|
||||||
selected = -1
|
selected = -1
|
||||||
@@ -568,8 +587,6 @@ def select_group(groups, item):
|
|||||||
selections = [['Original',res.get('number_of_seasons',0), res.get('number_of_episodes',0), '', item.thumbnail]]
|
selections = [['Original',res.get('number_of_seasons',0), res.get('number_of_episodes',0), '', item.thumbnail]]
|
||||||
ids = ['original']
|
ids = ['original']
|
||||||
for group in groups:
|
for group in groups:
|
||||||
# name = '{} Seasons: {} Episodes: {}'.format(group.get('name',''), group.get('group_count',0), group.get('episode_count',0))
|
|
||||||
# description = group.get('description','')
|
|
||||||
ID = group.get('id','')
|
ID = group.get('id','')
|
||||||
if ID:
|
if ID:
|
||||||
selections.append([group.get('name',''), group.get('group_count',0), group.get('episode_count',0), group.get('description',''), item.thumbnail])
|
selections.append([group.get('name',''), group.get('group_count',0), group.get('episode_count',0), group.get('description',''), item.thumbnail])
|
||||||
@@ -581,6 +598,7 @@ def select_group(groups, item):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
def get_group(Id):
|
def get_group(Id):
|
||||||
|
# from core.support import dbg;dbg()
|
||||||
url = 'https://api.themoviedb.org/3/tv/episode_group/{}?api_key=a1ab8b8669da03637a4b98fa39c39228&language={}'.format(Id, def_lang)
|
url = 'https://api.themoviedb.org/3/tv/episode_group/{}?api_key=a1ab8b8669da03637a4b98fa39c39228&language={}'.format(Id, def_lang)
|
||||||
group = requests.get(url).json().get('groups',[])
|
group = requests.get(url).json().get('groups',[])
|
||||||
return group
|
return group
|
||||||
@@ -884,7 +902,7 @@ class Tmdb(object):
|
|||||||
result = httptools.downloadpage(url, cookies=False, ignore_response_code=True)
|
result = httptools.downloadpage(url, cookies=False, ignore_response_code=True)
|
||||||
|
|
||||||
res_headers = result.headers
|
res_headers = result.headers
|
||||||
dict_data = jsontools.load(result.data)
|
dict_data = result.json
|
||||||
#logger.debug("result_data es %s" % dict_data)
|
#logger.debug("result_data es %s" % dict_data)
|
||||||
|
|
||||||
if "status_code" in dict_data:
|
if "status_code" in dict_data:
|
||||||
@@ -900,7 +918,7 @@ class Tmdb(object):
|
|||||||
|
|
||||||
res_headers = result.headers
|
res_headers = result.headers
|
||||||
# logger.debug("res_headers es %s" % res_headers)
|
# logger.debug("res_headers es %s" % res_headers)
|
||||||
dict_data = jsontools.load(result.data)
|
dict_data = result.json
|
||||||
# logger.debug("result_data es %s" % dict_data)
|
# logger.debug("result_data es %s" % dict_data)
|
||||||
|
|
||||||
# error getting data
|
# error getting data
|
||||||
@@ -1006,7 +1024,8 @@ class Tmdb(object):
|
|||||||
total_pages = resultado.get("total_pages", 0)
|
total_pages = resultado.get("total_pages", 0)
|
||||||
|
|
||||||
if total_results > 0:
|
if total_results > 0:
|
||||||
results = resultado["results"]
|
results = [r for r in resultado["results"] if r['first_air_date']]
|
||||||
|
# results = resultado["results"]
|
||||||
|
|
||||||
if self.busqueda_filtro and total_results > 1:
|
if self.busqueda_filtro and total_results > 1:
|
||||||
for key, value in list(dict(self.busqueda_filtro).items()):
|
for key, value in list(dict(self.busqueda_filtro).items()):
|
||||||
@@ -1136,20 +1155,22 @@ class Tmdb(object):
|
|||||||
num_result = min([num_result, self.total_results])
|
num_result = min([num_result, self.total_results])
|
||||||
|
|
||||||
cr = 0
|
cr = 0
|
||||||
|
# support.dbg()
|
||||||
for p in range(1, self.total_pages + 1):
|
for p in range(1, self.total_pages + 1):
|
||||||
for r in range(0, len(self.results)):
|
for r in range(0, len(self.results)):
|
||||||
try:
|
try:
|
||||||
if self.load_resultado(r, p):
|
if self.load_resultado(r, p):
|
||||||
result = self.result.copy()
|
result = self.result.copy()
|
||||||
|
if result['first_air_date']:
|
||||||
|
|
||||||
result['thumbnail'] = self.get_poster(size="w300")
|
result['thumbnail'] = self.get_poster(size="w300")
|
||||||
result['fanart'] = self.get_backdrop()
|
result['fanart'] = self.get_backdrop()
|
||||||
|
|
||||||
res.append(result)
|
res.append(result)
|
||||||
cr += 1
|
cr += 1
|
||||||
|
|
||||||
if cr >= num_result:
|
if cr >= num_result:
|
||||||
return res
|
return res
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1346,9 +1367,11 @@ class Tmdb(object):
|
|||||||
# append_to_response=credits
|
# append_to_response=credits
|
||||||
url = "http://api.themoviedb.org/3/tv/%s/season/%s?api_key=a1ab8b8669da03637a4b98fa39c39228&language=%s" \
|
url = "http://api.themoviedb.org/3/tv/%s/season/%s?api_key=a1ab8b8669da03637a4b98fa39c39228&language=%s" \
|
||||||
"&append_to_response=credits" % (self.result["id"], numtemporada, self.busqueda_idioma)
|
"&append_to_response=credits" % (self.result["id"], numtemporada, self.busqueda_idioma)
|
||||||
|
logger.debug('TMDB URL', url)
|
||||||
|
|
||||||
buscando = "id_Tmdb: " + str(self.result["id"]) + " season: " + str(numtemporada) + "\nURL: " + url
|
buscando = "id_Tmdb: " + str(self.result["id"]) + " season: " + str(numtemporada) + "\nURL: " + url
|
||||||
logger.debug("[Tmdb.py] Searcing " + buscando)
|
logger.debug("[Tmdb.py] Searcing " + buscando)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.temporada[numtemporada] = self.get_json(url)
|
self.temporada[numtemporada] = self.get_json(url)
|
||||||
if not isinstance(self.temporada[numtemporada], dict):
|
if not isinstance(self.temporada[numtemporada], dict):
|
||||||
@@ -1382,6 +1405,7 @@ class Tmdb(object):
|
|||||||
# "episode_crew" and "episode_guest_stars",
|
# "episode_crew" and "episode_guest_stars",
|
||||||
# With chapter == -1 the dictionary will only have the elements referring to the season
|
# With chapter == -1 the dictionary will only have the elements referring to the season
|
||||||
# --------------------------------------------------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
if not self.result["id"] or self.busqueda_tipo != "tv":
|
if not self.result["id"] or self.busqueda_tipo != "tv":
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@@ -1392,22 +1416,40 @@ class Tmdb(object):
|
|||||||
logger.debug("The episode or season number is not valid")
|
logger.debug("The episode or season number is not valid")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
# from core.support import dbg;dbg()
|
||||||
temporada = self.get_temporada(numtemporada)
|
temporada = self.get_temporada(numtemporada)
|
||||||
if not isinstance(temporada, dict):
|
if not isinstance(temporada, dict):
|
||||||
temporada = ast.literal_eval(temporada.decode('utf-8'))
|
temporada = ast.literal_eval(temporada.decode('utf-8'))
|
||||||
if not temporada:
|
if not temporada:
|
||||||
# An error has occurred
|
# An error has occurred
|
||||||
return {}
|
return {}
|
||||||
|
# if capitulo == 9: from core.support import dbg;dbg()
|
||||||
if len(temporada["episodes"]) == 0 or len(temporada["episodes"]) < capitulo:
|
if len(temporada["episodes"]) == 0:
|
||||||
# An error has occurred
|
# An error has occurred
|
||||||
logger.error("Episode %d of the season %d not found." % (capitulo, numtemporada))
|
logger.error("Episode %d of the season %d not found." % (capitulo, numtemporada))
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
elif len(temporada["episodes"]) < capitulo and temporada["episodes"][-1]['episode_number'] >= capitulo:
|
||||||
|
n = None
|
||||||
|
for i, chapters in enumerate(temporada["episodes"]):
|
||||||
|
if chapters['episode_number'] == capitulo:
|
||||||
|
n = i
|
||||||
|
break
|
||||||
|
if n != None:
|
||||||
|
capitulo = n
|
||||||
|
else:
|
||||||
|
logger.error("Episode %d of the season %d not found." % (capitulo, numtemporada))
|
||||||
|
return {}
|
||||||
|
# else:
|
||||||
|
# logger.error("Episode %d of the season %d not found." % (capitulo, numtemporada))
|
||||||
|
# return {}
|
||||||
|
|
||||||
ret_dic = dict()
|
ret_dic = dict()
|
||||||
# Get data for this season
|
# Get data for this season
|
||||||
ret_dic["temporada_nombre"] = temporada["name"]
|
ret_dic["temporada_nombre"] = temporada["name"]
|
||||||
ret_dic["temporada_sinopsis"] = temporada["overview"]
|
ret_dic["temporada_sinopsis"] = temporada["overview"]
|
||||||
|
ret_dic["temporada_id"] = temporada["id"]
|
||||||
ret_dic["temporada_num_episodios"] = len(temporada["episodes"])
|
ret_dic["temporada_num_episodios"] = len(temporada["episodes"])
|
||||||
if temporada["air_date"]:
|
if temporada["air_date"]:
|
||||||
date = temporada["air_date"].split("-")
|
date = temporada["air_date"].split("-")
|
||||||
@@ -1431,9 +1473,10 @@ class Tmdb(object):
|
|||||||
ret_dic["temporada_crew"] = list(dic_aux.values())
|
ret_dic["temporada_crew"] = list(dic_aux.values())
|
||||||
|
|
||||||
# Obtain chapter data if applicable
|
# Obtain chapter data if applicable
|
||||||
|
|
||||||
if capitulo != -1:
|
if capitulo != -1:
|
||||||
episodio = temporada["episodes"][capitulo - 1]
|
episodio = temporada["episodes"][capitulo - 1]
|
||||||
ret_dic["episodio_titulo"] = episodio.get("name", "")
|
ret_dic["episodio_titulo"] = episodio.get("name", )
|
||||||
ret_dic["episodio_sinopsis"] = episodio["overview"]
|
ret_dic["episodio_sinopsis"] = episodio["overview"]
|
||||||
if episodio["air_date"]:
|
if episodio["air_date"]:
|
||||||
date = episodio["air_date"].split("-")
|
date = episodio["air_date"].split("-")
|
||||||
@@ -1444,6 +1487,7 @@ class Tmdb(object):
|
|||||||
ret_dic["episodio_guest_stars"] = episodio["guest_stars"]
|
ret_dic["episodio_guest_stars"] = episodio["guest_stars"]
|
||||||
ret_dic["episodio_vote_count"] = episodio["vote_count"]
|
ret_dic["episodio_vote_count"] = episodio["vote_count"]
|
||||||
ret_dic["episodio_vote_average"] = episodio["vote_average"]
|
ret_dic["episodio_vote_average"] = episodio["vote_average"]
|
||||||
|
ret_dic["episodio_id"] = episodio["id"]
|
||||||
if episodio["still_path"]:
|
if episodio["still_path"]:
|
||||||
ret_dic["episodio_imagen"] = 'https://image.tmdb.org/t/p/original' + episodio["still_path"]
|
ret_dic["episodio_imagen"] = 'https://image.tmdb.org/t/p/original' + episodio["still_path"]
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -182,19 +182,24 @@ class autorenumber():
|
|||||||
self.group = self.renumberdict[self.title].get(GROUP, None)
|
self.group = self.renumberdict[self.title].get(GROUP, None)
|
||||||
busy(True)
|
busy(True)
|
||||||
itemlist = find_episodes(self.item)
|
itemlist = find_episodes(self.item)
|
||||||
busy(False)
|
|
||||||
|
|
||||||
if not self.group:
|
if not self.group:
|
||||||
self.group = tmdb.get_nfo(self.item, search_groups=True)
|
self.group = tmdb.get_nfo(self.item)
|
||||||
|
|
||||||
if 'episode_group' in self.group:
|
if not self.group:
|
||||||
seasons =[]
|
busy(False)
|
||||||
groupedSeasons = tmdb.get_group(self.group.replace('\n','').split('/')[-1])
|
return
|
||||||
for groupedSeason in groupedSeasons:
|
|
||||||
seasons.append({'season_number':groupedSeason['order'], 'episode_count':len(groupedSeason['episodes']), 'start_from':groupedSeason['episodes'][0]['episode_number']})
|
|
||||||
else:
|
|
||||||
seasons = tmdb.Tmdb(id_Tmdb=self.id).get_list_episodes()
|
|
||||||
|
|
||||||
|
# if 'episode_group' in self.group:
|
||||||
|
# seasons =[]
|
||||||
|
# groupedSeasons = tmdb.get_group(self.group.replace('\n','').split('/')[-1])
|
||||||
|
# for groupedSeason in groupedSeasons:
|
||||||
|
# if groupedSeason['episodes'][0]['season_number'] > 0:
|
||||||
|
# seasons.append({'season_number':groupedSeason['episodes'][0]['season_number'], 'episode_count':len(groupedSeason['episodes']), 'start_from':groupedSeason['episodes'][0]['episode_number']})
|
||||||
|
# else:
|
||||||
|
seasons = tmdb.Tmdb(id_Tmdb=self.id).get_list_episodes()
|
||||||
|
busy(False)
|
||||||
count = 0
|
count = 0
|
||||||
for season in seasons:
|
for season in seasons:
|
||||||
s = season['season_number']
|
s = season['season_number']
|
||||||
|
|||||||
Reference in New Issue
Block a user