Added notification to Sonarr/Radarr after downloading, uploading or deleting a subtitles file to make sure a rescan is initiated and that actual subtitles get indexed by them.

pull/1038/head
Louis Vézina 4 years ago
parent 6061ceb726
commit bfd024f1f8

@ -23,7 +23,7 @@ from get_languages import language_from_alpha3, alpha2_from_alpha3, alpha3_from_
from config import settings
from helper import path_mappings, pp_replace, get_target_folder, force_unicode
from list_subtitles import store_subtitles, list_missing_subtitles, store_subtitles_movie, list_missing_subtitles_movies
from utils import history_log, history_log_movie, get_binary, get_blacklist
from utils import history_log, history_log_movie, get_binary, get_blacklist, notify_sonarr, notify_radarr
from notifier import send_notifications, send_notifications_movie
from get_providers import get_providers, get_providers_auth, provider_throttle, provider_pool
from knowit import api
@ -264,10 +264,12 @@ def download_subtitle(path, language, audio_language, hi, forced, providers, pro
if media_type == 'series':
reversed_path = path_mappings.path_replace_reverse(path)
reversed_subtitles_path = path_mappings.path_replace_reverse(downloaded_path)
notify_sonarr(episode_metadata['sonarrSeriesId'])
else:
reversed_path = path_mappings.path_replace_reverse_movie(path)
reversed_subtitles_path = path_mappings.path_replace_reverse_movie(downloaded_path)
notify_radarr(movie_metadata['radarrId'])
track_event(category=downloaded_provider, action=action, label=downloaded_language)
@ -516,9 +518,11 @@ def manual_download_subtitle(path, language, audio_language, hi, forced, subtitl
if media_type == 'series':
reversed_path = path_mappings.path_replace_reverse(path)
reversed_subtitles_path = path_mappings.path_replace_reverse(downloaded_path)
notify_sonarr(episode_metadata['sonarrSeriesId'])
else:
reversed_path = path_mappings.path_replace_reverse_movie(path)
reversed_subtitles_path = path_mappings.path_replace_reverse_movie(downloaded_path)
notify_radarr(movie_metadata['radarrId'])
track_event(category=downloaded_provider, action="manually_downloaded",
label=downloaded_language)
@ -636,9 +640,11 @@ def manual_upload_subtitle(path, language, forced, title, scene_name, media_type
if media_type == 'series':
reversed_path = path_mappings.path_replace_reverse(path)
reversed_subtitles_path = path_mappings.path_replace_reverse(subtitle_path)
notify_sonarr(episode_metadata['sonarrSeriesId'])
else:
reversed_path = path_mappings.path_replace_reverse_movie(path)
reversed_subtitles_path = path_mappings.path_replace_reverse_movie(subtitle_path)
notify_radarr(movie_metadata['radarrId'])
return message, reversed_path, reversed_subtitles_path

@ -164,6 +164,18 @@ def get_sonarr_platform():
return sonarr_platform
def notify_sonarr(sonarr_series_id):
try:
url = url_sonarr() + "/api/command?apikey=" + settings.sonarr.apikey
data = {
'name': 'RescanSeries',
'seriesId': int(sonarr_series_id)
}
requests.post(url, json=data, timeout=60, verify=False)
except Exception as e:
logging.debug('BAZARR notify Sonarr')
def get_radarr_version():
radarr_version = ''
if settings.general.getboolean('use_radarr'):
@ -190,6 +202,18 @@ def get_radarr_platform():
return radarr_platform
def notify_radarr(radarr_id):
try:
url = url_radarr() + "/api/command?apikey=" + settings.radarr.apikey
data = {
'name': 'RescanMovie',
'movieId': int(radarr_id)
}
requests.post(url, json=data, timeout=60, verify=False)
except Exception as e:
logging.debug('BAZARR notify Radarr')
def delete_subtitles(media_type, language, forced, media_path, subtitles_path, sonarr_series_id=None,
sonarr_episode_id=None, radarr_id=None):
if not subtitles_path.endswith('.srt'):
@ -211,6 +235,7 @@ def delete_subtitles(media_type, language, forced, media_path, subtitles_path, s
video_path=path_mappings.path_replace_reverse(media_path),
subtitles_path=path_mappings.path_replace_reverse(subtitles_path))
store_subtitles(path_mappings.path_replace_reverse(media_path), media_path)
notify_sonarr(sonarr_series_id)
else:
try:
os.remove(path_mappings.path_replace_movie(subtitles_path))
@ -223,4 +248,5 @@ def delete_subtitles(media_type, language, forced, media_path, subtitles_path, s
video_path=path_mappings.path_replace_reverse_movie(media_path),
subtitles_path=path_mappings.path_replace_reverse_movie(subtitles_path))
store_subtitles_movie(path_mappings.path_replace_reverse_movie(media_path), media_path)
notify_radarr(radarr_id)
return True

Loading…
Cancel
Save