How to use the guessit.guess.Guess 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 guessit-io / guessit / guessit / newmatcher.py View on Github external
props = [ leaf for leaf in mtree.leaves()
              if (leaf.node_idx <= (len(mtree.children)-3,) and
                  ('videoCodec' in leaf.guess or
                   'format' in leaf.guess or
                   'language' in leaf.guess)) ]

    leftover = None
    if props:
        group_idx = props[0].node_idx[0]
        if all(g.node_idx[0] == group_idx for g in props):
            # if they're all in the same group, take leftover info from there
            leftover = mtree.node_at((group_idx,)).unidentified_leaves()

    if props and leftover:
        title_candidate = leftover[0]
        title_candidate.guess = Guess({ 'title': title_candidate.value }, confidence = 0.7)
    else:
        # first leftover group in the last path part sounds like a good candidate for title,
        # except if it's only one word and that the first group before has at least 3 words in it
        # (case where the filename contains an 8 chars short name and the movie title is
        #  actually in the parent directory name)
        leftover = mtree.node_at((-2,)).unidentified_leaves()
        try:
            previous_pgroup_leftover = mtree.node_at((-3,)).unidentified_leaves()
        except:
            previous_pgroup_leftover = []

        if leftover:
            title_candidate = leftover[0]

            if (title_candidate.clean_value.count(' ') == 0 and
                previous_pgroup_leftover and
github caronc / nzb-subliminal / Subliminal / guessit / __init__.py View on Github external
for infotype in info:
        if infotype == 'filename':
            result.append(_guess_filename(filename, options, **kwargs))

        elif infotype == 'hash_mpc':
            from guessit.hash_mpc import hash_file
            try:
                result.append(Guess({infotype: hash_file(filename)},
                                    confidence=1.0))
            except Exception as e:
                log.warning('Could not compute MPC-style hash because: %s' % e)

        elif infotype == 'hash_ed2k':
            from guessit.hash_ed2k import hash_file
            try:
                result.append(Guess({infotype: hash_file(filename)},
                                    confidence=1.0))
            except Exception as e:
                log.warning('Could not compute ed2k hash because: %s' % e)

        elif infotype.startswith('hash_'):
            import hashlib
            hashname = infotype[5:]
            try:
                hasher = getattr(hashlib, hashname)()
                hashers.append((infotype, hasher))
            except AttributeError:
                log.warning('Could not compute %s hash because it is not available from python\'s hashlib module' % hashname)

        elif infotype == 'video':
            g = guess_video_metadata(filename)
            if g:
github nzbget / VideoSort / lib / guessit / matcher.py View on Github external
def build_guess(node, name, value=None, confidence=1.0):
    guess = Guess({name: node.clean_value if value is None else value}, confidence=confidence)
    if value is None:
        guess.metadata().span = node.span
    guess.metadata().input = node.value if value is None else value
    return guess
github mdhiggins / sickbeard_mp4_automator / guessit / matcher.py View on Github external
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)
                        node.partition(span)
                        if node.is_leaf():
                            found_guess(node, guess, logger=self.logger)
                        else:
                            found_child = None
                            for child in node.children:
                                if child.span == absolute_span:
                                    found_guess(child, guess, logger=self.logger)
                                    found_child = child
                                    break
                            for child in node.children:
github guessit-io / guessit / guessit / transfo / guess_filetype.py View on Github external
filetype_container[0] = 'info'

        # look at the extension first
        fileext = os.path.splitext(filename)[1][1:].lower()
        if fileext in subtitle_exts:
            upgrade_subtitle()
            other = {'container': fileext}
        elif fileext in info_exts:
            upgrade_info()
            other = {'container': fileext}
        elif fileext in video_exts:
            other = {'container': fileext}
        else:
            if fileext and not options.get('name_only'):
                other = {'extension': fileext}
                list(mtree.unidentified_leaves())[-1].guess = Guess(other)

        # check whether we are in a 'Movies', 'Tv Shows', ... folder
        folder_rexps = [(r'Movies?', upgrade_movie),
                        (r'Films?', upgrade_movie),
                        (r'Tv[ _-]?Shows?', upgrade_episode),
                        (r'Series?', upgrade_episode),
                        (r'Episodes?', upgrade_episode)]
        for frexp, upgrade_func in folder_rexps:
            frexp = re.compile(frexp, re.IGNORECASE)
            for pathgroup in mtree.children:
                if frexp.match(pathgroup.value):
                    upgrade_func()
                    return filetype_container[0], other

        # check for a few specific cases which will unintentionally make the
        # following heuristics confused (eg: OSS 117 will look like an episode,
github guessit-io / guessit / guessit / newmatcher.py View on Github external
# (case where the filename contains an 8 chars short name and the movie title is
        #  actually in the parent directory name)
        leftover = mtree.node_at((-2,)).unidentified_leaves()
        try:
            previous_pgroup_leftover = mtree.node_at((-3,)).unidentified_leaves()
        except:
            previous_pgroup_leftover = []

        if leftover:
            title_candidate = leftover[0]

            if (title_candidate.clean_value.count(' ') == 0 and
                previous_pgroup_leftover and
                previous_pgroup_leftover[0].clean_value.count(' ') >= 2):

                previous_pgroup_leftover[0].guess = Guess({ 'title': previous_pgroup_leftover[0].clean_value },
                                                          confidence = 0.6)
            else:
                title_candidate.guess = Guess({ 'title': title_candidate.clean_value },
                                              confidence = 0.6)

        else:
            # if there were no leftover groups in the last path part, look in the one before that
            if previous_pgroup_leftover:
                title_candidate = previous_pgroup_leftover[0]
                title_candidate.guess = Guess({ 'title': title_candidate.clean_string },
                                              confidence = 0.6)
github nzbget / VideoSort / lib / guessit / language.py View on Github external
#    continue

        # confidence depends on alpha2, alpha3, english name, ...
        if len(lang) == 2:
            confidence = 0.8
        elif len(lang) == 3:
            confidence = 0.9
        elif prop == 'subtitleLanguage':
            confidence = 0.6  # Subtitle prefix found with language
        else:
            # Note: we could either be really confident that we found a
            #       language or assume that full language names are too
            #       common words and lower their confidence accordingly
            confidence = 0.3  # going with the low-confidence route here

        return Guess({prop: language}, confidence=confidence, input=string, span=(pos, end))

    return None
github pymedusa / Medusa / lib / guessit / matcher.py View on Github external
def build_guess(node, name, value=None, confidence=1.0):
    guess = Guess({name: node.clean_value if value is None else value}, confidence=confidence)
    guess.metadata().input = node.value if value is None else value
    if value is None:
        left_offset = 0
        right_offset = 0

        clean_value = node.clean_value

        if clean_value:
            for i in range(0, len(node.value)):
                if clean_value[0] == node.value[i]:
                    break
                left_offset += 1

            for i in reversed(range(0, len(node.value))):
                if clean_value[-1] == node.value[i]:
                    break
github pymedusa / Medusa / lib / guessit / matcher.py View on Github external
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)
                        node.partition(span)
                        if node.is_leaf():
                            found_guess(node, guess, logger=self.logger)
                        else:
                            found_child = None
                            for child in node.children:
                                if child.span == absolute_span:
                                    found_guess(child, guess, logger=self.logger)
                                    found_child = child
                                    break
                            for child in node.children: