This commit is contained in:
Louis Vézina 2019-10-28 22:09:24 -04:00
parent 9981df48af
commit a7a4aa97c6
4 changed files with 15 additions and 24 deletions

View File

@ -2,6 +2,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import os import os
import six
import requests import requests
import logging import logging
from queueconfig import notifications from queueconfig import notifications

View File

@ -891,7 +891,7 @@ def refine_from_db(path, video):
"table_episodes.video_codec, table_episodes.audio_codec, table_episodes.path " "table_episodes.video_codec, table_episodes.audio_codec, table_episodes.path "
"FROM table_episodes INNER JOIN table_shows on " "FROM table_episodes INNER JOIN table_shows on "
"table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId " "table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId "
"WHERE table_episodes.path = ?", (unicode(path_replace_reverse(path)),), only_one=True) "WHERE table_episodes.path = ?", (path_replace_reverse(path),), only_one=True)
if data: if data:
video.series, year, country = series_re.match(data['seriesTitle']).groups() video.series, year, country = series_re.match(data['seriesTitle']).groups()

View File

@ -73,16 +73,16 @@ def store_subtitles(original_path, reversed_path):
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)): if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)):
logging.debug("BAZARR external subtitles detected: " + "pb") logging.debug("BAZARR external subtitles detected: " + "pb")
actual_subtitles.append( actual_subtitles.append(
[str("pb"), original_path]) [str("pb"), path_replace_reverse(subtitle_path)])
elif str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese_forced)): elif str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese_forced)):
logging.debug("BAZARR external subtitles detected: " + "pb:forced") logging.debug("BAZARR external subtitles detected: " + "pb:forced")
actual_subtitles.append( actual_subtitles.append(
[str("pb:forced"), original_path]) [str("pb:forced"), path_replace_reverse(subtitle_path)])
elif str(language) != 'und': elif str(language) != 'und':
logging.debug("BAZARR external subtitles detected: " + str(language)) logging.debug("BAZARR external subtitles detected: " + str(language))
actual_subtitles.append( actual_subtitles.append(
[str(language), original_path]) [str(language), path_replace_reverse(subtitle_path)])
else: else:
if os.path.splitext(subtitle)[1] != ".sub": if os.path.splitext(subtitle)[1] != ".sub":
logging.debug("BAZARR falling back to file content analysis to detect language.") logging.debug("BAZARR falling back to file content analysis to detect language.")
@ -103,8 +103,7 @@ def store_subtitles(original_path, reversed_path):
logging.debug( logging.debug(
"BAZARR external subtitles detected and analysis guessed this language: " + str( "BAZARR external subtitles detected and analysis guessed this language: " + str(
detected_language)) detected_language))
actual_subtitles.append([str(detected_language), path_replace_reverse( actual_subtitles.append([str(detected_language), path_replace_reverse(subtitle_path)])
os.path.join(os.path.dirname(reversed_path), subtitle))])
database.execute("UPDATE table_episodes SET subtitles=? WHERE path=?", database.execute("UPDATE table_episodes SET subtitles=? WHERE path=?",
(str(actual_subtitles), original_path)) (str(actual_subtitles), original_path))
@ -164,24 +163,16 @@ def store_subtitles_movie(original_path, reversed_path):
pass pass
else: else:
for subtitle, language in six.iteritems(subtitles): for subtitle, language in six.iteritems(subtitles):
subtitle_path = get_external_subtitles_path(reversed_path, subtitle)
if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)): if str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese)):
logging.debug("BAZARR external subtitles detected: " + "pb") logging.debug("BAZARR external subtitles detected: " + "pb")
actual_subtitles.append( actual_subtitles.append([str("pb"), path_replace_reverse_movie(subtitle_path)])
[str("pb"),
path_replace_reverse_movie(os.path.join(os.path.dirname(reversed_path), dest_folder, subtitle))]
)
elif str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese_forced)): elif str(os.path.splitext(subtitle)[0]).lower().endswith(tuple(brazilian_portuguese_forced)):
logging.debug("BAZARR external subtitles detected: " + "pb:forced") logging.debug("BAZARR external subtitles detected: " + "pb:forced")
actual_subtitles.append( actual_subtitles.append([str("pb:forced"), path_replace_reverse_movie(subtitle_path)])
[str("pb:forced"),
path_replace_reverse_movie(os.path.join(os.path.dirname(reversed_path), dest_folder, subtitle))]
)
elif str(language) != 'und': elif str(language) != 'und':
logging.debug("BAZARR external subtitles detected: " + str(language)) logging.debug("BAZARR external subtitles detected: " + str(language))
actual_subtitles.append( actual_subtitles.append([str(language), path_replace_reverse_movie(subtitle_path)])
[str(language),
path_replace_reverse_movie(os.path.join(os.path.dirname(reversed_path), dest_folder, subtitle))]
)
else: else:
if os.path.splitext(subtitle)[1] != ".sub": if os.path.splitext(subtitle)[1] != ".sub":
logging.debug("BAZARR falling back to file content analysis to detect language.") logging.debug("BAZARR falling back to file content analysis to detect language.")
@ -200,10 +191,9 @@ def store_subtitles_movie(original_path, reversed_path):
else: else:
if len(detected_language) > 0: if len(detected_language) > 0:
logging.debug( logging.debug(
"BAZARR external subtitles detected and analysis guessed this language: " + str( "BAZARR external subtitles detected and analysis guessed this language: " +
detected_language)) str(detected_language))
actual_subtitles.append([str(detected_language), path_replace_reverse_movie( actual_subtitles.append([str(detected_language), path_replace_reverse_movie(subtitle_path)])
os.path.join(os.path.dirname(reversed_path), dest_folder, subtitle))])
database.execute("UPDATE table_movies SET subtitles=? WHERE path=?", database.execute("UPDATE table_movies SET subtitles=? WHERE path=?",
(str(actual_subtitles), original_path)) (str(actual_subtitles), original_path))

View File

@ -1733,7 +1733,7 @@ def remove_subtitles():
history_log(0, sonarrSeriesId, sonarrEpisodeId, result) history_log(0, sonarrSeriesId, sonarrEpisodeId, result)
except OSError as e: except OSError as e:
logging.exception('BAZARR cannot delete subtitles file: ' + subtitlesPath) logging.exception('BAZARR cannot delete subtitles file: ' + subtitlesPath)
store_subtitles(episodePath, unicode(episodePath)) store_subtitles(episodePath, path_replace(episodePath))
@route(base_url + 'remove_subtitles_movie', method='POST') @route(base_url + 'remove_subtitles_movie', method='POST')
@ -1784,7 +1784,7 @@ def get_subtitle():
score = result[4] score = result[4]
history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score) history_log(1, sonarrSeriesId, sonarrEpisodeId, message, path, language_code, provider, score)
send_notifications(sonarrSeriesId, sonarrEpisodeId, message) send_notifications(sonarrSeriesId, sonarrEpisodeId, message)
store_subtitles(episodePath, six.text_type(episodePath)) store_subtitles(path, episodePath)
redirect(ref) redirect(ref)
except OSError: except OSError:
pass pass