コード例 #1
0
    def is_same(self, value, expected):
        values = set(value) if is_iterable(value) else set((value,))
        expecteds = set(expected) if is_iterable(expected) else set((expected,))
        if len(values) != len(expecteds):
            return False
        if isinstance(next(iter(values)), babelfish.Language):

            expecteds = {babelfish.Language.fromguessit(expected) for expected in expecteds}
        elif isinstance(next(iter(values)), babelfish.Country):

            expecteds = {babelfish.Country.fromguessit(expected) for expected in expecteds}
        return values == expecteds
コード例 #2
0
ファイル: test_yml.py プロジェクト: ArthurGarnier/SickRage
 def is_same(self, value, expected):
     values = set(value) if is_iterable(value) else set((value,))
     expecteds = set(expected) if is_iterable(expected) else set((expected,))
     if len(values) != len(expecteds):
         return False
     if isinstance(next(iter(values)), babelfish.Language):
         # pylint: disable=no-member
         expecteds = set([babelfish.Language.fromguessit(expected) for expected in expecteds])
     elif isinstance(next(iter(values)), babelfish.Country):
         # pylint: disable=no-member
         expecteds = set([babelfish.Country.fromguessit(expected) for expected in expecteds])
     return values == expecteds
コード例 #3
0
 def ordering_validator(match):
     """
     Validator for season list. They should be in natural order to be validated.
     """
     values = match.children.to_dict(implicit=True)
     if 'season' in values and is_iterable(values['season']):
         # Season numbers must be in natural order to be validated.
         return list(sorted(values['season'])) == values['season']
     if 'episode' in values and is_iterable(values['episode']):
         # Season numbers must be in natural order to be validated.
         return list(sorted(values['episode'])) == values['episode']
     return True
コード例 #4
0
ファイル: episodes.py プロジェクト: zx900930/bazarr
    def ordering_validator(match):
        """
        Validator for season list. They should be in natural order to be validated.

        episode/season separated by a weak discrete separator should be consecutive, unless a strong discrete separator
        or a range separator is present in the chain (1.3&5 is valid, but 1.3-5 is not valid and 1.3.5 is not valid)
        """
        values = match.children.to_dict()
        if 'season' in values and is_iterable(values['season']):
            # Season numbers must be in natural order to be validated.
            if not list(sorted(values['season'])) == values['season']:
                return False
        if 'episode' in values and is_iterable(values['episode']):
            # Season numbers must be in natural order to be validated.
            if not list(sorted(values['episode'])) == values['episode']:
                return False

        def is_consecutive(property_name):
            """
            Check if the property season or episode has valid consecutive values.
            :param property_name:
            :type property_name:
            :return:
            :rtype:
            """
            previous_match = None
            valid = True
            for current_match in match.children.named(property_name):
                if previous_match:
                    match.children.previous(
                        current_match,
                        lambda m: m.name == property_name + 'Separator')
                    separator = match.children.previous(
                        current_match,
                        lambda m: m.name == property_name + 'Separator', 0)
                    if separator:
                        if separator.raw not in range_separators and separator.raw in weak_discrete_separators:
                            if not 0 < current_match.value - previous_match.value <= max_range_gap + 1:
                                valid = False
                        if separator.raw in strong_discrete_separators:
                            valid = True
                            break
                previous_match = current_match
            return valid

        return is_consecutive('episode') and is_consecutive('season')
コード例 #5
0
ファイル: episodes.py プロジェクト: SerhatG/nzbToMedia
    def ordering_validator(match):
        """
        Validator for season list. They should be in natural order to be validated.

        episode/season separated by a weak discrete separator should be consecutive, unless a strong discrete separator
        or a range separator is present in the chain (1.3&5 is valid, but 1.3-5 is not valid and 1.3.5 is not valid)
        """
        values = match.children.to_dict()
        if 'season' in values and is_iterable(values['season']):
            # Season numbers must be in natural order to be validated.
            if not list(sorted(values['season'])) == values['season']:
                return False
        if 'episode' in values and is_iterable(values['episode']):
            # Season numbers must be in natural order to be validated.
            if not list(sorted(values['episode'])) == values['episode']:
                return False

        def is_consecutive(property_name):
            """
            Check if the property season or episode has valid consecutive values.
            :param property_name:
            :type property_name:
            :return:
            :rtype:
            """
            previous_match = None
            valid = True
            for current_match in match.children.named(property_name):
                if previous_match:
                    match.children.previous(current_match,
                                            lambda m: m.name == property_name + 'Separator')
                    separator = match.children.previous(current_match,
                                                        lambda m: m.name == property_name + 'Separator', 0)
                    if separator.raw not in range_separators and separator.raw in weak_discrete_separators:
                        if not 0 < current_match.value - previous_match.value <= max_range_gap + 1:
                            valid = False
                    if separator.raw in strong_discrete_separators:
                        valid = True
                        break
                previous_match = current_match
            return valid

        return is_consecutive('episode') and is_consecutive('season')