mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-02-25 07:15:56 +08:00
Add minor changes to Sucha provider
This commit is contained in:
parent
3659b4e566
commit
9d41d44d6d
1 changed files with 34 additions and 34 deletions
|
@ -17,8 +17,9 @@ from subzero.language import Language
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
server_url = "http://sapidb.caretas.club/"
|
SERVER_URL = "http://sapidb.caretas.club/"
|
||||||
page_url = "https://sucha.caretas.club/"
|
PAGE_URL = "https://sucha.caretas.club/"
|
||||||
|
UNDESIRED_FILES = ("[eng]", ".en.", ".eng.", ".fr.", ".pt.")
|
||||||
|
|
||||||
|
|
||||||
class SuchaSubtitle(Subtitle):
|
class SuchaSubtitle(Subtitle):
|
||||||
|
@ -35,7 +36,7 @@ class SuchaSubtitle(Subtitle):
|
||||||
matches,
|
matches,
|
||||||
):
|
):
|
||||||
super(SuchaSubtitle, self).__init__(
|
super(SuchaSubtitle, self).__init__(
|
||||||
language, hearing_impaired=False, page_link=page_url
|
language, hearing_impaired=False, page_link=PAGE_URL
|
||||||
)
|
)
|
||||||
self.download_id = download_id
|
self.download_id = download_id
|
||||||
self.download_type = download_type
|
self.download_type = download_type
|
||||||
|
@ -71,7 +72,6 @@ class SuchaSubtitle(Subtitle):
|
||||||
|
|
||||||
class SuchaProvider(Provider):
|
class SuchaProvider(Provider):
|
||||||
"""Sucha Provider"""
|
"""Sucha Provider"""
|
||||||
|
|
||||||
languages = {Language.fromalpha2(l) for l in ["es"]}
|
languages = {Language.fromalpha2(l) for l in ["es"]}
|
||||||
language_list = list(languages)
|
language_list = list(languages)
|
||||||
video_types = (Episode, Movie)
|
video_types = (Episode, Movie)
|
||||||
|
@ -89,22 +89,21 @@ class SuchaProvider(Provider):
|
||||||
movie_year = video.year if video.year else "0"
|
movie_year = video.year if video.year else "0"
|
||||||
is_episode = isinstance(video, Episode)
|
is_episode = isinstance(video, Episode)
|
||||||
language = self.language_list[0]
|
language = self.language_list[0]
|
||||||
|
|
||||||
if is_episode:
|
if is_episode:
|
||||||
q = {
|
q = {"query": f"{video.series} S{video.season:02}E{video.episode:02}"}
|
||||||
"query": "{} S{:02}E{:02}".format(
|
|
||||||
video.series, video.season, video.episode
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
q = {"query": video.title, "year": movie_year}
|
q = {"query": video.title, "year": movie_year}
|
||||||
logger.debug("Searching subtitles: {}".format(q["query"]))
|
|
||||||
res = self.session.get(
|
logger.debug(f"Searching subtitles: {q}")
|
||||||
server_url + ("episode" if is_episode else "movie"), params=q, timeout=10
|
result = self.session.get(
|
||||||
|
SERVER_URL + ("episode" if is_episode else "movie"), params=q, timeout=10
|
||||||
)
|
)
|
||||||
res.raise_for_status()
|
result.raise_for_status()
|
||||||
result = res.json()
|
|
||||||
|
result_ = result.json()
|
||||||
subtitles = []
|
subtitles = []
|
||||||
for i in result:
|
for i in result_:
|
||||||
matches = set()
|
matches = set()
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
|
@ -115,18 +114,18 @@ class SuchaProvider(Provider):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
logger.debug("No subtitles found")
|
logger.debug("No subtitles found")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if is_episode:
|
if is_episode:
|
||||||
if (
|
if (
|
||||||
q["query"].lower() in i["title"].lower()
|
q["query"].lower() in i["title"].lower()
|
||||||
or q["query"].lower() in i["alt_title"].lower()
|
or q["query"].lower() in i["alt_title"].lower()
|
||||||
):
|
):
|
||||||
matches.add("title")
|
matches_ = ("title", "series", "season", "episode", "year")
|
||||||
matches.add("series")
|
[matches.add(match) for match in matches_]
|
||||||
matches.add("season")
|
|
||||||
matches.add("episode")
|
|
||||||
matches.add("year")
|
|
||||||
if str(i["year"]) == video.year:
|
if str(i["year"]) == video.year:
|
||||||
matches.add("year")
|
matches.add("year")
|
||||||
|
|
||||||
subtitles.append(
|
subtitles.append(
|
||||||
SuchaSubtitle(
|
SuchaSubtitle(
|
||||||
language,
|
language,
|
||||||
|
@ -144,40 +143,41 @@ class SuchaProvider(Provider):
|
||||||
|
|
||||||
def _check_response(self, response):
|
def _check_response(self, response):
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise ServiceUnavailable("Bad status code: " + str(response.status_code))
|
raise ServiceUnavailable(f"Bad status code: {response.status_code}")
|
||||||
|
|
||||||
def _get_archive(self, content):
|
def _get_archive(self, content):
|
||||||
archive_stream = io.BytesIO(content)
|
archive_stream = io.BytesIO(content)
|
||||||
|
|
||||||
if rarfile.is_rarfile(archive_stream):
|
if rarfile.is_rarfile(archive_stream):
|
||||||
logger.debug("Identified rar archive")
|
logger.debug("Identified rar archive")
|
||||||
archive = rarfile.RarFile(archive_stream)
|
return rarfile.RarFile(archive_stream)
|
||||||
elif zipfile.is_zipfile(archive_stream):
|
|
||||||
|
if zipfile.is_zipfile(archive_stream):
|
||||||
logger.debug("Identified zip archive")
|
logger.debug("Identified zip archive")
|
||||||
archive = zipfile.ZipFile(archive_stream)
|
return zipfile.ZipFile(archive_stream)
|
||||||
else:
|
|
||||||
raise APIThrottled("Unsupported compressed format")
|
raise APIThrottled("Unsupported compressed format")
|
||||||
return archive
|
|
||||||
|
|
||||||
def get_file(self, archive):
|
def get_file(self, archive):
|
||||||
for name in archive.namelist():
|
for name in archive.namelist():
|
||||||
if os.path.split(name)[-1].startswith("."):
|
if os.path.split(name)[-1].startswith("."):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not name.lower().endswith(SUBTITLE_EXTENSIONS):
|
if not name.lower().endswith(SUBTITLE_EXTENSIONS):
|
||||||
continue
|
continue
|
||||||
if (
|
|
||||||
"[eng]" in name.lower()
|
if any(undesired in name.lower() for undesired in UNDESIRED_FILES):
|
||||||
or ".en." in name.lower()
|
|
||||||
or ".eng." in name.lower()
|
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
logger.debug("Returning from archive: {}".format(name))
|
|
||||||
|
logger.debug(f"Returning from archive: {name}")
|
||||||
return archive.read(name)
|
return archive.read(name)
|
||||||
|
|
||||||
raise APIThrottled("Can not find the subtitle in the compressed file")
|
raise APIThrottled("Can not find the subtitle in the compressed file")
|
||||||
|
|
||||||
def download_subtitle(self, subtitle):
|
def download_subtitle(self, subtitle):
|
||||||
logger.info("Downloading subtitle %r", subtitle)
|
logger.info("Downloading subtitle %r", subtitle)
|
||||||
response = self.session.get(
|
response = self.session.get(
|
||||||
server_url + "download",
|
SERVER_URL + "download",
|
||||||
params={"id": subtitle.download_id, "type": subtitle.download_type},
|
params={"id": subtitle.download_id, "type": subtitle.download_type},
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue