def get_video_link(players, params): lister = Lister() for lang, lang_params in params.items(): for key, value in lang_params.items(): if isinstance(value, basestring): params[lang][key + '_+'] = value.replace(' ', '+') params[lang][key + '_-'] = value.replace(' ', '-') params[lang][key + '_escaped'] = value.replace(' ', '%2520') params[lang][key + '_escaped+'] = value.replace(' ', '%252B') selection = None try: if len(players) > 1: index = plugin.select('Play with...', [player.title for player in players]) if index == -1: return None players = [players[index]] resolve_f = lambda p: resolve_player(p, lister, params) result = resolve_f(players[0]) if result: title, links = result if len(links) == 1: selection = links[0] else: index = plugin.select('Play with...', [x['label'] for x in links]) if index > -1: selection = links[index] else: plugin.ok('Error', 'Video not found') finally: lister.stop() return selection
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