|
|
@ -14,7 +14,8 @@ import subliminal_patch
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from subzero.language import Language
|
|
|
|
from subzero.language import Language
|
|
|
|
from subzero.video import parse_video
|
|
|
|
from subzero.video import parse_video
|
|
|
|
from subliminal import region, Video, download_best_subtitles, save_subtitles, score, list_subtitles, download_subtitles
|
|
|
|
from subliminal import region, Video, download_best_subtitles, save_subtitles, score as subliminal_scores, \
|
|
|
|
|
|
|
|
list_subtitles, download_subtitles
|
|
|
|
from subliminal_patch.core import SZAsyncProviderPool as AsyncProviderPool
|
|
|
|
from subliminal_patch.core import SZAsyncProviderPool as AsyncProviderPool
|
|
|
|
from subliminal_patch.score import compute_score
|
|
|
|
from subliminal_patch.score import compute_score
|
|
|
|
from subliminal.subtitle import get_subtitle_path
|
|
|
|
from subliminal.subtitle import get_subtitle_path
|
|
|
@ -282,7 +283,7 @@ def download_subtitle(path, language, hi, providers, providers_auth, sceneName,
|
|
|
|
def manual_search(path, language, hi, providers, providers_auth, sceneName, media_type):
|
|
|
|
def manual_search(path, language, hi, providers, providers_auth, sceneName, media_type):
|
|
|
|
logging.debug('BAZARR Manually searching subtitles for this file: ' + path)
|
|
|
|
logging.debug('BAZARR Manually searching subtitles for this file: ' + path)
|
|
|
|
|
|
|
|
|
|
|
|
subtitles_dict = {}
|
|
|
|
final_subtitles = []
|
|
|
|
|
|
|
|
|
|
|
|
if hi == "True":
|
|
|
|
if hi == "True":
|
|
|
|
hi = True
|
|
|
|
hi = True
|
|
|
@ -302,62 +303,68 @@ def manual_search(path, language, hi, providers, providers_auth, sceneName, medi
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if sceneName == "None" or not use_scenename:
|
|
|
|
if sceneName == "None" or not use_scenename:
|
|
|
|
used_sceneName = False
|
|
|
|
|
|
|
|
video = parse_video(path, None, providers=providers)
|
|
|
|
video = parse_video(path, None, providers=providers)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
used_sceneName = True
|
|
|
|
|
|
|
|
video = Video.fromname(sceneName)
|
|
|
|
video = Video.fromname(sceneName)
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
logging.exception("BAZARR Error trying to get video information for this file: " + path)
|
|
|
|
logging.exception("BAZARR Error trying to get video information for this file: " + path)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
min_score = 60.0
|
|
|
|
max_score = 120.0
|
|
|
|
max_score = 120.0
|
|
|
|
|
|
|
|
scores = subliminal_scores.movie_scores.keys()
|
|
|
|
if media_type == "series":
|
|
|
|
if media_type == "series":
|
|
|
|
|
|
|
|
min_score = 240.0
|
|
|
|
max_score = 360.0
|
|
|
|
max_score = 360.0
|
|
|
|
|
|
|
|
scores = subliminal_scores.episode_scores.keys()
|
|
|
|
|
|
|
|
if video.is_special:
|
|
|
|
|
|
|
|
min_score = 180
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scores = set(scores)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
with AsyncProviderPool(max_workers=None, providers=providers, provider_configs=providers_auth) as p:
|
|
|
|
subtitles = list_subtitles([video], language_set,
|
|
|
|
subtitles = p.list_subtitles(video, language_set)
|
|
|
|
providers=providers,
|
|
|
|
|
|
|
|
provider_configs=providers_auth,
|
|
|
|
|
|
|
|
pool_class=AsyncProviderPool, # fixme: make async optional
|
|
|
|
|
|
|
|
throttle_callback=None, # fixme
|
|
|
|
|
|
|
|
language_hook=None) # fixme
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logging.exception("BAZARR Error trying to get subtitle list from provider for this file: " + path)
|
|
|
|
logging.exception("BAZARR Error trying to get subtitle list from provider for this file: " + path)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
subtitles_list = []
|
|
|
|
subtitles_list = []
|
|
|
|
for s in subtitles:
|
|
|
|
|
|
|
|
matched = set(s.get_matches(video))
|
|
|
|
for s in subtitles[video]:
|
|
|
|
not_matched = set()
|
|
|
|
try:
|
|
|
|
if media_type == "movie":
|
|
|
|
matches = s.get_matches(video)
|
|
|
|
if hi == s.hearing_impaired:
|
|
|
|
except AttributeError:
|
|
|
|
matched.add('hearing_impaired')
|
|
|
|
continue
|
|
|
|
not_matched = set(score.movie_scores.keys()) - matched
|
|
|
|
|
|
|
|
required = {'title'}
|
|
|
|
# skip wrong season/episodes
|
|
|
|
if any(elem in required for elem in not_matched):
|
|
|
|
if media_type == "series":
|
|
|
|
continue
|
|
|
|
can_verify_series = True
|
|
|
|
if used_sceneName:
|
|
|
|
if not s.hash_verifiable and "hash" in matches:
|
|
|
|
not_matched.remove('hash')
|
|
|
|
can_verify_series = False
|
|
|
|
|
|
|
|
|
|
|
|
elif media_type == "series":
|
|
|
|
if can_verify_series and not {"series", "season", "episode"}.issubset(matches):
|
|
|
|
if hi == s.hearing_impaired:
|
|
|
|
logging.debug(u"BAZARR Skipping %s, because it doesn't match our series/episode", s)
|
|
|
|
matched.add('hearing_impaired')
|
|
|
|
|
|
|
|
not_matched = set(score.episode_scores.keys()) - matched
|
|
|
|
|
|
|
|
required = {'series', 'season', 'episode'}
|
|
|
|
|
|
|
|
if any(elem in required for elem in not_matched):
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
if used_sceneName:
|
|
|
|
|
|
|
|
not_matched.remove('hash')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if type(s) is LegendasTVSubtitle:
|
|
|
|
not_matched = scores - matches
|
|
|
|
# The pickle doesn't work very well with RAR (rarfile.RarFile) or ZIP (zipfile.ZipFile)
|
|
|
|
score = compute_score(matches, s, video, hearing_impaired=hi)
|
|
|
|
s.archive.content = None
|
|
|
|
if score < min_score:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
subtitles_list.append(
|
|
|
|
subtitles_list.append(
|
|
|
|
dict(score=round((compute_score(matched, s, video, hearing_impaired=hi) / max_score * 100), 2),
|
|
|
|
dict(score=round((score / max_score * 100), 2),
|
|
|
|
language=alpha2_from_alpha3(s.language.alpha3), hearing_impaired=str(s.hearing_impaired),
|
|
|
|
language=alpha2_from_alpha3(s.language.alpha3), hearing_impaired=str(s.hearing_impaired),
|
|
|
|
provider=s.provider_name, subtitle=codecs.encode(pickle.dumps(s), "base64").decode(),
|
|
|
|
provider=s.provider_name,
|
|
|
|
url=s.page_link, matches=list(matched), dont_matches=list(not_matched)))
|
|
|
|
subtitle=codecs.encode(pickle.dumps(s.make_picklable()), "base64").decode(),
|
|
|
|
|
|
|
|
url=s.page_link, matches=list(matches), dont_matches=list(not_matched)))
|
|
|
|
|
|
|
|
|
|
|
|
subtitles_dict = sorted(subtitles_list, key=lambda x: x['score'], reverse=True)
|
|
|
|
final_subtitles = sorted(subtitles_list, key=lambda x: x['score'], reverse=True)
|
|
|
|
logging.debug('BAZARR ' + str(len(subtitles_dict)) + " subtitles have been found for this file: " + path)
|
|
|
|
logging.debug('BAZARR ' + str(len(final_subtitles)) + " subtitles have been found for this file: " + path)
|
|
|
|
logging.debug('BAZARR Ended searching subtitles for this file: ' + path)
|
|
|
|
logging.debug('BAZARR Ended searching subtitles for this file: ' + path)
|
|
|
|
return subtitles_dict
|
|
|
|
return final_subtitles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, media_type):
|
|
|
|
def manual_download_subtitle(path, language, hi, subtitle, provider, providers_auth, sceneName, media_type):
|
|
|
|