Guess

class guessit.guess.Guess(*args, **kwargs)

A Guess is a dictionary which has an associated confidence for each of its values.

As it is a subclass of dict, you can use it everywhere you expect a simple dict.

metadata(prop=None)

Return the metadata associated with the given property name

If no property name is given, get the global_metadata

nice_string(advanced=False)

Return a string with the property names and their values, that also displays the associated confidence to each property.

FIXME: doc with param

to_dict(advanced=False)

Return the guess as a dict containing only base types, ie: where dates, languages, countries, etc. are converted to strings.

if advanced is True, return the data as a json string containing also the raw information of the properties.

update_highest_confidence(other)

Update this guess with the values from the given one. In case there is property present in both, only the one with the highest one is kept.

guessit.guess.choose_int(g1, g2)

Function used by merge_similar_guesses to choose between 2 possible properties when they are integers.

guessit.guess.choose_string(g1, g2)

Function used by merge_similar_guesses to choose between 2 possible properties when they are strings.

If the 2 strings are similar, or one is contained in the other, the latter is returned with an increased confidence.

If the 2 strings are dissimilar, the one with the higher confidence is returned, with a weaker confidence.

Note that here, ‘similar’ means that 2 strings are either equal, or that they differ very little, such as one string being the other one with the ‘the’ word prepended to it.

>>> s(choose_string(('Hello', 0.75), ('World', 0.5)))
('Hello', 0.25)
>>> s(choose_string(('Hello', 0.5), ('hello', 0.5)))
('Hello', 0.75)
>>> s(choose_string(('Hello', 0.4), ('Hello World', 0.4)))
('Hello', 0.64)
>>> s(choose_string(('simpsons', 0.5), ('The Simpsons', 0.5)))
('The Simpsons', 0.75)
guessit.guess.merge_similar_guesses(guesses, prop, choose)

Take a list of guesses and merge those which have the same properties, increasing or decreasing the confidence depending on whether their values are similar.

guessit.guess.merge_all(guesses, append=None)

Merge all the guesses in a single result, remove very unlikely values, and return it. You can specify a list of properties that should be appended into a list instead of being merged.

>>> s(merge_all([ Guess({'season': 2}, confidence=0.6),
...               Guess({'episodeNumber': 13}, confidence=0.8) ]))
{'season': 2, 'episodeNumber': 13}
>>> s(merge_all([ Guess({'episodeNumber': 27}, confidence=0.02),
...               Guess({'season': 1}, confidence=0.2) ]))
{'season': 1}
>>> s(merge_all([ Guess({'other': 'PROPER'}, confidence=0.8),
...               Guess({'releaseGroup': '2HD'}, confidence=0.8) ],
...             append=['other']))
{'releaseGroup': '2HD', 'other': ['PROPER']}

GuessIt is a python library that tries to extract as much information as possible from a file.

Related Topics

Fork me on GitHub