def resolve_player(player, lister, params): results = [] for command_group in player.commands: if xbmc.Monitor().abortRequested() or not Lister().is_active(): return command_group_results = [] for command in command_group: if xbmc.Monitor().abortRequested() or not Lister().is_active(): return lang = command.get('language', 'en') if not lang in params: continue parameters = params[lang] #CHANGES link = text.apply_parameters(text.to_unicode(command['link']), parameters) # link = text.apply_parameters(text.to_unicode(command['link']), parameters).replace(' & ','%20%26%20') #modified the following line to replace " & " with " and " link = text.apply_parameters(text.to_unicode(command['link']), parameters).replace(' & ', ' and ') # xbmc.log(link, level=4) if link == 'movies' and player.media == 'movies': video = tools.get_movie_from_library(parameters['imdb']) if video: command_group_results.append(video) elif link == 'tvshows' and player.media == 'tvshows': video = tools.get_episode_from_library(parameters['id'], parameters['season'], parameters['episode']) if not video: video = tools.get_episode_from_library( parameters['tmdb'], parameters['season'], parameters['episode']) if video: command_group_results.append(video) elif not command.get('steps'): command_group_results.append({ 'label': player.title, 'path': text.urlencode_path(link), 'action': command.get('action', 'PLAY') }) else: steps = [text.to_unicode(step) for step in command['steps']] files, dirs = Lister().get(link, steps, parameters) if files: command_group_results += [{ 'label': f['label'], 'path': (f['path']), 'action': command.get('action', 'PLAY') } for f in files] if command_group_results: break results += command_group_results if results: return player.title, results
def resolve_player(player, lister, params): # xbmc.log(str('def resolve_player(player, lister, params):')+'===>OPENMETA', level=xbmc.LOGNOTICE) results = [] for command_group in player.commands: if xbmc.Monitor().abortRequested() or not lister.is_active(): return command_group_results = [] for command in command_group: if xbmc.Monitor().abortRequested() or not lister.is_active(): return lang = command.get('language', 'en') if not lang in params: continue parameters = params[lang] link = text.apply_parameters(text.to_unicode(command['link']), parameters) if link == 'movies' and player.media == 'movies': video = tools.get_movie_from_library(parameters['imdb']) if video: command_group_results.append(video) elif link == 'tvshows' and player.media == 'tvshows': video = tools.get_episode_from_library(parameters['id'], parameters['season'], parameters['episode']) if not video: video = tools.get_episode_from_library( parameters['tmdb'], parameters['season'], parameters['episode']) if video: command_group_results.append(video) elif not command.get('steps'): command_group_results.append({ 'label': player.title, 'path': text.urlencode_path(link), 'action': command.get('action', 'PLAY') }) else: steps = [text.to_unicode(step) for step in command['steps']] files, dirs = lister.get(link, steps, parameters) if files: command_group_results += [{ 'label': f['label'], 'path': player.postprocess(f['path']), 'action': command.get('action', 'PLAY') } for f in files] if command_group_results: break results += command_group_results if results: return player.title, results
def play_movie(tmdb_id, usedefault): from resources.lib.TheMovieDB import Movies play_plugin = meta_players.ADDON_SELECTOR.id players = meta_players.get_players('movies') players = [p for p in players if p.id == play_plugin] or players if not players or len(players) == 0: xbmc.executebuiltin('Action(Info)') play_base.action_cancel() return if usedefault == 'True': default = plugin.get_setting('moviesdefault', unicode) for player in players: if player.title == default: players = [player] movie = Movies(tmdb_id).info( language='en', append_to_response= 'external_ids,alternative_titles,credits,images,keywords,releases,translations,rating' ) movie_info = meta_info.get_movie_metadata(movie) imdb_id = movie['imdb_id'] if 'imdb_id' in movie else None id_type = 'imdb' if imdb_id and imdb_id.startswith('tt') else 'tmdb' id = imdb_id if imdb_id and imdb_id.startswith('tt') else tmdb_id trakt_ids = play_base.get_trakt_ids(id_type=id_type, id=id, type='movie') params = {} for lang in meta_players.get_needed_langs(players): if lang == 'en': tmdb_data = movie else: tmdb_data = Movies(tmdb_id).info( language=lang, append_to_response= 'external_ids,alternative_titles,credits,images,keywords,releases,translations,rating' ) params[lang] = get_movie_parameters(tmdb_data) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = movie_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: movie = Movies(tmdb_id).info(language='en') play_base.action_play({ 'label': movie_info['title'], 'path': link, 'info': movie_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': movie_info['poster'], 'poster': movie_info['poster'], 'fanart': movie_info['fanart'] })
def sort_players(players, filters={}): result = [] for player in players: filtered = False checked = False for filter_key, filter_value in filters.items(): value = player.filters.get(filter_key) if value: checked = True if to_unicode(value) != to_unicode(filter_value): filtered = True if not filtered: needs_browsing = False for command_group in player.commands: for command in command_group: if command.get('steps'): needs_browsing = True break result.append((not checked, needs_browsing, player.order, player.clean_title.lower(), player)) result.sort() return [x[-1] for x in result]
def play_movie(tmdb_id): from resources.lib.TheMovieDB import Movies play_plugin = meta_players.ADDON_SELECTOR.id players = meta_players.get_players('movies') players = [p for p in players if p.id == play_plugin] or players if not players or len(players) == 0: xbmc.executebuiltin('Action(Info)') play_base.action_cancel() return movie = Movies(tmdb_id).info( language='en', append_to_response= 'external_ids,alternative_titles,credits,images,keywords,releases,translations,rating' ) movie_info = meta_info.get_movie_metadata(movie) trakt_ids = play_base.get_trakt_ids('tmdb', tmdb_id, movie['original_title'], 'movie', text.parse_year(movie['release_date'])) params = {} for lang in meta_players.get_needed_langs(players): if lang == 'en': tmdb_data = movie else: tmdb_data = Movies(tmdb_id).info( language=lang, append_to_response= 'external_ids,alternative_titles,credits,images,keywords,releases,translations,rating' ) params[lang] = get_movie_parameters(tmdb_data) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = movie_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: movie = Movies(tmdb_id).info(language='en') play_base.action_play({ 'label': movie_info['title'], 'path': link, 'info': movie_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': movie_info['poster'], 'poster': movie_info['poster'], 'fanart': movie_info['fanart'] })
def tmdb_play_episode(id, season, episode): from resources.lib.TheMovieDB import TV, TV_Seasons, TV_Episodes tried = 'tvdb' id = int(id) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel('ListItem.DBID') try: dbid = int(dbid) except: dbid = None show = TV(id).info(language='en', append_to_response='external_ids,images') if 'first_air_date' in show and show['first_air_date'] != None: year = show['first_air_date'][:4] else: year = None trakt_ids = play_base.get_trakt_ids('tmdb', id) if 'status_code' in show: return trakt_play_episode(trakt_ids['trakt'], season, episode) if 'name' in show: title = show['name'] else: title = None show_info = meta_info.get_tvshow_metadata_tmdb(show) title = show_info['name'] preason = TV_Seasons(id, season).info(language='en', append_to_response='external_ids,images') if 'The resource you requested could not be found' in str(preason): return trakt_play_episode(trakt_ids['trakt'], season, episode) season_info = meta_info.get_season_metadata_tmdb(show_info, preason) prepisode = TV_Episodes(id, season, episode).info(language='en', append_to_response='external_ids,images') if prepisode == '{u"status_code": 34, u"status_message": u"The resource you requested could not be found."}': return trakt_play_episode(trakt_ids['tmdb'], season, episode) episode_info = meta_info.get_episode_metadata_tmdb(season_info, prepisode) if show_info['poster'] != None and show_info['poster'] != '': show_poster = show_info['poster'] else: show_poster = '' if show_info['fanart'] != None and show_info['fanart'] != '': show_fanart = show_info['fanart'] else: show_fanart = '' episodes = preason['episodes'] items = [] play_plugin = meta_players.ADDON_SELECTOR.id players = meta_players.get_players('tvshows') players = [p for p in players if p.id == play_plugin] or players if not players: return xbmc.executebuiltin('Action(Info)') trakt_ids = play_base.get_trakt_ids('tmdb', id, show_info['name'], 'show', show['first_air_date'][:4]) params = {} for lang in meta_players.get_needed_langs(players): if show['name'] is None: continue episode_parameters = get_tmdb_episode_parameters(show, preason, prepisode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids['trakt'] != None and trakt_ids['trakt'] != '': return trakt_play_episode(trakt_ids['trakt'], season, episode) else: msg = 'No TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'tmdb': id, 'season': season, 'episode': episode })) episode_metadata = meta_info.get_episode_metadata_tmdb(season_info, prepisode) play_base.action_play( { 'label': episode_info['title'], 'path': link, 'info': [], 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': str(show_info['fanart']) })
def tvmaze_play_episode(id, season, episode, title=None): title = '' try: id = int(id) except: title = id if title and title != '': url = 'https://api.tvmaze.com/search/shows?q=%s' % id response = urllib.urlopen(url) shows = json.loads(response.read()) if len(shows) > 0: show = shows[0] id = show['show']['id'] url = 'https://api.tvmaze.com/shows/%d?embed[]=seasons&embed[]=episodes' % int(id) response = urllib.urlopen(url) show = json.loads(response.read()) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel('ListItem.DBID') try: dbid = int(dbid) except: dbid = None if show['externals']: if show['externals']['thetvdb']: trakt_ids = play_base.get_trakt_ids('tvdb', show['externals']['thetvdb'], show['name'], 'show', show['premiered'][:4]) elif show['externals']['imdb']: trakt_ids = play_base.get_trakt_ids('imdb', show['externals']['imdb'], show['name'], 'show', show['premiered'][:4]) else: trakt_ids = play_base.get_trakt_ids(query=show['name'], type='show', year=show['premiered'][:4]) else: trakt_ids = play_base.get_trakt_ids(query=show['name'], type='show', year=show['premiered'][:4]) show_info = meta_info.get_tvshow_metadata_tvmaze(show) preasons = show['_embedded']['seasons'] for item in preasons: if item['number'] == season: preason = item season = preasons.index(item) + 1 elif item['premiereDate'] and item['endDate']: if int(item['premiereDate'][:4]) <= season and int(item['endDate'][:4]) >= season: preason = item season = preasons.index(item) + 1 prepisodes = show['_embedded']['episodes'] for item in prepisodes: if item['number'] == episode: prepisode = item season_info = meta_info.get_season_metadata_tvmaze(show_info, preason) episode_info = meta_info.get_episode_metadata_tvmaze(season_info, prepisode) if show_info['poster'] != None and show_info['poster'] != '': show_poster = show_info['poster'] else: show_poster = '' if show_info['fanart'] != None and show_info['fanart'] != '': show_fanart = show_info['fanart'] else: show_fanart = '' items = [] play_plugin = meta_players.ADDON_SELECTOR.id players = meta_players.get_players('tvshows') players = [p for p in players if p.id == play_plugin] or players if not players: return xbmc.executebuiltin('Action(Info)') params = {} for lang in meta_players.get_needed_langs(players): if show['name'] is None: continue episode_parameters = get_tvmaze_episode_parameters(show, preason, prepisode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids['tmdb'] != None and trakt_ids['tmdb'] != '' and tried != 'tmdb': tried = 'tmdb' return tvdb_play_episode(trakt_ids['tvdb'], season, episode) elif tried == 'tmdb': msg = 'No TVDb or TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) else: msg = 'No TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'tvdb': trakt_ids['tvdb'], 'season': season, 'episode': episode })) episode_metadata = meta_info.get_episode_metadata_tvmaze(season_info, prepisode) play_base.action_play( { 'label': episode_info['title'], 'path': link, 'info': [], 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': str(show_info['fanart']) })
def trakt_play_episode(id, season, episode): from resources.lib.Trakt import get_show, get_season, get_seasons, get_episode id = int(id) season = int(season) episode = int(episode) show = None preason = None prepisode = None dbid = xbmc.getInfoLabel('ListItem.DBID') try: dbid = int(dbid) except: dbid = None show = get_show(id) if 'name' in show: show_title = show['name'] elif 'title' in show: show_title = show['title'] if show: if show['first_aired']: year = show['first_aired'][:4] else: year = None trakt_ids = play_base.get_trakt_ids('trakt', id, show_title, 'show', year) preason = get_season(id, season) if preason: prepisode = get_episode(id, season, episode) elif not preason and season > 1900: seasons = get_seasons(id) for item in seasons: if item['first_aired'] != None: if int(item['first_aired'][:4]) == season: season_number = item['number'] preason = get_season(id, season_number) if not prepisode or not preason or not show: return tvmaze_play_episode(show_title, season, episode) show_info = meta_info.get_tvshow_metadata_trakt(show) season_info = meta_info.get_season_metadata_trakt(show_info, preason) episode_info = meta_info.get_episode_metadata_trakt(season_info, prepisode) title = show_info['name'] if show_info['poster'] != None and show_info['poster'] != '': show_poster = show_info['poster'] else: show_poster = '' if show_info['fanart'] != None and show_info['fanart'] != '': show_fanart = show_info['fanart'] else: show_fanart = '' items = [] play_plugin = meta_players.ADDON_SELECTOR.id players = meta_players.get_players('tvshows') players = [p for p in players if p.id == play_plugin] or players if not players: return xbmc.executebuiltin('Action(Info)') params = {} for lang in meta_players.get_needed_langs(players): if show['name'] is None: continue episode_parameters = get_trakt_episode_parameters(show, preason, prepisode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids['tmdb'] != None and trakt_ids['tmdb'] != '' and tried != 'tmdb': tried = 'tmdb' return tvdb_play_episode(trakt_ids['tvdb'], season, episode) elif tried == 'tmdb': msg = 'No TVDb or TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) else: msg = 'No TMDb information found for %s - S%sE%s' % (show_info['name'], season, episode) plugin.ok('Episode information not found', msg) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'trakt': id, 'season': season, 'episode': episode })) episode_metadata = meta_info.get_episode_metadata_trakt(season_info, prepisode) play_base.action_play( { 'label': episode_info['title'], 'path': link, 'info': episode_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': str(show_info['fanart']) })
def play_episode(id, season, episode): from resources.lib.TheTVDB import TVDB id = int(id) season = int(season) episode = int(episode) dbid = xbmc.getInfoLabel('ListItem.DBID') try: dbid = int(dbid) except: dbid = None show = TVDB[id] show_info = meta_info.get_tvshow_metadata_tvdb(show, banners=False) play_plugin = meta_players.ADDON_SELECTOR.id PLAYERS = meta_players.get_players('tvshows') players = [p for p in PLAYERS if p.id == play_plugin] or PLAYERS if not players or len(players) == 0: xbmc.executebuiltin('Action(Info)') play_base.action_cancel() return trakt_ids = play_base.get_trakt_ids('tvdb', id, show['seriesname'], 'show', show.get('year', 0)) params = {} for lang in meta_players.get_needed_langs(players): tvdb_data = show if tvdb_data['seriesname'] is None: continue episode_parameters = get_episode_parameters(tvdb_data, season, episode) if episode_parameters is not None: params[lang] = episode_parameters else: if trakt_ids['tmdb'] != None and trakt_ids['tmdb'] != '': return tmdb_play_episode(trakt_ids['tmdb'], season, episode) elif trakt_ids['tvdb'] == None or trakt_ids['tvdb'] == '': plugin.ok('Information not found for:', '%s - S%sE%s' % (show_info['name'], season, episode)) else: plugin.ok('Information not found for:', '%s - S%sE%s' % (show_info['name'], season, episode)) if trakt_ids != None: params[lang].update(trakt_ids) params[lang]['info'] = show_info params[lang] = text.to_unicode(params[lang]) link = play_base.on_play_video(players, params, trakt_ids) if link: plugin.setProperty('plugin.video.openmeta.data', json.dumps( { 'dbid': dbid, 'tvdb': id, 'season': season, 'episode': episode })) season_info = meta_info.get_season_metadata_tvdb(show_info, show[season], banners=False) episode_info = meta_info.get_episode_metadata_tvdb(season_info, show[season][episode]) play_base.action_play( { 'label': episode_info['name'], 'path': link, 'info': episode_info, 'is_playable': True, 'info_type': 'video', 'thumbnail': episode_info['poster'], 'poster': episode_info['poster'], 'fanart': episode_info['fanart'] })
def prep_search_str(self, string): t_text = text.to_unicode(string) for chr in t_text: if ord(chr) >= 1488 and ord(chr) <= 1514: return text.to_utf8(string[::-1]) return text.to_utf8(string)
def _has_match(item, pattern, parameters): season_infolabel_match = False if item.get('season'): item_season = str(item.get('season')) param_season = str(parameters.get('season', '')) if item_season == param_season: season_infolabel_match = True if pattern == '{season}' and season_infolabel_match: return True episode_infolabel_match = False if item.get('episode'): item_episode = str(item.get('episode')) param_episode = str(parameters.get('episode', '')) if item_episode == param_episode: episode_infolabel_match = True if pattern == '{episode}' and episode_infolabel_match: return True if pattern == '{season}x{episode}' and season_infolabel_match and episode_infolabel_match: return True label = item['label'] pattern = text.to_unicode(pattern) pattern = pattern.replace('$$', r'($|^|\s|\]|\[)') first_season = False if '{season}' in pattern and '1' == str(parameters.get('season')): pattern = pattern.replace('{season}', '(?P<season>\d*)') first_season = True pattern = text.apply_parameters(pattern, parameters) for c in IGNORE_CHARS: label = label.replace(c, ' ') pattern = text.to_unicode(text.to_utf8(pattern)) label = text.to_unicode(text.to_utf8(label)) if '$INFO[' in pattern: m = re.search('\\[(.*?)\]', pattern) info = m.group(1) pattern = pattern.replace('$INFO[%s]' % info, xbmc.getInfoLabel(info)) if '$LOCALIZE[' in pattern: m = re.search('\[(\d+)\]', pattern) id = int(m.group(1)) pattern = pattern.replace( '$LOCALIZE[%s]' % id, xbmc.getLocalizedString(id).encode('utf-8')) if '$ADDON[' in pattern: m = re.search('\[.*\ (\d+)\]', pattern) aid = m.group(0).strip('[]').split(' ')[0] id = int(m.group(1)) pattern = pattern.replace( '$ADDON[%s %s]' % (aid, id), xbmcaddon.Addon(aid).getLocalizedString(id).encode('utf-8')) if pattern.startswith('><'): label = re.sub(r'\[[^)].*?\]', '', label) pattern = pattern.strip('><') plugin.log.debug('matching pattern %s to label %s' % (text.to_utf8(pattern), text.to_utf8(label))) r = re.compile(pattern, re.I | re.UNICODE) match = r.match(label) if ', The' in label and match is None: label = u'The ' + label.replace(', The', '') match = r.match(label) if match is not None and match.end() == len(label): if first_season and not match.group('season') in ('1', '', '01', None): return False plugin.log.debug('match: ' + text.to_utf8(label)) return True return False