Subtitle

class subliminal.subtitle.Subtitle(language, hearing_impaired=False, page_link=None)[source]

Base class for subtitle.

Parameters:
  • language (Language) – language of the subtitle.
  • hearing_impaired (bool) – whether or not the subtitle is hearing impaired.
  • page_link (str) – URL of the web page from which the subtitle can be downloaded.
provider_name = u''

Name of the provider that returns that class of subtitle

language = None

Language of the subtitle

hearing_impaired = None

Whether or not the subtitle is hearing impaired

URL of the web page from which the subtitle can be downloaded

content = None

Content as bytes

encoding = None

Encoding to decode with when accessing text

id

Unique identifier of the subtitle.

text

Content as string.

If encoding is None, the encoding is guessed with guess_encoding()

is_valid()[source]

Check if a text is a valid SubRip format.

Returns:whether or not the subtitle is valid.
Return type:bool
guess_encoding()[source]

Guess encoding using the language, falling back on chardet.

Returns:the guessed encoding.
Return type:str
get_matches(video, hearing_impaired=False)[source]

Get the matches against the video.

Parameters:
  • video (Video) – the video to get the matches with.
  • hearing_impaired (bool) – hearing impaired preference.
Returns:

matches of the subtitle.

Return type:

set

subliminal.subtitle.compute_score(matches, video, scores=None)[source]

Compute the score of the matches against the video.

Some matches count as much as a combination of others in order to level the final score:

  • hash removes everything else
  • For Episode
    • imdb_id removes series, tvdb_id, season, episode, title and year
    • tvdb_id removes series and year
    • title removes season and episode
Parameters:
  • video (Video) – the video to get the score with.
  • scores (dict) – scores to use, if None, the scores from the video are used.
Returns:

score of the subtitle.

Return type:

int

subliminal.subtitle.get_subtitle_path(video_path, language=None, extension=u'.srt')[source]

Get the subtitle path using the video_path and language.

Parameters:
  • video_path (str) – path to the video.
  • language (Language) – language of the subtitle to put in the path.
  • extension (str) – extension of the subtitle.
Returns:

path of the subtitle.

Return type:

str

subliminal.subtitle.guess_matches(video, guess, partial=False)[source]

Get matches between a video and a guess.

If a guess is partial, the absence information won’t be counted as a match.

Parameters:
  • video (Video) – the video.
  • guess (dict) – the guess.
  • partial (bool) – whether or not the guess is partial.
Returns:

matches between the video and the guess.

Return type:

set

subliminal.subtitle.guess_properties(string)[source]

Extract properties from string using guessit’s guess_properties transformer.

Parameters:string (str) – the string potentially containing properties.
Returns:the guessed properties.
Return type:dict
subliminal.subtitle.fix_line_ending(content)[source]

Fix line ending of content by changing it to .

param bytes content:
 content of the subtitle.
return:the content with fixed line endings.
rtype:bytes