mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-26 01:27:07 +00:00
Continuing development.
This commit is contained in:
parent
1322dcde2f
commit
0d384be7e3
5 changed files with 47 additions and 25 deletions
|
@ -2,6 +2,7 @@ import enzyme
|
|||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import locale
|
||||
|
||||
from utils import get_binary
|
||||
|
||||
|
@ -27,7 +28,7 @@ class EmbeddedSubsReader:
|
|||
if self.ffprobe:
|
||||
detected_languages = []
|
||||
try:
|
||||
detected_languages = subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n")
|
||||
detected_languages = subprocess.check_output([self.ffprobe, "-loglevel", "error", "-select_streams", "s", "-show_entries", "stream_tags=language", "-of", "csv=p=0", file.encode(locale.getpreferredencoding())], universal_newlines=True, stderr=subprocess.STDOUT).strip().split("\n")
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise FFprobeError(e.output)
|
||||
else:
|
||||
|
|
|
@ -204,21 +204,22 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce
|
|||
downloaded_language = language_from_alpha3(downloaded_language_code3)
|
||||
downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
|
||||
downloaded_path = subtitle.storage_path
|
||||
is_forced_string = " forced" if subtitle.language.forced else ""
|
||||
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
|
||||
if is_upgrade:
|
||||
action = "upgraded"
|
||||
else:
|
||||
action = "downloaded"
|
||||
if video.used_scene_name:
|
||||
message = downloaded_language + " subtitles " + action + " from " + downloaded_provider + " with a score of " + unicode(
|
||||
message = downloaded_language + is_forced_string + " subtitles " + action + " from " + downloaded_provider + " with a score of " + unicode(
|
||||
round(subtitle.score * 100 / max_score, 2)) + "% using this scene name: " + sceneName
|
||||
else:
|
||||
message = downloaded_language + " subtitles " + action + " from " + downloaded_provider + " with a score of " + unicode(
|
||||
message = downloaded_language + is_forced_string + " subtitles " + action + " from " + downloaded_provider + " with a score of " + unicode(
|
||||
round(subtitle.score * 100 / max_score, 2)) + "% using filename guessing."
|
||||
|
||||
if use_postprocessing is True:
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language,
|
||||
downloaded_language_code2, downloaded_language_code3)
|
||||
downloaded_language_code2, downloaded_language_code3, subtitle.language.forced)
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE,
|
||||
|
@ -254,7 +255,7 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce
|
|||
else:
|
||||
reversed_path = path_replace_reverse_movie(path)
|
||||
|
||||
return message, reversed_path, downloaded_language_code2, downloaded_provider, subtitle.score
|
||||
return message, reversed_path, downloaded_language_code2, downloaded_provider, subtitle.score, subtitle.language.forced
|
||||
|
||||
if not saved_any:
|
||||
logging.debug('BAZARR No subtitles were found for this file: ' + path)
|
||||
|
@ -406,12 +407,13 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro
|
|||
downloaded_language_code2 = alpha2_from_alpha3(downloaded_language_code3)
|
||||
downloaded_path = saved_subtitle.storage_path
|
||||
logging.debug('BAZARR Subtitles file saved to disk: ' + downloaded_path)
|
||||
message = downloaded_language + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
|
||||
is_forced_string = " forced" if subtitle.language.forced else ""
|
||||
message = downloaded_language + is_forced_string + " subtitles downloaded from " + downloaded_provider + " with a score of " + unicode(
|
||||
score) + "% using manual search."
|
||||
|
||||
if use_postprocessing is True:
|
||||
command = pp_replace(postprocessing_cmd, path, downloaded_path, downloaded_language,
|
||||
downloaded_language_code2, downloaded_language_code3)
|
||||
downloaded_language_code2, downloaded_language_code3, subtitle.language.forced)
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
codepage = subprocess.Popen("chcp", shell=True, stdout=subprocess.PIPE,
|
||||
|
@ -446,7 +448,7 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro
|
|||
else:
|
||||
reversed_path = path_replace_reverse_movie(path)
|
||||
|
||||
return message, reversed_path, downloaded_language_code2, downloaded_provider, subtitle.score
|
||||
return message, reversed_path, downloaded_language_code2, downloaded_provider, subtitle.score, subtitle.language.forced
|
||||
else:
|
||||
logging.error(
|
||||
"BAZARR Tried to manually download a subtitles for file: " + path + " but we weren't able to do (probably throttled by " + str(
|
||||
|
@ -485,7 +487,8 @@ def series_download_subtitles(no):
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
|
@ -524,7 +527,8 @@ def episode_download_subtitles(no):
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
|
@ -555,7 +559,8 @@ def movies_download_subtitles(no):
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||
|
@ -608,7 +613,8 @@ def wanted_download_subtitles(path, l, count_episodes):
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
|
@ -660,7 +666,8 @@ def wanted_download_subtitles_movie(path, l, count_movies):
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||
|
@ -851,7 +858,8 @@ def upgrade_subtitles():
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles(path_replace(episode[0]))
|
||||
|
@ -870,7 +878,8 @@ def upgrade_subtitles():
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
store_subtitles_movie(path_replace_movie(movie[0]))
|
||||
|
|
|
@ -59,14 +59,16 @@ def path_replace_reverse_movie(path):
|
|||
return path
|
||||
|
||||
|
||||
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3):
|
||||
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3, forced):
|
||||
is_forced = ":forced" if forced else ""
|
||||
is_forced_string = " forced" if forced else ""
|
||||
pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
|
||||
pp_command = pp_command.replace('{{episode}}', episode)
|
||||
pp_command = pp_command.replace('{{episode_name}}', os.path.splitext(os.path.basename(episode))[0])
|
||||
pp_command = pp_command.replace('{{subtitles}}', subtitles)
|
||||
pp_command = pp_command.replace('{{subtitles_language}}', language)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code2}}', language_code2)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3)
|
||||
pp_command = pp_command.replace('{{subtitles_language}}', language + is_forced_string)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code2}}', language_code2 + is_forced)
|
||||
pp_command = pp_command.replace('{{subtitles_language_code3}}', language_code3 + is_forced)
|
||||
return pp_command
|
||||
|
||||
|
||||
|
|
|
@ -1792,7 +1792,8 @@ def get_subtitle():
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score)
|
||||
|
@ -1850,7 +1851,8 @@ def manual_get_subtitle():
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
history_log(2, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score)
|
||||
|
@ -1885,7 +1887,8 @@ def get_subtitle_movie():
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
history_log_movie(1, radarrId, message, path, language_code, provider, score)
|
||||
|
@ -1942,7 +1945,8 @@ def manual_get_subtitle_movie():
|
|||
if result is not None:
|
||||
message = result[0]
|
||||
path = result[1]
|
||||
language_code = result[2]
|
||||
forced = result[5]
|
||||
language_code = result[2] + ":forced" if forced else ""
|
||||
provider = result[3]
|
||||
score = result[4]
|
||||
history_log_movie(2, radarrId, message, path, language_code, provider, score)
|
||||
|
|
|
@ -9,11 +9,14 @@ from whichcraft import which
|
|||
from get_args import args
|
||||
|
||||
|
||||
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description, video_path=None, language=None, provider=None, score=None):
|
||||
def history_log(action, sonarrSeriesId, sonarrEpisodeId, description, video_path=None, language=None, provider=None, score=None, forced=False):
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
if forced:
|
||||
language = language + ":forced"
|
||||
|
||||
# Get Sonarr API URL from database config table
|
||||
history = c.execute(
|
||||
'''INSERT INTO table_history(action, sonarrSeriesId, sonarrEpisodeId, timestamp, description, video_path, language, provider, score) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||
|
@ -26,11 +29,14 @@ def history_log(action, sonarrSeriesId, sonarrEpisodeId, description, video_path
|
|||
db.close()
|
||||
|
||||
|
||||
def history_log_movie(action, radarrId, description, video_path=None, language=None, provider=None, score=None):
|
||||
def history_log_movie(action, radarrId, description, video_path=None, language=None, provider=None, score=None, forced=False):
|
||||
# Open database connection
|
||||
db = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30)
|
||||
c = db.cursor()
|
||||
|
||||
if forced:
|
||||
language = language + ":forced"
|
||||
|
||||
history = c.execute(
|
||||
'''INSERT INTO table_history_movie(action, radarrId, timestamp, description, video_path, language, provider, score) VALUES (?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||
(action, radarrId, time.time(), description, video_path, language, provider, score))
|
||||
|
|
Loading…
Reference in a new issue