Update half of providers to use subliminal_patch's guess_matches

This commit is contained in:
vitiko98 2021-06-08 18:44:30 -04:00
parent 5b1f479901
commit 14d467e645
13 changed files with 67 additions and 118 deletions

View File

@ -14,7 +14,7 @@ from . import Provider, TimeoutSafeTransport
from .. import __short_version__
from ..exceptions import (AuthenticationError, ConfigurationError, DownloadLimitExceeded, ProviderError,
ServiceUnavailable)
from ..subtitle import Subtitle, fix_line_ending, guess_matches
from ..subtitle import Subtitle, fix_line_ending
from ..utils import sanitize
from ..video import Episode, Movie
@ -56,7 +56,6 @@ class OpenSubtitlesSubtitle(Subtitle):
def get_matches(self, video):
matches = set()
# episode
if isinstance(video, Episode) and self.movie_kind == 'episode':
# tag match, assume series, year, season and episode matches
@ -78,9 +77,7 @@ class OpenSubtitlesSubtitle(Subtitle):
# title
if video.title and sanitize(self.series_title) == sanitize(video.title):
matches.add('title')
# guess
matches |= guess_matches(video, guessit(self.movie_release_name, {'type': 'episode'}))
matches |= guess_matches(video, guessit(self.filename, {'type': 'episode'}))
# hash
if 'opensubtitles' in video.hashes and self.hash == video.hashes['opensubtitles']:
if 'series' in matches and 'season' in matches and 'episode' in matches:
@ -99,9 +96,6 @@ class OpenSubtitlesSubtitle(Subtitle):
# year
if video.year and self.movie_year == video.year:
matches.add('year')
# guess
matches |= guess_matches(video, guessit(self.movie_release_name, {'type': 'movie'}))
matches |= guess_matches(video, guessit(self.filename, {'type': 'movie'}))
# hash
if 'opensubtitles' in video.hashes and self.hash == video.hashes['opensubtitles']:
if 'title' in matches:

View File

@ -4,6 +4,7 @@ import logging
import os
import io
import time
import urllib.parse
from zipfile import ZipFile
from guessit import guessit
@ -30,17 +31,26 @@ class ArgenteamSubtitle(Subtitle):
self.page_link = page_link
self.download_link = download_link
self.found_matches = matches
self.release_info = release_info
self._release_info = release_info
# Original subtitle filename guessed from the URL
self.release_info = urllib.parse.unquote(self.download_link.split("/")[-1])
@property
def id(self):
return self.download_link
def get_matches(self, video):
# Download links always have the srt filename with the release info.
# We combine it with the release info as guessit will return the first key match.
new_file = self.download_link.split("/")[-1] + self.release_info
self.found_matches |= guess_matches(video, guessit(new_file))
type_ = "episode" if isinstance(video, Episode) else "movie"
self.found_matches |= guess_matches(
video,
guessit(self.release_info, {"type": type_}),
)
self.found_matches |= guess_matches(
video,
guessit(self._release_info, {"type": type_}),
)
return self.found_matches

View File

@ -9,9 +9,8 @@ from requests.packages.urllib3.util.retry import Retry
from guessit import guessit
from subliminal_patch.providers import Provider
from subliminal_patch.subtitle import Subtitle
from subliminal_patch.subtitle import Subtitle, guess_matches
from subliminal_patch.exceptions import TooManyRequests
from subliminal.subtitle import guess_matches
from subliminal.video import Episode, Movie
from subzero.language import Language
from subliminal.exceptions import ServiceUnavailable

View File

@ -6,10 +6,11 @@ from random import randint
from subzero.language import Language
from guessit import guessit
from subliminal_patch.http import RetryingCFSession
from subliminal_patch.subtitle import guess_matches
from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST
from subliminal.providers import ParserBeautifulSoup, Provider
from subliminal.subtitle import SUBTITLE_EXTENSIONS, Subtitle, fix_line_ending, guess_matches
from subliminal.subtitle import SUBTITLE_EXTENSIONS, Subtitle, fix_line_ending
from subliminal.video import Episode, Movie
logger = logging.getLogger(__name__)
@ -38,6 +39,8 @@ class GreekSubsSubtitle(Subtitle):
# episode
if isinstance(video, Episode):
# Blatanly match the year
matches.add("year")
# other properties
matches |= guess_matches(video, guessit(self.version, {'type': 'episode'}), partial=True)
# movie

View File

@ -38,6 +38,7 @@ class GreekSubtitlesSubtitle(Subtitle):
# episode
if isinstance(video, Episode):
matches.add("year")
# other properties
matches |= guess_matches(video, guessit(self.version, {'type': 'episode'}), partial=True)
# movie

View File

@ -49,13 +49,11 @@ class HosszupuskaSubtitle(Subtitle):
provider_name = 'hosszupuska'
def __str__(self):
subtit = "Subtitle id: " + str(self.subtitle_id) \
+ " Series: " + self.series \
+ " Season: " + str(self.season) \
+ " Episode: " + str(self.episode) \
+ " Releases: " + str(self.releases)
subtit = (f"Subtitle id: {self.subtitle_id} Series: {self.series} "
f"Season: {self.season} Episode: {self.episode} "
f"Releases: {self.releases}")
if self.year:
subtit = subtit + " Year: " + str(self.year)
subtit = f"{subtit} Year: {self.year}"
if six.PY3:
return subtit
return subtit.encode('utf-8')
@ -104,19 +102,15 @@ class HosszupuskaSubtitle(Subtitle):
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')
# 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.release_info))
matches |= guess_matches(video, guessit(self.release_info), {"type": "episode"})
return matches

View File

@ -13,14 +13,14 @@ from guessit import guessit
from subliminal.cache import region
from subliminal.exceptions import ConfigurationError, AuthenticationError, ServiceUnavailable, DownloadLimitExceeded
from subliminal.providers import ParserBeautifulSoup
from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending, guess_matches
from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending
from subliminal.utils import sanitize, sanitize_release_group
from subliminal.video import Episode, Movie
from subliminal_patch.exceptions import TooManyRequests, IPAddressBlocked
from subliminal_patch.http import RetryingCFSession
from subliminal_patch.providers import Provider
from subliminal_patch.score import get_scores, framerate_equal
from subliminal_patch.subtitle import Subtitle
from subliminal_patch.subtitle import Subtitle, guess_matches
from subzero.language import Language
from dogpile.cache.api import NO_VALUE
@ -90,14 +90,15 @@ class LegendasdivxSubtitle(Subtitle):
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 isinstance(video, Movie):
if type_ == "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):
else:
if video.title and sanitize(video.title) in description:
matches.update(['title'])
if video.series:
@ -113,34 +114,7 @@ class LegendasdivxSubtitle(Subtitle):
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
matches |= guess_matches(video, guessit(description, {"type": type_}))
return matches

View File

@ -6,9 +6,11 @@ import os
from subliminal.exceptions import ConfigurationError
from subliminal.providers.legendastv import LegendasTVSubtitle as _LegendasTVSubtitle, \
LegendasTVProvider as _LegendasTVProvider, Episode, Movie, guess_matches, guessit, sanitize, region, type_map, \
LegendasTVProvider as _LegendasTVProvider, Episode, Movie, guessit, sanitize, region, type_map, \
raise_for_status, json, SHOW_EXPIRATION_TIME, title_re, season_re, datetime, pytz, NO_VALUE, releases_key, \
SUBTITLE_EXTENSIONS, language_converters
from subliminal_patch.subtitle import guess_matches
from subzero.language import Language
logger = logging.getLogger(__name__)
@ -59,7 +61,7 @@ class LegendasTVSubtitle(_LegendasTVSubtitle):
matches.add('imdb_id')
# name
matches |= guess_matches(video, guessit(self.name, {'type': self.type, 'single_value': True}))
matches |= guess_matches(video, guessit(self.name, {'type': self.type}))
return matches

View File

@ -15,11 +15,11 @@ from subzero.language import Language
from subliminal_patch.providers import Provider
from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin
from subliminal_patch.subtitle import Subtitle
from subliminal_patch.subtitle import Subtitle, guess_matches
from subliminal_patch.score import framerate_equal
from subliminal.exceptions import ProviderError
from subliminal.providers import ParserBeautifulSoup
from subliminal.subtitle import sanitize, guess_matches
from subliminal.subtitle import sanitize
from subliminal.video import Movie
from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST

View File

@ -11,6 +11,7 @@ import requests
from babelfish import language_converters
from dogpile.cache.api import NO_VALUE
from guessit import guessit
from subliminal.exceptions import ConfigurationError, ServiceUnavailable
from subliminal.providers.opensubtitles import OpenSubtitlesProvider as _OpenSubtitlesProvider,\
OpenSubtitlesSubtitle as _OpenSubtitlesSubtitle, Episode, Movie, ServerProxy, Unauthorized, NoSession, \
@ -21,6 +22,7 @@ from subliminal_patch.http import SubZeroRequestsTransport
from subliminal_patch.utils import sanitize, fix_inconsistent_naming
from subliminal.cache import region
from subliminal_patch.score import framerate_equal
from subliminal_patch.subtitle import guess_matches
from subzero.language import Language
from ..exceptions import TooManyRequests, APIThrottled
@ -72,14 +74,18 @@ class OpenSubtitlesSubtitle(_OpenSubtitlesSubtitle):
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 isinstance(video, Episode) and self.movie_kind == '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 isinstance(video, Movie) and self.movie_kind == '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)):

View File

@ -14,9 +14,10 @@ from subliminal_patch.exceptions import TooManyRequests
from subliminal.exceptions import DownloadLimitExceeded, AuthenticationError, ConfigurationError, ServiceUnavailable, \
ProviderError
from .mixins import ProviderRetryMixin
from subliminal_patch.subtitle import Subtitle, guess_matches
from subliminal_patch.subtitle import Subtitle
from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS
from subliminal_patch.providers import Provider
from subliminal_patch.subtitle import guess_matches
from subliminal_patch.utils import fix_inconsistent_naming
from subliminal.cache import region
from dogpile.cache.api import NO_VALUE
@ -74,9 +75,10 @@ class OpenSubtitlesComSubtitle(Subtitle):
def get_matches(self, video):
matches = set()
type_ = "movie" if isinstance(video, Movie) else "episode"
# handle movies and series separately
if isinstance(video, Episode):
if type_ == "episode":
# series
matches.add('series')
# year
@ -88,8 +90,7 @@ class OpenSubtitlesComSubtitle(Subtitle):
# episode
if video.episode == self.episode:
matches.add('episode')
# movie
elif isinstance(video, Movie):
else:
# title
matches.add('title')
# year
@ -103,17 +104,12 @@ class OpenSubtitlesComSubtitle(Subtitle):
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))
matches |= guess_matches(video, guessit(self.releases, {"type": type_}))
self.matches = matches

View File

@ -8,8 +8,8 @@ import io
from zipfile import ZipFile
from guessit import guessit
from subliminal.subtitle import guess_matches
from subliminal.utils import sanitize
from subliminal_patch.subtitle import guess_matches
from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin
try:
@ -84,7 +84,7 @@ class PodnapisiSubtitle(_PodnapisiSubtitle):
matches.add('episode')
# guess
for release in self.releases:
matches |= guess_matches(video, guessit(release, {'type': 'episode', "single_value": True}))
matches |= guess_matches(video, guessit(release, {'type': 'episode'}))
# movie
elif isinstance(video, Movie):
# title
@ -96,7 +96,7 @@ class PodnapisiSubtitle(_PodnapisiSubtitle):
matches.add('year')
# guess
for release in self.releases:
matches |= guess_matches(video, guessit(release, {'type': 'movie', "single_value": True}))
matches |= guess_matches(video, guessit(release, {'type': 'movie'}))
self.matches = matches

View File

@ -7,9 +7,8 @@ import os
from requests import Session
from guessit import guessit
from subliminal_patch.providers import Provider
from subliminal_patch.subtitle import Subtitle
from subliminal_patch.subtitle import Subtitle, guess_matches
from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending
from subliminal.subtitle import guess_matches
from subliminal.video import Episode, Movie
from subzero.language import Language
@ -40,18 +39,16 @@ class RegieLiveSubtitle(Subtitle):
return self.filename
def get_matches(self, video):
type_ = "movie" if isinstance(video, Movie) else "episode"
matches = set()
matches |= guess_matches(video, guessit(self.filename))
subtitle_filename = self.filename
# episode
if isinstance(video, Episode):
if type_ == "episode":
# already matched in search query
matches.update(['title', 'series', 'season', 'episode', 'year'])
# movie
elif isinstance(video, Movie):
else:
# already matched in search query
matches.update(['title', 'year'])
@ -59,34 +56,7 @@ class RegieLiveSubtitle(Subtitle):
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 |= guess_matches(video, guessit(self.filename, {"type": type_}))
return matches