summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2022-03-21 22:14:44 -0400
committermorpheus65535 <[email protected]>2022-03-21 22:14:44 -0400
commit012dc1cee977e4fb0b72a955736476f748c8314b (patch)
tree0ae855aeff919ebe4bf307bebfdc2ac42c66af9f
parentd66dc73b2082622b9d6ba95d83573c9a70dd11c7 (diff)
downloadbazarr-012dc1cee977e4fb0b72a955736476f748c8314b.tar.gz
bazarr-012dc1cee977e4fb0b72a955736476f748c8314b.zip
Added defer searching missing subtitles on live synchro with Sonarr and Radarr. #1765v1.0.4-beta.13
-rw-r--r--bazarr/api/webhooks/__init__.py4
-rw-r--r--bazarr/api/webhooks/radarr.py28
-rw-r--r--bazarr/api/webhooks/sonarr.py29
-rw-r--r--bazarr/config.py6
-rw-r--r--bazarr/get_episodes.py12
-rw-r--r--bazarr/get_movies.py12
-rw-r--r--bazarr/signalr_client.py5
-rw-r--r--frontend/src/pages/Settings/Radarr/index.tsx16
-rw-r--r--frontend/src/pages/Settings/Sonarr/index.tsx16
9 files changed, 116 insertions, 12 deletions
diff --git a/bazarr/api/webhooks/__init__.py b/bazarr/api/webhooks/__init__.py
index 76b8d62ff..9fc67bdd6 100644
--- a/bazarr/api/webhooks/__init__.py
+++ b/bazarr/api/webhooks/__init__.py
@@ -4,9 +4,13 @@ from flask import Blueprint
from flask_restful import Api
from .plex import WebHooksPlex
+from .sonarr import WebHooksSonarr
+from .radarr import WebHooksRadarr
api_bp_webhooks = Blueprint('api_webhooks', __name__)
api = Api(api_bp_webhooks)
api.add_resource(WebHooksPlex, '/webhooks/plex')
+api.add_resource(WebHooksSonarr, '/webhooks/sonarr')
+api.add_resource(WebHooksRadarr, '/webhooks/radarr')
diff --git a/bazarr/api/webhooks/radarr.py b/bazarr/api/webhooks/radarr.py
new file mode 100644
index 000000000..aa57912ea
--- /dev/null
+++ b/bazarr/api/webhooks/radarr.py
@@ -0,0 +1,28 @@
+# coding=utf-8
+
+from flask import request
+from flask_restful import Resource
+
+from database import TableMovies
+from get_subtitle.mass_download import movies_download_subtitles
+from list_subtitles import store_subtitles_movie
+from helper import path_mappings
+from ..utils import authenticate
+
+
+class WebHooksRadarr(Resource):
+ @authenticate
+ def post(self):
+ movie_file_id = request.form.get('radarr_moviefile_id')
+
+ radarrMovieId = TableMovies.select(TableMovies.radarrId,
+ TableMovies.path) \
+ .where(TableMovies.movie_file_id == movie_file_id) \
+ .dicts() \
+ .get_or_none()
+
+ if radarrMovieId:
+ store_subtitles_movie(radarrMovieId['path'], path_mappings.path_replace_movie(radarrMovieId['path']))
+ movies_download_subtitles(no=radarrMovieId['radarrId'])
+
+ return '', 200
diff --git a/bazarr/api/webhooks/sonarr.py b/bazarr/api/webhooks/sonarr.py
new file mode 100644
index 000000000..b28f01165
--- /dev/null
+++ b/bazarr/api/webhooks/sonarr.py
@@ -0,0 +1,29 @@
+# coding=utf-8
+
+from flask import request
+from flask_restful import Resource
+
+from database import TableEpisodes, TableShows
+from get_subtitle.mass_download import episode_download_subtitles
+from list_subtitles import store_subtitles
+from helper import path_mappings
+from ..utils import authenticate
+
+
+class WebHooksSonarr(Resource):
+ @authenticate
+ def post(self):
+ episode_file_id = request.form.get('sonarr_episodefile_id')
+
+ sonarrEpisodeId = TableEpisodes.select(TableEpisodes.sonarrEpisodeId,
+ TableEpisodes.path) \
+ .join(TableShows, on=(TableEpisodes.sonarrSeriesId == TableShows.sonarrSeriesId)) \
+ .where(TableEpisodes.episode_file_id == episode_file_id) \
+ .dicts() \
+ .get_or_none()
+
+ if sonarrEpisodeId:
+ store_subtitles(sonarrEpisodeId['path'], path_mappings.path_replace(sonarrEpisodeId['path']))
+ episode_download_subtitles(no=sonarrEpisodeId['sonarrEpisodeId'], send_progress=True)
+
+ return '', 200
diff --git a/bazarr/config.py b/bazarr/config.py
index 6d64bb3f5..08d4dc05e 100644
--- a/bazarr/config.py
+++ b/bazarr/config.py
@@ -103,7 +103,8 @@ defaults = {
'excluded_tags': '[]',
'excluded_series_types': '[]',
'use_ffprobe_cache': 'True',
- 'exclude_season_zero': 'False'
+ 'exclude_season_zero': 'False',
+ 'defer_search_signalr': 'False'
},
'radarr': {
'ip': '127.0.0.1',
@@ -117,7 +118,8 @@ defaults = {
'only_monitored': 'False',
'movies_sync': '60',
'excluded_tags': '[]',
- 'use_ffprobe_cache': 'True'
+ 'use_ffprobe_cache': 'True',
+ 'defer_search_signalr': 'False'
},
'proxy': {
'type': 'None',
diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py
index 34a38317f..a8e44d17d 100644
--- a/bazarr/get_episodes.py
+++ b/bazarr/get_episodes.py
@@ -165,7 +165,7 @@ def sync_episodes(series_id=None, send_event=True):
logging.debug('BAZARR All episodes synced from Sonarr into database.')
-def sync_one_episode(episode_id):
+def sync_one_episode(episode_id, defer_search=False):
logging.debug('BAZARR syncing this specific episode from Sonarr: {}'.format(episode_id))
url = url_sonarr()
apikey_sonarr = settings.sonarr.apikey
@@ -239,9 +239,13 @@ def sync_one_episode(episode_id):
store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
# Downloading missing subtitles
- logging.debug('BAZARR downloading missing subtitles for this episode: {}'.format(path_mappings.path_replace(
- episode['path'])))
- episode_download_subtitles(episode_id)
+ if defer_search:
+ logging.debug('BAZARR searching for missing subtitles is deferred until scheduled task execution for this '
+ 'episode: {}'.format(path_mappings.path_replace(episode['path'])))
+ else:
+ logging.debug('BAZARR downloading missing subtitles for this episode: {}'.format(path_mappings.path_replace(
+ episode['path'])))
+ episode_download_subtitles(episode_id)
def SonarrFormatAudioCodec(audio_codec):
diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py
index 0debf3378..d7759586f 100644
--- a/bazarr/get_movies.py
+++ b/bazarr/get_movies.py
@@ -166,7 +166,7 @@ def update_movies(send_event=True):
logging.debug('BAZARR All movies synced from Radarr into database.')
-def update_one_movie(movie_id, action):
+def update_one_movie(movie_id, action, defer_search=False):
logging.debug('BAZARR syncing this specific movie from Radarr: {}'.format(movie_id))
# Check if there's a row in database for this movie ID
@@ -262,9 +262,13 @@ def update_one_movie(movie_id, action):
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))
# Downloading missing subtitles
- logging.debug('BAZARR downloading missing subtitles for this movie: {}'.format(path_mappings.path_replace_movie(
- movie['path'])))
- movies_download_subtitles(movie_id)
+ if defer_search:
+ logging.debug('BAZARR searching for missing subtitles is deferred until scheduled task execution for this '
+ 'movie: {}'.format(path_mappings.path_replace_movie(movie['path'])))
+ else:
+ logging.debug('BAZARR downloading missing subtitles for this movie: {}'.format(path_mappings.path_replace_movie(
+ movie['path'])))
+ movies_download_subtitles(movie_id)
def get_profile_list():
diff --git a/bazarr/signalr_client.py b/bazarr/signalr_client.py
index 6ed49c743..d922b87ce 100644
--- a/bazarr/signalr_client.py
+++ b/bazarr/signalr_client.py
@@ -237,9 +237,10 @@ def dispatcher(data):
# this will happen if a season monitored status is changed.
sync_episodes(series_id=media_id, send_event=True)
elif topic == 'episode':
- sync_one_episode(episode_id=media_id)
+ sync_one_episode(episode_id=media_id, defer_search=settings.sonarr.getboolean('defer_search_signalr'))
elif topic == 'movie':
- update_one_movie(movie_id=media_id, action=action)
+ update_one_movie(movie_id=media_id, action=action,
+ defer_search=settings.radarr.getboolean('defer_search_signalr'))
except Exception as e:
logging.debug('BAZARR an exception occurred while parsing SignalR feed: {}'.format(repr(e)))
finally:
diff --git a/frontend/src/pages/Settings/Radarr/index.tsx b/frontend/src/pages/Settings/Radarr/index.tsx
index 7d0822a23..855b004f2 100644
--- a/frontend/src/pages/Settings/Radarr/index.tsx
+++ b/frontend/src/pages/Settings/Radarr/index.tsx
@@ -85,6 +85,22 @@ const SettingsRadarrView: FunctionComponent = () => {
movies in Radarr.
</Message>
</Input>
+ <Input>
+ <Check
+ label="Defer searching of subtitles until scheduled task execution"
+ settingKey="settings-radarr-defer_search_signalr"
+ ></Check>
+ <Message>
+ If enabled, this option will prevent Bazarr from searching
+ subtitles as soon as movies are imported.
+ </Message>
+ <Message>
+ Search can be triggered using this command: `curl -d
+ "radarr_moviefile_id=$radarr_moviefile_id" -H "x-api-key:
+ ###############################" -X POST
+ http://localhost:6767/api/webhooks/radarr`
+ </Message>
+ </Input>
</Group>
<Group header="Path Mappings">
<PathMappingTable type="radarr"></PathMappingTable>
diff --git a/frontend/src/pages/Settings/Sonarr/index.tsx b/frontend/src/pages/Settings/Sonarr/index.tsx
index 5baf10b9b..6f2cfb5de 100644
--- a/frontend/src/pages/Settings/Sonarr/index.tsx
+++ b/frontend/src/pages/Settings/Sonarr/index.tsx
@@ -100,6 +100,22 @@ const SettingsSonarrView: FunctionComponent = () => {
</Input>
<Input>
<Check
+ label="Defer searching of subtitles until scheduled task execution"
+ settingKey="settings-sonarr-defer_search_signalr"
+ ></Check>
+ <Message>
+ If enabled, this option will prevent Bazarr from searching
+ subtitles as soon as episodes are imported.
+ </Message>
+ <Message>
+ Search can be triggered using this command: `curl -d
+ "sonarr_episodefile_id=$sonarr_episodefile_id" -H "x-api-key:
+ ###############################" -X POST
+ http://localhost:6767/api/webhooks/sonarr`
+ </Message>
+ </Input>
+ <Input>
+ <Check
label="Exclude season zero (extras)"
settingKey="settings-sonarr-exclude_season_zero"
></Check>