How to use the rebulk.match.Match function in rebulk

To help you get started, we’ve selected a few rebulk 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 guessit-io / guessit / guessit / rules / properties / type.py View on Github external
def _type(matches, value):
    """
    Define type match with given value.
    :param matches:
    :param value:
    :return:
    """
    matches.append(Match(len(matches.input_string), len(matches.input_string), name='type', value=value))
github Toilal / rebulk / rebulk / pattern.py View on Github external
end = match_object.end()
            main_match = Match(start, end, pattern=self, input_string=input_string, **self._match_kwargs)

            if pattern.groups:
                for i in range(1, pattern.groups + 1):
                    name = names.get(i, main_match.name)
                    if self.repeated_captures:
                        for start, end in match_object.spans(i):
                            child_match = Match(start, end, name=name, parent=main_match, pattern=self,
                                                input_string=input_string, **self._children_match_kwargs)
                            if child_match:
                                main_match.children.append(child_match)
                    else:
                        start, end = match_object.span(i)
                        if start > -1 and end > -1:
                            child_match = Match(start, end, name=name, parent=main_match, pattern=self,
                                                input_string=input_string, **self._children_match_kwargs)
                            if child_match:
                                main_match.children.append(child_match)

            if main_match:
                yield main_match
github clinton-hall / nzbToMedia / libs / common / guessit / rules / properties / episodes.py View on Github external
to_remove.append(separator)

        previous_match = None
        for next_match in matches.named(self.property_name):
            if previous_match:
                separator = matches.input_string[previous_match.initiator.end:next_match.initiator.start]
                if separator not in self.range_separators:
                    separator = strip(separator)
                if separator in self.range_separators:
                    initiator = previous_match.initiator
                    for episode_number in range(previous_match.value + 1, next_match.value):
                        match = copy.copy(next_match)
                        match.value = episode_number
                        initiator.children.append(match)
                        to_append.append(match)
                    to_append.append(Match(previous_match.end, next_match.start - 1,
                                           name=self.property_name + 'Separator',
                                           private=True,
                                           input_string=matches.input_string))
                to_remove.append(next_match)  # Remove and append match to support proper ordering
                to_append.append(next_match)

            previous_match = next_match

        return to_remove, to_append
github Toilal / rebulk / rebulk / chain.py View on Github external
def _build_chain_match(self, current_chain_matches, input_string):
        start = None
        end = None
        for match in current_chain_matches:
            if start is None or start > match.start:
                start = match.start
            if end is None or end < match.end:
                end = match.end
        match = call(Match, start, end, pattern=self, input_string=input_string, **self._match_kwargs)
        for chain_match in current_chain_matches:
            if chain_match.children:
                for child in chain_match.children:
                    match.children.append(child)
            if chain_match not in match.children:
                match.children.append(chain_match)
                chain_match.parent = match
        return match
github h3llrais3r / Auto-Subliminal / lib / guessit / rules / properties / episodes.py View on Github external
to_append.append(match)
                to_append.append(next_match)
            to_remove.append(separator)

        previous_match = None
        for next_match in matches.named(self.property_name):
            if previous_match:
                separator = matches.input_string[previous_match.initiator.end:next_match.initiator.start]
                if separator not in self.range_separators:
                    separator = strip(separator)
                if separator in self.range_separators:
                    for episode_number in range(previous_match.value + 1, next_match.value):
                        match = copy.copy(next_match)
                        match.value = episode_number
                        to_append.append(match)
                    to_append.append(Match(previous_match.end, next_match.start - 1,
                                           name=self.property_name + 'Separator',
                                           private=True,
                                           input_string=matches.input_string))
                to_remove.append(next_match)  # Remove and append match to support proper ordering
                to_append.append(next_match)

            previous_match = next_match

        return to_remove, to_append
github clinton-hall / nzbToMedia / libs / guessit / rules / properties / release_group.py View on Github external
def when(self, matches, context):  # pylint:disable=inconsistent-return-statements
        if matches.named('release_group'):
            return

        to_remove = []
        to_append = []
        for filepart in matches.markers.named('path'):
            candidate = self.detect(matches, filepart.start, filepart.end, True)
            if candidate:
                to_remove.extend(matches.at_match(candidate))
            else:
                candidate = self.detect(matches, filepart.start, filepart.end, False)

            if candidate:
                releasegroup = Match(candidate.start, candidate.end, name='release_group',
                                     formatter=self.value_formatter, input_string=candidate.input_string)

                if releasegroup.value:
                    to_append.append(releasegroup)
                return to_remove, to_append
github morpheus65535 / bazarr / libs / guessit / jsonutils.py View on Github external
def default(self, o):  # pylint:disable=method-hidden
        if isinstance(o, Match):
            ret = OrderedDict()
            ret['value'] = o.value
            if o.raw:
                ret['raw'] = o.raw
            ret['start'] = o.start
            ret['end'] = o.end
            return ret
        elif hasattr(o, 'name'):  # Babelfish languages/countries long name
            return str(o.name)
        else:  # pragma: no cover
            return str(o)
github pymedusa / Medusa / ext / guessit / rules / properties / mimetype.py View on Github external
def then(self, matches, when_response, context):
        mime = when_response
        matches.append(Match(len(matches.input_string), len(matches.input_string), name='mimetype', value=mime))
github guessit-io / guessit / guessit / rules / properties / release_group.py View on Github external
def when(self, matches, context):  # pylint:disable=inconsistent-return-statements
        if matches.named('release_group'):
            return

        to_remove = []
        to_append = []
        for filepart in matches.markers.named('path'):
            candidate = self.detect(matches, filepart.start, filepart.end, True)
            if candidate:
                to_remove.extend(matches.at_match(candidate))
            else:
                candidate = self.detect(matches, filepart.start, filepart.end, False)

            if candidate:
                releasegroup = Match(candidate.start, candidate.end, name='release_group',
                                     formatter=self.value_formatter, input_string=candidate.input_string)

                if releasegroup.value:
                    to_append.append(releasegroup)
                if to_remove or to_append:
                    return to_remove, to_append
github pymedusa / Medusa / ext / guessit / rules / properties / screen_size.py View on Github external
to_append.append(frame_rate)

            values = match.children.to_dict()
            if 'height' not in values:
                continue

            scan_type = (values.get('scan_type') or 'p').lower()
            height = values['height']
            if 'width' not in values:
                match.value = '{0}{1}'.format(height, scan_type)
                continue

            width = values['width']
            calculated_ar = float(width) / float(height)

            aspect_ratio = Match(match.start, match.end, input_string=match.input_string,
                                 name='aspect_ratio', value=round(calculated_ar, 3))

            if not is_disabled(context, 'aspect_ratio'):
                to_append.append(aspect_ratio)

            if height in self.standard_heights and self.min_ar < calculated_ar < self.max_ar:
                match.value = '{0}{1}'.format(height, scan_type)
            else:
                match.value = '{0}x{1}'.format(width, height)

        return to_append