diff options
author | vitiko98 <[email protected]> | 2021-06-10 22:55:58 -0400 |
---|---|---|
committer | vitiko98 <[email protected]> | 2021-06-10 22:55:58 -0400 |
commit | a39a9e8bd52542ff34a4a7b94a9504073e5aeabd (patch) | |
tree | eb2b41f77642c6e66ea12469b7f5f8ab86d28f80 /libs/subliminal_patch | |
parent | e86d537ca2ffe49a6911b44d3c3611365461e232 (diff) | |
download | bazarr-a39a9e8bd52542ff34a4a7b94a9504073e5aeabd.tar.gz bazarr-a39a9e8bd52542ff34a4a7b94a9504073e5aeabd.zip |
Finish providers migration to subliminal_patch's guess_matchesv0.9.6-beta.23
Diffstat (limited to 'libs/subliminal_patch')
-rw-r--r-- | libs/subliminal_patch/providers/opensubtitles.py | 1 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/soustitreseu.py | 4 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/subs4free.py | 3 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/subs4series.py | 3 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/subscenter.py | 13 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/subssabbz.py | 3 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/subsunacs.py | 3 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/subtitulamostv.py | 36 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/supersubtitles.py | 9 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/titlovi.py | 19 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/titrari.py | 6 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/titulky.py | 4 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/tusubtitulo.py | 16 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/wizdom.py | 39 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/xsubs.py | 5 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/yavkanet.py | 3 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/zimuku.py | 8 |
17 files changed, 58 insertions, 117 deletions
diff --git a/libs/subliminal_patch/providers/opensubtitles.py b/libs/subliminal_patch/providers/opensubtitles.py index a31d5d9a0..0152b37d6 100644 --- a/libs/subliminal_patch/providers/opensubtitles.py +++ b/libs/subliminal_patch/providers/opensubtitles.py @@ -20,7 +20,6 @@ from .mixins import ProviderRetryMixin from subliminal.subtitle import fix_line_ending from subliminal_patch.http import SubZeroRequestsTransport from subliminal_patch.utils import sanitize, fix_inconsistent_naming -from subliminal_patch.subtitle import guess_matches from subliminal.cache import region from subliminal_patch.score import framerate_equal from subliminal_patch.subtitle import guess_matches diff --git a/libs/subliminal_patch/providers/soustitreseu.py b/libs/subliminal_patch/providers/soustitreseu.py index ae2745eec..a26600ba3 100644 --- a/libs/subliminal_patch/providers/soustitreseu.py +++ b/libs/subliminal_patch/providers/soustitreseu.py @@ -16,10 +16,10 @@ 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 get_scores, framerate_equal from subliminal.providers import ParserBeautifulSoup -from subliminal.subtitle import sanitize, guess_matches, SUBTITLE_EXTENSIONS +from subliminal.subtitle import sanitize, SUBTITLE_EXTENSIONS from subliminal.video import Episode, Movie from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST diff --git a/libs/subliminal_patch/providers/subs4free.py b/libs/subliminal_patch/providers/subs4free.py index c3a77fdb3..f71d29a11 100644 --- a/libs/subliminal_patch/providers/subs4free.py +++ b/libs/subliminal_patch/providers/subs4free.py @@ -17,9 +17,10 @@ from subliminal.providers import ParserBeautifulSoup, Provider from subliminal import __short_version__ from subliminal.cache import SHOW_EXPIRATION_TIME, region from subliminal.score import get_equivalent_release_groups -from subliminal.subtitle import SUBTITLE_EXTENSIONS, Subtitle, fix_line_ending, guess_matches +from subliminal.subtitle import SUBTITLE_EXTENSIONS, Subtitle, fix_line_ending from subliminal.utils import sanitize, sanitize_release_group from subliminal.video import Movie +from subliminal_patch.subtitle import guess_matches logger = logging.getLogger(__name__) diff --git a/libs/subliminal_patch/providers/subs4series.py b/libs/subliminal_patch/providers/subs4series.py index fb1f6d022..24acc5c72 100644 --- a/libs/subliminal_patch/providers/subs4series.py +++ b/libs/subliminal_patch/providers/subs4series.py @@ -15,9 +15,10 @@ from guessit import guessit from subliminal.providers import ParserBeautifulSoup, Provider from subliminal.cache import SHOW_EXPIRATION_TIME, region from subliminal.score import get_equivalent_release_groups -from subliminal.subtitle import SUBTITLE_EXTENSIONS, Subtitle, fix_line_ending, guess_matches +from subliminal.subtitle import SUBTITLE_EXTENSIONS, Subtitle, fix_line_ending from subliminal.utils import sanitize, sanitize_release_group from subliminal.video import Episode +from subliminal_patch.subtitle import guess_matches logger = logging.getLogger(__name__) diff --git a/libs/subliminal_patch/providers/subscenter.py b/libs/subliminal_patch/providers/subscenter.py index 4bcf1c4f2..92ccdeda7 100644 --- a/libs/subliminal_patch/providers/subscenter.py +++ b/libs/subliminal_patch/providers/subscenter.py @@ -1,9 +1,13 @@ # coding=utf-8 from __future__ import absolute_import + +from guessit import guessit +from subliminal.video import Episode from subliminal.providers.subscenter import SubsCenterProvider as _SubsCenterProvider, \ SubsCenterSubtitle as _SubsCenterSubtitle from subzero.language import Language +from subliminal_patch.subtitle import guess_matches class SubsCenterSubtitle(_SubsCenterSubtitle): @@ -17,6 +21,15 @@ class SubsCenterSubtitle(_SubsCenterSubtitle): self.release_info = u", ".join(releases) self.page_link = page_link + 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 __repr__(self): return '<%s %r %s [%s]>' % ( self.__class__.__name__, self.page_link, self.id, self.language) diff --git a/libs/subliminal_patch/providers/subssabbz.py b/libs/subliminal_patch/providers/subssabbz.py index c4bfe1fc6..ffd903835 100644 --- a/libs/subliminal_patch/providers/subssabbz.py +++ b/libs/subliminal_patch/providers/subssabbz.py @@ -14,9 +14,8 @@ from requests import Session from guessit import guessit from dogpile.cache.api import NO_VALUE from subliminal_patch.providers import Provider -from subliminal_patch.subtitle import Subtitle +from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal_patch.utils import sanitize, fix_inconsistent_naming -from subliminal.subtitle import guess_matches from subliminal.video import Episode, Movie from subliminal.subtitle import fix_line_ending from subliminal.cache import region diff --git a/libs/subliminal_patch/providers/subsunacs.py b/libs/subliminal_patch/providers/subsunacs.py index 3950f244f..ca76f0948 100644 --- a/libs/subliminal_patch/providers/subsunacs.py +++ b/libs/subliminal_patch/providers/subsunacs.py @@ -14,9 +14,8 @@ from requests import Session from guessit import guessit from dogpile.cache.api import NO_VALUE from subliminal_patch.providers import Provider -from subliminal_patch.subtitle import Subtitle +from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal_patch.utils import sanitize, fix_inconsistent_naming -from subliminal.subtitle import guess_matches from subliminal.video import Episode, Movie from subliminal.subtitle import fix_line_ending from subliminal.cache import region diff --git a/libs/subliminal_patch/providers/subtitulamostv.py b/libs/subliminal_patch/providers/subtitulamostv.py index b2ce75c7f..97daa68ae 100644 --- a/libs/subliminal_patch/providers/subtitulamostv.py +++ b/libs/subliminal_patch/providers/subtitulamostv.py @@ -5,10 +5,11 @@ import os from requests import Session from subzero.language import Language -from subliminal import Movie, Episode, ProviderError, __short_version__ +from guessit import guessit +from subliminal import Episode, __short_version__ from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal.providers import ParserBeautifulSoup -from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS +from subliminal.subtitle import fix_line_ending from subliminal_patch.providers import Provider logger = logging.getLogger(__name__) @@ -30,37 +31,10 @@ class SubtitulamosTVSubtitle(Subtitle): def get_matches(self, video): matches = {'series', 'season', 'episode', 'year', 'title'} - release_info_lower = self.release_info.lower() - - if video.release_group and video.release_group.lower() in release_info_lower: + if video.release_group and video.release_group.lower() in self.release_info.lower(): matches.add('release_group') - if video.resolution and video.resolution.lower() in release_info_lower: - matches.add('resolution') - - if video.source: - formats = [video.source.lower()] - if formats[0] == "web": - formats.append("webdl") - formats.append("web-dl") - formats.append("webrip") - for frmt in formats: - if frmt in release_info_lower: - matches.add('source') - break - - if video.video_codec: - video_codecs = [video.video_codec.lower()] - if video_codecs[0] == "h.264": - video_codecs.append("h264") - video_codecs.append("x264") - elif video_codecs[0] == "h.265": - video_codecs.append("h265") - video_codecs.append("x265") - for vc in video_codecs: - if vc in release_info_lower: - matches.add('video_codec') - break + matches = guess_matches(video, guessit(self.release_info, {"type": "episode"})) return matches diff --git a/libs/subliminal_patch/providers/supersubtitles.py b/libs/subliminal_patch/providers/supersubtitles.py index bed39aa03..a859d9183 100644 --- a/libs/subliminal_patch/providers/supersubtitles.py +++ b/libs/subliminal_patch/providers/supersubtitles.py @@ -108,7 +108,8 @@ class SuperSubtitlesSubtitle(Subtitle): return str(self.subtitle_id) def get_matches(self, video): - matches = guess_matches(video, guessit(self.release_info)) + type_ = "movie" if isinstance(video, Movie) else "episode" + matches = guess_matches(video, guessit(self.release_info, {"type": type_})) # episode if isinstance(video, Episode): @@ -150,12 +151,6 @@ class SuperSubtitlesSubtitle(Subtitle): 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') self.matches = matches return matches diff --git a/libs/subliminal_patch/providers/titlovi.py b/libs/subliminal_patch/providers/titlovi.py index 8c460ef9c..0a0ebd927 100644 --- a/libs/subliminal_patch/providers/titlovi.py +++ b/libs/subliminal_patch/providers/titlovi.py @@ -17,12 +17,11 @@ from guessit import guessit from subliminal_patch.http import RetryingCFSession 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.utils import sanitize, fix_inconsistent_naming as _fix_inconsistent_naming from subliminal.exceptions import ProviderError, AuthenticationError, ConfigurationError from subliminal.score import get_equivalent_release_groups from subliminal.utils import sanitize_release_group -from subliminal.subtitle import guess_matches from subliminal.video import Episode, Movie from subliminal.subtitle import fix_line_ending @@ -92,9 +91,9 @@ class TitloviSubtitle(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 if video.series and sanitize(self.title) == fix_inconsistent_naming(video.series) or sanitize( self.alt_title) == fix_inconsistent_naming(video.series): @@ -109,7 +108,7 @@ class TitloviSubtitle(Subtitle): if video.episode and self.episode == video.episode: matches.add('episode') # movie - elif isinstance(video, 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): @@ -125,14 +124,8 @@ class TitloviSubtitle(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') - # other properties - matches |= guess_matches(video, guessit(self.releases)) + + matches |= guess_matches(video, guessit(self.releases, {"type": type_})) self.matches = matches diff --git a/libs/subliminal_patch/providers/titrari.py b/libs/subliminal_patch/providers/titrari.py index 5889c37f7..b0773ed75 100644 --- a/libs/subliminal_patch/providers/titrari.py +++ b/libs/subliminal_patch/providers/titrari.py @@ -9,9 +9,10 @@ from random import randint from zipfile import ZipFile, is_zipfile from rarfile import RarFile, is_rarfile +from guessit import guessit 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.utils import sanitize, fix_inconsistent_naming as _fix_inconsistent_naming from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST from subliminal.exceptions import ProviderError @@ -82,8 +83,7 @@ class TitrariSubtitle(Subtitle): if video.release_group and video.release_group in self.comments: matches.add('release_group') - if video.resolution and video.resolution.lower() in self.comments: - matches.add('resolution') + matches |= guess_matches(video, guessit(self.comments, {"type": "movie"})) self.matches = matches diff --git a/libs/subliminal_patch/providers/titulky.py b/libs/subliminal_patch/providers/titulky.py index c86002ac0..66d6f8c7f 100644 --- a/libs/subliminal_patch/providers/titulky.py +++ b/libs/subliminal_patch/providers/titulky.py @@ -102,7 +102,7 @@ class TitulkySubtitle(Subtitle): if video.episode and self.episode == video.episode: matches.add('episode') # guess - matches |= guess_matches(video, guessit(self.version, {'type': 'episode', "single_value": True})) + matches |= guess_matches(video, guessit(self.version, {'type': 'episode'})) pass # movie elif isinstance(video, Movie): @@ -114,7 +114,7 @@ class TitulkySubtitle(Subtitle): if video.year and self.year == video.year: matches.add('year') # guess - matches |= guess_matches(video, guessit(self.version, {'type': 'movie', "single_value": True})) + matches |= guess_matches(video, guessit(self.version, {'type': 'movie'})) self.matches = matches diff --git a/libs/subliminal_patch/providers/tusubtitulo.py b/libs/subliminal_patch/providers/tusubtitulo.py index 6b4970b59..8385ebeab 100644 --- a/libs/subliminal_patch/providers/tusubtitulo.py +++ b/libs/subliminal_patch/providers/tusubtitulo.py @@ -15,15 +15,18 @@ from subliminal.cache import SHOW_EXPIRATION_TIME, region, EPISODE_EXPIRATION_TI from subliminal.exceptions import ServiceUnavailable from subliminal_patch.exceptions import APIThrottled from subliminal_patch.providers import Provider -from subliminal_patch.subtitle import Subtitle -from subliminal.subtitle import fix_line_ending, guess_matches +from subliminal_patch.subtitle import Subtitle, guess_matches +from subliminal.subtitle import fix_line_ending logger = logging.getLogger(__name__) +_EP_NUM_PATTERN = re.compile(r".*\d+x(0+)?(\d+) - .*?") +_CSS1 = "span.iconos-subtitulos" +_CSS2 = "ul > li.rng.download.green > a.fas.fa-bullhorn.notifi_icon" + BASE_URL = "https://www.tusubtitulo.com" -CSS1 = "span.iconos-subtitulos" -CSS2 = "ul > li.rng.download.green > a.fas.fa-bullhorn.notifi_icon" + class TuSubtituloSubtitle(Subtitle): @@ -87,7 +90,8 @@ class TuSubtituloProvider(Provider): def _title_available(item): try: title = item[2].find_all("a")[0] - episode_number = re.search(r".*\d+x(0+)?(\d+) - .*?", title.text).group(2) + episode_number = _EP_NUM_PATTERN.search(title.text).group(2) + # episode_number = re.search(r".*\d+x(0+)?(\d+) - .*?", title.text).group(2) episode_id = title.get("href").split("/")[4] return {"episode_number": episode_number, "episode_id": episode_id} except IndexError: @@ -214,7 +218,7 @@ class TuSubtituloProvider(Provider): discriminator = f".{episode_dict['season']}.{episode_dict['episode']}." soup = bso(r.content, "lxml") - for url, selected in zip(soup.select(CSS1), soup.select(CSS2)): + for url, selected in zip(soup.select(_CSS1), soup.select(_CSS2)): meta = ".".join( selected.get("href").split(discriminator)[-1].split(".")[:-1] ) diff --git a/libs/subliminal_patch/providers/wizdom.py b/libs/subliminal_patch/providers/wizdom.py index 7e7406f1a..147cccb16 100644 --- a/libs/subliminal_patch/providers/wizdom.py +++ b/libs/subliminal_patch/providers/wizdom.py @@ -46,8 +46,6 @@ class WizdomSubtitle(Subtitle): def get_matches(self, video): matches = set() - subtitle_filename = self.release.lower() - # episode if isinstance(video, Episode): # series @@ -64,50 +62,17 @@ class WizdomSubtitle(Subtitle): 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) + matches |= guess_matches(video, guessit(self.release, {'type': 'episode'})) # movie elif isinstance(video, Movie): # guess - matches |= guess_matches(video, guessit(self.release, {'type': 'movie'}), partial=True) + 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') - # 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 - return matches diff --git a/libs/subliminal_patch/providers/xsubs.py b/libs/subliminal_patch/providers/xsubs.py index 98160d62c..70fc47760 100644 --- a/libs/subliminal_patch/providers/xsubs.py +++ b/libs/subliminal_patch/providers/xsubs.py @@ -12,9 +12,10 @@ from subliminal import __short_version__ from subliminal.cache import SHOW_EXPIRATION_TIME, region from subliminal.exceptions import AuthenticationError, ConfigurationError from subliminal.score import get_equivalent_release_groups -from subliminal.subtitle import Subtitle, fix_line_ending, guess_matches +from subliminal.subtitle import Subtitle, fix_line_ending from subliminal.utils import sanitize, sanitize_release_group from subliminal.video import Episode +from subliminal_patch.subtitle import guess_matches logger = logging.getLogger(__name__) article_re = re.compile(r'^([A-Za-z]{1,3}) (.*)$') @@ -69,7 +70,7 @@ class XSubsSubtitle(Subtitle): 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) + matches |= guess_matches(video, guessit(self.version, {'type': 'episode'})) return matches diff --git a/libs/subliminal_patch/providers/yavkanet.py b/libs/subliminal_patch/providers/yavkanet.py index 157f50e03..83c77d93a 100644 --- a/libs/subliminal_patch/providers/yavkanet.py +++ b/libs/subliminal_patch/providers/yavkanet.py @@ -14,9 +14,8 @@ from requests import Session from guessit import guessit from dogpile.cache.api import NO_VALUE from subliminal_patch.providers import Provider -from subliminal_patch.subtitle import Subtitle +from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal_patch.utils import sanitize -from subliminal.subtitle import guess_matches from subliminal.video import Episode, Movie from subliminal.subtitle import fix_line_ending from subliminal.cache import region diff --git a/libs/subliminal_patch/providers/zimuku.py b/libs/subliminal_patch/providers/zimuku.py index 528fbd9e5..1facb5348 100644 --- a/libs/subliminal_patch/providers/zimuku.py +++ b/libs/subliminal_patch/providers/zimuku.py @@ -66,7 +66,7 @@ class ZimukuSubtitle(Subtitle): if isinstance(video, Episode): info = guessit(self.version, {"type": "episode"}) # other properties - matches |= guess_matches(video, info, partial=True) + matches |= guess_matches(video, info) # 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']): @@ -74,9 +74,7 @@ class ZimukuSubtitle(Subtitle): # movie elif isinstance(video, Movie): # other properties - matches |= guess_matches( - video, guessit(self.version, {"type": "movie"}), partial=True - ) + matches |= guess_matches(video, guessit(self.version, {"type": "movie"})) return matches @@ -389,4 +387,4 @@ def num_to_cn(number): else: part1 = "十" if number[0] == "1" else trans_map[number[0]] + "十" part2 = trans_map[number[1]] if number[1] != "0" else "" - return part1 + part2
\ No newline at end of file + return part1 + part2 |