Beispiel #1
0
    def __init__(self, filename, options=None, **kwargs):
        options = dict(options or {})
        for k, v in kwargs.items():
            if k not in options or not options[k]:
                options[
                    k] = v  # options dict has priority over keyword arguments
        self._validate_options(options)
        if not PY3 and not isinstance(filename, unicode):
            log.warning('Given filename to matcher is not unicode...')
            filename = filename.decode('utf-8')

        filename = normalize_unicode(filename)
        clean_function = None
        if options and options.get('clean_function'):
            clean_function = options.get('clean_function')
            if not hasattr(clean_function, '__call__'):
                module, function = clean_function.rsplit('.')
                if not module:
                    module = 'guessit.textutils'
                clean_function = getattr(__import__(module), function)
                if not clean_function:
                    log.error(
                        'Can\'t find clean function %s. Default will be used.'
                        % options.get('clean_function'))
                    clean_function = clean_default
        else:
            clean_function = clean_default

        self.match_tree = MatchTree(filename, clean_function=clean_function)
        self.options = options
        self._transfo_calls = []

        # sanity check: make sure we don't process a (mostly) empty string
        if clean_function(filename).strip() == '':
            return

        from guessit.plugins import transformers

        try:
            mtree = self.match_tree
            if 'type' in self.options:
                mtree.guess.set('type', self.options['type'], confidence=0.0)

            # Process
            for transformer in transformers.all_transformers():
                disabled = options.get('disabled_transformers')
                if not disabled or not transformer.name in disabled:
                    self._process(transformer, False)

            # Post-process
            for transformer in transformers.all_transformers():
                disabled = options.get('disabled_transformers')
                if not disabled or not transformer.name in disabled:
                    self._process(transformer, True)

            log.debug('Found match tree:\n%s' % u(mtree))
        except TransformerException as e:
            log.debug('An error has occurred in Transformer %s: %s' %
                      (e.transformer, e))
Beispiel #2
0
    def __init__(self, filename, options=None, **kwargs):
        options = dict(options or {})
        for k, v in kwargs.items():
            if k not in options or not options[k]:
                options[k] = v  # options dict has priority over keyword arguments
        self._validate_options(options)
        if not PY3 and not isinstance(filename, unicode):
            log.warning('Given filename to matcher is not unicode...')
            filename = filename.decode('utf-8')

        filename = normalize_unicode(filename)
        clean_function = None
        if options and options.get('clean_function'):
            clean_function = options.get('clean_function')
            if not hasattr(clean_function, '__call__'):
                module, function = clean_function.rsplit('.')
                if not module:
                    module = 'guessit.textutils'
                clean_function = getattr(__import__(module), function)
                if not clean_function:
                    log.error('Can\'t find clean function %s. Default will be used.' % options.get('clean_function'))
                    clean_function = clean_default
        else:
            clean_function = clean_default

        self.match_tree = MatchTree(filename, clean_function=clean_function)
        self.options = options
        self._transfo_calls = []

        # sanity check: make sure we don't process a (mostly) empty string
        if clean_function(filename).strip() == '':
            return

        from guessit.plugins import transformers

        try:
            mtree = self.match_tree
            if 'type' in self.options:
                mtree.guess.set('type', self.options['type'], confidence=0.0)

            # Process
            for transformer in transformers.all_transformers():
                disabled = options.get('disabled_transformers')
                if not disabled or not transformer.name in disabled:
                    self._process(transformer, False)

            # Post-process
            for transformer in transformers.all_transformers():
                disabled = options.get('disabled_transformers')
                if not disabled or not transformer.name in disabled:
                    self._process(transformer, True)

            log.debug('Found match tree:\n%s' % u(mtree))
        except TransformerException as e:
            log.debug('An error has occurred in Transformer %s: %s' % (e.transformer, e))
def _supported_properties():
    from guessit.plugins import transformers

    all_properties = {}
    transformers_properties = []
    for transformer in transformers.all_transformers():
        supported_properties = transformer.supported_properties()
        transformers_properties.append((transformer, supported_properties))

        if isinstance(supported_properties, dict):
            for property_name, possible_values in supported_properties.items():
                current_possible_values = all_properties.get(property_name)
                if current_possible_values is None:
                    current_possible_values = []
                    all_properties[property_name] = current_possible_values
                if possible_values:
                    current_possible_values.extend(possible_values)
        else:
            for property_name in supported_properties:
                current_possible_values = all_properties.get(property_name)
                if current_possible_values is None:
                    current_possible_values = []
                    all_properties[property_name] = current_possible_values

    return (all_properties, transformers_properties)
Beispiel #4
0
def _supported_properties():
    from guessit.plugins import transformers

    all_properties = {}
    transformers_properties = []
    for transformer in transformers.all_transformers():
        supported_properties = transformer.supported_properties()
        transformers_properties.append((transformer, supported_properties))

        if isinstance(supported_properties, dict):
            for property_name, possible_values in supported_properties.items():
                current_possible_values = all_properties.get(property_name)
                if current_possible_values is None:
                    current_possible_values = []
                    all_properties[property_name] = current_possible_values
                if possible_values:
                    current_possible_values.extend(possible_values)
        else:
            for property_name in supported_properties:
                current_possible_values = all_properties.get(property_name)
                if current_possible_values is None:
                    current_possible_values = []
                    all_properties[property_name] = current_possible_values

    return (all_properties, transformers_properties)
Beispiel #5
0
    def __init__(self, filename, options=None, **kwargs):
        options = dict(options or {})
        for k, v in kwargs.items():
            if k not in options or not options[k]:
                options[
                    k] = v  # options dict has priority over keyword arguments
        self._validate_options(options)
        if not PY3 and not isinstance(filename, unicode):
            log.warning('Given filename to matcher is not unicode...')
            filename = filename.decode('utf-8')

        filename = normalize_unicode(filename)
        self.match_tree = MatchTree(filename)
        self.options = options
        self._transfo_calls = []

        # sanity check: make sure we don't process a (mostly) empty string
        if clean_string(filename) == '':
            return

        from guessit.plugins import transformers

        try:
            mtree = self.match_tree
            if 'type' in self.options:
                mtree.guess.set('type', self.options['type'], confidence=0.0)

            # Process
            for transformer in transformers.all_transformers():
                self._process(transformer, False)

            # Post-process
            for transformer in transformers.all_transformers():
                self._process(transformer, True)

            log.debug('Found match tree:\n%s' % u(mtree))
        except TransformerException as e:
            log.debug('An error has occurred in Transformer %s: %s' %
                      (e.transformer, e))
Beispiel #6
0
    def __init__(self, filename, options=None, **kwargs):
        options = dict(options or {})
        for k, v in kwargs.items():
            if k not in options or not options[k]:
                options[k] = v  # options dict has priority over keyword arguments
        self._validate_options(options)
        if not PY3 and not isinstance(filename, unicode):
            log.warning('Given filename to matcher is not unicode...')
            filename = filename.decode('utf-8')

        filename = normalize_unicode(filename)
        self.match_tree = MatchTree(filename)
        self.options = options
        self._transfo_calls = []

        # sanity check: make sure we don't process a (mostly) empty string
        if clean_string(filename) == '':
            return

        from guessit.plugins import transformers

        try:
            mtree = self.match_tree
            if 'type' in self.options:
                mtree.guess.set('type', self.options['type'], confidence=0.0)

            # Process
            for transformer in transformers.all_transformers():
                self._process(transformer, False)

            # Post-process
            for transformer in transformers.all_transformers():
                self._process(transformer, True)

            log.debug('Found match tree:\n%s' % u(mtree))
        except TransformerException as e:
            log.debug('An error has occured in Transformer %s: %s' % (e.transformer, e))
Beispiel #7
0
def _supported_properties():
    all_properties = defaultdict(list)
    transformers_properties = []
    for transformer in transformers.all_transformers():
        supported_properties = transformer.supported_properties()
        transformers_properties.append((transformer, supported_properties))

        if isinstance(supported_properties, dict):
            for property_name, possible_values in supported_properties.items():
                all_properties[property_name].extend(possible_values)
        else:
            for property_name in supported_properties:
                all_properties[property_name]  # just make sure it exists

    return (all_properties, transformers_properties)
Beispiel #8
0
def _supported_properties():
    all_properties = defaultdict(list)
    transformers_properties = []
    for transformer in transformers.all_transformers():
        supported_properties = transformer.supported_properties()
        transformers_properties.append((transformer, supported_properties))

        if isinstance(supported_properties, dict):
            for property_name, possible_values in supported_properties.items():
                all_properties[property_name].extend(possible_values)
        else:
            for property_name in supported_properties:
                all_properties[property_name] # just make sure it exists

    return (all_properties, transformers_properties)
def best_quality(*guesses):
    """Retrieve the best quality guess.

    :param guesses: Guesses to rate
    :type guesses: :class:`guessit.guess.Guess`

    :return: Best quality guess from all passed guesses
    :rtype: :class:`guessit.guess.Guess`
    """
    best_guess = None
    best_rate = None
    for guess in guesses:
        for transformer in all_transformers():
            rate = transformer.rate_quality(guess)
            if best_rate is None or best_rate < rate:
                best_rate = rate
                best_guess = guess
    return best_guess
def best_quality_properties(props, *guesses):
    """Retrieve the best quality guess, based on given properties

    :param props: Properties to include in the rating
    :type props: list of strings
    :param guesses: Guesses to rate
    :type guesses: :class:`guessit.guess.Guess`

    :return: Best quality guess from all passed guesses
    :rtype: :class:`guessit.guess.Guess`
    """
    best_guess = None
    best_rate = None
    for guess in guesses:
        for transformer in all_transformers():
            rate = transformer.rate_quality(guess, *props)
            if best_rate is None or best_rate < rate:
                best_rate = rate
                best_guess = guess
    return best_guess