mirror of https://github.com/morpheus65535/bazarr
Added defer searching missing subtitles on live synchro with Sonarr and Radarr. #1765
This commit is contained in:
parent
d66dc73b20
commit
012dc1cee9
|
@ -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')
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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',
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -98,6 +98,22 @@ const SettingsSonarrView: FunctionComponent = () => {
|
|||
episodes in Sonarr.
|
||||
</Message>
|
||||
</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)"
|
||||
|
|
Loading…
Reference in New Issue