Beispiel #1
0
def resolve_player(player, lister, params):
    results = []
    for command_group in player.commands:
        if xbmc.abortRequested or not lister.is_active(): return
        command_group_results = []
        for command in command_group:
            if xbmc.abortRequested or not lister.is_active(): return
            lang = command.get("language", "en")
            if not lang in params: continue
            parameters = params[lang]
            try:
                link = apply_parameters(to_unicode(command["link"]),
                                        parameters)
            except:
                print_exc()
                continue
            if link == "movies" and player.media == "movies":
                video = get_movie_from_library(parameters['imdb'])
                if video:
                    command_group_results.append(video)
            elif link == "tvshows" and player.media == "tvshows":
                video = get_episode_from_library(parameters['id'],
                                                 parameters['season'],
                                                 parameters['episode'])
                if not video:
                    video = 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':
                    urlencode_path(link),
                    'action':
                    command.get("action", "PLAY")
                })
            else:
                steps = [to_unicode(step) for step in command["steps"]]
                files, dirs = lister.get(link, steps, parameters)
                if command.get("action", "PLAY") == "ACTIVATE":
                    files += dirs
                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
Beispiel #2
0
def resolve_player(player, lister, params):
    results = []
    for command_group in player.commands:
        if xbmc.abortRequested or not lister.is_active():
            return
        command_group_results = []
        for command in command_group:
            if xbmc.abortRequested or not lister.is_active():
                return
            lang = command.get("language", "en")
            if not lang in params:
                continue
            parameters = params[lang]
            try:
                link = apply_parameters(to_unicode(command["link"]), parameters)
            except:
                print_exc()
                continue
            if link == "movies" and player.media == "movies":
                video = get_movie_from_library(parameters["imdb"])
                if video:
                    command_group_results.append(video)
            elif link == "tvshows" and player.media == "tvshows":
                video = get_episode_from_library(parameters["id"], parameters["season"], parameters["episode"])
                if not video:
                    video = 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": urlencode_path(link), "action": command.get("action", "PLAY")}
                )
            else:
                steps = [to_unicode(step) for step in command["steps"]]
                files, dirs = lister.get(link, steps, parameters)
                if command.get("action", "PLAY") == "ACTIVATE":
                    files += dirs
                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
Beispiel #3
0
    def _has_match(item, pattern, parameters):
        # Match by season info label
        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

        # Match by episode info label
        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

        # Match by season and episode info labels
        if pattern == "{season}x{episode}" and \
         season_infolabel_match and episode_infolabel_match:
            return True

        # Match by label
        label = item['label']
        pattern = to_unicode(pattern)
        # Custom $$ shortcut for unicode word boundary
        pattern = pattern.replace("$$", r"($|^|\s|\]|\[)")

        # Detect season number if searching for season 1
        #   to later allow first season to have no number
        first_season = False
        if '{season}' in pattern and '1' == str(parameters.get('season')):
            pattern = pattern.replace('{season}', '(?P<season>\d*)')
            first_season = True

        # Apply parameters to pattern
        pattern = apply_parameters(pattern, parameters)

        # Remove special chars
        for c in IGNORE_CHARS:
            #pattern = pattern.replace("\\"+c, ' ')
            label = label.replace(c, ' ')

        # Make sure both label and pattern are unicode
        pattern = to_unicode(to_utf8(pattern))
        label = to_unicode(to_utf8(label))

        plugin.log.debug("matching pattern {0} to label {1}".format(
            to_utf8(pattern), to_utf8(label)))

        # Test for a match
        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 full match
        if match is not None and match.end() == len(label):
            # Special handling of first season
            if first_season and not match.group('season') in ('1', '', '01',
                                                              None):
                return False

            # Matched!
            plugin.log.debug("match: " + to_utf8(label))
            return True

        return False
Beispiel #4
0
    def _has_match(item, pattern, parameters):
        # Match by season info label
        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
        
        # Match by episode info label
        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
        
        # Match by season and episode info labels
        if pattern == "{season}x{episode}" and \
         season_infolabel_match and episode_infolabel_match:
            return True
                
        # Match by label
        label = item['label']
        pattern = to_unicode(pattern)
        # Custom $$ shortcut for unicode word boundary
        pattern = pattern.replace("$$", r"($|^|\s|\]|\[)")
                
        # Detect season number if searching for season 1
        #   to later allow first season to have no number
        first_season = False
        if '{season}' in pattern and '1' == str(parameters.get('season')):
            pattern = pattern.replace('{season}', '(?P<season>\d*)')
            first_season = True
            
        # Apply parameters to pattern
        pattern = apply_parameters(pattern, parameters)    
        
        # Remove special chars
        for c in IGNORE_CHARS:
            #pattern = pattern.replace("\\"+c, ' ')
            label = label.replace(c, ' ')

        # Make sure both label and pattern are unicode
        pattern = to_unicode(to_utf8(pattern))               
        label = to_unicode(to_utf8(label))
        
        plugin.log.debug("matching pattern {0} to label {1}".format(to_utf8(pattern), to_utf8(label)))
         
        # Test for a match
        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 full match
        if match is not None and match.end() == len(label):
            # Special handling of first season
            if first_season and not match.group('season') in ('1', '', '01', None):
                return False
            
            # Matched!
            plugin.log.debug("match: " + to_utf8(label))
            return True
            
        return False