aggiornamento ricerca alternativa
This commit is contained in:
+327
-106
@@ -1,13 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from platformcode.platformtools import calcResolution
|
||||
from core.item import Item
|
||||
from typing import OrderedDict
|
||||
from core.item import InfoLabels, Item
|
||||
import re
|
||||
from core import filetools, jsontools, trakt_tools
|
||||
from core import support, tmdb
|
||||
from core.tmdb import Tmdb
|
||||
from core.scrapertools import htmlclean, decodeHtmlentities
|
||||
from core.support import nextPage, thumb, typo, match, dbg
|
||||
from core import httptools, trakt_tools, tmdb, support, jsontools
|
||||
from platformcode import config, logger, platformtools
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
langs = Item(tmdb=[tmdb.def_lang, 'de', 'fr', 'pt', 'it', 'es-MX', 'ca', 'en', 'es'],
|
||||
@@ -16,7 +13,7 @@ lang = Item(tmdb=langs.tmdb[config.get_setting('tmdb', 'tvmoviedb')],
|
||||
tmdbfallback= langs.tmdb[config.get_setting('tmdbfallback', 'tvmoviedb')],
|
||||
imdb=langs.imdb[config.get_setting('imdb', 'tvmoviedb')])
|
||||
|
||||
|
||||
imdb_host = 'http://www.imdb.com'
|
||||
mal_adult = config.get_setting('adult_mal', 'tvmoviedb')
|
||||
mal_key = 'MzE1MDQ2cGQ5N2llYTY4Z2xwbGVzZjFzbTY='
|
||||
# fanart = filetools.join(config.get_runtime_path(), re 'fanart.jpg')
|
||||
@@ -26,17 +23,31 @@ def mainlist(item):
|
||||
logger.debug()
|
||||
itemlist = [item.clone(title='TMDB', action='tmdbMenu', thumbnail=support.thumb('tmdb')),
|
||||
item.clone(title='IMDB', action='imdbMenu', thumbnail=support.thumb('imdb'))]
|
||||
itemlist += [item.clone(title=config.get_localized_string(70415), action='trakt', thumbnail=support.thumb('trakt')),
|
||||
itemlist += [item.clone(title=config.get_localized_string(70415), action='traktMenu', thumbnail=support.thumb('trakt')),
|
||||
item.clone(title=config.get_localized_string(70026), action='mal', thumbnail=support.thumb('mal')),
|
||||
item.clone(title=typo(config.get_localized_string(70027), 'bold'), action='configuracion', folder=False, thumbnail=support.thumb('setting'))]
|
||||
item.clone(title=support.typo(config.get_localized_string(70027), 'bold'), action='configuracion', folder=False, thumbnail=support.thumb('setting'))]
|
||||
return itemlist
|
||||
|
||||
|
||||
def _search(item):
|
||||
text = platformtools.dialog_input(heading=item.title)
|
||||
if text:
|
||||
if item.search:
|
||||
item.search['query'] = text
|
||||
return tmdbResults(item)
|
||||
else:
|
||||
item.url = item.url.format(text)
|
||||
return imdbResults(item)
|
||||
|
||||
########## TMDB ##########
|
||||
|
||||
def tmdbMenu(item):
|
||||
if not item.args:
|
||||
return thumb([item.clone(title=config.get_localized_string(70741) % config.get_localized_string(30122), args='movie'),
|
||||
item.clone(title=config.get_localized_string(70741) % config.get_localized_string(30123), args='tv')])
|
||||
return support.thumb([item.clone(title=config.get_localized_string(30122), args='movie'),
|
||||
item.clone(title=config.get_localized_string(30123), args='tv'),
|
||||
item.clone(title=config.get_localized_string(70033), action='tmdbResults', args='person/popular'),
|
||||
item.clone(title=config.get_localized_string(70036), action='_search', search={'url': 'search/person', 'language': lang.tmdb, 'page': 1}),
|
||||
item.clone(title=config.get_localized_string(70037), action='_search', search={'url': 'search/person', 'language': lang.tmdb, 'page': 1}, crew=True)])
|
||||
|
||||
item.contentType = item.args.replace('tv', 'tvshow')
|
||||
|
||||
@@ -46,20 +57,12 @@ def tmdbMenu(item):
|
||||
item.clone(title=config.get_localized_string(70032), action='tmdbIndex', mode='genre'),
|
||||
item.clone(title=config.get_localized_string(70042), action='tmdbIndex', mode='year')]
|
||||
|
||||
if item.args == 'movie':
|
||||
itemlist.extend([item.clone(title=config.get_localized_string(70033), action='tmdbResults', args='person/popular'),
|
||||
item.clone(title=config.get_localized_string(70034), action='tmdbResults', args=item.args + '/upcoming')])
|
||||
|
||||
|
||||
itemlist.extend([item.clone(title=config.get_localized_string(70035) % config.get_localized_string(60244 if item.args == 'movie' else 60245).lower(), action='_search', search={'url': 'search/%s' % item.args, 'language': lang.tmdb, 'page': 1}),
|
||||
item.clone(title=config.get_localized_string(70036), action='_search', search={'url': 'search/person', 'language': lang.tmdb, 'page': 1})])
|
||||
item.clone(title=support.typo(config.get_localized_string(70038),'bold'), action='filter', db_type='tmdb' )])
|
||||
|
||||
if item.args == 'movie': itemlist.append(item.clone(title=config.get_localized_string(70037), action='_search', search={'url': 'search/person', 'language': lang.tmdb, 'page': 1}, crew=True))
|
||||
|
||||
itemlist.extend([item.clone(title=typo(config.get_localized_string(70038),'bold'), action='filter', ),
|
||||
item.clone(title=typo(config.get_localized_string(70039),'bold'), action='filter', )])
|
||||
|
||||
return thumb(itemlist)
|
||||
return support.thumb(itemlist)
|
||||
|
||||
|
||||
def tmdbResults(item):
|
||||
@@ -80,126 +83,344 @@ def tmdbResults(item):
|
||||
itemlist.append(it)
|
||||
|
||||
if item.page < obj.total_pages:
|
||||
support.nextPage(itemlist, item, 'peliculas', page=item.page + 1, total_pages=obj.total_pages)
|
||||
support.nextPage(itemlist, item, 'tmdbResults', page=item.page + 1, total_pages=obj.total_pages)
|
||||
return itemlist
|
||||
|
||||
|
||||
def tmdbIndex(item):
|
||||
itemlist = []
|
||||
from datetime import datetime
|
||||
|
||||
if item.mode == 'genre':
|
||||
url = '{}/{}/list?api_key={}&language={}'.format(tmdb.host, item.mode, tmdb.api, lang.tmdb)
|
||||
genres = match(url, cookies=False).response.json['genres']
|
||||
genres = support.match(url, cookies=False).response.json['genres']
|
||||
|
||||
date = datetime.now().strftime('%Y-%m-%d')
|
||||
sort_by = 'release_date.desc'
|
||||
param_year = 'release_date.lte'
|
||||
if item.contentType == 'tvshow':
|
||||
sort_by = 'first_air_date.desc'
|
||||
param_year = 'air_date.lte'
|
||||
sort_by = 'first_air_date.desc' if item.contentType == 'tvshow' else 'release_date.desc'
|
||||
param_year = 'air_date.lte' if item.contentType == 'tvshow' else 'release_date.lte'
|
||||
for genre in genres:
|
||||
search = {'url': 'discover/{}'.format(item.args), 'with_genres': genre['id'], 'sort_by': sort_by, param_year: date,'language': lang.tmdb, 'page': 1}
|
||||
new_item = item.clone(title=genre['name'], action='tmdbResults', search=search, mode='')
|
||||
itemlist.append(new_item)
|
||||
|
||||
itemlist.sort(key=lambda item: item.title)
|
||||
thumb(itemlist, mode='genre')
|
||||
support.thumb(itemlist, mode='genre')
|
||||
else:
|
||||
year = datetime.now().year + 3
|
||||
for i in range(year, 1899, -1):
|
||||
if item.contentType == 'tvshow':
|
||||
param_year = 'first_air_date_year'
|
||||
else:
|
||||
param_year = 'primary_release_year'
|
||||
param_year = 'first_air_date_year' if item.contentType == 'tvshow' else 'primary_release_year'
|
||||
search = {'url': 'discover/{}'.format(item.args), param_year: i, 'language': lang.tmdb, 'page': 1}
|
||||
itemlist.append(item.clone(title=str(i), action='tmdbResults', search=search))
|
||||
|
||||
return itemlist
|
||||
|
||||
def _search(item):
|
||||
text = platformtools.dialog_input(heading=item.title)
|
||||
if text:
|
||||
item.search['query'] = text
|
||||
return tmdbResults(item)
|
||||
|
||||
########## IMDB ##########
|
||||
|
||||
def imdbMenu(item):
|
||||
itemlist = []
|
||||
if not item.args:
|
||||
itemlist.extend([item.clone(title=config.get_localized_string(30122), args='movie'),
|
||||
item.clone(title=config.get_localized_string(30123), args='tvshow'),
|
||||
item.clone(title=config.get_localized_string(70033), action='imdbResults', args=['actors']),
|
||||
item.clone(title=config.get_localized_string(70036), action='_search', url='/search/name?name={}', args=['actors']),
|
||||
item.clone(title=config.get_localized_string(30980), action='_search', url= '/search/title?title={}')])
|
||||
else:
|
||||
item.contentType = item.args
|
||||
|
||||
itemlist.append(item.clone(title=config.get_localized_string(70028), action='imdbResults', args=[item.contentType]))
|
||||
itemlist.append(item.clone(title=config.get_localized_string(70029), action='imdbResults', args=[item.contentType,'top']))
|
||||
if item.contentType == 'movie':
|
||||
itemlist.extend([item.clone(title=config.get_localized_string(70030), action='imdbResults', args=['cinema']),
|
||||
item.clone(title=config.get_localized_string(70034), action='imdbResults', args=['soon'])])
|
||||
|
||||
itemlist.extend([item.clone(title=config.get_localized_string(70032), action='imdbIndex', args='genre'),
|
||||
item.clone(title=config.get_localized_string(70042), action='imdbIndex', args='year'),
|
||||
item.clone(title=support.typo(config.get_localized_string(70038),'color kod'), action='filter', db_type='imdb')])
|
||||
|
||||
return support.thumb(itemlist)
|
||||
|
||||
|
||||
def imdbResults(item):
|
||||
itemlist = []
|
||||
|
||||
params = {'movie':'/search/title?&title_type=feature,tv_movie',
|
||||
'tvshow':'/search/title?&title_type=tv_series,tv_special,mini_series',
|
||||
'top':'&num_votes=25000,&sort=user_rating,desc',
|
||||
'cinema':'/showtimes/location?ref_=inth_ov_sh_sm',
|
||||
'actors': '/search/name?gender=male,female&ref_=nv_cel_m_3',
|
||||
'soon': '/movies-coming-soon/?ref_=shlc_cs'}
|
||||
|
||||
if item.search: item.url = imdb_host + params[item.contentType] + '&' + support.urlencode(item.search)
|
||||
elif not item.url: item.url = imdb_host + ''.join(params[a] for a in item.args)
|
||||
else: item.url = imdb_host + item.url
|
||||
if item.prevthumb: item.thumbnail = item.prevthumb
|
||||
if 'actors' in item.args:
|
||||
data = support.match(item.url, patron=r'nm\d+[^>]*>\s*<img alt="([^"]+)" height="\d+" src="([^"]+)')
|
||||
for title, thumb in data.matches:
|
||||
item.thumbnail = thumb.split('._V1_')[0] + '._V1_UX482.jpg' if thumb else thumb
|
||||
itemlist.append(item.clone(title=title, action='showCast', channel='infoplus', text=title, folder=False))
|
||||
else:
|
||||
data = support.match(item.url, patron=r'"(?:image|lister-item-image)[^>]+>\s*<a href="/[^/]+/(tt\d+)/[^>]+>.*?<img.*?alt="([^"]+)" (?:class|title)="[^"]+" (?:loadlate|src)="([^"]+)', debug=True)
|
||||
|
||||
for imdb_id, title, thumb in data.matches:
|
||||
item.infoLabels['imdb_id'] = imdb_id
|
||||
item.thumbnail = thumb.split('@')[0] + '@._UX482.jpg' if thumb else thumb
|
||||
itemlist.append(item.clone(title=title.split('(')[0], action='start', channel='infoplus', folder=False))
|
||||
tmdb.set_infoLabels_itemlist(itemlist, seekTmdb=True)
|
||||
support.nextPage(itemlist, item, data=data.data, patron=r'<a href="([^"]+)"[^>]*>Next')
|
||||
return itemlist
|
||||
|
||||
|
||||
def imdbIndex(item):
|
||||
itemlist = []
|
||||
params = {'movie':'&title_type=feature,tv_movie',
|
||||
'tvshow':'&title_type=tv_series,tv_special,mini_series',}
|
||||
item.action = 'imdbResults'
|
||||
url = '/search/title'
|
||||
if item.args == 'genre':
|
||||
matches = support.match(imdb_host + url, patronBlock=r'<h3>Genres</h3>(.*?)</table>', patron=r' value="([^"]+)"\s*>\s*<label.*?>([^<]+)<').matches
|
||||
if matches:
|
||||
itemlist = [item.clone(title=title, url='{}?genres={}{}'.format(url, value, params[item.contentType]))for value, title in matches]
|
||||
support.thumb(itemlist, mode='genre')
|
||||
elif item.args == 'year':
|
||||
year = datetime.now().year + 3
|
||||
for i in range(year, 1899, -1):
|
||||
itemlist.append(item.clone(title=str(i), url='{}?release_date={}{}'.format(url, i, params[item.contentType])))
|
||||
return itemlist
|
||||
|
||||
|
||||
########## TRAKT ##########
|
||||
|
||||
def traktMenu(item):
|
||||
itemlist = []
|
||||
token_auth = config.get_setting("token_trakt", "trakt")
|
||||
if not item.args:
|
||||
itemlist.extend([item.clone(title=config.get_localized_string(30122), args='movies'),
|
||||
item.clone(title=config.get_localized_string(30123), args='shows')])
|
||||
if token_auth: itemlist.append(item.clone(title=support.typo(config.get_localized_string(70057), 'bold'), action="traktResults", url="/users/me/lists"))
|
||||
else: itemlist.append(item.clone(title=support.typo(config.get_localized_string(70054), 'bold'), action="traktAuth", folder=False))
|
||||
else:
|
||||
item.contentType = item.args.replace('shows', 'tvshow').replace('movies', 'movie')
|
||||
item.title = config.get_localized_string(30122 if item.contentType == 'movie' else 30123)
|
||||
itemlist.extend([item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70049)), action='traktResults', url= item.args + '/popular'),
|
||||
item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70050)), action='traktResults', url= item.args + '/trending'),
|
||||
item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70053)), action='traktResults', url= item.args + '/watched/all'),
|
||||
item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70051)), action='traktResults', url= item.args + '/anticipated')])
|
||||
if token_auth:
|
||||
itemlist.extend([item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70052)), action='traktResults', url='/recommendations/' + item.args),
|
||||
item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70055)), action='traktResults', url='/users/me/watchlist/' + item.args),
|
||||
item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70056)), action='traktResults', url='/users/me/watched/' + item.args),
|
||||
item.clone(title='{} [{}]'.format(item.title, config.get_localized_string(70068)), action='traktResults', url='/users/me/collection/' + item.args)])
|
||||
return itemlist
|
||||
|
||||
|
||||
def traktResults(item):
|
||||
prepage = config.get_setting('pagination', default=20)
|
||||
if not item.page: item.page = 1
|
||||
if item.itemlist:
|
||||
itemlist = support.pagination(support.itemlistdb(), item, 'traktResults')
|
||||
tmdb.set_infoLabels_itemlist(itemlist, True)
|
||||
return itemlist
|
||||
|
||||
if item.prevthumb: item.thumbnail = item.prevthumb
|
||||
token_auth = config.get_setting('token_trakt', 'trakt')
|
||||
itemlist = []
|
||||
client_id = trakt_tools.client_id
|
||||
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)
|
||||
|
||||
url = '{}{}?page={}&limit=20&extended=full'.format(trakt_tools.host, item.url, item.page)
|
||||
|
||||
data = httptools.downloadpage(url, post=post, headers=headers)
|
||||
if data.code == '401':
|
||||
trakt_tools.token_trakt(item.clone(args='renew'))
|
||||
token_auth = config.get_setting('token_trakt', 'trakt')
|
||||
headers[3][1] = 'Bearer {}'.format(token_auth)
|
||||
data = httptools.downloadpage(url, post=post, headers=headers)
|
||||
|
||||
|
||||
data = data.json
|
||||
|
||||
if data and 'recommendations' in item.url:
|
||||
ratings = []
|
||||
|
||||
for i, entry in enumerate(data):
|
||||
new_item = item.clone(action='start',
|
||||
channel='infoplus',
|
||||
folder=False,
|
||||
title = entry['title'])
|
||||
new_item.infoLabels['tmdb_id'] = entry['ids']['tmdb']
|
||||
try: ratings.append(entry['rating'])
|
||||
except: ratings.append(0.0)
|
||||
itemlist.append(new_item)
|
||||
|
||||
|
||||
tmdb.set_infoLabels_itemlist(itemlist, True)
|
||||
for i, new_item in enumerate(itemlist):
|
||||
if new_item.infoLabels['title']: new_item.title = new_item.infoLabels['title']
|
||||
if len(itemlist) == prepage:
|
||||
support.nextPage(itemlist, item, 'traktResults', page=item.page + 1)
|
||||
|
||||
|
||||
elif data and not item.url.endswith('lists'):
|
||||
ratings = []
|
||||
try:
|
||||
for entry in data:
|
||||
logger.debug(jsontools.dump(entry))
|
||||
new_item = item.clone(action='start', channel='infoplus', folder=False)
|
||||
if 'show' in entry:
|
||||
entry = entry['show']
|
||||
new_item.contentType = 'tvshow'
|
||||
elif 'movie' in entry:
|
||||
entry = entry['movie']
|
||||
new_item.contentType = 'movie'
|
||||
|
||||
new_item.title = entry['title']
|
||||
new_item.infoLabels['tmdb_id'] = entry['ids']['tmdb']
|
||||
try: ratings.append(entry['rating'])
|
||||
except: ratings.append('')
|
||||
itemlist.append(new_item)
|
||||
|
||||
if len(itemlist) > prepage:
|
||||
itemlist= support.pagination(itemlist, item, 'traktResults')
|
||||
elif len(itemlist) == prepage:
|
||||
support.nextPage(itemlist, item, 'traktResults', page=item.page + 1, total_pages=item.total_pages)
|
||||
|
||||
tmdb.set_infoLabels_itemlist(itemlist, True)
|
||||
for i, new_item in enumerate(itemlist):
|
||||
if new_item.infoLabels['title']: new_item.title = new_item.infoLabels['title']
|
||||
new_item.infoLabels['trakt_rating'] = ratings[i]
|
||||
|
||||
|
||||
except:
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
else:
|
||||
for entry in data:
|
||||
new_item = item.clone()
|
||||
new_item.title = entry['name'] + support.typo(str(entry['item_count']),'color kod _ []')
|
||||
new_item.infoLabels['plot'] = entry.get('description')
|
||||
new_item.url = 'users/me/lists/{}/items/'.format(entry['ids']['trakt'])
|
||||
new_item.order = entry.get('sort_by')
|
||||
new_item.how = entry.get('sort_how')
|
||||
new_item.total_pages = int(entry['item_count'] / prepage)
|
||||
itemlist.append(new_item)
|
||||
|
||||
return itemlist
|
||||
|
||||
|
||||
def traktAuth(item):
|
||||
return trakt_tools.auth_trakt()
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
|
||||
def filter(item):
|
||||
logger.debug()
|
||||
import xbmcgui
|
||||
orderTitle = [config.get_localized_string(70456), config.get_localized_string(70457), config.get_localized_string(70458), config.get_localized_string(70459), config.get_localized_string(70460), config.get_localized_string(70461), config.get_localized_string(70462), config.get_localized_string(70462)]
|
||||
tmdbOrder = ['popularity.desc', 'popularity.asc', 'release_date.desc', 'release_date.asc', 'vote_average.desc', 'vote_average.asc', 'title.asc', 'title.desc']
|
||||
imdbOrder = ['moviemeter,asc', 'moviemeter,desc', 'release_date,asc', 'release_date,desc', 'user_rating,asc', 'user_rating,desc', 'alpha,asc', 'alpha,desc']
|
||||
defControls = {'year':{'title': config.get_localized_string(60232), 'values': '', 'order':0},
|
||||
'genre':{'title': config.get_localized_string(70032), 'values': '', 'order':1},
|
||||
'rating':{'title': config.get_localized_string(70473), 'values': '', 'order':2},
|
||||
'order': {'title': config.get_localized_string(70455), 'values': orderTitle[0], 'order':3}}
|
||||
|
||||
from datetime import datetime
|
||||
list_controls = []
|
||||
valores = {}
|
||||
controls = dict(sorted(config.get_setting('controls', item.channel, default=defControls).items(), key=lambda k: k[1]['order']))
|
||||
class Filter(xbmcgui.WindowXMLDialog):
|
||||
def start(self, item):
|
||||
self.item = item
|
||||
self.controls = controls
|
||||
self.order = tmdbOrder if item.db_type == 'tmdb' else imdbOrder
|
||||
self.doModal()
|
||||
if self.controls and self.controls['order']['values'] == orderTitle[0]: self.controls['order']['values'] = self.order[0]
|
||||
return self.controls
|
||||
|
||||
dict_values = None
|
||||
def onInit(self):
|
||||
for n, v in enumerate(self.controls.values()):
|
||||
title = v['title']
|
||||
value = v['values']
|
||||
self.getControl(n + 100).setLabel('{}: {}'.format(title, value))
|
||||
|
||||
list_controls.append({'id': 'years', 'label': config.get_localized_string(60232), 'enabled': True, 'type': 'list', 'default': -1, 'visible': True})
|
||||
list_controls[0]['lvalues'] = []
|
||||
valores['years'] = []
|
||||
year = datetime.now().year + 1
|
||||
for i in range(1900, year + 1):
|
||||
list_controls[0]['lvalues'].append(str(i))
|
||||
valores['years'].append(str(i))
|
||||
list_controls[0]['lvalues'].append(config.get_localized_string(70450))
|
||||
valores['years'].append('')
|
||||
def onClick(self, control):
|
||||
logger.debug('CONTROL', control)
|
||||
if control in [100]: # Year
|
||||
years = [str(i) for i in range(datetime.now().year + 3, 1899, -1)]
|
||||
selection = platformtools.dialog_select('', years)
|
||||
self.controls['year']['values'] = years[selection] if selection > -1 else ''
|
||||
self.getControl(100).setLabel('{}: {}'.format(self.controls['year']['title'], self.controls['year']['values']))
|
||||
elif control in [101]: # Genre
|
||||
genresIds = []
|
||||
genresNames = []
|
||||
# support.dbg()
|
||||
if self.item.db_type == 'tmdb':
|
||||
url = ('{}/genre/{}/list?api_key={}&language={}'.format(tmdb.host, item.args, tmdb.api, langs.tmdb))
|
||||
genres = httptools.downloadpage(url).json['genres']
|
||||
for genre in genres:
|
||||
genresNames.append(genre['name'])
|
||||
genresIds.append(str(genre['id']))
|
||||
else:
|
||||
genres = support.match(imdb_host + '/search/title', patronBlock=r'<h3>Genres</h3>(.*?)</table>', patron=r' value="([^"]+)"\s*>\s*<label.*?>([^<]+)<').matches
|
||||
for value, genre in genres:
|
||||
genresNames.append(genre)
|
||||
genresIds.append(value)
|
||||
selected = [genresIds.index(i.strip()) for i in self.controls['genre']['values'].split(',') if i]
|
||||
selections = platformtools.dialog_multiselect('', genresNames, preselect=selected)
|
||||
self.controls['genre']['values'] = ','.join(genresIds[g] for g in selections)
|
||||
names= ', '.join(genresNames[g] for g in selections)
|
||||
self.getControl(101).setLabel('{}: {}'.format(self.controls['genre']['title'], names))
|
||||
elif control in [102]:
|
||||
rating = [str(i) for i in range(1, 11)]
|
||||
selection = platformtools.dialog_select('', rating, preselect=rating.index(self.controls['rating']['values']) if self.controls['rating']['values'] else 0)
|
||||
self.controls['rating']['values'] = rating[selection]
|
||||
self.getControl(102).setLabel('{}: {}'.format(self.controls['rating']['title'], self.controls['rating']['values']))
|
||||
elif control in [103]:
|
||||
selection = platformtools.dialog_select('', orderTitle)
|
||||
if selection > -1:
|
||||
self.controls['order']['values'] = self.order[selection]
|
||||
self.getControl(103).setLabel('{}: {}'.format(self.controls['order']['title'], orderTitle[selection]))
|
||||
|
||||
if config.get_localized_string(70038) in item.title:
|
||||
# Se utilizan los valores por defecto/guardados
|
||||
saved_values = config.get_setting("default_filter_" + item.args, item.channel)
|
||||
if saved_values:
|
||||
dict_values = saved_values
|
||||
# dbg()
|
||||
url = '{}/genre/{}/list?api_key={}&language={}'.format(tmdb.host, item.args, tmdb.api, lang.tmdb)
|
||||
# try:
|
||||
lista = support.match(url, cookies=False).response.json["genres"]
|
||||
if lista:
|
||||
list_controls.append({'id': 'labelgenre', 'enabled': True, 'type': 'label', 'default': None, 'label': config.get_localized_string(70451), 'visible': True})
|
||||
for l in lista:
|
||||
list_controls.append({'id': 'genre' + str(l["id"]), 'label': l["name"], 'enabled': True, 'type': 'bool', 'default': False, 'visible': True})
|
||||
# except:
|
||||
# pass
|
||||
elif control in [200]:
|
||||
self.close()
|
||||
|
||||
list_controls.append({'id': 'orden', 'label': config.get_localized_string(70455), 'enabled': True, 'type': 'list', 'default': -1, 'visible': True})
|
||||
orden = [config.get_localized_string(70456), config.get_localized_string(70457), config.get_localized_string(70458), config.get_localized_string(70459), config.get_localized_string(70460), config.get_localized_string(70461)]
|
||||
if item.args == "movie":
|
||||
orden.extend([config.get_localized_string(70462), config.get_localized_string(70463)])
|
||||
orden_tmdb = ['popularity.desc', 'popularity.asc', 'release_date.desc', 'release_date.asc', 'vote_average.desc', 'vote_average.asc', 'original_title.asc', 'original_title.desc']
|
||||
valores['orden'] = []
|
||||
list_controls[-1]['lvalues'] = []
|
||||
for i, tipo_orden in enumerate(orden):
|
||||
list_controls[-1]['lvalues'].insert(0, tipo_orden)
|
||||
valores['orden'].insert(0, orden_tmdb[i])
|
||||
elif control in [201]:
|
||||
config.set_setting('controls', self.controls, self.item.channel)
|
||||
platformtools.dialog_notification('TMDB', 'Filtro salvato', time=1000, sound=False)
|
||||
|
||||
list_controls.append({'id': 'espacio', 'label': '', 'enabled': False, 'type': 'label', 'default': None, 'visible': True})
|
||||
list_controls.append({'id': 'save', 'label': config.get_localized_string(70464), 'enabled': True, 'type': 'bool', 'default': False, 'visible': True})
|
||||
else:
|
||||
list_controls.append({'id': 'keyword', 'label': config.get_localized_string(70465), 'enabled': True, 'type': 'text', 'default': '', 'visible': True})
|
||||
elif control in [202]:
|
||||
config.set_setting('controls', defControls, self.item.channel)
|
||||
platformtools.dialog_notification('TMDB', 'Filtro eliminato', time=1000, sound=False)
|
||||
self.controls = None
|
||||
self.close()
|
||||
return filter(self.item)
|
||||
|
||||
item.valores = valores
|
||||
return platformtools.show_channel_settings(list_controls=list_controls, dict_values=dict_values, caption=config.get_localized_string(70320), item=item, callback='filtered')
|
||||
elif control in [203]:
|
||||
self.controls = None
|
||||
self.close()
|
||||
|
||||
def filtered(item, values):
|
||||
values_copy = values.copy()
|
||||
# Save the filter to be the one loaded by default
|
||||
if "save" in values and values["save"]:
|
||||
values_copy.pop("save")
|
||||
config.set_setting("default_filter_" + item.args, values_copy, item.channel)
|
||||
def onAction(self, action):
|
||||
action = action.getId()
|
||||
if action in [10,92]:
|
||||
self.controls = None
|
||||
self.close()
|
||||
|
||||
year = item.valores["years"][values["years"]]
|
||||
if config.get_localized_string(70038) in item.title:
|
||||
orden = item.valores["orden"][values["orden"]]
|
||||
if item.args == "tv": orden = orden.replace('release_date', 'first_air_date')
|
||||
|
||||
genre_ids = []
|
||||
for v in values:
|
||||
if "genre" in v:
|
||||
if values[v]: genre_ids.append(v.replace('genre', ''))
|
||||
genre_ids = ",".join(genre_ids)
|
||||
controls = Filter('Filter.xml', config.get_runtime_path()).start(item)
|
||||
if controls:
|
||||
item.search = {'url': 'discover/' + item.args, 'vote_count.gte': 10} if item.db_type == 'tmdb' else {}
|
||||
|
||||
if config.get_localized_string(70465).lower() in item.title.lower(): item.search = {'url': 'search/%s' % item.args, 'year': year, 'query': values["keyword"], 'language': lang.tmdb, 'page': 1}
|
||||
elif item.args == "movie": item.search = {'url': 'discover/%s' % item.args, 'sort_by': orden, 'primary_release_year': year, 'with_genres': genre_ids, 'vote_count.gte': '10', 'language': lang.tmdb, 'page': 1}
|
||||
else: item.search = {'url': 'discover/%s' % item.args, 'sort_by': orden, 'first_air_date_year': year, 'with_genres': genre_ids, 'vote_count.gte': '10', 'language': lang.tmdb, 'page': 1}
|
||||
params ={'year':{'tmdb':'first_air_date_year', 'imdb':'year'},
|
||||
'genre':{'tmdb':'with_genres', 'imdb':'genres'},
|
||||
'rating': {'tmdb':'vote_average.gte', 'imdb':'user_rating'},
|
||||
'order': {'tmdb':'sort_by', 'imdb':'sort'}}
|
||||
|
||||
item.action = "list_tmdb"
|
||||
return tmdbResults(item)
|
||||
for k, v in controls.items():
|
||||
k = params[k][item.db_type]
|
||||
v = v['values']
|
||||
if v:
|
||||
item.search[k] = v
|
||||
logger.debug(item.search)
|
||||
return tmdbResults(item) if item.db_type == tmdb else imdbResults(item)
|
||||
|
||||
+64
-99
@@ -58,16 +58,17 @@ def list_az(item):
|
||||
else:
|
||||
v = v['item'].infoLabels
|
||||
if 'director' in v:
|
||||
v = v.get('director').split(',')
|
||||
v = v.get('director','').split(',')
|
||||
else:
|
||||
v= v.get('writer').split(',')
|
||||
cast += [c[0].strip() for c in v]
|
||||
v= v.get('writer','').split(',')
|
||||
cast += [c[0].strip() for c in v if c]
|
||||
|
||||
az = [] #[c[0] for c in cast if c[0] not in az]
|
||||
az = []
|
||||
for c in cast:
|
||||
if c[0] not in az:
|
||||
az.append(c[0])
|
||||
return [item.clone(title=i, action=item.next_action) for i in az]#['A','B','C','D','I','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']]
|
||||
itemlist = [item.clone(title=i, action=item.next_action) for i in az]
|
||||
return sorted(itemlist, key=lambda it: it.title)
|
||||
|
||||
|
||||
def list_genres(item):
|
||||
@@ -81,11 +82,11 @@ def list_genres(item):
|
||||
itemlist = []
|
||||
for g in genres:
|
||||
g = g.strip()
|
||||
if g and g not in [it.genre for it in itemlist]:
|
||||
it = item.clone(title = g, action='list_{}s'.format(item.contentType), genre=g)
|
||||
if g and g not in [it.list_genre for it in itemlist]:
|
||||
it = item.clone(title = g, action='list_{}s'.format(item.contentType), list_genre=g)
|
||||
itemlist.append(it)
|
||||
|
||||
itemlist.sort(key=lambda it: it.genre)
|
||||
itemlist.sort(key=lambda it: it.list_genre)
|
||||
thumb(itemlist, True)
|
||||
return itemlist
|
||||
|
||||
@@ -116,11 +117,11 @@ def list_directors(item):
|
||||
itemlist = []
|
||||
for i, d in enumerate(directors):
|
||||
d = d.strip()
|
||||
if d and d[0][0] == item.title and d not in [it.director for it in itemlist]:
|
||||
it = item.clone(title = d, action='list_{}s'.format(item.contentType), director=d, thumbnail=director_images[i] if len(director_images) > i else '')
|
||||
if d and d[0][0] == item.title and d not in [it.list_director for it in itemlist]:
|
||||
it = item.clone(title = d, action='list_{}s'.format(item.contentType), list_director=d, thumbnail=director_images[i] if len(director_images) > i else filetools.join(config.get_runtime_path(), 'resources','skins','Default','media','Infoplus','no_photo.png'))
|
||||
itemlist.append(it)
|
||||
|
||||
itemlist.sort(key=lambda it: it.director)
|
||||
itemlist.sort(key=lambda it: it.list_director)
|
||||
return itemlist
|
||||
|
||||
|
||||
@@ -132,11 +133,11 @@ def list_years(item):
|
||||
|
||||
itemlist = []
|
||||
for y in years:
|
||||
if y and y not in [it.year for it in itemlist]:
|
||||
it = item.clone(title = str(y), action='list_{}s'.format(item.contentType), year=y)
|
||||
if y and y not in [it.list_year for it in itemlist]:
|
||||
it = item.clone(title = str(y), action='list_{}s'.format(item.contentType), list_year=y)
|
||||
itemlist.append(it)
|
||||
|
||||
itemlist.sort(key=lambda it: it.year, reverse=True)
|
||||
itemlist.sort(key=lambda it: it.list_year, reverse=True)
|
||||
return itemlist
|
||||
|
||||
|
||||
@@ -148,11 +149,11 @@ def list_ratings(item):
|
||||
|
||||
itemlist = []
|
||||
for r in ratings:
|
||||
if r and r not in [it.rating for it in itemlist]:
|
||||
it = item.clone(title = str(r), action='list_{}s'.format(item.contentType), rating=r)
|
||||
if r and r not in [it.list_rating for it in itemlist]:
|
||||
it = item.clone(title = str(r), action='list_{}s'.format(item.contentType), list_rating=r)
|
||||
itemlist.append(it)
|
||||
|
||||
itemlist.sort(key=lambda it: it.rating, reverse=True)
|
||||
itemlist.sort(key=lambda it: it.list_rating, reverse=True)
|
||||
return itemlist
|
||||
|
||||
|
||||
@@ -166,11 +167,11 @@ def list_actors(item):
|
||||
|
||||
itemlist = []
|
||||
for a in actors:
|
||||
if a and a[0][0] == item.title and a[0] not in [it.initial for it in itemlist]:
|
||||
it = item.clone(title = a[0], action='list_{}s'.format(item.contentType), initial=a[0], thumbnail=a[1])
|
||||
if a and a[0][0] == item.title and a[0] not in [it.list_actor for it in itemlist]:
|
||||
it = item.clone(title = a[0], action='list_{}s'.format(item.contentType), list_actor=a[0], thumbnail=a[1] if a[1] else filetools.join(config.get_runtime_path(), 'resources','skins','Default','media','Infoplus','no_photo.png'))
|
||||
itemlist.append(it)
|
||||
|
||||
itemlist.sort(key=lambda it: it.actor)
|
||||
itemlist.sort(key=lambda it: it.list_actor)
|
||||
return itemlist
|
||||
|
||||
|
||||
@@ -186,12 +187,11 @@ def list_movies(item, silent=False):
|
||||
logger.debug()
|
||||
|
||||
videos = dict(videolibrarydb['movie']).values()
|
||||
|
||||
if item.year: itemlist = [v['item'] for v in videos if item.year == v['item'].infoLabels['year']]
|
||||
elif item.rating: itemlist = [v['item'] for v in videos if item.rating == int(float(v['item'].infoLabels['rating']))]
|
||||
elif item.genre: itemlist = [v['item'] for v in videos if item.genre in v['item'].infoLabels['genre']]
|
||||
elif item.actor: itemlist = [v['item'] for v in videos if item.actor in str(v['item'].infoLabels['castandrole'])]
|
||||
elif item.director: itemlist = [v['item'] for v in videos if item.actor in v['item'].infoLabels['director']]
|
||||
if item.list_year: itemlist = [v['item'] for v in videos if item.list_year == v['item'].infoLabels['year']]
|
||||
elif item.list_rating: itemlist = [v['item'] for v in videos if item.list_rating == int(float(v['item'].infoLabels['rating']))]
|
||||
elif item.list_genre: itemlist = [v['item'] for v in videos if item.list_genre in v['item'].infoLabels['genre']]
|
||||
elif item.list_actor: itemlist = [v['item'] for v in videos if item.list_actor in str(v['item'].infoLabels['castandrole'])]
|
||||
elif item.list_director: itemlist = [v['item'] for v in videos if item.list_director in v['item'].infoLabels['director']]
|
||||
elif item.set: itemlist = [v['item'] for v in videos if item.set == v['item'].infoLabels.get('setid', '')]
|
||||
elif config.get_setting('collection') and not item.text: itemlist = [v['item'] for v in videos if (item.text.lower() in v['item'].title.lower() and not 'setid' in v['item'].infoLabels)] + [v for v in dict(videolibrarydb['collection']).values()]
|
||||
else: itemlist = [v['item'] for v in videos if item.text.lower() in v['item'].title.lower()]
|
||||
@@ -212,11 +212,11 @@ def list_tvshows(item):
|
||||
|
||||
videos = dict(videolibrarydb['tvshow']).values()
|
||||
|
||||
if item.year: series = [v['item'] for v in videos if item.year == v['item'].infoLabels['year']]
|
||||
elif item.rating: series = [v['item'] for v in videos if item.rating == int(float(v['item'].infoLabels['rating']))]
|
||||
elif item.genre: series = [v['item'] for v in videos if item.genre in v['item'].infoLabels['genre']]
|
||||
elif item.actor: series = [v['item'] for v in videos if item.actor in str(v['item'].infoLabels['castandrole'])]
|
||||
elif item.director: series = [v['item'] for v in videos if item.actor in v['item'].infoLabels['director']]
|
||||
if item.list_year: series = [v['item'] for v in videos if item.list_year == v['item'].infoLabels['year']]
|
||||
elif item.list_rating: series = [v['item'] for v in videos if item.list_rating == int(float(v['item'].infoLabels['rating']))]
|
||||
elif item.list_genre: series = [v['item'] for v in videos if item.list_genre in v['item'].infoLabels['genre']]
|
||||
elif item.list_actor: series = [v['item'] for v in videos if item.list_actor in str(v['item'].infoLabels['castandrole'])]
|
||||
elif item.list_director: series = [v['item'] for v in videos if item.list_director in v['item'].infoLabels['director'] or item.list_director in v['item'].infoLabels['writer']]
|
||||
else: series = [v['item'] for v in videos if item.text.lower() in v['item'].title.lower()]
|
||||
|
||||
def sub_thread(it):
|
||||
@@ -936,7 +936,6 @@ class subcontext(object):
|
||||
index = xbmcgui.Dialog().contextmenu(self.context)
|
||||
if index >= 0: xbmc.executebuiltin('RunPlugin({}?{})'.format(sys.argv[0], self.commands[index].tourl()))
|
||||
|
||||
|
||||
class set_images(object):
|
||||
def __init__(self, item):
|
||||
self.item = item
|
||||
@@ -1045,6 +1044,7 @@ def add_download_items(item, itemlist):
|
||||
#-------------- DELETE --------------
|
||||
|
||||
def delete(item):
|
||||
# support.dbg()
|
||||
from platformcode import xbmc_videolibrary
|
||||
select = None
|
||||
delete = None
|
||||
@@ -1109,44 +1109,44 @@ def delete(item):
|
||||
else:
|
||||
platformtools.itemlist_refresh(-1)
|
||||
|
||||
# delete channel from video item
|
||||
if select and select > 0:
|
||||
channel_name = channels[select - 1]
|
||||
# delete channel from video item
|
||||
if select and select > 0:
|
||||
channel_name = channels[select - 1]
|
||||
|
||||
if item.contentType != 'movie':
|
||||
episodes = videolibrarydb['episode'][item.videolibrary_id]
|
||||
seasons = videolibrarydb['season'][item.videolibrary_id]
|
||||
episodes_dict = dict(episodes)
|
||||
seasons_dict = dict(seasons)
|
||||
if item.contentType != 'movie':
|
||||
episodes = videolibrarydb['episode'][item.videolibrary_id]
|
||||
seasons = videolibrarydb['season'][item.videolibrary_id]
|
||||
episodes_dict = dict(episodes)
|
||||
seasons_dict = dict(seasons)
|
||||
|
||||
# delete episodes if they have no channels
|
||||
for key, episode in episodes_dict.items():
|
||||
if len(episode['channels']) > 1 and channel_name in episode['channels']:
|
||||
del episode['channels'][channel_name]
|
||||
elif channel_name in episode['channels']:
|
||||
xbmc_videolibrary.clean_by_id(episodes[key]['item'])
|
||||
del episodes[key]
|
||||
# delete episodes if they have no channels
|
||||
for key, episode in episodes_dict.items():
|
||||
if len(episode['channels']) > 1 and channel_name in episode['channels']:
|
||||
del episode['channels'][channel_name]
|
||||
elif channel_name in episode['channels']:
|
||||
xbmc_videolibrary.clean_by_id(episodes[key]['item'])
|
||||
del episodes[key]
|
||||
|
||||
videolibrarydb['episode'][item.videolibrary_id] = episodes
|
||||
seasons_list = []
|
||||
videolibrarydb['episode'][item.videolibrary_id] = episodes
|
||||
seasons_list = []
|
||||
|
||||
# delete seasons if they have no channels
|
||||
for episode in episodes:
|
||||
season = int(episode.split('x')[0])
|
||||
if season not in seasons_list:
|
||||
seasons_list.append(season)
|
||||
# delete seasons if they have no channels
|
||||
for episode in episodes:
|
||||
season = int(episode.split('x')[0])
|
||||
if season not in seasons_list:
|
||||
seasons_list.append(season)
|
||||
|
||||
for season in seasons_dict.keys():
|
||||
if season not in seasons_list:
|
||||
xbmc_videolibrary.clean_by_id(seasons[season])
|
||||
del seasons[season]
|
||||
videolibrarydb['season'][item.videolibrary_id] = seasons
|
||||
for season in seasons_dict.keys():
|
||||
if season not in seasons_list:
|
||||
xbmc_videolibrary.clean_by_id(seasons[season])
|
||||
del seasons[season]
|
||||
videolibrarydb['season'][item.videolibrary_id] = seasons
|
||||
|
||||
channel = videolibrarydb[item.contentType][item.videolibrary_id]
|
||||
channels = channel['channels']
|
||||
del channels[channel_name]
|
||||
channel['channels'] = channels
|
||||
videolibrarydb[item.contentType][item.videolibrary_id] = channel
|
||||
channel = videolibrarydb[item.contentType][item.videolibrary_id]
|
||||
channels = channel['channels']
|
||||
del channels[channel_name]
|
||||
channel['channels'] = channels
|
||||
videolibrarydb[item.contentType][item.videolibrary_id] = channel
|
||||
|
||||
videolibrarydb.close()
|
||||
|
||||
@@ -1360,41 +1360,6 @@ def get_results(nfo_path, root, Type, local=False):
|
||||
else: item = Item()
|
||||
return item, value
|
||||
|
||||
# def add_local_episodes(item):
|
||||
# logger.debug()
|
||||
|
||||
# done, local_episodes_path = videolibrarytools.config_local_episodes_path(item.path, item, silent=True)
|
||||
# if done < 0:
|
||||
# logger.debug('An issue has occurred while configuring local episodes')
|
||||
# elif local_episodes_path:
|
||||
# nfo_path = filetools.join(item.path, 'tvshow.nfo')
|
||||
# head_nfo, item_nfo = videolibrarytools.read_nfo(nfo_path)
|
||||
# item_nfo.local_episodes_path = local_episodes_path
|
||||
# if not item_nfo.active:
|
||||
# item_nfo.active = 1
|
||||
# filetools.write(nfo_path, head_nfo + item_nfo.tojson())
|
||||
|
||||
# update_tvshow(item)
|
||||
|
||||
# platformtools.itemlist_refresh()
|
||||
|
||||
|
||||
# def remove_local_episodes(item):
|
||||
# logger.debug()
|
||||
|
||||
# nfo_path = filetools.join(item.path, 'tvshow.nfo')
|
||||
# head_nfo, item_nfo = videolibrarytools.read_nfo(nfo_path)
|
||||
|
||||
# for season_episode in item_nfo.local_episodes_list:
|
||||
# filetools.remove(filetools.join(item.path, season_episode + '.strm'))
|
||||
|
||||
# item_nfo.local_episodes_list = []
|
||||
# item_nfo.local_episodes_path = ''
|
||||
# filetools.write(nfo_path, head_nfo + item_nfo.tojson())
|
||||
|
||||
# update_tvshow(item)
|
||||
|
||||
# platformtools.itemlist_refresh()
|
||||
|
||||
def convert_videolibrary(item):
|
||||
videolibrarytools.convert_videolibrary()
|
||||
|
||||
Reference in New Issue
Block a user