How to use the guessit.matchtree.MatchTree function in guessit

To help you get started, we’ve selected a few guessit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caronc / nzb-subliminal / Subliminal / guessit / matcher.py View on Github external
filename = normalize_unicode(filename)
        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():
github pymedusa / Medusa / lib / guessit / matcher.py View on Github external
filename = normalize_unicode(filename)
        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():
github h3llrais3r / Auto-Subliminal / lib / guessit / matcher.py View on Github external
filename = normalize_unicode(filename)
        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():
github guessit-io / guessit / guessit / matcher.py View on Github external
filename = normalize_unicode(filename)
        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():
github caronc / nzb-subliminal / Subliminal / guessit / matcher.py View on Github external
if partial_span:
                    span = (span[0] + partial_span[0], span[1] + partial_span[0])

                partition_spans = None
                if self.options and 'skip_nodes' in self.options:
                    skip_nodes = self.options.get('skip_nodes')
                    for skip_node in skip_nodes:
                        if skip_node.parent.node_idx == node.node_idx[:len(skip_node.parent.node_idx)] and\
                            skip_node.span == span or\
                                skip_node.span == (span[0] + skip_node.offset, span[1] + skip_node.offset):
                            if partition_spans is None:
                                partition_spans = _get_split_spans(node, skip_node.span)
                            else:
                                new_partition_spans = []
                                for partition_span in partition_spans:
                                    tmp_node = MatchTree(value, span=partition_span, parent=node)
                                    tmp_partitions_spans = _get_split_spans(tmp_node, skip_node.span)
                                    new_partition_spans.extend(tmp_partitions_spans)
                                partition_spans.extend(new_partition_spans)

                if not partition_spans:
                    # restore sentinels compensation

                    if isinstance(result, Guess):
                        guess = result
                    else:
                        guess = Guess(result, confidence=self.confidence, input=string, span=span)

                    if not iterative:
                        found_guess(node, guess, logger=self.logger)
                    else:
                        absolute_span = (span[0] + node.offset, span[1] + node.offset)
github guessit-io / guessit / guessit / matchtree.py View on Github external
def add_child(self, span, category=None):
        """Add a new child node to this node with the given span.

        :param span: span of the new MatchTree
        :param category: category of the new MatchTree
        :return: A new MatchTree instance having self as a parent
        """
        child = MatchTree(self.string, span=span, parent=self, clean_function=self._clean_function, category=category)
        self.children.append(child)
        return child
github pymedusa / Medusa / lib / guessit / matcher.py View on Github external
if partial_span:
                    span = (span[0] + partial_span[0], span[1] + partial_span[0])

                partition_spans = None
                if self.options and 'skip_nodes' in self.options:
                    skip_nodes = self.options.get('skip_nodes')
                    for skip_node in skip_nodes:
                        if skip_node.parent.node_idx == node.node_idx[:len(skip_node.parent.node_idx)] and\
                            skip_node.span == span or\
                                skip_node.span == (span[0] + skip_node.offset, span[1] + skip_node.offset):
                            if partition_spans is None:
                                partition_spans = _get_split_spans(node, skip_node.span)
                            else:
                                new_partition_spans = []
                                for partition_span in partition_spans:
                                    tmp_node = MatchTree(value, span=partition_span, parent=node)
                                    tmp_partitions_spans = _get_split_spans(tmp_node, skip_node.span)
                                    new_partition_spans.extend(tmp_partitions_spans)
                                partition_spans.extend(new_partition_spans)

                if not partition_spans:
                    # restore sentinels compensation

                    if isinstance(result, Guess):
                        guess = result
                    else:
                        guess = Guess(result, confidence=self.confidence, input=string, span=span)

                    if not iterative:
                        found_guess(node, guess, logger=self.logger)
                    else:
                        absolute_span = (span[0] + node.offset, span[1] + node.offset)
github mdhiggins / sickbeard_mp4_automator / guessit / matchtree.py View on Github external
def add_child(self, span):
        """Add a new child node to this node with the given span."""
        child = MatchTree(self.string, span=span, parent=self, clean_function=self._clean_function)
        self.children.append(child)
        return child
github nzbget / VideoSort / lib / guessit / matcher.py View on Github external
if partial_span:
                    span = (span[0] + partial_span[0], span[1] + partial_span[0])

                partition_spans = None
                if self.options and 'skip_nodes' in self.options:
                    skip_nodes = self.options.get('skip_nodes')
                    for skip_node in skip_nodes:
                        if skip_node.parent.node_idx == node.node_idx[:len(skip_node.parent.node_idx)] and\
                            skip_node.span == span or\
                                skip_node.span == (span[0] + skip_node.offset, span[1] + skip_node.offset):
                            if partition_spans is None:
                                partition_spans = _get_split_spans(node, skip_node.span)
                            else:
                                new_partition_spans = []
                                for partition_span in partition_spans:
                                    tmp_node = MatchTree(value, span=partition_span, parent=node)
                                    tmp_partitions_spans = _get_split_spans(tmp_node, skip_node.span)
                                    new_partition_spans.extend(tmp_partitions_spans)
                                partition_spans.extend(new_partition_spans)

                if not partition_spans:
                    # restore sentinels compensation

                    guess = None
                    if isinstance(result, Guess):
                        guess = result
                    else:
                        guess = Guess(result, confidence=self.confidence, input=string, span=span)

                    if not iterative:
                        found_guess(node, guess, logger=self.logger)
                    else:
github h3llrais3r / Auto-Subliminal / lib / guessit / matcher.py View on Github external
if partial_span:
                    span = (span[0] + partial_span[0], span[1] + partial_span[0])

                partition_spans = None
                if self.options and 'skip_nodes' in self.options:
                    skip_nodes = self.options.get('skip_nodes')
                    for skip_node in skip_nodes:
                        if skip_node.parent.node_idx == node.node_idx[:len(skip_node.parent.node_idx)] and\
                            skip_node.span == span or\
                                skip_node.span == (span[0] + skip_node.offset, span[1] + skip_node.offset):
                            if partition_spans is None:
                                partition_spans = _get_split_spans(node, skip_node.span)
                            else:
                                new_partition_spans = []
                                for partition_span in partition_spans:
                                    tmp_node = MatchTree(value, span=partition_span, parent=node)
                                    tmp_partitions_spans = _get_split_spans(tmp_node, skip_node.span)
                                    new_partition_spans.extend(tmp_partitions_spans)
                                partition_spans.extend(new_partition_spans)

                if not partition_spans:
                    # restore sentinels compensation

                    if isinstance(result, Guess):
                        guess = result
                    else:
                        guess = Guess(result, confidence=self.confidence, input=string, span=span)

                    if not iterative:
                        found_guess(node, guess, logger=self.logger)
                    else:
                        absolute_span = (span[0] + node.offset, span[1] + node.offset)