# Path: Subliminal/subliminal/video.py
# class Episode(Video):
#     """Episode :class:`Video`
# 
#     Scores are defined by a set of equations, see :func:`~subliminal.score.get_episode_equations`
# 
#     :param string series: series of the episode
#     :param int season: season number of the episode
#     :param int episode: episode number of the episode
#     :param string title: title of the episode
#     :param int tvdb_id: TheTVDB id of the episode
# 
#     """
#     scores = {'title': 12, 'video_codec': 2, 'imdb_id': 35, 'audio_codec': 1, 'tvdb_id': 23, 'resolution': 2,
#               'season': 6, 'release_group': 6, 'series': 23, 'episode': 6, 'hash': 46}
# 
#     def __init__(self, name, series, season, episode, release_group=None, resolution=None, video_codec=None,
#                  audio_codec=None, imdb_id=None, hashes=None, size=None, subtitle_languages=None, title=None,
#                  tvdb_id=None):
#         super(Episode, self).__init__(name, release_group, resolution, video_codec, audio_codec, imdb_id, hashes,
#                                       size, subtitle_languages)
#         self.series = series
#         self.season = season
#         self.episode = episode
#         self.title = title
#         self.tvdb_id = tvdb_id
# 
#     @classmethod
#     def fromguess(cls, name, guess):
#         if guess['type'] != 'episode':
#             raise ValueError('The guess must be an episode guess')
#         if 'series' not in guess or 'season' not in guess or 'episodeNumber' not in guess:
#             raise ValueError('Insufficient data to process the guess')
#         return cls(name, guess['series'], guess['season'], guess['episodeNumber'],
#                    release_group=guess.get('releaseGroup'), resolution=guess.get('screenSize'),
#                    video_codec=guess.get('videoCodec'), audio_codec=guess.get('audioCodec'),
#                    title=guess.get('title'))
# 
#     def __repr__(self):
#         return '<%s [%r, %rx%r]>' % (self.__class__.__name__, self.series, self.season, self.episode)
# 
#     def __hash__(self):
#         return hash((
#             self.series,
#             self.season,
#             self.episode,
#         ))
# 
#     def __eq__(self, other):
#         return self.__class__.__name__ == other.__class__.__name__\
#                 and self.series == other.series\
#                 and self.season == other.season\
#                 and self.episode == other.episode
# 
# class Movie(Video):
#     """Movie :class:`Video`
# 
#     Scores are defined by a set of equations, see :func:`~subliminal.score.get_movie_equations`
# 
#     :param string title: title of the movie
#     :param int year: year of the movie
# 
#     """
#     scores = {'title': 13, 'video_codec': 2, 'resolution': 2, 'audio_codec': 1, 'year': 7, 'imdb_id': 31,
#               'release_group': 6, 'hash': 31}
# 
#     def __init__(self, name, title, release_group=None, resolution=None, video_codec=None, audio_codec=None,
#                  imdb_id=None, hashes=None, size=None, subtitle_languages=None, year=None):
#         super(Movie, self).__init__(name, release_group, resolution, video_codec, audio_codec, imdb_id, hashes,
#                                     size, subtitle_languages)
#         self.title = title
#         self.year = year
# 
#     @classmethod
#     def fromguess(cls, name, guess):
#         if guess['type'] != 'movie':
#             raise ValueError('The guess must be a movie guess')
#         if 'title' not in guess:
#             raise ValueError('Insufficient data to process the guess')
#         return cls(name, guess['title'], release_group=guess.get('releaseGroup'), resolution=guess.get('screenSize'),
#                    video_codec=guess.get('videoCodec'), audio_codec=guess.get('audioCodec'),
#                    year=guess.get('year'))
# 
#     def __repr__(self):
#         if self.year is None:
#             return '<%s [%r]>' % (self.__class__.__name__, self.title)
#         return '<%s [%r, %r]>' % (self.__class__.__name__, self.title, self.year)
# 
#     def __hash__(self):
#         if self.year is None:
#             return hash((
#                 self.title,
#                 self.year,
#             ))
#         return hash(self.title)
# 
#     def __eq__(self, other):
#         return self.__class__.__name__ == other.__class__.__name__\
#                 and self.title == other.title\
#                 and self.year == other.year


import logging
import os.path
import babelfish
import pysrt
import re
from .video import Episode, Movie
from chardet import detect as chardet_detect
from chared.detector import get_model_path, EncodingDetector
def is_valid_subtitle(subtitle_text):
    """Check if a subtitle text is a valid SubRip format

    :return: `True` if the subtitle is valid, `False` otherwise
    :rtype: bool

    """
    try:
        pysrt.from_string(subtitle_text, error_handling=pysrt.ERROR_RAISE)
        return True
    except pysrt.Error as e:
        if e.args[0] > 80:
            return True
    except:
        logger.exception('Unexpected error when validating subtitle')
    return False


def compute_guess_matches(video, guess):
    """Compute matches between a `video` and a `guess`

    :param video: the video to compute the matches on
    :type video: :class:`~subliminal.video.Video`
    :param guess: the guess to compute the matches on
    :type guess: :class:`guessit.Guess`
    :return: matches of the `guess`
    :rtype: set

    """
    matches = set()

# Path: Subliminal/subliminal/video.py
# class Episode(Video):
#     """Episode :class:`Video`
# 
#     Scores are defined by a set of equations, see :func:`~subliminal.score.get_episode_equations`
# 
#     :param string series: series of the episode
#     :param int season: season number of the episode
#     :param int episode: episode number of the episode
#     :param string title: title of the episode
#     :param int tvdb_id: TheTVDB id of the episode
# 
#     """
#     scores = {'title': 12, 'video_codec': 2, 'imdb_id': 35, 'audio_codec': 1, 'tvdb_id': 23, 'resolution': 2,
#               'season': 6, 'release_group': 6, 'series': 23, 'episode': 6, 'hash': 46}
# 
#     def __init__(self, name, series, season, episode, release_group=None, resolution=None, video_codec=None,
#                  audio_codec=None, imdb_id=None, hashes=None, size=None, subtitle_languages=None, title=None,
#                  tvdb_id=None):
#         super(Episode, self).__init__(name, release_group, resolution, video_codec, audio_codec, imdb_id, hashes,
#                                       size, subtitle_languages)
#         self.series = series
#         self.season = season
#         self.episode = episode
#         self.title = title
#         self.tvdb_id = tvdb_id
# 
#     @classmethod
#     def fromguess(cls, name, guess):
#         if guess['type'] != 'episode':
#             raise ValueError('The guess must be an episode guess')
#         if 'series' not in guess or 'season' not in guess or 'episodeNumber' not in guess:
#             raise ValueError('Insufficient data to process the guess')
#         return cls(name, guess['series'], guess['season'], guess['episodeNumber'],
#                    release_group=guess.get('releaseGroup'), resolution=guess.get('screenSize'),
#                    video_codec=guess.get('videoCodec'), audio_codec=guess.get('audioCodec'),
#                    title=guess.get('title'))
# 
#     def __repr__(self):
#         return '<%s [%r, %rx%r]>' % (self.__class__.__name__, self.series, self.season, self.episode)
# 
#     def __hash__(self):
#         return hash((
#             self.series,
#             self.season,
#             self.episode,
#         ))
# 
#     def __eq__(self, other):
#         return self.__class__.__name__ == other.__class__.__name__\
#                 and self.series == other.series\
#                 and self.season == other.season\
#                 and self.episode == other.episode
# 
# class Movie(Video):
#     """Movie :class:`Video`
# 
#     Scores are defined by a set of equations, see :func:`~subliminal.score.get_movie_equations`
# 
#     :param string title: title of the movie
#     :param int year: year of the movie
# 
#     """
#     scores = {'title': 13, 'video_codec': 2, 'resolution': 2, 'audio_codec': 1, 'year': 7, 'imdb_id': 31,
#               'release_group': 6, 'hash': 31}
# 
#     def __init__(self, name, title, release_group=None, resolution=None, video_codec=None, audio_codec=None,
#                  imdb_id=None, hashes=None, size=None, subtitle_languages=None, year=None):
#         super(Movie, self).__init__(name, release_group, resolution, video_codec, audio_codec, imdb_id, hashes,
#                                     size, subtitle_languages)
#         self.title = title
#         self.year = year
# 
#     @classmethod
#     def fromguess(cls, name, guess):
#         if guess['type'] != 'movie':
#             raise ValueError('The guess must be a movie guess')
#         if 'title' not in guess:
#             raise ValueError('Insufficient data to process the guess')
#         return cls(name, guess['title'], release_group=guess.get('releaseGroup'), resolution=guess.get('screenSize'),
#                    video_codec=guess.get('videoCodec'), audio_codec=guess.get('audioCodec'),
#                    year=guess.get('year'))
# 
#     def __repr__(self):
#         if self.year is None:
#             return '<%s [%r]>' % (self.__class__.__name__, self.title)
#         return '<%s [%r, %r]>' % (self.__class__.__name__, self.title, self.year)
# 
#     def __hash__(self):
#         if self.year is None:
#             return hash((
#                 self.title,
#                 self.year,
#             ))
#         return hash(self.title)
# 
#     def __eq__(self, other):
#         return self.__class__.__name__ == other.__class__.__name__\
#                 and self.title == other.title\
#                 and self.year == other.year


# Path: Subliminal/subliminal/subtitle.py
import logging
import os.path
import babelfish
import pysrt
import re
from .video import Episode, Movie
from chardet import detect as chardet_detect
from chared.detector import get_model_path, EncodingDetector

def is_valid_subtitle(subtitle_text):
    """Check if a subtitle text is a valid SubRip format

    :return: `True` if the subtitle is valid, `False` otherwise
    :rtype: bool

    """
    try:
        pysrt.from_string(subtitle_text, error_handling=pysrt.ERROR_RAISE)
        return True
    except pysrt.Error as e:
        if e.args[0] > 80:
            return True
    except:
        logger.exception('Unexpected error when validating subtitle')
    return False


def compute_guess_matches(video, guess):
    """Compute matches between a `video` and a `guess`

    :param video: the video to compute the matches on
    :type video: :class:`~subliminal.video.Video`
    :param guess: the guess to compute the matches on
    :type guess: :class:`guessit.Guess`
    :return: matches of the `guess`
    :rtype: set

    """
    matches = set()

    if isinstance(video, Episode):