Merge pull request #1146 from vitiko98/tusubtitulo-english

English support for TuSubtitulo and minor fixes with Sucha and Subdivx
This commit is contained in:
morpheus65535 2020-10-12 08:22:21 -04:00 committed by GitHub
commit 9babc4f6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 35 deletions

View File

@ -86,6 +86,8 @@ class SubdivxSubtitle(Subtitle):
elif video_codecs[0] == "h.265": elif video_codecs[0] == "h.265":
video_codecs.append("h265") video_codecs.append("h265")
video_codecs.append("x265") video_codecs.append("x265")
elif video_codecs[0] == "divx":
video_codecs.append("divx")
for vc in video_codecs: for vc in video_codecs:
if vc in self.description: if vc in self.description:
matches.add('video_codec') matches.add('video_codec')
@ -118,9 +120,15 @@ class SubdivxSubtitlesProvider(Provider):
if isinstance(video, Episode): if isinstance(video, Episode):
query = "{} S{:02d}E{:02d}".format(video.series, video.season, video.episode) query = "{} S{:02d}E{:02d}".format(video.series, video.season, video.episode)
else: else:
# Subdvix has problems searching foreign movies if the year is
# appended. For example: if we search "Memories of Murder 2003",
# Subdix won't return any results; but if we search "Memories of
# Murder", it will. That's because in Subdvix foreign titles have
# the year after the original title ("Salinui chueok (2003) aka
# Memories of Murder").
# A proper solution would be filtering results with the year in
# _parse_subtitles_page.
query = video.title query = video.title
if video.year:
query += ' {:4d}'.format(video.year)
params = { params = {
'q': query, # search string 'q': query, # search string
@ -145,7 +153,7 @@ class SubdivxSubtitlesProvider(Provider):
subtitles += page_subtitles subtitles += page_subtitles
if len(page_subtitles) < 20: if len(page_subtitles) < 100:
break # this is the last page break # this is the last page
params['pg'] += 1 # search next page params['pg'] += 1 # search next page
@ -188,6 +196,11 @@ class SubdivxSubtitlesProvider(Provider):
# title # title
title = title_soup.find("a").text.replace("Subtitulos de ", "") title = title_soup.find("a").text.replace("Subtitulos de ", "")
# filter by year
if video.year and str(video.year) not in title:
continue
page_link = title_soup.find("a")["href"] page_link = title_soup.find("a")["href"]
# description # description

View File

@ -1,19 +1,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import io
import logging import logging
import os import os
import io
import rarfile
import zipfile import zipfile
import rarfile
from requests import Session from requests import Session
from subzero.language import Language from subliminal import Episode, Movie
from subliminal import Movie, Episode
from subliminal_patch.exceptions import APIThrottled
from subliminal.exceptions import ServiceUnavailable from subliminal.exceptions import ServiceUnavailable
from subliminal_patch.subtitle import Subtitle from subliminal.subtitle import SUBTITLE_EXTENSIONS, fix_line_ending
from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS from subliminal_patch.exceptions import APIThrottled
from subliminal_patch.providers import Provider from subliminal_patch.providers import Provider
from subliminal_patch.subtitle import Subtitle
from subzero.language import Language
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -26,13 +25,21 @@ class SuchaSubtitle(Subtitle):
hash_verifiable = False hash_verifiable = False
def __init__( def __init__(
self, language, page_link, filename, download_link, hearing_impaired, matches self,
language,
page_link,
filename,
guessit_dict,
download_link,
hearing_impaired,
matches,
): ):
super(SuchaSubtitle, self).__init__( super(SuchaSubtitle, self).__init__(
language, hearing_impaired=hearing_impaired, page_link=page_url language, hearing_impaired=hearing_impaired, page_link=page_url
) )
self.download_link = download_link self.download_link = download_link
self.referer = page_link self.referer = page_link
self.guessit = guessit_dict
self.language = language self.language = language
self.release_info = filename self.release_info = filename
self.filename = filename self.filename = filename
@ -43,23 +50,33 @@ class SuchaSubtitle(Subtitle):
return self.download_link return self.download_link
def get_matches(self, video): def get_matches(self, video):
if video.resolution and video.resolution.lower() in self.release_info.lower(): if (
self.found_matches.add("resolution") video.release_group
and str(video.release_group).lower() in self.filename.lower()
):
self.found_matches.add("release_group")
if video.source and video.source.lower() in self.release_info.lower(): if video.source and video.source.lower() in self.guessit["source"].lower():
self.found_matches.add("source") self.found_matches.add("source")
if video.video_codec: if (
if video.video_codec == "H.264" and "x264" in self.release_info.lower(): video.resolution
self.found_matches.add("video_codec") and video.resolution.lower() in self.guessit["resolution"].lower()
elif video.video_codec == "H.265" and "x265" in self.release_info.lower(): ):
self.found_matches.add("video_codec") self.found_matches.add("resolution")
elif video.video_codec.lower() in self.release_info.lower():
self.found_matches.add("video_codec") if (
video.audio_codec
and video.audio_codec.lower() in self.guessit["audio_codec"].lower()
):
self.found_matches.add("audio_codec")
if (
video.video_codec
and video.video_codec.lower() in self.guessit["video_codec"].lower()
):
self.found_matches.add("video_codec")
if video.audio_codec:
if video.audio_codec.lower().replace(" ", ".") in self.release_info.lower():
self.found_matches.add("audio_codec")
return self.found_matches return self.found_matches
@ -115,6 +132,7 @@ class SuchaProvider(Provider):
if q["query"].lower() in i["title"].lower(): if q["query"].lower() in i["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")
@ -122,11 +140,24 @@ class SuchaProvider(Provider):
matches.add("year") matches.add("year")
if imdb_id: if imdb_id:
matches.add("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["referer"],
i["pseudo_file"], filename,
i["guessit"],
i["download_url"], i["download_url"],
i["hearing_impaired"], i["hearing_impaired"],
matches, matches,

View File

@ -21,6 +21,7 @@ BASE = "https://www.tusubtitulo.com/series.php?/"
class TuSubtituloSubtitle(Subtitle): class TuSubtituloSubtitle(Subtitle):
provider_name = "tusubtitulo" provider_name = "tusubtitulo"
hash_verifiable = False
def __init__(self, language, filename, download_link, page_link, matches): def __init__(self, language, filename, download_link, page_link, matches):
super(TuSubtituloSubtitle, self).__init__( super(TuSubtituloSubtitle, self).__init__(
@ -52,9 +53,16 @@ class TuSubtituloSubtitle(Subtitle):
elif video.video_codec.lower() in self.release_info.lower(): elif video.video_codec.lower() in self.release_info.lower():
self.found_matches.add("video_codec") self.found_matches.add("video_codec")
if (
video.release_group
and video.release_group.lower() in self.release_info.lower()
):
self.found_matches.add("release_group")
if video.audio_codec: if video.audio_codec:
if video.audio_codec.lower().replace(" ", ".") in self.release_info.lower(): if video.audio_codec.lower().replace(" ", ".") in self.release_info.lower():
self.found_matches.add("audio_codec") self.found_matches.add("audio_codec")
return self.found_matches return self.found_matches
@ -62,8 +70,7 @@ class TuSubtituloProvider(Provider):
"""TuSubtitulo.com Provider""" """TuSubtitulo.com Provider"""
BASE = "https://www.tusubtitulo.com/series.php?/" BASE = "https://www.tusubtitulo.com/series.php?/"
languages = {Language.fromalpha2(l) for l in ["es"]} languages = {Language.fromietf(lang) for lang in ["en", "es"]}
language_list = list(languages)
logger.debug(languages) logger.debug(languages)
video_types = (Episode,) video_types = (Episode,)
@ -146,7 +153,13 @@ class TuSubtituloProvider(Provider):
try: try:
content = tables[tr + inc].find_all("td") content = tables[tr + inc].find_all("td")
language = content[4].text language = content[4].text
completed = content[5] if "eng" in language.lower():
language = "en"
elif "esp" in language.lower():
language = "es"
else:
language = None
completed = True if not "%" in content[5].text else False
url = content[6].find_all("a")[0].get("href") url = content[6].find_all("a")[0].get("href")
sub_id = parse.parse_qs(parse.urlparse(url).query)["id"][0] sub_id = parse.parse_qs(parse.urlparse(url).query)["id"][0]
lang_id = parse.parse_qs(parse.urlparse(url).query)["lang"][0] lang_id = parse.parse_qs(parse.urlparse(url).query)["lang"][0]
@ -158,12 +171,13 @@ class TuSubtituloProvider(Provider):
lang_id, sub_id, version_ lang_id, sub_id, version_
) )
) )
if "esp" in language.lower(): if language and completed:
season_subs.append( season_subs.append(
{ {
"episode_id": sub_id, "episode_id": sub_id,
"metadata": source_var, "metadata": source_var,
"download_url": download_url, "download_url": download_url,
"language": language,
} }
) )
inc += 1 inc += 1
@ -180,6 +194,7 @@ class TuSubtituloProvider(Provider):
"episode_url": i["episode_url"], "episode_url": i["episode_url"],
"metadata": t["metadata"], "metadata": t["metadata"],
"download_url": t["download_url"], "download_url": t["download_url"],
"language": t["language"],
} }
) )
return final_list return final_list
@ -206,7 +221,6 @@ class TuSubtituloProvider(Provider):
logger.debug("Episode not found") logger.debug("Episode not found")
def query(self, languages, video): def query(self, languages, video):
language = self.language_list[0]
query = "{} {} {}".format(video.series, video.season, video.episode) query = "{} {} {}".format(video.series, video.season, video.episode)
logger.debug("Searching subtitles: {}".format(query)) logger.debug("Searching subtitles: {}".format(query))
results = self.search(video.series, str(video.season), str(video.episode)) results = self.search(video.series, str(video.season), str(video.episode))
@ -223,7 +237,7 @@ class TuSubtituloProvider(Provider):
matches.add("year") matches.add("year")
subtitles.append( subtitles.append(
TuSubtituloSubtitle( TuSubtituloSubtitle(
language, Language.fromietf(i["language"]),
i["metadata"], i["metadata"],
i["download_url"], i["download_url"],
i["episode_url"], i["episode_url"],

View File

@ -516,7 +516,7 @@
<div class="form-group col-sm-8"> <div class="form-group col-sm-8">
<label class="custom-control custom-checkbox"> <label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input provider" id="subtitulamostv"> <input type="checkbox" class="custom-control-input provider" id="subtitulamostv">
<span class="custom-control-label">Spanish subtitles provider.</span> <span class="custom-control-label">Spanish Subtitles Provider.</span>
</label> </label>
</div> </div>
</div> </div>
@ -528,7 +528,7 @@
<div class="form-group col-sm-8"> <div class="form-group col-sm-8">
<label class="custom-control custom-checkbox"> <label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input provider" id="sucha"> <input type="checkbox" class="custom-control-input provider" id="sucha">
<span class="custom-control-label">Spanish subtitles provider.</span> <span class="custom-control-label">Spanish Subtitles Provider.</span>
</label> </label>
</div> </div>
</div> </div>
@ -596,7 +596,7 @@
<div class="form-group col-sm-8"> <div class="form-group col-sm-8">
<label class="custom-control custom-checkbox"> <label class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input provider" id="tusubtitulo"> <input type="checkbox" class="custom-control-input provider" id="tusubtitulo">
<span class="custom-control-label">Spanish subtitles provider.</span> <span class="custom-control-label">Spanish/English Subtitles Provider for TV Shows.</span>
</label> </label>
</div> </div>
</div> </div>