mirror of https://github.com/morpheus65535/bazarr
Sucha's new api
This commit is contained in:
parent
757f23a43a
commit
3b516427a3
|
@ -17,7 +17,7 @@ from subzero.language import Language
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
server_url = "http://sapi.caretas.club/"
|
server_url = "http://sapidb.caretas.club/"
|
||||||
page_url = "https://sucha.caretas.club/"
|
page_url = "https://sucha.caretas.club/"
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,38 +28,44 @@ class SuchaSubtitle(Subtitle):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
language,
|
language,
|
||||||
page_link,
|
release_info,
|
||||||
filename,
|
filename,
|
||||||
guessit_dict,
|
download_id,
|
||||||
download_link,
|
download_type,
|
||||||
hearing_impaired,
|
|
||||||
matches,
|
matches,
|
||||||
):
|
):
|
||||||
super(SuchaSubtitle, self).__init__(
|
super(SuchaSubtitle, self).__init__(
|
||||||
language, hearing_impaired=hearing_impaired, page_link=page_url
|
language, hearing_impaired=False, page_link=page_url
|
||||||
)
|
)
|
||||||
self.download_link = download_link
|
self.download_id = download_id
|
||||||
self.referer = page_link
|
self.download_type = download_type
|
||||||
self.guessit = guessit_dict
|
|
||||||
self.language = language
|
self.language = language
|
||||||
self.release_info = filename
|
self.guessed_release_info = release_info
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
self.release_info = (
|
||||||
|
release_info if len(release_info) > len(filename) else filename
|
||||||
|
)
|
||||||
self.found_matches = matches
|
self.found_matches = matches
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self):
|
def id(self):
|
||||||
return self.download_link
|
return self.download_id
|
||||||
|
|
||||||
def get_matches(self, video):
|
def get_matches(self, video):
|
||||||
if isinstance(video, Episode):
|
|
||||||
self.found_matches |= guess_matches(
|
self.found_matches |= guess_matches(
|
||||||
video, guessit(self.filename, {"type": "episode"})
|
video,
|
||||||
|
guessit(
|
||||||
|
self.filename,
|
||||||
|
{"type": "episode" if isinstance(video, Episode) else "movie"},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
self.found_matches |= guess_matches(
|
self.found_matches |= guess_matches(
|
||||||
video, guessit(self.filename, {"type": "movie"})
|
video,
|
||||||
|
guessit(
|
||||||
|
self.guessed_release_info,
|
||||||
|
{"type": "episode" if isinstance(video, Episode) else "movie"},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.found_matches
|
return self.found_matches
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +74,6 @@ class SuchaProvider(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)
|
||||||
logger.debug(languages)
|
|
||||||
video_types = (Episode, Movie)
|
video_types = (Episode, Movie)
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
|
@ -81,9 +86,9 @@ class SuchaProvider(Provider):
|
||||||
self.session.close()
|
self.session.close()
|
||||||
|
|
||||||
def query(self, languages, video):
|
def query(self, languages, video):
|
||||||
movie_year = video.year if video.year else None
|
movie_year = video.year if video.year else "0"
|
||||||
is_episode = True if isinstance(video, Episode) else False
|
is_episode = isinstance(video, Episode)
|
||||||
imdb_id = video.imdb_id if video.imdb_id else None
|
logger.debug("Is episode {}".format(is_episode))
|
||||||
language = self.language_list[0]
|
language = self.language_list[0]
|
||||||
if is_episode:
|
if is_episode:
|
||||||
q = {
|
q = {
|
||||||
|
@ -91,58 +96,45 @@ class SuchaProvider(Provider):
|
||||||
video.series, video.season, video.episode
|
video.series, video.season, video.episode
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
if imdb_id:
|
|
||||||
q = {"query": imdb_id}
|
|
||||||
else:
|
else:
|
||||||
q = {"query": video.title, "year": movie_year}
|
q = {"query": video.title, "year": movie_year}
|
||||||
|
|
||||||
logger.debug("Searching subtitles: {}".format(q["query"]))
|
logger.debug("Searching subtitles: {}".format(q["query"]))
|
||||||
|
res = self.session.get(
|
||||||
res = self.session.get(server_url + "search", params=q, timeout=10)
|
server_url + ("episode" if is_episode else "movie"), params=q, timeout=10
|
||||||
|
)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
result = res.json()
|
result = res.json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subtitles = []
|
subtitles = []
|
||||||
for i in result["results"]:
|
for i in result:
|
||||||
|
logger.debug("year from sucha {}".format(i["year"]))
|
||||||
|
logger.debug("year from video {}".format(video.year))
|
||||||
matches = set()
|
matches = set()
|
||||||
# We use 'in' instead of '==' since Subdivx titles are
|
if (
|
||||||
# irregular
|
video.title.lower() in i["title"].lower()
|
||||||
if video.title.lower() in i["title"].lower():
|
or video.title.lower() in i["alt_title"].lower()
|
||||||
|
):
|
||||||
matches.add("title")
|
matches.add("title")
|
||||||
if is_episode:
|
if is_episode:
|
||||||
if q["query"].lower() in i["title"].lower():
|
if (
|
||||||
|
q["query"].lower() in i["title"].lower()
|
||||||
|
or q["query"].lower() in i["alt_title"].lower()
|
||||||
|
):
|
||||||
matches.add("title")
|
matches.add("title")
|
||||||
matches.add("series")
|
matches.add("series")
|
||||||
matches.add("imdb_id")
|
|
||||||
matches.add("season")
|
matches.add("season")
|
||||||
matches.add("episode")
|
matches.add("episode")
|
||||||
matches.add("year")
|
matches.add("year")
|
||||||
if i["year"] == video.year:
|
if str(i["year"]) == video.year:
|
||||||
matches.add("year")
|
matches.add("year")
|
||||||
if imdb_id:
|
|
||||||
matches.add("imdb_id")
|
|
||||||
|
|
||||||
# We'll add release group info (if found) to the pseudo filename
|
|
||||||
# in order to show it in the manual search
|
|
||||||
filename = i["pseudo_file"]
|
|
||||||
if (
|
|
||||||
video.release_group
|
|
||||||
and str(video.release_group).lower() in i["original_description"]
|
|
||||||
):
|
|
||||||
filename = i["pseudo_file"].replace(
|
|
||||||
".es.srt", "-" + str(video.release_group) + ".es.srt"
|
|
||||||
)
|
|
||||||
|
|
||||||
subtitles.append(
|
subtitles.append(
|
||||||
SuchaSubtitle(
|
SuchaSubtitle(
|
||||||
language,
|
language,
|
||||||
i["referer"],
|
i["release"],
|
||||||
filename,
|
i["filename"],
|
||||||
i["guessit"],
|
str(i["id"]),
|
||||||
i["download_url"],
|
"episode" if is_episode else "movie",
|
||||||
i["hearing_impaired"],
|
|
||||||
matches,
|
matches,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -189,7 +181,9 @@ class SuchaProvider(Provider):
|
||||||
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(
|
||||||
subtitle.download_link, headers={"Referer": subtitle.page_link}, timeout=10
|
server_url + "download",
|
||||||
|
params={"id": subtitle.download_id, "type": subtitle.download_type},
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
self._check_response(response)
|
self._check_response(response)
|
||||||
|
|
Loading…
Reference in New Issue