Finish providers migration to subliminal_patch's guess_matches

pull/1439/head v0.9.6-beta.23
vitiko98 3 years ago
parent e86d537ca2
commit a39a9e8bd5

@ -57,14 +57,6 @@ class SubsCenterSubtitle(Subtitle):
# 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):

@ -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

@ -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

@ -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__)

@ -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__)

@ -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)

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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]
)

@ -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

@ -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

@ -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

@ -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
return part1 + part2

Loading…
Cancel
Save