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 _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