From 7fc50a20a8860aa986bba53802cfe9f384686260 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Sat, 15 Aug 2020 08:30:04 -0400
Subject: [PATCH 01/21] Version bump.
---
bazarr/main.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bazarr/main.py b/bazarr/main.py
index 4446c725a..8a2bad4bf 100644
--- a/bazarr/main.py
+++ b/bazarr/main.py
@@ -1,6 +1,6 @@
# coding=utf-8
-bazarr_version = '0.9.0.2'
+bazarr_version = '0.9.0.3'
import os
os.environ["BAZARR_VERSION"] = bazarr_version
From 36cf8ca344a571774dc19badf1f7d2e7449da8ab Mon Sep 17 00:00:00 2001
From: josdion
Date: Sun, 16 Aug 2020 11:01:21 +0300
Subject: [PATCH 02/21] subssabbz, subsunacs, yavkanet - add frame rate to
release info
- add subtitle frame rate to release info
- better handling of exceptions while dolwnloading subtitles
---
libs/subliminal_patch/providers/subssabbz.py | 30 ++++++++------
libs/subliminal_patch/providers/subsunacs.py | 41 +++++++++++---------
libs/subliminal_patch/providers/yavkanet.py | 30 ++++++++------
3 files changed, 61 insertions(+), 40 deletions(-)
diff --git a/libs/subliminal_patch/providers/subssabbz.py b/libs/subliminal_patch/providers/subssabbz.py
index 386e3c19f..960d36429 100644
--- a/libs/subliminal_patch/providers/subssabbz.py
+++ b/libs/subliminal_patch/providers/subssabbz.py
@@ -55,7 +55,12 @@ class SubsSabBzSubtitle(Subtitle):
self.video = video
self.fps = fps
self.num_cds = num_cds
- self.release_info = os.path.splitext(filename)[0]
+ self.release_info = filename
+ if fps:
+ if video.fps and float(video.fps) == fps:
+ self.release_info += " [{:.3f}]".format(fps)
+ else:
+ self.release_info += " [{:.3f}]".format(fps)
@property
def id(self):
@@ -168,7 +173,7 @@ class SubsSabBzProvider(Provider):
element = a_element_wrapper.find('a')
if element:
link = element.get('href')
- notes = element.get('onmouseover')
+ notes = re.sub(r'ddrivetip\(\'(.*)\',\'#[0-9]+\'\)', r'\1', element.get('onmouseover'))
title = element.get_text()
try:
@@ -248,12 +253,15 @@ class SubsSabBzProvider(Provider):
else:
logger.info('Cache file: %s', codecs.encode(cache_key, 'hex_codec').decode('utf-8'))
- archive_stream = io.BytesIO(request.content)
- if is_rarfile(archive_stream):
- return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
- elif is_zipfile(archive_stream):
- return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
- else:
- logger.error('Ignore unsupported archive %r', request.headers)
- region.delete(cache_key)
- return []
+ try:
+ archive_stream = io.BytesIO(request.content)
+ if is_rarfile(archive_stream):
+ return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
+ elif is_zipfile(archive_stream):
+ return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
+ except:
+ pass
+
+ logger.error('Ignore unsupported archive %r', request.headers)
+ region.delete(cache_key)
+ return []
diff --git a/libs/subliminal_patch/providers/subsunacs.py b/libs/subliminal_patch/providers/subsunacs.py
index 19c5eff86..137d2f7bf 100644
--- a/libs/subliminal_patch/providers/subsunacs.py
+++ b/libs/subliminal_patch/providers/subsunacs.py
@@ -55,7 +55,12 @@ class SubsUnacsSubtitle(Subtitle):
self.video = video
self.fps = fps
self.num_cds = num_cds
- self.release_info = os.path.splitext(filename)[0]
+ self.release_info = filename
+ if fps:
+ if video.fps and float(video.fps) == fps:
+ self.release_info += " [{:.3f}]".format(fps)
+ else:
+ self.release_info += " [{:.3f}]".format(fps)
@property
def id(self):
@@ -168,7 +173,7 @@ class SubsUnacsProvider(Provider):
element = a_element_wrapper.find('a', {'class': 'tooltip'})
if element:
link = element.get('href')
- notes = element.get('title')
+ notes = re.sub(r'()', r"", element.get('title'))
title = element.get_text()
try:
@@ -230,11 +235,8 @@ class SubsUnacsProvider(Provider):
is_7zip = isinstance(archiveStream, SevenZipFile)
if is_7zip:
- try:
- file_content = archiveStream.readall()
- file_list = sorted(file_content)
- except:
- return []
+ file_content = archiveStream.readall()
+ file_list = sorted(file_content)
else:
file_list = sorted(archiveStream.namelist())
@@ -268,14 +270,17 @@ class SubsUnacsProvider(Provider):
else:
logger.info('Cache file: %s', codecs.encode(cache_key, 'hex_codec').decode('utf-8'))
- archive_stream = io.BytesIO(request.content)
- if is_rarfile(archive_stream):
- return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
- elif is_zipfile(archive_stream):
- return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
- elif archive_stream.seek(0) == 0 and is_7zfile(archive_stream):
- return self.process_archive_subtitle_files(SevenZipFile(archive_stream), language, video, link, fps, num_cds)
- else:
- logger.error('Ignore unsupported archive %r', request.headers)
- region.delete(cache_key)
- return []
+ try:
+ archive_stream = io.BytesIO(request.content)
+ if is_rarfile(archive_stream):
+ return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
+ elif is_zipfile(archive_stream):
+ return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
+ elif archive_stream.seek(0) == 0 and is_7zfile(archive_stream):
+ return self.process_archive_subtitle_files(SevenZipFile(archive_stream), language, video, link, fps, num_cds)
+ except:
+ pass
+
+ logger.error('Ignore unsupported archive %r', request.headers)
+ region.delete(cache_key)
+ return []
diff --git a/libs/subliminal_patch/providers/yavkanet.py b/libs/subliminal_patch/providers/yavkanet.py
index 6de60ef35..4555fd177 100644
--- a/libs/subliminal_patch/providers/yavkanet.py
+++ b/libs/subliminal_patch/providers/yavkanet.py
@@ -37,7 +37,12 @@ class YavkaNetSubtitle(Subtitle):
self.type = type
self.video = video
self.fps = fps
- self.release_info = os.path.splitext(filename)[0]
+ self.release_info = filename
+ if fps:
+ if video.fps and float(video.fps) == fps:
+ self.release_info += " [{:.3f}]".format(fps)
+ else:
+ self.release_info += " [{:.3f}]".format(fps)
@property
def id(self):
@@ -141,7 +146,7 @@ class YavkaNetProvider(Provider):
element = row.find('a', {'class': 'selector'})
if element:
link = element.get('href')
- notes = element.get('content')
+ notes = re.sub(r'(?s)
(.*)
', r"\1", element.get('content'))
title = element.get_text()
try:
@@ -205,12 +210,15 @@ class YavkaNetProvider(Provider):
else:
logger.info('Cache file: %s', codecs.encode(cache_key, 'hex_codec').decode('utf-8'))
- archive_stream = io.BytesIO(request.content)
- if is_rarfile(archive_stream):
- return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps)
- elif is_zipfile(archive_stream):
- return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps)
- else:
- logger.error('Ignore unsupported archive %r', request.headers)
- region.delete(cache_key)
- return []
+ try:
+ archive_stream = io.BytesIO(request.content)
+ if is_rarfile(archive_stream):
+ return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps)
+ elif is_zipfile(archive_stream):
+ return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps)
+ except:
+ pass
+
+ logger.error('Ignore unsupported archive %r', request.headers)
+ region.delete(cache_key)
+ return []
From b4165408fbd6afbfe9992a335aa35f4a89fa9b92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Mon, 17 Aug 2020 23:52:48 -0400
Subject: [PATCH 03/21] Another attempt to fix #1034.
---
bazarr/get_providers.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py
index a29abac35..5e65d4eea 100644
--- a/bazarr/get_providers.py
+++ b/bazarr/get_providers.py
@@ -30,8 +30,8 @@ hours_until_end_of_day = time_until_end_of_day().seconds // 3600 + 1
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled,
ParseResponseError, IPAddressBlocked)
-VALID_COUNT_EXCEPTIONS = ('TooManyRequests', 'ServiceUnavailable', 'APIThrottled', requests.Timeout,
- requests.ReadTimeout, socket.timeout)
+VALID_COUNT_EXCEPTIONS = ('TooManyRequests', 'ServiceUnavailable', 'APIThrottled', requests.exceptions.Timeout,
+ requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout, socket.timeout)
PROVIDER_THROTTLE_MAP = {
"default": {
@@ -40,9 +40,10 @@ PROVIDER_THROTTLE_MAP = {
ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
ParseResponseError: (datetime.timedelta(hours=6), "6 hours"),
- requests.Timeout: (datetime.timedelta(hours=1), "1 hour"),
+ requests.exceptions.Timeout: (datetime.timedelta(hours=1), "1 hour"),
socket.timeout: (datetime.timedelta(hours=1), "1 hour"),
- requests.ReadTimeout: (datetime.timedelta(hours=1), "1 hour"),
+ requests.exceptions.ConnectTimeout: (datetime.timedelta(hours=1), "1 hour"),
+ requests.exceptions.ReadTimeout: (datetime.timedelta(hours=1), "1 hour"),
},
"opensubtitles": {
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
From 55cff621397bd218bbad66bd48200f32f01cd015 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 18 Aug 2020 09:12:01 -0400
Subject: [PATCH 04/21] Fix for #1074.
---
bazarr/subsyncer.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/bazarr/subsyncer.py b/bazarr/subsyncer.py
index b0cfa018c..0d85665a5 100644
--- a/bazarr/subsyncer.py
+++ b/bazarr/subsyncer.py
@@ -49,9 +49,11 @@ class SubSyncer:
'{0}'.format(self.srtin))
else:
if result['sync_was_successful']:
+ offset_seconds = result['offset_seconds'] or 0
+ framerate_scale_factor = result['framerate_scale_factor'] or 0
message = "{0} subtitles synchronization ended with an offset of {1} seconds and a framerate scale " \
- "factor of {2}.".format(language_from_alpha3(srt_lang), result['offset_seconds'],
- "{:.2f}".format(result['framerate_scale_factor']))
+ "factor of {2}.".format(language_from_alpha3(srt_lang), offset_seconds,
+ "{:.2f}".format(framerate_scale_factor))
if media_type == 'series':
history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id,
From f740231e641fd679e4744f12d4e54542f491bdaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 18 Aug 2020 13:20:45 -0400
Subject: [PATCH 05/21] Fix for missing language name from Radarr v3.
---
bazarr/get_movies.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py
index 39f24ce62..b056bb819 100644
--- a/bazarr/get_movies.py
+++ b/bazarr/get_movies.py
@@ -151,7 +151,8 @@ def update_movies():
audio_language = profile_id_to_language(movie['qualityProfileId'], audio_profiles)
else:
if len(movie['movieFile']['languages']):
- audio_language = movie['movieFile']['languages'][0]['name']
+ if 'name' in movie['movieFile']['languages'][0]:
+ audio_language = movie['movieFile']['languages'][0]['name']
tags = [d['label'] for d in tagsDict if d['id'] in movie['tags']]
From d95dc2b8233da3f0767ee7b0118cc553ac2c8cc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 18 Aug 2020 15:24:31 -0400
Subject: [PATCH 06/21] Another fix for Radarr v3.
---
bazarr/get_movies.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py
index b056bb819..ffa19051e 100644
--- a/bazarr/get_movies.py
+++ b/bazarr/get_movies.py
@@ -150,7 +150,7 @@ def update_movies():
if radarr_version.startswith('0'):
audio_language = profile_id_to_language(movie['qualityProfileId'], audio_profiles)
else:
- if len(movie['movieFile']['languages']):
+ if 'language' in movie['movieFile'] and len(movie['movieFile']['languages']):
if 'name' in movie['movieFile']['languages'][0]:
audio_language = movie['movieFile']['languages'][0]['name']
From d6ce71b16f85a1c6d5ba61fdf0ac125647752f86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 18 Aug 2020 15:28:07 -0400
Subject: [PATCH 07/21] Another fix for Radarr v3.
---
bazarr/get_movies.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py
index ffa19051e..ce730f9af 100644
--- a/bazarr/get_movies.py
+++ b/bazarr/get_movies.py
@@ -150,7 +150,7 @@ def update_movies():
if radarr_version.startswith('0'):
audio_language = profile_id_to_language(movie['qualityProfileId'], audio_profiles)
else:
- if 'language' in movie['movieFile'] and len(movie['movieFile']['languages']):
+ if 'languages' in movie['movieFile'] and len(movie['movieFile']['languages']):
if 'name' in movie['movieFile']['languages'][0]:
audio_language = movie['movieFile']['languages'][0]['name']
From 5dbde75893e984b667c8e35f224bff48fd7825e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Tue, 18 Aug 2020 16:35:06 -0400
Subject: [PATCH 08/21] Another attempt to fix audio languages for Radarr v3.
---
bazarr/get_movies.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py
index ce730f9af..ff3505795 100644
--- a/bazarr/get_movies.py
+++ b/bazarr/get_movies.py
@@ -151,8 +151,11 @@ def update_movies():
audio_language = profile_id_to_language(movie['qualityProfileId'], audio_profiles)
else:
if 'languages' in movie['movieFile'] and len(movie['movieFile']['languages']):
- if 'name' in movie['movieFile']['languages'][0]:
- audio_language = movie['movieFile']['languages'][0]['name']
+ for item in movie['movieFile']['languages']:
+ if isinstance(item, dict):
+ if 'name' in item:
+ audio_language = item['name']
+ break
tags = [d['label'] for d in tagsDict if d['id'] in movie['tags']]
From 6ad4843cdfbe213141f14ff760e4117ed6688d5b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Wed, 19 Aug 2020 15:23:43 -0400
Subject: [PATCH 09/21] Multiple fixes to ffsubsync.
---
libs/ffsubsync/ffsubsync.py | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/libs/ffsubsync/ffsubsync.py b/libs/ffsubsync/ffsubsync.py
index 18d772c12..31815762f 100644
--- a/libs/ffsubsync/ffsubsync.py
+++ b/libs/ffsubsync/ffsubsync.py
@@ -41,12 +41,15 @@ def make_test_case(args, npy_savename, sync_was_successful):
raise ValueError('need non-null npy_savename')
tar_dir = '{}.{}'.format(
args.reference,
- datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
+ datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
)
logger.info('creating test archive {}.tar.gz...'.format(tar_dir))
os.mkdir(tar_dir)
try:
- shutil.move('ffsubsync.log', tar_dir)
+ log_path = 'ffsubsync.log'
+ if args.log_dir_path and os.path.isdir(args.log_dir_path):
+ log_path = os.path.join(args.log_dir_path, log_path)
+ shutil.move(log_path, tar_dir)
shutil.copy(args.srtin, tar_dir)
if sync_was_successful:
shutil.move(args.srtout, tar_dir)
@@ -62,10 +65,10 @@ def make_test_case(args, npy_savename, sync_was_successful):
if archive_format in supported_formats:
shutil.make_archive(tar_dir, 'gztar', os.curdir, tar_dir)
break
- else:
- logger.error('failed to create test archive; no formats supported '
- '(this should not happen)')
- return 1
+ else:
+ logger.error('failed to create test archive; no formats supported '
+ '(this should not happen)')
+ return 1
logger.info('...done')
finally:
shutil.rmtree(tar_dir)
@@ -265,7 +268,10 @@ def run(args):
result['retval'] = 1
return result
if args.make_test_case:
- handler = logging.FileHandler('ffsubsync.log')
+ log_path = 'ffsubsync.log'
+ if args.log_dir_path and os.path.isdir(args.log_dir_path):
+ log_path = os.path.join(args.log_dir_path, log_path)
+ handler = logging.FileHandler(log_path)
logger.addHandler(handler)
if args.extract_subs_from_stream is not None:
result['retval'] = extract_subtitles_from_reference(args)
@@ -286,6 +292,8 @@ def run(args):
srt_pipes = make_srt_pipes(args)
sync_was_successful = try_sync(args, reference_pipe, srt_pipes, result)
if args.make_test_case:
+ handler.close()
+ logger.removeHandler(handler)
result['retval'] += make_test_case(args, npy_savename, sync_was_successful)
return result
@@ -354,6 +362,8 @@ def add_cli_only_args(parser):
'--ffmpeg-path', '--ffmpegpath', default=None,
help='Where to look for ffmpeg and ffprobe. Uses the system PATH by default.'
)
+ parser.add_argument('--log-dir-path', default=None, help='Where to save ffsubsync.log file (must be an existing '
+ 'directory).')
parser.add_argument('--vlc-mode', action='store_true', help=argparse.SUPPRESS)
parser.add_argument('--gui-mode', action='store_true', help=argparse.SUPPRESS)
From 88452468cf88ae14335c5115e66c3c97d69d1796 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Wed, 19 Aug 2020 15:40:33 -0400
Subject: [PATCH 10/21] Added debug mode for subtitles synchronization.
---
bazarr/config.py | 3 ++-
bazarr/subsyncer.py | 41 ++++++++++++++++++++++--------------
views/settingssubtitles.html | 17 +++++++++++++--
3 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/bazarr/config.py b/bazarr/config.py
index b266280a2..72fe3cb3e 100644
--- a/bazarr/config.py
+++ b/bazarr/config.py
@@ -162,7 +162,8 @@ defaults = {
'use_subsync_threshold': 'False',
'subsync_threshold': '90',
'use_subsync_movie_threshold': 'False',
- 'subsync_movie_threshold': '70'
+ 'subsync_movie_threshold': '70',
+ 'debug': 'False'
}
}
diff --git a/bazarr/subsyncer.py b/bazarr/subsyncer.py
index 0d85665a5..220f492ae 100644
--- a/bazarr/subsyncer.py
+++ b/bazarr/subsyncer.py
@@ -5,6 +5,8 @@ from utils import get_binary
from utils import history_log, history_log_movie
from get_languages import alpha2_from_alpha3, language_from_alpha3
from helper import path_mappings
+from config import settings
+from get_args import args
class SubSyncer:
@@ -15,12 +17,13 @@ class SubSyncer:
self.ffmpeg_path = None
self.args = None
self.vad = 'subs_then_auditok'
+ self.log_dir_path = os.path.join(args.config_dir, 'log')
def sync(self, video_path, srt_path, srt_lang, media_type, sonarr_series_id=None, sonarr_episode_id=None,
radarr_id=None):
self.reference = video_path
self.srtin = srt_path
- self.srtout = None
+ self.srtout = '{}.synced.srt'.format(os.path.splitext(self.srtin)[0])
self.args = None
ffprobe_exe = get_binary('ffprobe')
@@ -39,8 +42,10 @@ class SubSyncer:
self.ffmpeg_path = os.path.dirname(ffmpeg_exe)
try:
- unparsed_args = [self.reference, '-i', self.srtin, '--overwrite-input', '--ffmpegpath', self.ffmpeg_path,
- '--vad', self.vad]
+ unparsed_args = [self.reference, '-i', self.srtin, '-o', self.srtout, '--ffmpegpath', self.ffmpeg_path,
+ '--vad', self.vad, '--log-dir-path', self.log_dir_path]
+ if settings.subsync.getboolean('debug'):
+ unparsed_args.append('--make-test-case')
parser = make_parser()
self.args = parser.parse_args(args=unparsed_args)
result = run(self.args)
@@ -49,20 +54,24 @@ class SubSyncer:
'{0}'.format(self.srtin))
else:
if result['sync_was_successful']:
- offset_seconds = result['offset_seconds'] or 0
- framerate_scale_factor = result['framerate_scale_factor'] or 0
- message = "{0} subtitles synchronization ended with an offset of {1} seconds and a framerate scale " \
- "factor of {2}.".format(language_from_alpha3(srt_lang), offset_seconds,
- "{:.2f}".format(framerate_scale_factor))
+ if not settings.subsync.getboolean('debug'):
+ os.remove(self.srtin)
+ os.rename(self.srtout, self.srtin)
+
+ offset_seconds = result['offset_seconds'] or 0
+ framerate_scale_factor = result['framerate_scale_factor'] or 0
+ message = "{0} subtitles synchronization ended with an offset of {1} seconds and a framerate " \
+ "scale factor of {2}.".format(language_from_alpha3(srt_lang), offset_seconds,
+ "{:.2f}".format(framerate_scale_factor))
- if media_type == 'series':
- history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id,
- description=message, video_path=path_mappings.path_replace_reverse(self.reference),
- language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path)
- else:
- history_log_movie(action=5, radarr_id=radarr_id, description=message,
- video_path=path_mappings.path_replace_reverse_movie(self.reference),
- language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path)
+ if media_type == 'series':
+ history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id,
+ description=message, video_path=path_mappings.path_replace_reverse(self.reference),
+ language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path)
+ else:
+ history_log_movie(action=5, radarr_id=radarr_id, description=message,
+ video_path=path_mappings.path_replace_reverse_movie(self.reference),
+ language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path)
else:
logging.error('BAZARR unable to sync subtitles: {0}'.format(self.srtin))
diff --git a/views/settingssubtitles.html b/views/settingssubtitles.html
index c04197aad..e01012f93 100644
--- a/views/settingssubtitles.html
+++ b/views/settingssubtitles.html
@@ -412,14 +412,26 @@
{% endif %}
- Subtitles synchronization
+ Automatic subtitles synchronization
-
+
+
+
+
+
+ Subtitles synchronization debugging
+
+
+
+
@@ -680,6 +692,7 @@
$('#settings-general-chmod_enabled').prop('checked', {{'true' if settings.general.getboolean('chmod_enabled') else 'false'}}).trigger('change');
$('#settings-subsync-use_subsync').prop('checked', {{'true' if settings.subsync.getboolean('use_subsync') else 'false'}}).trigger('change');
$('#settings-subsync-use_subsync_threshold').prop('checked', {{'true' if settings.subsync.getboolean('use_subsync_threshold') else 'false'}}).trigger('change');
+ $('#settings-subsync-debug').prop('checked', {{'true' if settings.subsync.getboolean('debug') else 'false'}}).trigger('change');
$('#settings-subsync-use_subsync_movie_threshold').prop('checked', {{'true' if settings.subsync.getboolean('use_subsync_movie_threshold') else 'false'}}).trigger('change');
$('#settings-general-use_postprocessing').prop('checked', {{'true' if settings.general.getboolean('use_postprocessing') else 'false'}}).trigger('change');
$('#settings-general-use_postprocessing_threshold').prop('checked', {{'true' if settings.general.getboolean('use_postprocessing_threshold') else 'false'}}).trigger('change');
From ebde79a8cd5efcbc1d9584a71ed652f7e983060a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Louis=20V=C3=A9zina?=
<5130500+morpheus65535@users.noreply.github.com>
Date: Thu, 20 Aug 2020 10:19:34 -0400
Subject: [PATCH 11/21] Switched to the actual episodes audio language instead
of series audio profile language.
---
bazarr/api.py | 13 +++++++++----
bazarr/database.py | 1 +
bazarr/get_episodes.py | 15 ++++++++++++---
bazarr/get_subtitle.py | 12 ++++++------
views/episodes.html | 10 +++++++---
views/series.html | 4 ++--
views/serieseditor.html | 2 +-
7 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/bazarr/api.py b/bazarr/api.py
index c61da14bf..a40fd6e3a 100644
--- a/bazarr/api.py
+++ b/bazarr/api.py
@@ -462,6 +462,11 @@ class Episodes(Resource):
# Add Datatables rowId
item.update({"DT_RowId": 'row_' + str(item['sonarrEpisodeId'])})
+ # Parse audio language
+ item.update({"audio_language": {"name": item['audio_language'],
+ "code2": alpha2_from_language(item['audio_language']) or None,
+ "code3": alpha3_from_language(item['audio_language']) or None}})
+
# Parse subtitles
if item['subtitles']:
item.update({"subtitles": ast.literal_eval(item['subtitles'])})
@@ -540,8 +545,8 @@ class EpisodesSubtitlesDownload(Resource):
title = request.form.get('title')
providers_list = get_providers()
providers_auth = get_providers_auth()
- audio_language = database.execute("SELECT audio_language FROM table_shows WHERE sonarrSeriesId=?",
- (sonarrSeriesId,), only_one=True)['audio_language']
+ audio_language = database.execute("SELECT audio_language FROM table_episodes WHERE sonarrEpisodeId=?",
+ (sonarrEpisodeId,), only_one=True)['audio_language']
try:
result = download_subtitle(episodePath, language, audio_language, hi, forced, providers_list, providers_auth, sceneName,
@@ -609,8 +614,8 @@ class EpisodesSubtitlesManualDownload(Resource):
sonarrEpisodeId = request.form.get('sonarrEpisodeId')
title = request.form.get('title')
providers_auth = get_providers_auth()
- audio_language = database.execute("SELECT audio_language FROM table_shows WHERE sonarrSeriesId=?",
- (sonarrSeriesId,), only_one=True)['audio_language']
+ audio_language = database.execute("SELECT audio_language FROM table_episodes WHERE sonarrEpisodeId=?",
+ (sonarrEpisodeId,), only_one=True)['audio_language']
try:
result = manual_download_subtitle(episodePath, language, audio_language, hi, forced, subtitle,
diff --git a/bazarr/database.py b/bazarr/database.py
index 15e9c2d60..5046f9974 100644
--- a/bazarr/database.py
+++ b/bazarr/database.py
@@ -99,6 +99,7 @@ def db_upgrade():
['table_episodes', 'video_codec', 'text'],
['table_episodes', 'audio_codec', 'text'],
['table_episodes', 'episode_file_id', 'integer'],
+ ['table_episodes', 'audio_language', 'text'],
['table_movies', 'sortTitle', 'text'],
['table_movies', 'year', 'text'],
['table_movies', 'alternativeTitles', 'text'],
diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py
index d9e485422..1e303a8f5 100644
--- a/bazarr/get_episodes.py
+++ b/bazarr/get_episodes.py
@@ -85,6 +85,13 @@ def sync_episodes():
videoCodec = None
audioCodec = None
+ audio_language = None
+ if 'language' in episode['episodeFile'] and len(episode['episodeFile']['language']):
+ item = episode['episodeFile']['language']
+ if isinstance(item, dict):
+ if 'name' in item:
+ audio_language = item['name']
+
# Add episodes in sonarr to current episode list
current_episodes_sonarr.append(episode['id'])
@@ -101,7 +108,8 @@ def sync_episodes():
'resolution': resolution,
'video_codec': videoCodec,
'audio_codec': audioCodec,
- 'episode_file_id': episode['episodeFile']['id']})
+ 'episode_file_id': episode['episodeFile']['id'],
+ 'audio_language': audio_language})
else:
episodes_to_add.append({'sonarrSeriesId': episode['seriesId'],
'sonarrEpisodeId': episode['id'],
@@ -115,7 +123,8 @@ def sync_episodes():
'resolution': resolution,
'video_codec': videoCodec,
'audio_codec': audioCodec,
- 'episode_file_id': episode['episodeFile']['id']})
+ 'episode_file_id': episode['episodeFile']['id'],
+ 'audio_language': audio_language})
# Remove old episodes from DB
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
@@ -131,7 +140,7 @@ def sync_episodes():
episode_in_db_list = []
episodes_in_db = database.execute("SELECT sonarrSeriesId, sonarrEpisodeId, title, path, season, episode, "
"scene_name, monitored, format, resolution, video_codec, audio_codec, "
- "episode_file_id FROM table_episodes")
+ "episode_file_id, audio_language FROM table_episodes")
for item in episodes_in_db:
episode_in_db_list.append(item)
diff --git a/bazarr/get_subtitle.py b/bazarr/get_subtitle.py
index b30d5a911..4ac1fc120 100644
--- a/bazarr/get_subtitle.py
+++ b/bazarr/get_subtitle.py
@@ -641,7 +641,7 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type
def series_download_subtitles(no):
episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, monitored, "
"table_episodes.sonarrEpisodeId, table_episodes.scene_name, table_shows.tags, "
- "table_shows.seriesType FROM table_episodes INNER JOIN table_shows on "
+ "table_shows.seriesType, table_episodes.audio_language FROM table_episodes INNER JOIN table_shows on "
"table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE "
"table_episodes.sonarrSeriesId=? and missing_subtitles!='[]'", (no,))
episodes_details = filter_exclusions(episodes_details, 'series')
@@ -650,7 +650,7 @@ def series_download_subtitles(no):
return
series_details = database.execute(
- "SELECT hearing_impaired, audio_language, title, forced FROM table_shows WHERE sonarrSeriesId=?",
+ "SELECT hearing_impaired, title, forced FROM table_shows WHERE sonarrSeriesId=?",
(no,), only_one=True)
if not series_details:
logging.debug("BAZARR no series with that sonarrSeriesId can be found in database:", str(no))
@@ -667,7 +667,7 @@ def series_download_subtitles(no):
if language is not None:
result = download_subtitle(path_mappings.path_replace(episode['path']),
str(alpha3_from_alpha2(language.split(':')[0])),
- series_details['audio_language'],
+ episode['audio_language'],
series_details['hearing_impaired'],
"True" if len(language.split(':')) > 1 else "False",
providers_list,
@@ -697,7 +697,7 @@ def episode_download_subtitles(no):
episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, monitored, "
"table_episodes.sonarrEpisodeId, table_episodes.scene_name, table_shows.tags, "
"table_shows.hearing_impaired, table_shows.title, table_shows.sonarrSeriesId, "
- "table_shows.forced, table_shows.audio_language, table_shows.seriesType FROM "
+ "table_shows.forced, table_episodes.audio_language, table_shows.seriesType FROM "
"table_episodes LEFT JOIN table_shows on table_episodes.sonarrSeriesId = "
"table_shows.sonarrSeriesId WHERE sonarrEpisodeId=?", (no,))
episodes_details = filter_exclusions(episodes_details, 'series')
@@ -792,7 +792,7 @@ def movies_download_subtitles(no):
def wanted_download_subtitles(path, l, count_episodes):
episodes_details = database.execute("SELECT table_episodes.path, table_episodes.missing_subtitles, "
"table_episodes.sonarrEpisodeId, table_episodes.sonarrSeriesId, "
- "table_shows.hearing_impaired, table_shows.audio_language, table_episodes.scene_name,"
+ "table_shows.hearing_impaired, table_episodes.audio_language, table_episodes.scene_name,"
"table_episodes.failedAttempts, table_shows.title, table_shows.forced "
"FROM table_episodes LEFT JOIN table_shows on "
"table_episodes.sonarrSeriesId = table_shows.sonarrSeriesId "
@@ -1071,7 +1071,7 @@ def upgrade_subtitles():
if settings.general.getboolean('use_sonarr'):
upgradable_episodes = database.execute("SELECT table_history.video_path, table_history.language, "
"table_history.score, table_shows.hearing_impaired, "
- "table_shows.audio_language, table_episodes.scene_name, table_episodes.title,"
+ "table_episodes.audio_language, table_episodes.scene_name, table_episodes.title,"
"table_episodes.sonarrSeriesId, table_episodes.sonarrEpisodeId,"
"MAX(table_history.timestamp) as timestamp, table_episodes.monitored, "
"table_shows.languages, table_shows.forced, table_shows.tags, "
diff --git a/views/episodes.html b/views/episodes.html
index 9d6995ae1..0fa3509e9 100644
--- a/views/episodes.html
+++ b/views/episodes.html
@@ -113,6 +113,7 @@
|
Episode |
Title |
+
Audio Language |
Existing Subtitles |
Missing Subtitles |
Manual Search |
@@ -232,7 +233,7 @@
- Audio Language
+ Audio Profile