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
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
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
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')
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')