Exemplo n.º 1
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(OpenSubtitlesSubtitle, self).get_matches(video)

        type_ = "episode" if isinstance(video, Episode) else "movie"
        matches |= guess_matches(
            video, guessit(self.movie_release_name, {'type': type_}))
        matches |= guess_matches(video, guessit(self.filename,
                                                {'type': type_}))

        # episode
        if type_ == "episode" and self.movie_kind == "episode":
            # series
            if fix_tv_naming(video.series) and (sanitize(self.series_name) in (
                    sanitize(name) for name in [fix_tv_naming(video.series)] +
                    video.alternative_series)):
                matches.add('series')
        # movie
        elif type_ == "movie" and self.movie_kind == "movie":
            # title
            if fix_movie_naming(video.title) and (sanitize(
                    self.movie_name) in (
                        sanitize(name)
                        for name in [fix_movie_naming(video.title)] +
                        video.alternative_titles)):
                matches.add('title')

        sub_fps = None
        try:
            sub_fps = float(self.fps)
        except ValueError:
            pass

        # video has fps info, sub also, and sub's fps is greater than 0
        if video.fps and sub_fps and not framerate_equal(video.fps, self.fps):
            self.wrong_fps = True

            if self.skip_wrong_fps:
                logger.debug(
                    "Wrong FPS (expected: %s, got: %s, lowering score massively)",
                    video.fps, self.fps)
                # fixme: may be too harsh
                return set()
            else:
                logger.debug("Wrong FPS (expected: %s, got: %s, continuing)",
                             video.fps, self.fps)

        # matched by tag?
        if self.matched_by == "tag":
            # treat a tag match equally to a hash match
            logger.debug(
                "Subtitle matched by tag, treating it as a hash-match. Tag: '%s'",
                self.query_parameters.get("tag", None))
            matches.add("hash")

        # imdb_id match so we'll consider year as matching
        if self.movie_imdb_id and video.imdb_id and (self.movie_imdb_id
                                                     == video.imdb_id):
            matches.add("year")

        return matches
Exemplo n.º 2
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(OpenSubtitlesSubtitle, self).get_matches(video)

        sub_fps = None
        try:
            sub_fps = float(self.fps)
        except ValueError:
            pass

        # video has fps info, sub also, and sub's fps is greater than 0
        if video.fps and sub_fps and not framerate_equal(video.fps, self.fps):
            self.wrong_fps = True

            if self.skip_wrong_fps:
                logger.debug(
                    "Wrong FPS (expected: %s, got: %s, lowering score massively)",
                    video.fps, self.fps)
                # fixme: may be too harsh
                return set()
            else:
                logger.debug("Wrong FPS (expected: %s, got: %s, continuing)",
                             video.fps, self.fps)

        # matched by tag?
        if self.matched_by == "tag":
            # treat a tag match equally to a hash match
            logger.debug(
                "Subtitle matched by tag, treating it as a hash-match. Tag: '%s'",
                self.query_parameters.get("tag", None))
            matches.add("hash")

        return matches
Exemplo n.º 3
0
    def get_matches(self, video):
        matches = set()

        if isinstance(video, Movie):
            # title
            if video.title and sanitize(self.title) == sanitize(video.title):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')
            # imdb id
            if video.imdb_id and self.imdb_id == video.imdb_id:
                matches.add('imdb_id')
            # fps
            if video.fps and self.fps and not framerate_equal(
                    video.fps, self.fps):
                logger.warning("nekur: Wrong FPS (expected: %s, got: %s)",
                               video.fps, self.fps)
            # guess additional info from notes
            matches |= guess_matches(video,
                                     guessit(self.notes, {'type': 'movie'}),
                                     partial=True)

        self.matches = matches
        return matches
Exemplo n.º 4
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(OpenSubtitlesSubtitle, self).get_matches(video)

        # episode
        if isinstance(video, Episode) and self.movie_kind == 'episode':
            # series
            if video.series and (sanitize(self.series_name) in (
                    sanitize(name)
                    for name in [video.series] + video.alternative_series)):
                matches.add('series')
        # movie
        elif isinstance(video, Movie) and self.movie_kind == 'movie':
            # title
            if video.title and (sanitize(self.movie_name) in (
                    sanitize(name)
                    for name in [video.title] + video.alternative_titles)):
                matches.add('title')

        sub_fps = None
        try:
            sub_fps = float(self.fps)
        except ValueError:
            pass

        # video has fps info, sub also, and sub's fps is greater than 0
        if video.fps and sub_fps and not framerate_equal(video.fps, self.fps):
            self.wrong_fps = True

            if self.skip_wrong_fps:
                logger.debug(
                    "Wrong FPS (expected: %s, got: %s, lowering score massively)",
                    video.fps, self.fps)
                # fixme: may be too harsh
                return set()
            else:
                logger.debug("Wrong FPS (expected: %s, got: %s, continuing)",
                             video.fps, self.fps)

        # matched by tag?
        if self.matched_by == "tag":
            # treat a tag match equally to a hash match
            logger.debug(
                "Subtitle matched by tag, treating it as a hash-match. Tag: '%s'",
                self.query_parameters.get("tag", None))
            matches.add("hash")

        return matches
Exemplo n.º 5
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(OpenSubtitlesSubtitle, self).get_matches(video)

        # episode
        if isinstance(video, Episode) and self.movie_kind == 'episode':
            # series
            if video.series and (sanitize(self.series_name) in (
                    sanitize(name) for name in [video.series] + video.alternative_series)):
                matches.add('series')
        # movie
        elif isinstance(video, Movie) and self.movie_kind == 'movie':
            # title
            if video.title and (sanitize(self.movie_name) in (
                    sanitize(name) for name in [video.title] + video.alternative_titles)):
                matches.add('title')

        sub_fps = None
        try:
            sub_fps = float(self.fps)
        except ValueError:
            pass

        # video has fps info, sub also, and sub's fps is greater than 0
        if video.fps and sub_fps and not framerate_equal(video.fps, self.fps):
            self.wrong_fps = True

            if self.skip_wrong_fps:
                logger.debug("Wrong FPS (expected: %s, got: %s, lowering score massively)", video.fps, self.fps)
                # fixme: may be too harsh
                return set()
            else:
                logger.debug("Wrong FPS (expected: %s, got: %s, continuing)", video.fps, self.fps)

        # matched by tag?
        if self.matched_by == "tag":
            # treat a tag match equally to a hash match
            logger.debug("Subtitle matched by tag, treating it as a hash-match. Tag: '%s'",
                         self.query_parameters.get("tag", None))
            matches.add("hash")

        return matches
Exemplo n.º 6
0
    def get_matches(self, video):
        matches = set()
        _type = 'movie' if isinstance(video, Movie) else 'episode'

        sub_names = self._remove_season_episode_string(self.names)

        if _type == 'episode':
            ## EPISODE

            # match imdb_id of a series
            if video.series_imdb_id and video.series_imdb_id == self.imdb_id:
                matches.add('series_imdb_id')

            # match season/episode
            if self.season and self.season == video.season:
                matches.add('season')
            if self.episode and self.episode == video.episode:
                matches.add('episode')

            # match series name
            series_names = [video.series] + video.alternative_series
            logger.debug(
                f"Titulky.com: Finding exact match between subtitle names {sub_names} and series names {series_names}"
            )
            if _contains_element(_from=series_names,
                                 _in=sub_names,
                                 exactly=True):
                matches.add('series')

            # match episode title
            episode_titles = [video.title]
            logger.debug(
                f"Titulky.com: Finding exact match between subtitle names {sub_names} and episode titles {episode_titles}"
            )
            if _contains_element(_from=episode_titles,
                                 _in=sub_names,
                                 exactly=True):
                matches.add('episode_title')

        elif _type == 'movie':
            ## MOVIE

            # match imdb_id of a movie
            if video.imdb_id and video.imdb_id == self.imdb_id:
                matches.add('imdb_id')

            # match movie title
            video_titles = [video.title] + video.alternative_titles
            logger.debug(
                f"Titulky.com: Finding exact match between subtitle names {sub_names} and video titles {video_titles}"
            )
            if _contains_element(_from=video_titles,
                                 _in=sub_names,
                                 exactly=True):
                matches.add('title')

        ## MOVIE OR EPISODE

        # match year
        if video.year and video.year == self.year:
            matches.add('year')

        # match other properties based on release infos
        for release in self.releases:
            matches |= guess_matches(video, guessit(release, {"type": _type}))

        # If turned on in settings, then do not match if video FPS is not equal to subtitle FPS
        if self.skip_wrong_fps and video.fps and self.fps and not framerate_equal(
                video.fps, self.fps):
            logger.info(f"Titulky.com: Skipping subtitle {self}: wrong FPS")
            matches.clear()

        self.matches = matches

        return matches
Exemplo n.º 7
0
    def get_matches(self, video):
        matches = set()

        # if skip_wrong_fps = True no point to continue if they don't match
        subtitle_fps = None
        try:
            subtitle_fps = float(self.sub_frame_rate)
        except ValueError:
            pass

        # check fps match and skip based on configuration
        if video.fps and subtitle_fps and not framerate_equal(
                video.fps, subtitle_fps):
            self.wrong_fps = True

            if self.skip_wrong_fps:
                logger.debug(
                    "Legendasdivx :: Skipping subtitle due to FPS mismatch (expected: %s, got: %s)",
                    video.fps, self.sub_frame_rate)
                # not a single match :)
                return set()
            logger.debug(
                "Legendasdivx :: Frame rate mismatch (expected: %s, got: %s, but continuing...)",
                video.fps, self.sub_frame_rate)

        description = sanitize(self.description)

        video_filename = video.name
        video_filename = os.path.basename(video_filename)
        video_filename, _ = os.path.splitext(video_filename)
        video_filename = sanitize_release_group(video_filename)

        if sanitize(video_filename) in description:
            matches.update(['title'])
            # relying people won' use just S01E01 for the file name
            if isinstance(video, Episode):
                matches.update(['series'])
                matches.update(['season'])
                matches.update(['episode'])

        # can match both movies and series
        if video.year and '{:04d}'.format(video.year) in description:
            matches.update(['year'])

        # match movie title (include alternative movie names)
        if isinstance(video, Movie):
            if video.title:
                for movie_name in [video.title] + video.alternative_titles:
                    if sanitize(movie_name) in description:
                        matches.update(['title'])

        if isinstance(video, Episode):
            if video.title and sanitize(video.title) in description:
                matches.update(['title'])
            if video.series:
                for series_name in [video.series] + video.alternative_series:
                    if sanitize(series_name) in description:
                        matches.update(['series'])
            if video.season and 's{:02d}'.format(video.season) in description:
                matches.update(['season'])
            if video.episode and 'e{:02d}'.format(
                    video.episode) in description:
                matches.update(['episode'])

        # release_group
        if video.release_group and sanitize_release_group(
                video.release_group) in sanitize_release_group(description):
            matches.update(['release_group'])

        # resolution
        if video.resolution and video.resolution.lower() in description:
            matches.update(['resolution'])

        # source
        formats = []
        if video.source:
            formats = [video.source.lower()]
            if formats[0] == "web":
                formats.append("webdl")
                formats.append("webrip")
                formats.append("web")
            for frmt in formats:
                if frmt in description:
                    matches.update(['source'])
                    break

        # video_codec
        if video.video_codec:
            video_codecs = [video.video_codec.lower()]
            if video_codecs[0] == "H.264":
                video_codecs.append("x264")
            elif video_codecs[0] == "H.265":
                video_codecs.append("x265")
            for vc in video_codecs:
                if vc in description:
                    matches.update(['video_codec'])
                    break

        return matches
Exemplo n.º 8
0
    def get_matches(self, video):
        matches = set()

        # if skip_wrong_fps = True no point to continue if they don't match
        subtitle_fps = None
        try:
            subtitle_fps = float(self.sub_frame_rate)
        except ValueError:
            pass

        # check fps match and skip based on configuration
        if video.fps and subtitle_fps and not framerate_equal(video.fps, subtitle_fps):
            self.wrong_fps = True

            if self.skip_wrong_fps:
                logger.debug("Legendasdivx :: Skipping subtitle due to FPS mismatch (expected: %s, got: %s)", video.fps, self.sub_frame_rate)
                # not a single match :)
                return set()
            logger.debug("Legendasdivx :: Frame rate mismatch (expected: %s, got: %s, but continuing...)", video.fps, self.sub_frame_rate)

        description = sanitize(self.description)

        video_filename = video.name
        video_filename = os.path.basename(video_filename)
        video_filename, _ = os.path.splitext(video_filename)
        video_filename = sanitize_release_group(video_filename)

        if sanitize(video_filename) in description:
            matches.update(['title'])
            # relying people won' use just S01E01 for the file name
            if isinstance(video, Episode):
                matches.update(['series'])
                matches.update(['season'])
                matches.update(['episode'])

        # can match both movies and series
        if video.year and '{:04d}'.format(video.year) in description:
            matches.update(['year'])

        type_ = "movie" if isinstance(video, Movie) else "episode"
        # match movie title (include alternative movie names)
        if type_ == "movie":
            if video.title:
                for movie_name in [video.title] + video.alternative_titles:
                    if sanitize(movie_name) in description:
                        matches.update(['title'])

        else:
            if video.title and sanitize(video.title) in description:
                matches.update(['title'])
            if video.series:
                for series_name in [video.series] + video.alternative_series:
                    if sanitize(series_name) in description:
                        matches.update(['series'])
            if video.season and 's{:02d}'.format(video.season) in description:
                matches.update(['season'])
            if video.episode and 'e{:02d}'.format(video.episode) in description:
                matches.update(['episode'])

        # release_group
        if video.release_group and sanitize_release_group(video.release_group) in sanitize_release_group(description):
            matches.update(['release_group'])

        matches |= guess_matches(video, guessit(description, {"type": type_}))

        return matches