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

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

        # episode
        if isinstance(video, Episode):
            info = guessit(self.version, {"type": "episode"})
            # other properties
            matches |= guess_matches(video, info, partial=True)

            # add year to matches if video doesn't have a year but series, season and episode are matched
            if not video.year and all(
                    item in matches
                    for item in ['series', 'season', 'episode']):
                matches |= {'year'}
        # movie
        elif isinstance(video, Movie):
            # other properties
            matches |= guess_matches(video,
                                     guessit(self.version, {"type": "movie"}),
                                     partial=True)

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

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and sanitize(self.series) == sanitize(video.series):
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # imdb_id
            if video.series_imdb_id and self.imdb_id == video.series_imdb_id:
                matches.add('series_imdb_id')
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guessit(release, {'type': 'episode'}))
        # movie
        elif isinstance(video, Movie):
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guessit(release, {'type': 'movie'}))

        # title
        if video.title and sanitize(self.title) == sanitize(video.title):
            matches.add('title')

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

        video_filename = video.name
        video_filename = os.path.basename(video_filename)
        video_filename, _ = os.path.splitext(video_filename)
        video_filename = re.sub(r'\[\w+\]$', '',
                                video_filename).strip().upper()

        subtitle_filename = self.filename
        subtitle_filename = os.path.basename(subtitle_filename)
        subtitle_filename, _ = os.path.splitext(subtitle_filename)
        subtitle_filename = re.sub(r'\[\w+\]$', '',
                                   subtitle_filename).strip().upper()

        if ((video_filename == subtitle_filename)
                or (self.single_file is True
                    and video_filename in self.notes.upper())):
            matches.add('hash')

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

        matches |= guess_matches(video, guessit(self.title,
                                                {'type': self.type}))
        matches |= guess_matches(video,
                                 guessit(self.filename, {'type': self.type}))
        return matches
Exemplo n.º 4
0
    def get_matches(self, video):
        matches = set()

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and sanitize(self.series) == sanitize(
                    video.series):
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            for release in self.releases:
                matches |= guess_matches(video,
                                         guessit(release, {'type': 'episode'}))
        # movie
        elif isinstance(video, Movie):
            # guess
            for release in self.releases:
                matches |= guess_matches(video,
                                         guessit(release, {'type': 'movie'}))

        # title
        if video.title and sanitize(self.title) == sanitize(video.title):
            matches.add('title')

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

        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)

        subtitle_filename = self.filename
        subtitle_filename = os.path.basename(subtitle_filename)
        subtitle_filename, _ = os.path.splitext(subtitle_filename)
        subtitle_filename = sanitize_release_group(subtitle_filename)

        if video_filename == subtitle_filename:
            matches.add('hash')

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

        matches |= guess_matches(
            video,
            guessit(self.title, {
                'type': self.type,
                'allowed_countries': [None]
            }))
        matches |= guess_matches(
            video,
            guessit(self.filename, {
                'type': self.type,
                'allowed_countries': [None]
            }))
        return matches
Exemplo n.º 6
0
    def get_matches(self, video):
        matches = set()

        video_filename = video.name
        video_filename = os.path.basename(video_filename)
        video_filename, _ = os.path.splitext(video_filename)
        video_filename = re.sub(r'\[\w+\]$', '',
                                video_filename).strip().upper()

        subtitle_filename = self.filename
        subtitle_filename = os.path.basename(subtitle_filename)
        subtitle_filename, _ = os.path.splitext(subtitle_filename)
        subtitle_filename = re.sub(r'\[\w+\]$', '',
                                   subtitle_filename).strip().upper()

        if ((video_filename == subtitle_filename)
                or (self.single_file is True
                    and video_filename in self.notes.upper())):
            matches.add('hash')

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

        matches |= guess_matches(video, guessit(self.title,
                                                {'type': self.type}))

        guess_filename = guessit(self.filename, video.hints)
        matches |= guess_matches(video, guess_filename)

        if isinstance(video, Movie) and (self.num_cds > 1
                                         or 'cd' in guess_filename):
            # reduce score of subtitles for multi-disc movie releases
            return set()

        return matches
Exemplo n.º 7
0
    def get_matches(self, video):
        """
        patch: set guessit to single_value
        :param video:
        :return:
        """
        matches = set()

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and (sanitize(self.title) in (
                    sanitize(name)
                    for name in [video.series] + video.alternative_series)):
                matches.add('series')
            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            for release in self.releases:
                matches |= guess_matches(
                    video,
                    guessit(release, {
                        'type': 'episode',
                        "single_value": True
                    }))
        # movie
        elif isinstance(video, Movie):
            # title
            if video.title and (sanitize(self.title) in (
                    sanitize(name)
                    for name in [video.title] + video.alternative_titles)):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')
            # guess
            for release in self.releases:
                matches |= guess_matches(
                    video,
                    guessit(release, {
                        'type': 'movie',
                        "single_value": True
                    }))

        self.matches = matches

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

        # episode
        if isinstance(video, Episode):
            # other properties
            matches |= guess_matches(video, guessit(self.version, {'type': 'episode'}), partial=True)
        # movie
        elif isinstance(video, Movie):
            # other properties
            matches |= guess_matches(video, guessit(self.version, {'type': 'movie'}), partial=True)

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

        # series name
        if video.series and sanitize(self.series) in (
                sanitize(name) for name in [video.series] + video.alternative_series):
            matches.add('series')
        # season
        if video.season and self.season == video.season:
            matches.add('season')
        # episode
        if video.episode and self.episode == video.episode:
            matches.add('episode')
        # title of the episode
        if video.title and sanitize(self.title) == sanitize(video.title):
            matches.add('title')
        # year
        if video.original_series and self.year is None or video.year and video.year == self.year:
            matches.add('year')
        # release_group
        if (video.release_group and self.version and
                any(r in sanitize_release_group(self.version)
                    for r in get_equivalent_release_groups(sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # resolution
        if video.resolution and self.version and video.resolution in self.version.lower():
            matches.add('resolution')
        # source
        if video.source and self.version and video.source.lower() in self.version.lower():
            matches.add('source')
        # other properties
        matches |= guess_matches(video, guessit(self.version), partial=True)

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

        # series
        if video.series and sanitize(self.series) == sanitize(video.series):
            matches.add('series')
        # season
        if video.season and self.season == video.season:
            matches.add('season')
        # episode
        if video.episode and self.episode == video.episode:
            matches.add('episode')
        # title
        if video.title and sanitize(self.title) == sanitize(video.title):
            matches.add('title')
        # year
        if video.original_series and self.year is None or video.year and video.year == self.year:
            matches.add('year')
        # release_group
        if (video.release_group and self.version and
                any(r in sanitize_release_group(self.version)
                    for r in get_equivalent_release_groups(sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # resolution
        if video.resolution and self.version and video.resolution in self.version.lower():
            matches.add('resolution')
        # format
        if video.format and self.version and video.format.lower() in self.version.lower():
            matches.add('format')
        # other properties
        matches |= guess_matches(video, guessit(self.version), partial=True)

        return matches
Exemplo n.º 11
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.º 12
0
def test_guess_matches_movie(movies):
    video = movies['man_of_steel']
    guess = {'title': video.title.upper(), 'year': video.year, 'releaseGroup': video.release_group.upper(),
             'screenSize': video.resolution, 'format': video.format.upper(), 'videoCodec': video.video_codec,
             'audioCodec': video.audio_codec}
    expected = {'title', 'year', 'release_group', 'resolution', 'format', 'video_codec', 'audio_codec'}
    assert guess_matches(video, guess) == expected
Exemplo n.º 13
0
    def get_matches(self, video):
        matches = set()

        # episode
        if isinstance(video, Episode):
            # series name
            if video.series and sanitize(self.series) in (
                    sanitize(name)
                    for name in [video.series] + video.alternative_series):
                matches.add('series')
            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')

        # release_group
        if (video.release_group and self.version
                and any(r in sanitize_release_group(self.version)
                        for r in get_equivalent_release_groups(
                            sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # other properties
        matches |= guess_matches(video,
                                 guessit(self.version, {'type': 'episode'}),
                                 partial=True)

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

        # movie
        if isinstance(video, Movie):
            # title
            if video.title and (sanitize(self.title) in (
                    sanitize(name)
                    for name in [video.title] + video.alternative_titles)):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')

        # release_group
        if (video.release_group and self.version
                and any(r in sanitize_release_group(self.version)
                        for r in get_equivalent_release_groups(
                            sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # other properties
        matches |= guess_matches(video,
                                 guessit(self.version, {'type': 'movie'}),
                                 partial=True)

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

        # episode
        if isinstance(video, Episode):
            # already matched in search query
            matches.update(["title", "series", "season", "episode", "year"])

        # movie
        elif isinstance(video, Movie):
            # already matched in search query
            matches.update(["title", "year"])

        # Special string comparisons are unnecessary. Guessit can match keys
        # from any string and find even more keywords.
        matches |= guess_matches(
            video,
            guessit(
                self.description,
                {"type": "episode" if isinstance(video, Episode) else "movie"},
            ),
        )

        # Don't lowercase; otherwise it will match a lot of false positives
        if video.release_group and video.release_group in self.description:
            matches.add("release_group")

        return matches
Exemplo n.º 16
0
def test_guess_matches_movie(movies):
    video = movies['man_of_steel']
    guess = {'title': video.title.upper(), 'year': video.year, 'releaseGroup': video.release_group.upper(),
             'screenSize': video.resolution, 'format': video.format.upper(), 'videoCodec': video.video_codec,
             'audioCodec': video.audio_codec}
    expected = {'title', 'year', 'release_group', 'resolution', 'format', 'video_codec', 'audio_codec'}
    assert guess_matches(video, guess) == expected
Exemplo n.º 17
0
def test_guess_matches_episode(episodes):
    video = episodes['bbt_s07e05']
    guess = {'series': video.series, 'season': video.season, 'episodeNumber': video.episode, 'year': video.year,
             'title': video.title.upper(), 'releaseGroup': video.release_group.upper(), 'screenSize': video.resolution,
             'format': video.format.upper(), 'videoCodec': video.video_codec, 'audioCodec': video.audio_codec}
    expected = {'series', 'season', 'episode', 'title', 'year', 'release_group', 'resolution', 'format', 'video_codec',
                'audio_codec'}
    assert guess_matches(video, guess) == expected
Exemplo n.º 18
0
def test_guess_matches_episode(episodes):
    video = episodes['bbt_s07e05']
    guess = {'series': video.series, 'season': video.season, 'episodeNumber': video.episode, 'year': video.year,
             'title': video.title.upper(), 'releaseGroup': video.release_group.upper(), 'screenSize': video.resolution,
             'format': video.format.upper(), 'videoCodec': video.video_codec, 'audioCodec': video.audio_codec}
    expected = {'series', 'season', 'episode', 'title', 'year', 'release_group', 'resolution', 'format', 'video_codec',
                'audio_codec'}
    assert guess_matches(video, guess) == expected
Exemplo n.º 19
0
def test_guess_matches_episode_no_year(episodes):
    video = episodes['dallas_s01e03']
    guess = {
        'series': video.series,
        'season': video.season,
        'episodeNumber': video.episode
    }
    expected = {'series', 'season', 'episode', 'year'}
    assert guess_matches(video, guess) == expected
Exemplo n.º 20
0
 def get_matches(self, video):
     self.found_matches |= guess_matches(
         video,
         guessit(
             self.release_info,
             {"type": "episode"},
         ),
     )
     return self.found_matches
Exemplo n.º 21
0
    def get_matches(self, video):
        matches = set()

        # episode
        if isinstance(video, Episode):
            # always make year a match
            info = guessit(self.version, {"type": "episode"})
            info["year"] = video.year
            # other properties
            matches |= guess_matches(video, info, partial=True)
        # movie
        elif isinstance(video, Movie):
            # other properties
            matches |= guess_matches(video,
                                     guessit(self.version, {"type": "movie"}),
                                     partial=True)

        return matches
Exemplo n.º 22
0
    def _get_subtitle_from_archive(archive, subtitle):
        _valid_names = []
        for name in archive.namelist():
            # discard hidden files
            # discard non-subtitle files
            if not os.path.split(name)[-1].startswith(".") and name.lower().endswith(
                SUBTITLE_EXTENSIONS
            ):
                _valid_names.append(name)

        # archive with only 1 subtitle
        if len(_valid_names) == 1:
            logger.debug(
                f"returning from archive: {_valid_names[0]} (single subtitle file)"
            )
            return archive.read(_valid_names[0])

        # in archives with more than 1 subtitle (season pack) we try to guess the best subtitle file
        _scores = get_scores(subtitle.video)
        _max_score = 0
        _max_name = ""
        for name in _valid_names:
            _guess = guessit(name)
            if "season" not in _guess:
                _guess["season"] = -1
            if "episode" not in _guess:
                _guess["episode"] = -1

            if isinstance(subtitle.video, Episode):
                logger.debug("guessing %s" % name)
                logger.debug(
                    f"subtitle S{_guess['season']}E{_guess['episode']} video "
                    f"S{subtitle.video.season}E{subtitle.video.episode}"
                )

                if (
                    subtitle.video.episode != _guess["episode"]
                    or subtitle.video.season != _guess["season"]
                ):
                    logger.debug("subtitle does not match video, skipping")
                    continue

            matches = set()
            matches |= guess_matches(subtitle.video, _guess)
            _score = sum((_scores.get(match, 0) for match in matches))
            logger.debug("srt matches: %s, score %d" % (matches, _score))
            if _score > _max_score:
                _max_score = _score
                _max_name = name
                logger.debug(f"new max: {name} {_score}")

        if _max_score > 0:
            logger.debug(f"returning from archive: {_max_name} scored {_max_score}")
            return archive.read(_max_name)

        raise APIThrottled("Can not find the subtitle in the compressed file")
Exemplo n.º 23
0
    def get_matches(self, video):
        matches = set()

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

        # episode
        if isinstance(video, Episode):
            info = guessit(self.version, {"type": "episode"})
            # other properties
            matches |= guess_matches(video, info, partial=True)
        # movie
        elif isinstance(video, Movie):
            # other properties
            matches |= guess_matches(
                video, guessit(self.version, {"type": "movie"}), partial=True
            )

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

        # handle movies and series separately
        if isinstance(video, Episode):
            # series
            if video.series and sanitize(
                    self.title) == fix_inconsistent_naming(
                        video.series) or sanitize(
                            self.alt_title) == fix_inconsistent_naming(
                                video.series):
                matches.add('series')
            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
        # movie
        elif isinstance(video, Movie):
            # title
            if video.title and sanitize(self.title) == fix_inconsistent_naming(
                    video.title) or sanitize(
                        self.alt_title) == fix_inconsistent_naming(
                            video.title):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')

        # rest is same for both groups

        # release_group
        if (video.release_group and self.releases
                and any(r in sanitize_release_group(self.releases)
                        for r in get_equivalent_release_groups(
                            sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # resolution
        if video.resolution and self.releases and video.resolution in self.releases.lower(
        ):
            matches.add('resolution')
        # source
        if video.source and self.releases and video.source.lower(
        ) in self.releases.lower():
            matches.add('source')
        # other properties
        matches |= guess_matches(video, guessit(self.releases))

        self.matches = matches

        return matches
Exemplo n.º 25
0
    def get_matches(self, video):
        """
        patch: set guessit to single_value
        :param video:
        :return:
        """
        matches = set()

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and (fix_inconsistent_naming(self.title) in (
                    fix_inconsistent_naming(name) for name in [video.series] + video.alternative_series)):
                matches.add('series')
            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guessit(release, {'type': 'episode', "single_value": True}))
        # movie
        elif isinstance(video, Movie):
            # title
            if video.title and (sanitize(self.title) in (
                    sanitize(name) for name in [video.title] + video.alternative_titles)):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guessit(release, {'type': 'movie', "single_value": True}))

        self.matches = matches

        return matches
Exemplo n.º 26
0
    def _get_subtitle_from_archive(archive, subtitle):
        _valid_names = []
        for name in archive.namelist():
            # discard hidden files
            # discard non-subtitle files
            if not os.path.split(name)[-1].startswith('.') and name.lower(
            ).endswith(SUBTITLE_EXTENSIONS):
                _valid_names.append(name)

        # archive with only 1 subtitle
        if len(_valid_names) == 1:
            logger.debug(
                "returning from archive: {} (single subtitle file)".format(
                    _valid_names[0]))
            return archive.read(_valid_names[0])

        # in archives with more than 1 subtitle (season pack) we try to guess the best subtitle file
        _scores = get_scores(subtitle.video)
        _max_score = 0
        _max_name = ""
        for name in _valid_names:
            _guess = guessit(name)
            if 'season' not in _guess:
                _guess['season'] = -1
            if 'episode' not in _guess:
                _guess['episode'] = -1

            if isinstance(subtitle.video, Episode):
                logger.debug("guessing %s" % name)
                logger.debug("subtitle S{}E{} video S{}E{}".format(
                    _guess['season'], _guess['episode'], subtitle.video.season,
                    subtitle.video.episode))

                if subtitle.video.episode != _guess[
                        'episode'] or subtitle.video.season != _guess['season']:
                    logger.debug('subtitle does not match video, skipping')
                    continue

            matches = set()
            matches |= guess_matches(subtitle.video, _guess)
            _score = sum((_scores.get(match, 0) for match in matches))
            logger.debug('srt matches: %s, score %d' % (matches, _score))
            if _score > _max_score:
                _max_score = _score
                _max_name = name
                logger.debug("new max: {} {}".format(name, _score))

        if _max_score > 0:
            logger.debug("returning from archive: {} scored {}".format(
                _max_name, _max_score))
            return archive.read(_max_name)

        raise APIThrottled('Can not find the subtitle in the compressed file')
Exemplo n.º 27
0
    def get_matches(self, video):
        matches = set()
        matches |= guess_matches(video, guessit(self.filename))

        subtitle_filename = self.filename

        # episode
        if isinstance(video, Episode):
            # already matched in search query
            matches.update(['title', 'series', 'season', 'episode', 'year'])

        # movie
        elif isinstance(video, Movie):
            # already matched in search query
            matches.update(['title', 'year'])

        # release_group
        if video.release_group and video.release_group.lower(
        ) in subtitle_filename:
            matches.add('release_group')

        # resolution
        if video.resolution and video.resolution.lower() in subtitle_filename:
            matches.add('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.lower() in subtitle_filename:
                    matches.add('source')
                    break

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

        matches.add('hash')

        return matches
Exemplo n.º 28
0
    def _get_subtitle_from_archive(self, archive, subtitle):
        # some files have a non subtitle with .txt extension
        _tmp = list(SUBTITLE_EXTENSIONS)
        _tmp.remove('.txt')
        _subtitle_extensions = tuple(_tmp)
        _max_score = 0
        _scores = get_scores(subtitle.video)

        for name in archive.namelist():
            # discard hidden files
            if os.path.split(name)[-1].startswith('.'):
                continue

            # discard non-subtitle files
            if not name.lower().endswith(_subtitle_extensions):
                continue

            _guess = guessit(name)
            if isinstance(subtitle.video, Episode):
                logger.debug("Legendasdivx.pt :: guessing %s", name)
                logger.debug("Legendasdivx.pt :: subtitle S%sE%s video S%sE%s",
                             _guess['season'], _guess['episode'],
                             subtitle.video.season, subtitle.video.episode)

                if subtitle.video.episode != _guess[
                        'episode'] or subtitle.video.season != _guess['season']:
                    logger.debug(
                        'Legendasdivx.pt :: subtitle does not match video, skipping'
                    )
                    continue

            matches = set()
            matches |= guess_matches(subtitle.video, _guess)
            logger.debug('Legendasdivx.pt :: sub matches: %s', matches)
            _score = sum((_scores.get(match, 0) for match in matches))
            if _score > _max_score:
                _max_name = name
                _max_score = _score
                logger.debug("Legendasdivx.pt :: new max: %s %s", name, _score)

        if _max_score > 0:
            logger.debug(
                "Legendasdivx.pt :: returning from archive: %s scored %s",
                _max_name, _max_score)
            return archive.read(_max_name)

        logger.error(
            "Legendasdivx.pt :: No subtitle found on compressed file. Max score was 0"
        )
        return None
Exemplo n.º 29
0
    def get_matches(self, video):
        matches = set()

        if self.is_perfect_match:
            if isinstance(video, Episode):
                matches.add('series')
            else:
                matches.add('title')

        # guess additional info from data
        matches |= guess_matches(video, self.data)

        self.matches = matches
        self.data = None  # removing this make the subtitles object unpickable
        return matches
Exemplo n.º 30
0
    def get_matches(self, video):
        matches = set()
        video_type = None

        # episode
        if isinstance(video, Episode):
            video_type = 'episode'
            # series name
            if video.series and sanitize(self.series) in (
                    sanitize(name)
                    for name in [video.series] + video.alternative_series):
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # title of the episode
            if video.title and sanitize(self.title) == sanitize(video.title):
                matches.add('title')
            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')
        # movie
        elif isinstance(video, Movie):
            video_type = 'movie'
            # title
            if video.title and (sanitize(self.title) in (
                    sanitize(name)
                    for name in [video.title] + video.alternative_titles)):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')

        # release_group
        if (video.release_group and self.version
                and any(r in sanitize_release_group(self.version)
                        for r in get_equivalent_release_groups(
                            sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # other properties
        matches |= guess_matches(video,
                                 guessit(self.version, {'type': video_type}),
                                 partial=True)

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

        # handle movies and series separately
        if isinstance(video, Episode):
            # series
            if video.series and sanitize(self.title) == fix_inconsistent_naming(video.series) or sanitize(
                    self.alt_title) == fix_inconsistent_naming(video.series):
                matches.add('series')
            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
        # movie
        elif isinstance(video, Movie):
            # title
            if video.title and sanitize(self.title) == fix_inconsistent_naming(video.title) or sanitize(
                    self.alt_title) == fix_inconsistent_naming(video.title):
                matches.add('title')
            # year
            if video.year and self.year == video.year:
                matches.add('year')

        # rest is same for both groups

        # release_group
        if (video.release_group and self.releases and
                any(r in sanitize_release_group(self.releases)
                    for r in get_equivalent_release_groups(sanitize_release_group(video.release_group)))):
            matches.add('release_group')
        # resolution
        if video.resolution and self.releases and video.resolution in self.releases.lower():
            matches.add('resolution')
        # format
        if video.format and self.releases and video.format.lower() in self.releases.lower():
            matches.add('format')
        # other properties
        matches |= guess_matches(video, guessit(self.releases))

        self.matches = matches

        return matches
Exemplo n.º 32
0
    def get_matches(self, video):
        matches = set()
        matches |= guess_matches(video, guessit(self.filename))

        # episode
        if isinstance(video, Episode):
            # already matched in search query
            matches.update(["title", "series", "season", "episode", "year"])

        # movie
        elif isinstance(video, Movie):
            # already matched in search query
            matches.update(["title", "year"])

        matches.add("hash")

        return matches
Exemplo n.º 33
0
    def _get_subtitle_from_archive(self, archive, subtitle):
        # some files have a non subtitle with .txt extension
        _tmp = list(SUBTITLE_EXTENSIONS)
        _tmp.remove('.txt')
        _subtitle_extensions = tuple(_tmp)
        _max_score = 0
        _scores = get_scores(subtitle.video)

        for name in archive.namelist():
            # discard hidden files
            if os.path.split(name)[-1].startswith('.'):
                continue

            # discard non-subtitle files
            if not name.lower().endswith(_subtitle_extensions):
                continue

            _guess = guessit(name)
            if isinstance(subtitle.video, Episode):
                logger.debug("guessing %s" % name)
                logger.debug("subtitle S{}E{} video S{}E{}".format(
                    _guess['season'], _guess['episode'], subtitle.video.season,
                    subtitle.video.episode))

                if subtitle.video.episode != _guess[
                        'episode'] or subtitle.video.season != _guess['season']:
                    logger.debug('subtitle does not match video, skipping')
                    continue

            matches = set()
            matches |= guess_matches(subtitle.video, _guess)
            logger.debug('srt matches: %s' % matches)
            _score = sum((_scores.get(match, 0) for match in matches))
            if _score > _max_score:
                _max_name = name
                _max_score = _score
                logger.debug("new max: {} {}".format(name, _score))

        if _max_score > 0:
            logger.debug("returning from archive: {} scored {}".format(
                _max_name, _max_score))
            return archive.read(_max_name)

        raise ParseResponseError(
            'Can not find the subtitle in the compressed file')
Exemplo n.º 34
0
    def get_matches(self, video):
        matches = set()

        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)

        subtitle_filename = self.filename
        subtitle_filename = os.path.basename(subtitle_filename)
        subtitle_filename, _ = os.path.splitext(subtitle_filename)
        subtitle_filename = sanitize_release_group(subtitle_filename)

        if video_filename == subtitle_filename:
            matches.add('hash')

        matches |= guess_matches(video,
                                 guessit(self.filename, {'type': self.type}))
        return matches
Exemplo n.º 35
0
    def _get_subtitle_from_archive(self, archive, video):
        subtitles = []

        # some files have a non subtitle with .txt extension
        _tmp = list(SUBTITLE_EXTENSIONS)
        _tmp.remove('.txt')
        _subtitle_extensions = tuple(_tmp)
        _scores = get_scores(video)

        for name in archive.namelist():
            # discard hidden files
            if os.path.split(name)[-1].startswith('.'):
                continue

            # discard non-subtitle files
            if not name.lower().endswith(_subtitle_extensions):
                continue

            # get subtitles language
            if '.en.' in name.lower():
                language = Language.fromopensubtitles('eng')
            else:
                language = Language.fromopensubtitles('fre')

            release = name[:-4].lower().rstrip('tag').rstrip('en').rstrip('fr')
            _guess = guessit(release)
            if isinstance(video, Episode):
                if video.episode != _guess[
                        'episode'] or video.season != _guess['season']:
                    continue

            matches = set()
            matches |= guess_matches(video, _guess)
            _score = sum((_scores.get(match, 0) for match in matches))
            content = archive.read(name)
            subtitles.append(
                SoustitreseuSubtitle(language, video, name, _guess, content,
                                     self.is_perfect_match))

        return subtitles
Exemplo n.º 36
0
    def get_matches(self, video, hearing_impaired=False):
        matches = set()

        # episode
        if isinstance(video, Episode) and self.type == 'episode':
            # series
            if video.series and (sanitize(self.title) in (
                    sanitize(name)
                    for name in [video.series] + video.alternative_series)):
                matches.add('series')

            # year
            if video.original_series and self.year is None or video.year and video.year == self.year:
                matches.add('year')

            # imdb_id
            if video.series_imdb_id and self.imdb_id == video.series_imdb_id:
                matches.add('series_imdb_id')

        # movie
        elif isinstance(video, Movie) and self.type == 'movie':
            # title
            if video.title and (sanitize(self.title) in (
                    sanitize(name)
                    for name in [video.title] + video.alternative_titles)):
                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')

        # name
        matches |= guess_matches(video, guessit(self.name,
                                                {'type': self.type}))

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

        # series
        if video.series and sanitize(self.series) == sanitize(video.series):
            matches.add('series')
        # season
        if video.season and self.season == video.season:
            matches.add('season')
        # episode
        if video.episode and self.episode == video.episode:
            matches.add('episode')
        # format
        if video.format and video.format.lower() in self.format.lower():
            matches.add('format')
        if video.year and self.year == video.year:
            matches.add('year')
        if video.series_tvdb_id and self.tvdb_id == video.series_tvdb_id:
            matches.add('series_tvdb_id')

        # other properties
        matches |= guess_matches(video, guessit(self.full_data), partial=True)

        return matches
Exemplo n.º 38
0
def test_guess_matches_episode_no_year(episodes):
    video = episodes['dallas_s01e03']
    guess = {'series': video.series, 'season': video.season, 'episodeNumber': video.episode}
    expected = {'series', 'season', 'episode', 'year'}
    assert guess_matches(video, guess) == expected