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
def get_matches(self, video): matches = set() if self.release_info.strip() == get_video_filename(video): logger.debug("Using hash match as the release name is the same") matches |= {"hash"} # episode if isinstance(video, Episode): guess = guessit(self.release_info, {'type': 'episode'}) self.season = guess.get("season") self.episode = guess.get("episode") matches |= guess_matches(video, guess) if "season" in matches and "episode" not in guess: # pack matches.add("episode") logger.debug("%r is a pack", self) self.is_pack = True # movie else: guess = guessit(self.release_info, {'type': 'movie'}) matches |= guess_matches(video, guess) if video.release_group and "release_group" not in matches and "release_group" in guess: if sanitize_release_group(video.release_group) in sanitize_release_group(guess["release_group"]): matches.add("release_group") self.matches = matches return matches
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
def get_matches(self, video): matches = set() logger.debug("--ScrewZiraSubtitle--\n{}".format(self.__dict__)) # 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 matches |= guess_matches( video, guessit(self.release, {'type': 'episode'})) # movie elif isinstance(video, Movie): # title if video.title and (sanitize(self.series) 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 matches |= guess_matches(video, guessit(self.release, {'type': 'movie'})) logger.debug("ScrewZira subtitle criteria match:\n{}".format(matches)) return matches
def get_matches(self, video): 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") # 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 matches |= guess_matches( video, guessit(self.release, {"type": "episode"})) # movie elif isinstance(video, Movie): # guess matches |= guess_matches(video, guessit(self.release, {"type": "movie"})) # title if video.title and (sanitize(self.title) in ( sanitize(name) for name in [video.title] + video.alternative_titles)): matches.add("title") return matches
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
def get_matches(self, video): if isinstance(video, Episode): self.found_matches |= guess_matches( video, guessit(self.filename, {"type": "episode"})) else: self.found_matches |= guess_matches( video, guessit(self.filename, {"type": "movie"})) return self.found_matches
def get_matches(self, video): self.found_matches |= guess_matches( video, guessit(self.filename, ), ) self.found_matches |= guess_matches( video, guessit(self.release_info, ), ) return self.found_matches
def get_matches(self, video): type_ = "episode" if isinstance(video, Episode) else "movie" self.found_matches |= guess_matches( video, guessit(self.filename, {"type": type_}), ) self.found_matches |= guess_matches( video, guessit(self.guessed_release_info, {"type": type_}), ) return self.found_matches
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: 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 matches |= guess_matches( video, guessit(self.version, { 'type': 'episode', "single_value": True })) pass # 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 matches |= guess_matches( video, guessit(self.version, { 'type': 'movie', "single_value": True })) self.matches = matches return matches
def get_matches(self, video): matches = set() if video.year and self.year == video.year: matches.add('year') if video.release_group and video.release_group in self.comments: matches.add('release_group') if isinstance(video, Movie): # title if video.title and sanitize(self.title) == fix_inconsistent_naming( video.title): matches.add('title') # imdb if video.imdb_id and self.imdb_id == video.imdb_id: matches.add('imdb_id') # guess match others matches |= guess_matches(video, guessit(self.comments, {"type": "movie"})) else: # title seasonless_title = re.sub(r'\s-\sSezonul\s\d+$', '', self.title.rstrip()) if video.series and fix_inconsistent_naming( video.series) == sanitize(seasonless_title): matches.add('series') # imdb if video.series_imdb_id and self.imdb_id == video.series_imdb_id: matches.add('imdb_id') # season if f"Sezonul {video.season}" in self.comments: matches.add('season') # episode if {"imdb_id", "season"}.issubset(matches): matches.add('episode') # guess match others matches |= guess_matches( video, guessit(self.comments, {"type": "episode"})) self.matches = matches return matches
def get_matches(self, video): matches = set() 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') # 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') # other properties matches |= guess_matches(video, guessit(self.version, {'type': 'episode'})) return matches
def get_matches(self, video): matches = set() # series if video.series and ( sanitize(self.series) == sanitize(fix_inconsistent_naming(video.series)) or 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') # year if ('series' in matches and 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.release_info.encode("utf-8"))) return matches
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
def get_matches(self, video): matches = set() # series if video.series and (sanitize(self.series) == sanitize( fix_inconsistent_naming(video.series)) or 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') # year if ('series' in matches and video.original_series and self.year is None or video.year and video.year == self.year): matches.add('year') logger.debug("Matches: %s", matches) # 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') matches |= guess_matches(video, guessit(self.release_info), {"type": "episode"}) return matches
def get_matches(self, video): type_ = "movie" if isinstance(video, Movie) else "episode" matches = guess_matches(video, guessit(self.release_info, {"type": type_})) # episode if isinstance(video, Episode): # series if video.series and sanitize(self.series) == sanitize( video.series): matches.add('series') # imdb_id if video.series_imdb_id and self.imdb_id and str( self.imdb_id) == str(video.series_imdb_id): matches.add('series_imdb_id') matches.add('series') matches.add('year') # year if 'year' not in matches and 'series' in matches and video.original_series and self.year is None: matches.add('year') # movie elif isinstance(video, Movie): # title if video.title and (sanitize(self.series) in ( sanitize(name) for name in [video.title] + video.alternative_titles)): matches.add('title') # imdb_id if video.imdb_id and self.imdb_id == video.imdb_id: matches.add('imdb_id') matches.add('title') matches.add('year') # year if video.year and self.year == video.year: matches.add('year') # release_group if video.release_group and self.releases: video_release_groups = get_equivalent_release_groups( sanitize_release_group(video.release_group)) for release in self.releases: if any(r in sanitize_release_group(release) for r in video_release_groups): matches.add('release_group') if video.resolution and video.resolution in release.lower( ): matches.add('resolution') if video.source and video.source in release.lower(): matches.add('source') # We don't have to continue in case it is a perfect match if all(m in matches for m in ['release_group', 'resolution', 'source']): break self.matches = matches return matches
def get_matches(self, video): matches = guess_matches(video, guessit(self.release_info.encode("utf-8"))) # 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 and str( self.imdb_id) == str(video.series_imdb_id): matches.add('series_imdb_id') matches.add('series') matches.add('year') # year if ('series' in matches and video.original_series and self.year is None or video.year and video.year == self.year): matches.add('year') # movie elif isinstance(video, Movie): # title if video.title and (sanitize(self.series) in ( sanitize(name) for name in [video.title] + video.alternative_titles)): matches.add('title') # imdb_id if video.imdb_id and self.imdb_id == video.imdb_id: matches.add('imdb_id') matches.add('title') matches.add('year') # 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') # 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') self.matches = matches return matches
def get_matches(self, video): matches = set() # series if video.series and ( sanitize(self.series) == sanitize(fix_inconsistent_naming(video.series)) or 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') # year if ('series' in matches and 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.release_info)) return matches
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
def get_matches(self, video): matches = super().get_matches(video) type_ = "episode" if isinstance(video, Episode) else "movie" for release in self.releases: matches |= guess_matches(video, guessit(release, {'type': type_})) return matches
def get_matches(self, video): matches = self.matches if isinstance(video, Episode): matches |= guess_matches(video, guessit( self.video_name, {'type': 'episode'}), partial=True) return matches
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): if all(key in _guess for key in ('season', '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 else: logger.debug( 'Legendasdivx.pt :: no "season" and/or "episode" on "_guess" , 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
def get_matches(self, video): matches = {'series', 'season', 'episode', 'year', 'title'} if video.release_group and video.release_group.lower() in self.release_info.lower(): matches.add('release_group') matches = guess_matches(video, guessit(self.release_info, {"type": "episode"})) return matches
def get_matches(self, video): 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') # 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 matches |= guess_matches(video, guessit(self.release, {'type': 'episode'}), partial=True) # movie elif isinstance(video, Movie): # guess matches |= guess_matches(video, guessit(self.release, {'type': 'movie'}), partial=True) # title if video.title and (sanitize(self.title) in ( sanitize(name) for name in [video.title] + video.alternative_titles)): matches.add('title') return matches
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
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
def get_matches(self, video): matches = set() type_ = "movie" if isinstance(video, Movie) else "episode" # handle movies and series separately if type_ == "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 else: # 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') matches |= guess_matches(video, guessit(self.releases, {"type": type_})) self.matches = matches return matches
def get_matches(self, video): matches = set() # handle movies and series separately if isinstance(video, Episode): # series matches.add('series') # year if video.year == self.year: matches.add('year') # season if video.season == self.season: matches.add('season') # episode if video.episode == self.episode: matches.add('episode') # movie elif isinstance(video, Movie): # title matches.add('title') # year if video.year == self.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') # hash if self.hash_matched: matches.add('hash') # other properties matches |= guess_matches(video, guessit(self.releases)) self.matches = matches return matches
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
def get_matches(self, video): matches = set() type_ = "movie" if isinstance(video, Movie) else "episode" # handle movies and series separately if type_ == "episode": # series matches.add('series') # year if video.year == self.year: matches.add('year') # season if video.season == self.season: matches.add('season') # episode if video.episode == self.episode: matches.add('episode') else: # title matches.add('title') # year if video.year == self.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') if self.hash_matched: matches.add('hash') # other properties matches |= guess_matches(video, guessit(self.releases, {"type": type_})) self.matches = matches return matches
def get_matches(self, video): type_ = "movie" if isinstance(video, Movie) else "episode" matches = set() subtitle_filename = self.filename # episode if type_ == "episode": # already matched in search query matches.update(['title', 'series', 'season', 'episode', 'year']) # movie else: # 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') matches |= guess_matches(video, guessit(self.filename, {"type": type_})) return matches
def get_matches(self, video): matches = set() # series if isinstance(video, Episode) and self.movie_kind == 'episode': if video.series and (sanitize(self.title) 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') # tvdb_id if video.tvdb_id and str(self.tvdb_id) == str(video.tvdb_id): matches.add('tvdb_id') elif isinstance(video, Movie) and self.movie_kind == 'movie': # title if video.title and (sanitize(self.title) in ( sanitize(name) for name in [video.title] + video.alternative_titles)): matches.add('title') # imdb_id if video.imdb_id and self.imdb_id and str(self.imdb_id) == str(video.imdb_id): matches.add('imdb_id') # year if video.year and self.year == video.year: matches.add('year') else: logger.info('%r is not a valid movie_kind', self.movie_kind) return matches # release_group if video.release_group and self.release: rg = sanitize_release_group(video.release_group) if any(r in sanitize_release_group(self.release) for r in get_equivalent_release_groups(rg)): matches.add('release_group') # blatantly assume we've got a matching format if the release group matches # fixme: smart? #matches.add('format') # resolution if video.resolution and self.version and str(video.resolution) in self.version.lower(): matches.add('resolution') # format if video.format and self.format: formats = [video.format] if video.format == "WEB-DL": formats.append("WEB") for fmt in formats: if fmt.lower() in self.format.lower(): matches.add('format') break matches |= guess_matches(video, guessit(self.release_info), partial=True) self.matches = matches return matches
def get_matches(self, video): matches = guess_matches(video, guessit(self.video_name)) return matches