aggiornamento ricerca alternativa
This commit is contained in:
+108
-105
@@ -227,10 +227,10 @@ class scrape:
|
||||
self.itemlist = [i for i in self.itemlist if i.action not in ['add_movie_to_library', 'add_serie_to_library']]
|
||||
|
||||
if not self.group and not self.args.get('groupExplode') and ((self.pagination and len(self.matches) <= self.pag * self.pagination) or not self.pagination): # next page with pagination
|
||||
if self.patronNext and inspect.stack()[1][3] not in ['newest'] and len(inspect.stack()) > 2 and inspect.stack()[2][3] not in ['get_channel_results']:
|
||||
if self.patronNext and not stackCheck('newest') and not stackCheck('get_channel_results'):
|
||||
nextPage(self.itemlist, item, self.function, data=self.data, patron=self.patronNext, patron_total_pages=self.patronTotalPages)
|
||||
|
||||
if self.numerationEnabled and inspect.stack()[1][3] not in ['find_episodes']:
|
||||
if self.numerationEnabled and not stackCheck('find_episodes'):
|
||||
from platformcode import autorenumber
|
||||
if self.function == 'episodios':
|
||||
autorenumber.start(self.itemlist, item)
|
||||
@@ -242,7 +242,7 @@ class scrape:
|
||||
else: autorenumber.start(self.itemlist)
|
||||
|
||||
|
||||
if inspect.stack()[1][3] not in ['add_tvshow', 'get_episodes', 'update', 'find_episodes']:
|
||||
if not stackCheck(['add_tvshow', 'get_episodes', 'update', 'find_episodes']):
|
||||
if len(self.seasons) > 1 and self.seasonPagination:
|
||||
self.itemlist = season_pagination(self.itemlist, item, self.seasons, self.function)
|
||||
elif self.pagination or (self.function in ['episodios'] and self.seasonPagination):
|
||||
@@ -250,12 +250,12 @@ class scrape:
|
||||
|
||||
if self.tmdbEnabled and (
|
||||
self.action != 'play' and 'patronMenu' not in self.args and 'patronGenreMenu' not in self.args
|
||||
and inspect.stack()[1][3] not in ['add_tvshow'] and (self.function not in ['episodios', 'mainlist']
|
||||
and not stackCheck('add_tvshow') and (self.function not in ['episodios', 'mainlist']
|
||||
or (self.function in ['episodios'] and config.get_setting('episode_info')))):
|
||||
|
||||
tmdb.set_infoLabels_itemlist(self.itemlist, seekTmdb=True)
|
||||
|
||||
if inspect.stack()[1][3] not in ['find_episodes', 'add_tvshow']:
|
||||
if not stackCheck(['find_episodes', 'add_tvshow']):
|
||||
if self.videlibraryEnabled and (item.infoLabels["title"] or item.fulltitle):
|
||||
# item.fulltitle = item.infoLabels["title"]
|
||||
videolibrary(self.itemlist, item, function=self.function)
|
||||
@@ -305,20 +305,20 @@ class scrape:
|
||||
elif v.startswith('/'):
|
||||
domain = scrapertools.find_single_match(item.url, 'https?://[a-z0-9.-]+')
|
||||
v = domain + v
|
||||
self.itemParams.__setattr__(k, v.strip() if type(v) == str else v)
|
||||
self.itemParams.__setattr__('_'+k, v.strip() if type(v) == str else v)
|
||||
|
||||
self.itemParams.title = cleantitle(self.itemParams.title)
|
||||
if self.group and self.itemParams.title in contents and not item.grouped: # same title and grouping enabled
|
||||
self.itemParams._title = cleantitle(self.itemParams._title)
|
||||
if self.group and self.itemParams._title in contents and not item.grouped: # same title and grouping enabled
|
||||
continue
|
||||
if item.grouped and self.itemParams.title != item.fulltitle: # inside a group different tvshow should not be included
|
||||
if item.grouped and self.itemParams._title != item.fulltitle: # inside a group different tvshow should not be included
|
||||
continue
|
||||
|
||||
contents.append(self.itemParams.title)
|
||||
contents.append(self.itemParams._title)
|
||||
|
||||
self.itemParams.title2 = cleantitle(self.itemParams.title2) if not self.group or item.grouped else ''
|
||||
self.itemParams.quality = self.itemParams.quality
|
||||
self.itemParams.plot = cleantitle(self.itemParams.plot)
|
||||
self.itemParams.language = scrapeLang(self.itemParams, self.lang)
|
||||
self.itemParams._title2 = cleantitle(self.itemParams._title2) if not self.group or item.grouped else ''
|
||||
self.itemParams._quality = self.itemParams._quality
|
||||
self.itemParams._plot = cleantitle(self.itemParams._plot)
|
||||
self.itemParams._language = scrapeLang(self.itemParams, self.lang)
|
||||
|
||||
self.set_infolabels(item)
|
||||
if self.sceneTitle: self.set_sceneTitle()
|
||||
@@ -326,9 +326,9 @@ class scrape:
|
||||
if not self.group or item.grouped:
|
||||
self.set_episodes(item)
|
||||
|
||||
if self.itemParams.episode2: self.itemParams.second_episode = scrapertools.find_single_match(self.itemParams.episode2, r'(\d+)').split('x')
|
||||
if self.itemParams.season: self.itemParams.infoLabels['season'] = int(self.itemParams.season)
|
||||
if self.itemParams.episode: self.itemParams.infoLabels['episode'] = int(self.itemParams.episode)
|
||||
if self.itemParams._episode2: self.itemParams._second_episode = scrapertools.find_single_match(self.itemParams._episode2, r'(\d+)').split('x')
|
||||
if self.itemParams._season: self.itemParams.infoLabels['season'] = int(self.itemParams._season)
|
||||
if self.itemParams._episode: self.itemParams.infoLabels['episode'] = int(self.itemParams._episode)
|
||||
|
||||
it = self.set_item(item, match)
|
||||
if it: itemlist.append(it)
|
||||
@@ -344,25 +344,27 @@ class scrape:
|
||||
infolabels = item.infoLabels
|
||||
else:
|
||||
infolabels = {'mediatype':item.contentType}
|
||||
if self.itemParams.year:
|
||||
infolabels['year'] = self.itemParams.year
|
||||
if self.itemParams.plot:
|
||||
infolabels['plot'] = self.itemParams.plot
|
||||
if self.itemParams.duration:
|
||||
dur = scrapertools.find_multiple_matches(self.itemParams.duration, r'([0-9])\s*?(?:[hH]|:|\.|,|\\|\/|\||\s)\s*?([0-9]+)')
|
||||
if self.itemParams._year:
|
||||
infolabels['year'] = self.itemParams._year
|
||||
if self.itemParams._plot:
|
||||
infolabels['plot'] = self.itemParams._plot
|
||||
if self.itemParams._duration:
|
||||
dur = scrapertools.find_multiple_matches(self.itemParams._duration, r'([0-9])\s*?(?:[hH]|:|\.|,|\\|\/|\||\s)\s*?([0-9]+)')
|
||||
for h, m in dur:
|
||||
self.itemParams.duration = int(h) * 60 + int(m)
|
||||
self.itemParams._duration = int(h) * 60 + int(m)
|
||||
if not dur:
|
||||
self.itemParams.duration = scrapertools.find_single_match(self.itemParams.duration, r'(\d+)')
|
||||
self.itemParams._duration = scrapertools.find_single_match(self.itemParams._duration, r'(\d+)')
|
||||
try:
|
||||
infolabels['duration'] = int(self.itemParams.duration) * 60
|
||||
infolabels['duration'] = int(self.itemParams._duration) * 60
|
||||
except:
|
||||
self.itemParams.duration = ''
|
||||
if self.itemParams.genre:
|
||||
genres = scrapertools.find_multiple_matches(self.itemParams.genre, '[A-Za-z]+')
|
||||
self.itemParams._duration = ''
|
||||
if self.itemParams._genre:
|
||||
genres = scrapertools.find_multiple_matches(self.itemParams._genre, '[A-Za-z]+')
|
||||
infolabels['genere'] = ", ".join(genres)
|
||||
if self.itemParams.rating:
|
||||
infolabels['rating'] = scrapertools.decodeHtmlentities(self.itemParams.rating)
|
||||
if self.itemParams._rating:
|
||||
rating = scrapertools.decodeHtmlentities(self.itemParams._rating)
|
||||
if rating.isdigit():
|
||||
infolabels['rating'] = float(rating)
|
||||
|
||||
self.itemParams.infoLabels = infolabels
|
||||
logger.debug
|
||||
@@ -370,71 +372,71 @@ class scrape:
|
||||
def set_sceneTitle(self):
|
||||
from lib.guessit import guessit
|
||||
try:
|
||||
parsedTitle = guessit(self.itemParams.title)
|
||||
self.itemParams.title = parsedTitle.get('title', '')
|
||||
logger.debug('TITOLO',self.itemParams.title)
|
||||
parsedTitle = guessit(self.itemParams._title)
|
||||
self.itemParams._title = parsedTitle.get('title', '')
|
||||
logger.debug('TITOLO',self.itemParams._title)
|
||||
if parsedTitle.get('source'):
|
||||
self.itemParams.quality = str(parsedTitle.get('source'))
|
||||
self.itemParams._quality = str(parsedTitle.get('source'))
|
||||
if parsedTitle.get('screen_size'):
|
||||
self.itemParams.quality += ' ' + str(parsedTitle.get('screen_size', ''))
|
||||
if not self.itemParams.year:
|
||||
self.itemParams._quality += ' ' + str(parsedTitle.get('screen_size', ''))
|
||||
if not self.itemParams._year:
|
||||
if type(parsedTitle.get('year', '')) == list:
|
||||
self.itemParams.infoLabels['year'] = parsedTitle.get('year', '')[0]
|
||||
else:
|
||||
self.itemParams.infoLabels['year'] = parsedTitle.get('year', '')
|
||||
if parsedTitle.get('episode') and parsedTitle.get('season'):
|
||||
if type(parsedTitle.get('season')) == list:
|
||||
self.itemParams.season = str(parsedTitle.get('season')[0])
|
||||
self.itemParams._season = str(parsedTitle.get('season')[0])
|
||||
elif parsedTitle.get('season'):
|
||||
self.itemParams.season = str(parsedTitle.get('season'))
|
||||
self.itemParams._season = str(parsedTitle.get('season'))
|
||||
|
||||
if type(parsedTitle.get('episode')) == list:
|
||||
self.itemParams.episode = str(parsedTitle.get('episode')[0])
|
||||
self.itemParams.second_episode = str(parsedTitle.get('episode')[1:])
|
||||
self.itemParams._episode = str(parsedTitle.get('episode')[0])
|
||||
self.itemParams._second_episode = str(parsedTitle.get('episode')[1:])
|
||||
else:
|
||||
self.itemParams.infoLabels['episode'] = parsedTitle.get('episode')
|
||||
|
||||
elif parsedTitle.get('season') and type(parsedTitle.get('season')) == list:
|
||||
self.itemParams.extraInfo = '{}: {}-{}'.format(config.get_localized_string(30140), parsedTitle.get('season')[0], parsedTitle.get('season')[-1])
|
||||
self.itemParams._extraInfo = '{}: {}-{}'.format(config.get_localized_string(30140), parsedTitle.get('season')[0], parsedTitle.get('season')[-1])
|
||||
elif parsedTitle.get('season'):
|
||||
self.itemParams.season = str(parsedTitle.get('season'))
|
||||
self.itemParams._season = str(parsedTitle.get('season'))
|
||||
if parsedTitle.get('episode_title'):
|
||||
self.itemParams.extraInfo += parsedTitle.get('episode_title')
|
||||
self.itemParams._extraInfo += parsedTitle.get('episode_title')
|
||||
except:
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
def set_episodes(self, item):
|
||||
ep = unifyEp(self.itemParams.episode) if self.itemParams.episode else ''
|
||||
se = self.itemParams.season if self.itemParams.season.isdigit() else ''
|
||||
ep = unifyEp(self.itemParams._episode) if self.itemParams._episode else ''
|
||||
se = self.itemParams._season if self.itemParams._season.isdigit() else ''
|
||||
if ep and se:
|
||||
self.itemParams.season = se
|
||||
self.itemParams._season = se
|
||||
if 'x' in ep:
|
||||
ep_list = ep.split('x')
|
||||
self.itemParams.episode = ep_list[0]
|
||||
self.itemParams.second_episode = ep_list[1:]
|
||||
self.itemParams._episode = ep_list[0]
|
||||
self.itemParams._second_episode = ep_list[1:]
|
||||
else:
|
||||
self.itemParams.episode = ep
|
||||
self.itemParams._episode = ep
|
||||
|
||||
elif item.season:
|
||||
self.itemParams.season = item.season
|
||||
if ep: self.itemParams.episode = int(scrapertools.find_single_match(self.itemParams.episode, r'(\d+)'))
|
||||
self.itemParams._season = item.season
|
||||
if ep: self.itemParams._episode = int(scrapertools.find_single_match(self.itemParams._episode, r'(\d+)'))
|
||||
|
||||
elif item.contentType == 'tvshow' and (self.itemParams.episode == '' and self.itemParams.season == '' and self.itemParams.season == ''):
|
||||
elif item.contentType == 'tvshow' and (self.itemParams._episode == '' and self.itemParams._season == '' and self.itemParams._season == ''):
|
||||
item.news = 'season_completed'
|
||||
|
||||
else:
|
||||
try:
|
||||
if 'x' in ep:
|
||||
ep_list = ep.split('x')
|
||||
self.itemParams.episode = ep_list[1].strip()
|
||||
self.itemParams.season = ep_list[0].strip()
|
||||
self.itemParams._episode = ep_list[1].strip()
|
||||
self.itemParams._season = ep_list[0].strip()
|
||||
if len(ep_list) > 2:
|
||||
self.itemParams.second_episode = ep_list[2:]
|
||||
self.itemParams._second_episode = ep_list[2:]
|
||||
else:
|
||||
self.itemParams.episode = ep
|
||||
self.itemParams._episode = ep
|
||||
except:
|
||||
logger.debug('invalid episode: ' + self.itemParams.episode)
|
||||
logger.debug('invalid episode: ' + self.itemParams._episode)
|
||||
pass
|
||||
|
||||
def set_item(self, item, match):
|
||||
@@ -442,41 +444,41 @@ class scrape:
|
||||
CT = ''
|
||||
if self.typeContentDict:
|
||||
for name, variants in self.typeContentDict.items():
|
||||
if str(self.itemParams.type).lower() in variants:
|
||||
if str(self.itemParams._type).lower() in variants:
|
||||
CT = name
|
||||
break
|
||||
else: CT = item.contentType
|
||||
if self.typeActionDict:
|
||||
for name, variants in self.typeActionDict.items():
|
||||
if str(self.itemParams.type).lower() in variants:
|
||||
if str(self.itemParams._type).lower() in variants:
|
||||
AC = name
|
||||
break
|
||||
else: AC = self.action
|
||||
if (not self.itemParams.title or self.itemParams.title not in self.blacklist) and (self.search.lower() in self.itemParams.title.lower()):
|
||||
it = item.clone(title=self.itemParams.title,
|
||||
fulltitle=self.itemParams.title,
|
||||
show=self.itemParams.title,
|
||||
if (not self.itemParams._title or self.itemParams._title not in self.blacklist) and (self.search.lower() in self.itemParams._title.lower()):
|
||||
it = item.clone(title=self.itemParams._title,
|
||||
fulltitle=self.itemParams._title,
|
||||
show=self.itemParams._title,
|
||||
infoLabels=self.itemParams.infoLabels,
|
||||
grouped = self.group,
|
||||
episode2 = self.itemParams.second_episode,
|
||||
extraInfo = self.itemParams.extraInfo,
|
||||
episode2 = self.itemParams._second_episode,
|
||||
extraInfo = self.itemParams._extraInfo,
|
||||
disable_videolibrary = not self.args.get('addVideolibrary', True),
|
||||
size = self.itemParams.size,
|
||||
seed = self.itemParams.seed)
|
||||
size = self.itemParams._size,
|
||||
seed = self.itemParams._seed)
|
||||
if self.itemParams.infoLabels.get('season'): it.contentSeason = self.itemParams.infoLabels.get('season')
|
||||
if self.itemParams.infoLabels.get('episode'): it.contentEpisodeNumber = self.itemParams.infoLabels.get('episode')
|
||||
if self.itemParams.url: it.url = self.itemParams.url
|
||||
if self.function == 'episodios': it.fulltitle = it.show = self.itemParams.title
|
||||
if self.itemParams.quality: it.quality = self.itemParams.quality
|
||||
if self.itemParams.language: it.contentLanguage = self.itemParams.language
|
||||
if self.itemParams._url: it.url = self.itemParams._url
|
||||
if self.function == 'episodios': it.fulltitle = it.show = self.itemParams._title
|
||||
if self.itemParams._quality: it.quality = self.itemParams._quality
|
||||
if self.itemParams._language: it.contentLanguage = self.itemParams._language
|
||||
if item.prevthumb: it.thumbnail = item.prevthumb
|
||||
elif self.itemParams.thumb: it.thumbnail = self.itemParams.thumb
|
||||
elif self.itemParams._thumb: it.thumbnail = self.itemParams._thumb
|
||||
it.contentType = 'episode' if self.function == 'episodios' else CT if CT else item.contentType
|
||||
if it.contentType not in ['movie'] and self.function != 'episodios' or it.contentType in ['undefined']: it.contentSerieName = self.itemParams.title
|
||||
if self.function == 'peliculas': it.contentTitle= self.itemParams.title
|
||||
if self.itemParams.title2: it.title2 = self.itemParams.title2
|
||||
if it.contentType not in ['movie'] and self.function != 'episodios' or it.contentType in ['undefined']: it.contentSerieName = self.itemParams._title
|
||||
if self.function == 'peliculas': it.contentTitle= self.itemParams._title
|
||||
if self.itemParams._title2: it.title2 = self.itemParams._title2
|
||||
|
||||
if self.itemParams.episode and self.group and not item.grouped:
|
||||
if self.itemParams._episode and self.group and not item.grouped:
|
||||
it.action = self.function
|
||||
elif AC:
|
||||
it.action = AC
|
||||
@@ -852,7 +854,7 @@ def nextPage(itemlist, item, function_or_level=1, **kwargs):
|
||||
total_pages = integer, the number of total pages
|
||||
'''
|
||||
logger.debug()
|
||||
if 'channel_search' in [s[3] for s in inspect.stack()]:
|
||||
if stackCheck('channel_search'):
|
||||
return itemlist
|
||||
|
||||
# get optional args
|
||||
@@ -897,6 +899,7 @@ def nextPage(itemlist, item, function_or_level=1, **kwargs):
|
||||
page=page if page else item.page + 1 if item.page else 2,
|
||||
prevthumb = item.thumbnail,
|
||||
thumbnail=thumb()))
|
||||
|
||||
if total_pages:
|
||||
itemlist.append(item.clone(action='gotopage',
|
||||
real_action = inspect.stack()[function_or_level][3] if type(function_or_level) == int else function_or_level,
|
||||
@@ -911,7 +914,7 @@ def nextPage(itemlist, item, function_or_level=1, **kwargs):
|
||||
|
||||
|
||||
def pagination(itemlist, item, function_level=1):
|
||||
if 'channel_search' in [s[3] for s in inspect.stack()]:
|
||||
if stackCheck('channel_search'):
|
||||
return itemlist
|
||||
|
||||
if not item.page:
|
||||
@@ -923,7 +926,8 @@ def pagination(itemlist, item, function_level=1):
|
||||
if perpage and (item.page - 1) * perpage > i: continue # pagination
|
||||
if perpage and i >= item.page * perpage: break # pagination
|
||||
itlist.append(it)
|
||||
if len(itemlist) >= item.page * perpage:
|
||||
|
||||
if len(itemlist) > item.page * perpage:
|
||||
itemlistdb(itemlist)
|
||||
itlist.append(
|
||||
Item(channel=item.channel,
|
||||
@@ -936,35 +940,26 @@ def pagination(itemlist, item, function_level=1):
|
||||
itemlist = True,
|
||||
prevthumb = item.thumbnail,
|
||||
thumbnail=thumb()))
|
||||
itlist.append(
|
||||
Item(channel=item.channel,
|
||||
contentType=item.contentType,
|
||||
action='gotopage',
|
||||
real_action=action,
|
||||
title=typo(config.get_localized_string(90007), 'color kod bold'),
|
||||
page=item.page + 1,
|
||||
total_pages=round(len(itemlist)/perpage),
|
||||
nextPage = True,
|
||||
itemlist = True,
|
||||
prevthumb = item.thumbnail,
|
||||
thumbnail=thumb(),
|
||||
folder = False))
|
||||
# itlist.append(
|
||||
# item.clone(channel=item.channel,
|
||||
# action=action,
|
||||
# contentType=item.contentType,
|
||||
# title=typo(config.get_localized_string(90006), 'color kod bold'),
|
||||
# page=item.page + 1,
|
||||
# total_pages=round(len(itemlist)/perpage),
|
||||
# nextPage = True,
|
||||
# itemlist = True,
|
||||
# prevthumb = item.thumbnail,
|
||||
# thumbnail=thumb()))
|
||||
if len(itemlist) > perpage:
|
||||
itlist.append(
|
||||
Item(channel=item.channel,
|
||||
contentType=item.contentType,
|
||||
action='gotopage',
|
||||
real_action=action,
|
||||
title=typo(config.get_localized_string(90007), 'color kod bold'),
|
||||
page=item.page + 1,
|
||||
total_pages=round(len(itemlist)/perpage),
|
||||
nextPage = True,
|
||||
itemlist = True,
|
||||
prevthumb = item.thumbnail,
|
||||
thumbnail=thumb(),
|
||||
folder = False))
|
||||
|
||||
return itlist
|
||||
|
||||
|
||||
def season_pagination(itemlist, item, seasons=[], function_level=1):
|
||||
if 'channel_search' in [s[3] for s in inspect.stack()]:
|
||||
if stackCheck('channel_search'):
|
||||
return itemlist
|
||||
|
||||
action = function_level if type(function_level) == str else inspect.stack()[function_level][3]
|
||||
@@ -1881,3 +1876,11 @@ def itemlistdb(itemlist=None):
|
||||
itemlist = db['itemlist'].get('itemlist',[])
|
||||
db.close()
|
||||
return itemlist
|
||||
|
||||
|
||||
def stackCheck(values):
|
||||
stacks = [s[3] for s in inspect.stack()]
|
||||
if type(values) == str:
|
||||
return values in stacks
|
||||
else:
|
||||
return any(v in values for v in stacks)
|
||||
+7
-21
@@ -17,10 +17,9 @@ from future.builtins import object
|
||||
|
||||
import ast, copy, re, time
|
||||
|
||||
from core import filetools, httptools, jsontools, scrapertools, support
|
||||
from core import filetools, httptools, jsontools, scrapertools
|
||||
from core.item import InfoLabels
|
||||
from platformcode import config, logger, platformtools
|
||||
import threading
|
||||
|
||||
info_language = ["de", "en", "es", "fr", "it", "pt"] # from videolibrary.json
|
||||
def_lang = info_language[config.get_setting("info_language", "videolibrary")]
|
||||
@@ -214,7 +213,8 @@ def set_infoLabels_itemlist(itemlist, seekTmdb=False, search_language=def_lang,
|
||||
logger.error(traceback.format_exc(1))
|
||||
|
||||
return (_i, _item, ret)
|
||||
# from core.support import dbg;dbg()
|
||||
|
||||
# from core.support import dbg; dbg()
|
||||
# for i, item in enumerate(itemlist):
|
||||
# r_list.append(sub_thread(item, i, seekTmdb))
|
||||
with futures.ThreadPoolExecutor() as executor:
|
||||
@@ -428,7 +428,7 @@ def set_infoLabels_item(item, seekTmdb=True, search_language=def_lang):
|
||||
item.fulltitle = new_title
|
||||
return True
|
||||
# We check what type of content it is...
|
||||
# from core.support import dbg;dbg()
|
||||
|
||||
if item.contentType == 'movie':
|
||||
search_type = 'movie'
|
||||
elif item.contentType == 'undefined': # don't know
|
||||
@@ -537,10 +537,7 @@ def get_nfo(item, search_groups=False):
|
||||
info_nfo = 'https://www.themoviedb.org/tv/{}/episode_group/{}'.format(item.infoLabels['tmdb_id'], Id)
|
||||
return info_nfo + '\n'
|
||||
else: return
|
||||
# from core.support import dbg;dbg()
|
||||
# if "season" in item.infoLabels and "episode" in item.infoLabels:
|
||||
# info_nfo = "https://www.themoviedb.org/tv/{}/season/{}/episode/{}" .format(item.infoLabels['tmdb_id'], item.contentSeason, item.contentEpisodeNumber)
|
||||
# else:
|
||||
|
||||
info_nfo = ', '.join(item.infoLabels['url_scraper'])
|
||||
|
||||
return info_nfo + '\n'
|
||||
@@ -586,7 +583,6 @@ def select_group(groups, item):
|
||||
return ''
|
||||
|
||||
def get_group(Id):
|
||||
# from core.support import dbg;dbg()
|
||||
url = '{}/tv/episode_group/{}?api_key={}&language={}'.format(host, Id, api, def_lang)
|
||||
group = requests.get(url).json().get('groups',[])
|
||||
return group
|
||||
@@ -627,7 +623,6 @@ def discovery(item, dict_=False, cast=False):
|
||||
|
||||
def get_dic_genres(search_type):
|
||||
lang = def_lang
|
||||
# from core.support import dbg;dbg()
|
||||
genres = Tmdb(search_type=search_type)
|
||||
|
||||
return genres.dic_genres[lang]
|
||||
@@ -891,7 +886,6 @@ class Tmdb(object):
|
||||
@staticmethod
|
||||
@cache_response
|
||||
def get_json(url, cache=True):
|
||||
# from core.support import dbg;dbg()
|
||||
try:
|
||||
result = httptools.downloadpage(url, cookies=False, ignore_response_code=True)
|
||||
|
||||
@@ -948,14 +942,12 @@ class Tmdb(object):
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
def __by_id(self, source='tmdb'):
|
||||
# from core.support import dbg;dbg()
|
||||
|
||||
if self.search_id:
|
||||
if source == "tmdb":
|
||||
url = ('{}/{}/{}?api_key={}&language={}&append_to_response=images,videos,external_ids,credits&include_image_language={},en,null'.format(host, self.search_type, self.search_id, api, self.search_language, self.search_language))
|
||||
searching = "id_Tmdb: {}".format(self.search_id)
|
||||
else:
|
||||
url = ('{}/find/{}?external_source={}&api_key={}8&language={}'.format(host, self.search_id, source, api, self.search_language))
|
||||
url = ('{}/find/{}?external_source={}&api_key={}&language={}'.format(host, self.search_id, source, api, self.search_language))
|
||||
searching = "{}: {}".format(source.capitalize(), self.search_id)
|
||||
|
||||
logger.debug("[Tmdb.py] Searching %s:\n%s" % (searching, url))
|
||||
@@ -999,7 +991,7 @@ class Tmdb(object):
|
||||
url = ('{}/search/{}?api_key={}&query={}&language={}&include_adult={}&page={}'.format(host, self.search_type, api, text_quote, self.search_language, True, page))
|
||||
|
||||
if self.search_year:
|
||||
if self.search_type == 'movie':
|
||||
if self.search_type in ['movie', 'multi']:
|
||||
url += '&primary_release_year=%s' % self.search_year
|
||||
else:
|
||||
url += '&first_air_date_year=%s' % self.search_year
|
||||
@@ -1220,7 +1212,6 @@ class Tmdb(object):
|
||||
:rtype: str
|
||||
"""
|
||||
ret = ""
|
||||
# from core.support import dbg;dbg()
|
||||
|
||||
if 'id' in self.result:
|
||||
ret = self.result.get('overview')
|
||||
@@ -1366,7 +1357,6 @@ class Tmdb(object):
|
||||
|
||||
searching = "id_Tmdb: " + str(self.result["id"]) + " season: " + str(seasonNumber) + "\nURL: " + url
|
||||
logger.debug("[Tmdb.py] Searching " + searching)
|
||||
# from core.support import dbg;dbg()
|
||||
try:
|
||||
self.season[seasonNumber] = self.get_json(url)
|
||||
if not isinstance(self.season[seasonNumber], dict):
|
||||
@@ -1482,7 +1472,6 @@ class Tmdb(object):
|
||||
|
||||
|
||||
# Obtain chapter data if applicable
|
||||
# from core.support import dbg;dbg()
|
||||
ret_dic = {}
|
||||
if chapter > 0:
|
||||
# episode = season["episodes"][chapter - 1]
|
||||
@@ -1653,7 +1642,6 @@ class Tmdb(object):
|
||||
continue
|
||||
|
||||
if k == 'media_type':
|
||||
# from core.support import dbg;dbg()
|
||||
ret_infoLabels['mediatype'] = v if v in ['tv', 'tvshow'] else 'movie'
|
||||
|
||||
elif k == 'overview':
|
||||
@@ -1745,7 +1733,6 @@ class Tmdb(object):
|
||||
ret_infoLabels[k] = v
|
||||
|
||||
elif k == 'production_countries' or k == 'origin_country':
|
||||
# support.dbg()
|
||||
if isinstance(v, str):
|
||||
l_country = list(set(l_country + v.split(',')))
|
||||
|
||||
@@ -1762,7 +1749,6 @@ class Tmdb(object):
|
||||
elif k == 'credits_crew' or k == 'episode_crew' or k == 'season_crew':
|
||||
for crew in v:
|
||||
if crew['job'].lower() == 'director':
|
||||
# from core.support import dbg;dbg()
|
||||
l_director = list(set(l_director + [crew['name']]))
|
||||
l_director_image += ['https://image.tmdb.org/t/p/original' + crew['profile_path'] if crew['profile_path'] else '']
|
||||
l_director_id += [crew['id']]
|
||||
|
||||
+109
-39
@@ -12,13 +12,15 @@ import sys
|
||||
if sys.version_info[0] >= 3: from concurrent import futures
|
||||
else: from concurrent_py2 import futures
|
||||
|
||||
client_id = "502bd1660b833c1ae69828163c0848e84e9850061e5529f30930e7356cae73b1"
|
||||
client_secret = "1d30d5b24acf223a5e1ab6c61d08b69992d98ed5b0c7e26b052b5e6a592035a4"
|
||||
host = 'https://api.trakt.tv'
|
||||
client_id = '502bd1660b833c1ae69828163c0848e84e9850061e5529f30930e7356cae73b1'
|
||||
client_secret = '1d30d5b24acf223a5e1ab6c61d08b69992d98ed5b0c7e26b052b5e6a592035a4'
|
||||
token_auth = config.get_setting("token_trakt", "trakt")
|
||||
|
||||
|
||||
def auth_trakt():
|
||||
item = Item()
|
||||
folder = (config.get_platform() == "plex")
|
||||
folder = (config.get_platform() == 'plex')
|
||||
item.folder = folder
|
||||
# Autentificación de cuenta Trakt
|
||||
headers = {'Content-Type': 'application/json', 'trakt-api-key': client_id, 'trakt-api-version': '2'}
|
||||
@@ -26,24 +28,23 @@ def auth_trakt():
|
||||
post = {'client_id': client_id}
|
||||
post = jsontools.dump(post)
|
||||
# Se solicita url y código de verificación para conceder permiso a la app
|
||||
url = "http://api.trakt.tv/oauth/device/code"
|
||||
data = httptools.downloadpage(url, post=post, headers=headers).data
|
||||
data = jsontools.load(data)
|
||||
item.verify_url = data["verification_url"]
|
||||
item.user_code = data["user_code"]
|
||||
item.device_code = data["device_code"]
|
||||
item.intervalo = data["interval"]
|
||||
url = host + '/oauth/device/code'
|
||||
data = httptools.downloadpage(url, post=post, headers=headers).json
|
||||
item.verify_url = data['verification_url']
|
||||
item.user_code = data['user_code']
|
||||
item.device_code = data['device_code']
|
||||
item.intervalo = data['interval']
|
||||
if not item.folder:
|
||||
token_trakt(item)
|
||||
|
||||
else:
|
||||
itemlist = []
|
||||
title = config.get_localized_string(60248) % item.verify_url
|
||||
itemlist.append(item.clone(title=title, action=""))
|
||||
itemlist.append(item.clone(title=title, action=''))
|
||||
title = config.get_localized_string(60249) % item.user_code
|
||||
itemlist.append(item.clone(title=title, action=""))
|
||||
itemlist.append(item.clone(title=title, action=''))
|
||||
title = config.get_localized_string(60250)
|
||||
itemlist.append(item.clone(title=title, action="token_trakt"))
|
||||
itemlist.append(item.clone(title=title, action='token_trakt'))
|
||||
return itemlist
|
||||
except:
|
||||
import traceback
|
||||
@@ -55,17 +56,17 @@ def token_trakt(item):
|
||||
|
||||
headers = {'Content-Type': 'application/json', 'trakt-api-key': client_id, 'trakt-api-version': '2'}
|
||||
try:
|
||||
if item.extra == "renew":
|
||||
refresh = config.get_setting("refresh_token_trakt", "trakt")
|
||||
url = "http://api.trakt.tv/oauth/device/token"
|
||||
if item.extra == 'renew':
|
||||
refresh = config.get_setting('refresh_token_trakt', 'trakt')
|
||||
url = host + '/oauth/device/token'
|
||||
post = {'refresh_token': refresh, 'client_id': client_id, 'client_secret': client_secret,
|
||||
'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token'}
|
||||
post = jsontools.dump(post)
|
||||
data = httptools.downloadpage(url, post=post, headers=headers).data
|
||||
data = jsontools.load(data)
|
||||
elif item.action == "token_trakt":
|
||||
url = "http://api.trakt.tv/oauth/device/token"
|
||||
post = "code=%s&client_id=%s&client_secret=%s" % (item.device_code, client_id, client_secret)
|
||||
elif item.action == 'token_trakt':
|
||||
url = host + '/oauth/device/token'
|
||||
post = 'code={}&client_id={}&client_secret={}'.format(item.device_code, client_id, client_secret)
|
||||
data = httptools.downloadpage(url, post=post, headers=headers).data
|
||||
data = jsontools.load(data)
|
||||
else:
|
||||
@@ -80,15 +81,15 @@ def token_trakt(item):
|
||||
time.sleep(item.intervalo)
|
||||
try:
|
||||
if dialog_auth.iscanceled():
|
||||
config.set_setting("trakt_sync", False)
|
||||
config.set_setting('trakt_sync', False)
|
||||
return
|
||||
|
||||
url = "http://api.trakt.tv/oauth/device/token"
|
||||
url = host + '/oauth/device/token'
|
||||
post = {'code': item.device_code, 'client_id': client_id, 'client_secret': client_secret}
|
||||
post = jsontools.dump(post)
|
||||
data = httptools.downloadpage(url, post=post, headers=headers).data
|
||||
data = jsontools.load(data)
|
||||
if "access_token" in data:
|
||||
if 'access_token' in data:
|
||||
# Código introducido, salimos del bucle
|
||||
break
|
||||
except:
|
||||
@@ -99,16 +100,16 @@ def token_trakt(item):
|
||||
except:
|
||||
pass
|
||||
|
||||
token = data["access_token"]
|
||||
refresh = data["refresh_token"]
|
||||
token = data['access_token']
|
||||
refresh = data['refresh_token']
|
||||
|
||||
config.set_setting("token_trakt", token, "trakt")
|
||||
config.set_setting("refresh_token_trakt", refresh, "trakt")
|
||||
config.set_setting('token_trakt', token, 'trakt')
|
||||
config.set_setting('refresh_token_trakt', refresh, 'trakt')
|
||||
if not item.folder:
|
||||
platformtools.dialog_notification(config.get_localized_string(60255), config.get_localized_string(60256))
|
||||
if config.is_xbmc():
|
||||
import xbmc
|
||||
xbmc.executebuiltin("Container.Refresh")
|
||||
xbmc.executebuiltin('Container.Refresh')
|
||||
return
|
||||
|
||||
except:
|
||||
@@ -116,13 +117,13 @@ def token_trakt(item):
|
||||
logger.error(traceback.format_exc())
|
||||
if not item.folder:
|
||||
return platformtools.dialog_notification(config.get_localized_string(60527), config.get_localized_string(60258))
|
||||
token = ""
|
||||
token = ''
|
||||
|
||||
itemlist = []
|
||||
if token:
|
||||
itemlist.append(item.clone(title=config.get_localized_string(60256), action=""))
|
||||
itemlist.append(item.clone(title=config.get_localized_string(60256), action=''))
|
||||
else:
|
||||
itemlist.append(item.clone(title=config.get_localized_string(60260), action=""))
|
||||
itemlist.append(item.clone(title=config.get_localized_string(60260), action=''))
|
||||
|
||||
return itemlist
|
||||
|
||||
@@ -138,34 +139,35 @@ def set_trakt_info(item):
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def get_trakt_watched(id_type, mediatype, update=False):
|
||||
logger.debug()
|
||||
|
||||
id_list = []
|
||||
id_dict = dict()
|
||||
|
||||
token_auth = config.get_setting("token_trakt", "trakt")
|
||||
token_auth = config.get_setting('token_trakt', 'trakt')
|
||||
|
||||
if token_auth:
|
||||
sync_path = os.path.join(config.get_data_path(), 'settings_channels', 'trakt')
|
||||
|
||||
if os.path.exists(sync_path) and not update:
|
||||
trakt_node = jsontools.get_node_from_file('trakt', "TRAKT")
|
||||
trakt_node = jsontools.get_node_from_file('trakt', 'TRAKT')
|
||||
if mediatype == 'shows':
|
||||
return trakt_node['shows']
|
||||
if mediatype == 'movies':
|
||||
return trakt_node['movies']
|
||||
|
||||
else:
|
||||
token_auth = config.get_setting("token_trakt", "trakt")
|
||||
token_auth = config.get_setting('token_trakt', 'trakt')
|
||||
if token_auth:
|
||||
try:
|
||||
token_auth = config.get_setting("token_trakt", "trakt")
|
||||
token_auth = config.get_setting('token_trakt', 'trakt')
|
||||
headers = [['Content-Type', 'application/json'], ['trakt-api-key', client_id],
|
||||
['trakt-api-version', '2']]
|
||||
if token_auth:
|
||||
headers.append(['Authorization', "Bearer %s" % token_auth])
|
||||
url = "https://api.trakt.tv/sync/watched/%s" % mediatype
|
||||
headers.append(['Authorization', 'Bearer ' + token_auth])
|
||||
url = host + '/sync/watched/' + mediatype
|
||||
data = httptools.downloadpage(url, headers=headers).data
|
||||
watched_dict = jsontools.load(data)
|
||||
|
||||
@@ -233,7 +235,7 @@ def get_sync_from_file():
|
||||
sync_path = os.path.join(config.get_data_path(), 'settings_channels', 'trakt_data.json')
|
||||
trakt_node = {}
|
||||
if os.path.exists(sync_path):
|
||||
trakt_node = jsontools.get_node_from_file('trakt', "TRAKT")
|
||||
trakt_node = jsontools.get_node_from_file('trakt', 'TRAKT')
|
||||
|
||||
trakt_node['movies'] = get_trakt_watched('tmdb', 'movies')
|
||||
trakt_node['shows'] = get_trakt_watched('tmdb', 'shows')
|
||||
@@ -245,7 +247,7 @@ def update_trakt_data(mediatype, trakt_data):
|
||||
|
||||
sync_path = os.path.join(config.get_data_path(), 'settings_channels', 'trakt_data.json')
|
||||
if os.path.exists(sync_path):
|
||||
trakt_node = jsontools.get_node_from_file('trakt', "TRAKT")
|
||||
trakt_node = jsontools.get_node_from_file('trakt', 'TRAKT')
|
||||
trakt_node[mediatype] = trakt_data
|
||||
jsontools.update_node(trakt_node, 'trakt', 'TRAKT')
|
||||
|
||||
@@ -257,7 +259,7 @@ def ask_install_script():
|
||||
|
||||
respuesta = platformtools.dialog_yesno(config.get_localized_string(20000), config.get_localized_string(70521))
|
||||
if respuesta:
|
||||
xbmc.executebuiltin("InstallAddon(script.trakt)")
|
||||
xbmc.executebuiltin('InstallAddon(script.trakt)')
|
||||
return
|
||||
else:
|
||||
config.set_setting('install_trakt', False)
|
||||
@@ -283,3 +285,71 @@ def update_all():
|
||||
trakt_data = get_trakt_watched('tmdb', mediatype, True)
|
||||
update_trakt_data(mediatype, trakt_data)
|
||||
|
||||
|
||||
def context(item):
|
||||
Type = item.contentType.replace("tv", "") + "s"
|
||||
item.action = 'traktResults'
|
||||
title = config.get_localized_string(30122 if item.contentType == 'movie' else 30123)
|
||||
context = []
|
||||
commands = []
|
||||
condition = "'tmdb': " + item.infoLabels["tmdb_id"]
|
||||
try:
|
||||
result = execute(item.clone(url="/sync/watched/" + Type))
|
||||
post = {Type: [{"ids": {"tmdb": item.infoLabels["tmdb_id"]}}]}
|
||||
if condition in str(result):
|
||||
context.append(config.get_localized_string(60016 if item.contentType == 'movie' else 60020))
|
||||
commands.append(item.clone(url="/sync/history/remove", post=post))
|
||||
else:
|
||||
context.append(config.get_localized_string(60017 if item.contentType == 'movie' else 60021))
|
||||
commands.append(item.clone(url="/sync/history", post=post))
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
from core.support import dbg;dbg()
|
||||
result = execute(item.clone(url="/sync/watchlist/" + Type))
|
||||
post = {Type: [{"ids": {"tmdb": item.infoLabels["tmdb_id"]}}]}
|
||||
if condition in str(result):
|
||||
context.append(config.get_localized_string(70343) % title)
|
||||
commands.append(item.clone(url="/sync/watchlist/remove", post=post))
|
||||
else:
|
||||
context.append(config.get_localized_string(70344) % title)
|
||||
commands.append(item.clone(url="/sync/watchlist", post=post))
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
result = execute(item.clone(url="/sync/collection/" + Type))
|
||||
post = {Type: [{"ids": {"tmdb": item.infoLabels["tmdb_id"]}}]}
|
||||
if condition in str(result):
|
||||
context.append(config.get_localized_string(70345) % title)
|
||||
commands.append(item.clone(url="/sync/collection/remove", post=post))
|
||||
else:
|
||||
context.append(config.get_localized_string(70346) % title)
|
||||
commands.append(item.clone(url="/sync/collection", post=post))
|
||||
except:
|
||||
pass
|
||||
|
||||
if context:
|
||||
import xbmcgui
|
||||
index = xbmcgui.Dialog().contextmenu(context)
|
||||
if index > -1:
|
||||
execute(commands[index])
|
||||
|
||||
def execute(item):
|
||||
from platformcode.platformtools import dialog_notification
|
||||
url = host + item.url
|
||||
|
||||
headers = [['Content-Type', 'application/json'], ['trakt-api-key', client_id], ['trakt-api-version', '2']]
|
||||
if token_auth: headers.append(['Authorization', 'Bearer {}'.format(token_auth)])
|
||||
|
||||
post = None
|
||||
if item.post: post = jsontools.dump(item.post)
|
||||
|
||||
data = httptools.downloadpage(url, post=post, headers=headers).json
|
||||
|
||||
if not post:
|
||||
return data
|
||||
else:
|
||||
if 'not_found' in data: return dialog_notification('Trakt', config.get_localized_string(70347))
|
||||
else: return dialog_notification('Trakt', config.get_localized_string(70348))
|
||||
Reference in New Issue
Block a user