1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-27 01:57:33 +00:00

Fixed uploaded subtitles not preserved when it should. #1879

This commit is contained in:
morpheus65535 2022-06-28 23:31:21 -04:00
parent 3a14099e36
commit 44ffac67b3

View file

@ -1,12 +1,14 @@
# coding=utf-8 # coding=utf-8
# fmt: off # fmt: off
import os
import sys import sys
import logging import logging
from subzero.language import Language from subzero.language import Language
from subliminal_patch.core import save_subtitles from subliminal_patch.core import save_subtitles
from subliminal_patch.subtitle import Subtitle from subliminal_patch.subtitle import Subtitle
from pysubs2.formats import get_format_identifier
from languages.get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, \ from languages.get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_alpha2, \
alpha2_from_language, alpha3_from_language alpha2_from_language, alpha3_from_language
@ -17,7 +19,7 @@ from utilities.path_mappings import path_mappings
from radarr.notify import notify_radarr from radarr.notify import notify_radarr
from sonarr.notify import notify_sonarr from sonarr.notify import notify_sonarr
from languages.custom_lang import CustomLanguage from languages.custom_lang import CustomLanguage
from app.database import TableEpisodes, TableMovies from app.database import TableEpisodes, TableMovies, TableShows, get_profiles_list
from app.event_handler import event_stream from app.event_handler import event_stream
from .sync import sync_subtitles from .sync import sync_subtitles
@ -62,6 +64,35 @@ def manual_upload_subtitle(path, language, forced, hi, title, scene_name, media_
if settings.general.getboolean('utf8_encode'): if settings.general.getboolean('utf8_encode'):
sub.set_encoding("utf-8") sub.set_encoding("utf-8")
if media_type == 'series':
episode_metadata = TableEpisodes.select(TableEpisodes.sonarrSeriesId,
TableEpisodes.sonarrEpisodeId,
TableShows.profileId) \
.join(TableShows, on=(TableEpisodes.sonarrSeriesId == TableShows.sonarrSeriesId)) \
.where(TableEpisodes.path == path_mappings.path_replace_reverse(path)) \
.dicts() \
.get_or_none()
if episode_metadata:
use_original_format = bool(get_profiles_list(episode_metadata["profileId"])["originalFormat"])
else:
use_original_format = False
else:
movie_metadata = TableMovies.select(TableMovies.radarrId, TableMovies.profileId) \
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path)) \
.dicts() \
.get_or_none()
if movie_metadata:
use_original_format = bool(get_profiles_list(movie_metadata["profileId"])["originalFormat"])
else:
use_original_format = False
try:
sub.format = (get_format_identifier(os.path.splitext(subtitle.filename)[1]),)
except Exception:
pass
saved_subtitles = [] saved_subtitles = []
try: try:
saved_subtitles = save_subtitles(path, saved_subtitles = save_subtitles(path,
@ -70,7 +101,7 @@ def manual_upload_subtitle(path, language, forced, hi, title, scene_name, media_
tags=None, # fixme tags=None, # fixme
directory=get_target_folder(path), directory=get_target_folder(path),
chmod=chmod, chmod=chmod,
formats=(sub.format,), formats=(sub.format,) if use_original_format else ("srt",),
path_decoder=force_unicode) path_decoder=force_unicode)
except Exception: except Exception:
logging.exception('BAZARR Error saving Subtitles file to disk for this file:' + path) logging.exception('BAZARR Error saving Subtitles file to disk for this file:' + path)
@ -103,10 +134,6 @@ def manual_upload_subtitle(path, language, forced, hi, title, scene_name, media_
audio_language_code3 = alpha3_from_language(audio_language) audio_language_code3 = alpha3_from_language(audio_language)
if media_type == 'series': if media_type == 'series':
episode_metadata = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId) \
.where(TableEpisodes.path == path_mappings.path_replace_reverse(path)) \
.dicts() \
.get_or_none()
if not episode_metadata: if not episode_metadata:
return return
series_id = episode_metadata['sonarrSeriesId'] series_id = episode_metadata['sonarrSeriesId']
@ -115,10 +142,6 @@ def manual_upload_subtitle(path, language, forced, hi, title, scene_name, media_
percent_score=100, sonarr_series_id=episode_metadata['sonarrSeriesId'], forced=forced, percent_score=100, sonarr_series_id=episode_metadata['sonarrSeriesId'], forced=forced,
sonarr_episode_id=episode_metadata['sonarrEpisodeId']) sonarr_episode_id=episode_metadata['sonarrEpisodeId'])
else: else:
movie_metadata = TableMovies.select(TableMovies.radarrId) \
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path)) \
.dicts() \
.get_or_none()
if not movie_metadata: if not movie_metadata:
return return
series_id = "" series_id = ""