summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2022-02-11 10:59:09 -0500
committermorpheus65535 <[email protected]>2022-02-11 10:59:09 -0500
commit026eba9b13e9683f5813ae99cbcf52d868e36079 (patch)
treee51a3bb3479afc62c1fe90b39c157bf884744d0a
parenta22bb0fd124f7951be4d328740a356c0e1951c9c (diff)
downloadbazarr-026eba9b13e9683f5813ae99cbcf52d868e36079.tar.gz
bazarr-026eba9b13e9683f5813ae99cbcf52d868e36079.zip
no log: improved usage of some database queries to prevent exceptions.
-rw-r--r--bazarr/api/episodes/blacklist.py5
-rw-r--r--bazarr/api/episodes/episodes_subtitles.py20
-rw-r--r--bazarr/api/movies/blacklist.py5
-rw-r--r--bazarr/api/movies/movies_subtitles.py20
-rw-r--r--bazarr/api/providers/providers_episodes.py10
-rw-r--r--bazarr/api/providers/providers_movies.py10
-rw-r--r--bazarr/api/subtitles/subtitles.py12
-rw-r--r--bazarr/api/webhooks/plex.py5
-rw-r--r--bazarr/database.py23
-rw-r--r--bazarr/embedded_subs_reader.py4
-rw-r--r--bazarr/get_episodes.py17
-rw-r--r--bazarr/get_movies.py13
-rw-r--r--bazarr/get_series.py13
-rw-r--r--bazarr/get_subtitle/download.py3
-rw-r--r--bazarr/get_subtitle/manual.py11
-rw-r--r--bazarr/get_subtitle/mass_download/movies.py5
-rw-r--r--bazarr/get_subtitle/mass_download/series.py10
-rw-r--r--bazarr/get_subtitle/processing.py8
-rw-r--r--bazarr/get_subtitle/refiners/ffprobe.py6
-rw-r--r--bazarr/get_subtitle/upload.py8
-rw-r--r--bazarr/get_subtitle/wanted/movies.py5
-rw-r--r--bazarr/get_subtitle/wanted/series.py5
-rw-r--r--bazarr/list_subtitles.py23
-rw-r--r--bazarr/notifier.py21
24 files changed, 179 insertions, 83 deletions
diff --git a/bazarr/api/episodes/blacklist.py b/bazarr/api/episodes/blacklist.py
index 2cdf74bfa..d519eaabd 100644
--- a/bazarr/api/episodes/blacklist.py
+++ b/bazarr/api/episodes/blacklist.py
@@ -59,7 +59,10 @@ class EpisodesBlacklist(Resource):
episodeInfo = TableEpisodes.select(TableEpisodes.path)\
.where(TableEpisodes.sonarrEpisodeId == sonarr_episode_id)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not episodeInfo:
+ return 'Episode not found', 501
media_path = episodeInfo['path']
subtitles_path = request.form.get('subtitles_path')
diff --git a/bazarr/api/episodes/episodes_subtitles.py b/bazarr/api/episodes/episodes_subtitles.py
index 05ce17425..9165b9ee3 100644
--- a/bazarr/api/episodes/episodes_subtitles.py
+++ b/bazarr/api/episodes/episodes_subtitles.py
@@ -1,6 +1,7 @@
# coding=utf-8
import os
+import logging
from flask import request
from flask_restful import Resource
@@ -33,7 +34,10 @@ class EpisodesSubtitles(Resource):
.join(TableShows, on=(TableEpisodes.sonarrSeriesId == TableShows.sonarrSeriesId)) \
.where(TableEpisodes.sonarrEpisodeId == sonarrEpisodeId)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not episodeInfo:
+ return 'Episode not found', 501
title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
@@ -89,7 +93,10 @@ class EpisodesSubtitles(Resource):
TableEpisodes.audio_language)\
.where(TableEpisodes.sonarrEpisodeId == sonarrEpisodeId)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not episodeInfo:
+ return 'Episode not found', 501
title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
@@ -117,7 +124,9 @@ class EpisodesSubtitles(Resource):
subtitle=subFile,
audio_language=audio_language)
- if result is not None:
+ if not result:
+ logging.debug(f"BAZARR unable to process subtitles for this episode: {episodePath}")
+ else:
message = result[0]
path = result[1]
subs_path = result[2]
@@ -150,7 +159,10 @@ class EpisodesSubtitles(Resource):
TableEpisodes.audio_language)\
.where(TableEpisodes.sonarrEpisodeId == sonarrEpisodeId)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not episodeInfo:
+ return 'Episode not found', 501
episodePath = path_mappings.path_replace(episodeInfo['path'])
diff --git a/bazarr/api/movies/blacklist.py b/bazarr/api/movies/blacklist.py
index f2b7a0fac..0538fe437 100644
--- a/bazarr/api/movies/blacklist.py
+++ b/bazarr/api/movies/blacklist.py
@@ -55,7 +55,10 @@ class MoviesBlacklist(Resource):
forced = False
hi = False
- data = TableMovies.select(TableMovies.path).where(TableMovies.radarrId == radarr_id).dicts().get()
+ data = TableMovies.select(TableMovies.path).where(TableMovies.radarrId == radarr_id).dicts().get_or_none()
+
+ if not data:
+ return 'Movie not found', 501
media_path = data['path']
subtitles_path = request.form.get('subtitles_path')
diff --git a/bazarr/api/movies/movies_subtitles.py b/bazarr/api/movies/movies_subtitles.py
index 51814281f..7d84ab44d 100644
--- a/bazarr/api/movies/movies_subtitles.py
+++ b/bazarr/api/movies/movies_subtitles.py
@@ -1,6 +1,7 @@
# coding=utf-8
import os
+import logging
from flask import request
from flask_restful import Resource
@@ -33,7 +34,10 @@ class MoviesSubtitles(Resource):
TableMovies.audio_language)\
.where(TableMovies.radarrId == radarrId)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not movieInfo:
+ return 'Movie not found', 501
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
sceneName = movieInfo['sceneName'] or 'None'
@@ -90,7 +94,10 @@ class MoviesSubtitles(Resource):
TableMovies.audio_language) \
.where(TableMovies.radarrId == radarrId) \
.dicts() \
- .get()
+ .get_or_none()
+
+ if not movieInfo:
+ return 'Movie not found', 501
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
sceneName = movieInfo['sceneName'] or 'None'
@@ -119,7 +126,9 @@ class MoviesSubtitles(Resource):
subtitle=subFile,
audio_language=audioLanguage)
- if result is not None:
+ if not result:
+ logging.debug(f"BAZARR unable to process subtitles for this movie: {moviePath}")
+ else:
message = result[0]
path = result[1]
subs_path = result[2]
@@ -147,7 +156,10 @@ class MoviesSubtitles(Resource):
movieInfo = TableMovies.select(TableMovies.path) \
.where(TableMovies.radarrId == radarrId) \
.dicts() \
- .get()
+ .get_or_none()
+
+ if not movieInfo:
+ return 'Movie not found', 501
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
diff --git a/bazarr/api/providers/providers_episodes.py b/bazarr/api/providers/providers_episodes.py
index 28d5b180f..1555e4017 100644
--- a/bazarr/api/providers/providers_episodes.py
+++ b/bazarr/api/providers/providers_episodes.py
@@ -27,7 +27,10 @@ class ProviderEpisodes(Resource):
.join(TableShows, on=(TableEpisodes.sonarrSeriesId == TableShows.sonarrSeriesId))\
.where(TableEpisodes.sonarrEpisodeId == sonarrEpisodeId) \
.dicts() \
- .get()
+ .get_or_none()
+
+ if not episodeInfo:
+ return 'Episode not found', 501
title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
@@ -52,7 +55,10 @@ class ProviderEpisodes(Resource):
.join(TableShows, on=(TableEpisodes.sonarrSeriesId == TableShows.sonarrSeriesId)) \
.where(TableEpisodes.sonarrEpisodeId == sonarrEpisodeId) \
.dicts() \
- .get()
+ .get_or_none()
+
+ if not episodeInfo:
+ return 'Episode not found', 501
title = episodeInfo['title']
episodePath = path_mappings.path_replace(episodeInfo['path'])
diff --git a/bazarr/api/providers/providers_movies.py b/bazarr/api/providers/providers_movies.py
index f412866fe..575148aa2 100644
--- a/bazarr/api/providers/providers_movies.py
+++ b/bazarr/api/providers/providers_movies.py
@@ -26,7 +26,10 @@ class ProviderMovies(Resource):
TableMovies.profileId) \
.where(TableMovies.radarrId == radarrId) \
.dicts() \
- .get()
+ .get_or_none()
+
+ if not movieInfo:
+ return 'Movie not found', 501
title = movieInfo['title']
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
@@ -50,7 +53,10 @@ class ProviderMovies(Resource):
TableMovies.audio_language) \
.where(TableMovies.radarrId == radarrId) \
.dicts() \
- .get()
+ .get_or_none()
+
+ if not movieInfo:
+ return 'Movie not found', 501
title = movieInfo['title']
moviePath = path_mappings.path_replace_movie(movieInfo['path'])
diff --git a/bazarr/api/subtitles/subtitles.py b/bazarr/api/subtitles/subtitles.py
index 0bd6e7fb5..8c26e1bfc 100644
--- a/bazarr/api/subtitles/subtitles.py
+++ b/bazarr/api/subtitles/subtitles.py
@@ -30,11 +30,19 @@ class Subtitles(Resource):
metadata = TableEpisodes.select(TableEpisodes.path, TableEpisodes.sonarrSeriesId)\
.where(TableEpisodes.sonarrEpisodeId == id)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not metadata:
+ return 'Episode not found', 501
+
video_path = path_mappings.path_replace(metadata['path'])
else:
subtitles_path = path_mappings.path_replace_movie(subtitles_path)
- metadata = TableMovies.select(TableMovies.path).where(TableMovies.radarrId == id).dicts().get()
+ metadata = TableMovies.select(TableMovies.path).where(TableMovies.radarrId == id).dicts().get_or_none()
+
+ if not metadata:
+ return 'Movie not found', 501
+
video_path = path_mappings.path_replace_movie(metadata['path'])
if action == 'sync':
diff --git a/bazarr/api/webhooks/plex.py b/bazarr/api/webhooks/plex.py
index 557623b50..32b9953a5 100644
--- a/bazarr/api/webhooks/plex.py
+++ b/bazarr/api/webhooks/plex.py
@@ -56,7 +56,7 @@ class WebHooksPlex(Resource):
TableEpisodes.season == season,
TableEpisodes.episode == episode) \
.dicts() \
- .get()
+ .get_or_none()
if sonarrEpisodeId:
episode_download_subtitles(no=sonarrEpisodeId['sonarrEpisodeId'], send_progress=True)
@@ -69,7 +69,8 @@ class WebHooksPlex(Resource):
radarrId = TableMovies.select(TableMovies.radarrId)\
.where(TableMovies.imdbId == movie_imdb_id)\
.dicts()\
- .get()
+ .get_or_none()
+
if radarrId:
movies_download_subtitles(no=radarrId['radarrId'])
diff --git a/bazarr/database.py b/bazarr/database.py
index 217292323..dd791b174 100644
--- a/bazarr/database.py
+++ b/bazarr/database.py
@@ -512,18 +512,27 @@ def get_audio_profile_languages(series_id=None, episode_id=None, movie_id=None):
def get_profile_id(series_id=None, episode_id=None, movie_id=None):
if series_id:
- profileId = TableShows.get(TableShows.sonarrSeriesId == series_id).profileId
+ data = TableShows.select(TableShows.profileId)\
+ .where(TableShows.sonarrSeriesId == series_id)\
+ .get_or_none()
+ if data:
+ return data.profileId
elif episode_id:
- profileId = TableShows.select(TableShows.profileId)\
+ data = TableShows.select(TableShows.profileId)\
.join(TableEpisodes, on=(TableShows.sonarrSeriesId == TableEpisodes.sonarrSeriesId))\
.where(TableEpisodes.sonarrEpisodeId == episode_id)\
- .get().profileId
+ .get_or_none()
+ if data:
+ return data.profileId
+
elif movie_id:
- profileId = TableMovies.get(TableMovies.radarrId == movie_id).profileId
- else:
- return None
+ data = TableMovies.select(TableMovies.profileId)\
+ .where(TableMovies.radarrId == movie_id)\
+ .get_or_none()
+ if data:
+ return data.profileId
- return profileId
+ return None
def convert_list_to_clause(arr: list):
diff --git a/bazarr/embedded_subs_reader.py b/bazarr/embedded_subs_reader.py
index 5f8f16655..5d554e86b 100644
--- a/bazarr/embedded_subs_reader.py
+++ b/bazarr/embedded_subs_reader.py
@@ -79,12 +79,12 @@ def parse_video_metadata(file, file_size, episode_file_id=None, movie_file_id=No
cache_key = TableEpisodes.select(TableEpisodes.ffprobe_cache)\
.where(TableEpisodes.path == path_mappings.path_replace_reverse(file))\
.dicts()\
- .get()
+ .get_or_none()
elif movie_file_id:
cache_key = TableMovies.select(TableMovies.ffprobe_cache)\
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(file))\
.dicts()\
- .get()
+ .get_or_none()
else:
cache_key = None
diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py
index a4e8720a5..34a38317f 100644
--- a/bazarr/get_episodes.py
+++ b/bazarr/get_episodes.py
@@ -3,7 +3,7 @@
import os
import requests
import logging
-from peewee import DoesNotExist, IntegrityError
+from peewee import IntegrityError
from database import TableEpisodes, TableShows
from config import settings, url_sonarr
@@ -93,7 +93,9 @@ def sync_episodes(series_id=None, send_event=True):
TableEpisodes.sonarrEpisodeId)\
.where(TableEpisodes.sonarrEpisodeId == removed_episode)\
.dicts()\
- .get()
+ .get_or_none()
+ if not episode_to_delete:
+ continue
try:
TableEpisodes.delete().where(TableEpisodes.sonarrEpisodeId == removed_episode).execute()
except Exception as e:
@@ -169,13 +171,10 @@ def sync_one_episode(episode_id):
apikey_sonarr = settings.sonarr.apikey
# Check if there's a row in database for this episode ID
- try:
- existing_episode = TableEpisodes.select(TableEpisodes.path, TableEpisodes.episode_file_id)\
- .where(TableEpisodes.sonarrEpisodeId == episode_id)\
- .dicts()\
- .get()
- except DoesNotExist:
- existing_episode = None
+ existing_episode = TableEpisodes.select(TableEpisodes.path, TableEpisodes.episode_file_id)\
+ .where(TableEpisodes.sonarrEpisodeId == episode_id)\
+ .dicts()\
+ .get_or_none()
try:
# Get episode data from sonarr api
diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py
index d369c1f3d..0debf3378 100644
--- a/bazarr/get_movies.py
+++ b/bazarr/get_movies.py
@@ -3,7 +3,7 @@
import os
import requests
import logging
-from peewee import DoesNotExist, IntegrityError
+from peewee import IntegrityError
from config import settings, url_radarr
from helper import path_mappings
@@ -170,13 +170,10 @@ def update_one_movie(movie_id, action):
logging.debug('BAZARR syncing this specific movie from Radarr: {}'.format(movie_id))
# Check if there's a row in database for this movie ID
- try:
- existing_movie = TableMovies.select(TableMovies.path)\
- .where(TableMovies.radarrId == movie_id)\
- .dicts()\
- .get()
- except DoesNotExist:
- existing_movie = None
+ existing_movie = TableMovies.select(TableMovies.path)\
+ .where(TableMovies.radarrId == movie_id)\
+ .dicts()\
+ .get_or_none()
# Remove movie from DB
if action == 'deleted':
diff --git a/bazarr/get_series.py b/bazarr/get_series.py
index 13dd566ea..62007a640 100644
--- a/bazarr/get_series.py
+++ b/bazarr/get_series.py
@@ -3,7 +3,7 @@
import os
import requests
import logging
-from peewee import DoesNotExist, IntegrityError
+from peewee import IntegrityError
from config import settings, url_sonarr
from list_subtitles import list_missing_subtitles
@@ -142,13 +142,10 @@ def update_one_series(series_id, action):
logging.debug('BAZARR syncing this specific series from Sonarr: {}'.format(series_id))
# Check if there's a row in database for this series ID
- try:
- existing_series = TableShows.select(TableShows.path)\
- .where(TableShows.sonarrSeriesId == series_id)\
- .dicts()\
- .get()
- except DoesNotExist:
- existing_series = None
+ existing_series = TableShows.select(TableShows.path)\
+ .where(TableShows.sonarrSeriesId == series_id)\
+ .dicts()\
+ .get_or_none()
# Delete series from DB
if action == 'deleted' and existing_series:
diff --git a/bazarr/get_subtitle/download.py b/bazarr/get_subtitle/download.py
index a5340415b..dce7c012c 100644
--- a/bazarr/get_subtitle/download.py
+++ b/bazarr/get_subtitle/download.py
@@ -97,6 +97,9 @@ def generate_subtitles(path, languages, audio_language, sceneName, title, media_
processed_subtitle = process_subtitle(subtitle=subtitle, media_type=media_type,
audio_language=audio_language, is_upgrade=is_upgrade,
is_manual=False, path=path, max_score=max_score)
+ if not processed_subtitle:
+ logging.debug(f"BAZARR unable to process this subtitles: {subtitle}")
+ continue
yield processed_subtitle
if not saved_any:
diff --git a/bazarr/get_subtitle/manual.py b/bazarr/get_subtitle/manual.py
index 1cb073cad..5fc148e41 100644
--- a/bazarr/get_subtitle/manual.py
+++ b/bazarr/get_subtitle/manual.py
@@ -204,9 +204,14 @@ def manual_download_subtitle(path, audio_language, hi, forced, subtitle, provide
if saved_subtitles:
_, max_score, _ = _get_scores(media_type)
for saved_subtitle in saved_subtitles:
- return process_subtitle(subtitle=saved_subtitle, media_type=media_type,
- audio_language=audio_language, is_upgrade=False,
- is_manual=True, path=path, max_score=max_score)
+ processed_subtitle = process_subtitle(subtitle=saved_subtitle, media_type=media_type,
+ audio_language=audio_language, is_upgrade=False,
+ is_manual=True, path=path, max_score=max_score)
+ if processed_subtitle:
+ return processed_subtitle
+ else:
+ logging.debug(f"BAZARR unable to process this subtitles: {subtitle}")
+ continue
else:
logging.error(
"BAZARR Tried to manually download a Subtitles for file: " + path
diff --git a/bazarr/get_subtitle/mass_download/movies.py b/bazarr/get_subtitle/mass_download/movies.py
index 0f5dd6b10..bbafeaaa5 100644
--- a/bazarr/get_subtitle/mass_download/movies.py
+++ b/bazarr/get_subtitle/mass_download/movies.py
@@ -63,7 +63,10 @@ def movies_download_subtitles(no):
confirmed_missing_subs = TableMovies.select(TableMovies.missing_subtitles) \
.where(TableMovies.radarrId == movie['radarrId']) \
.dicts() \
- .get()
+ .get_or_none()
+ if not confirmed_missing_subs:
+ continue
+
if language not in ast.literal_eval(confirmed_missing_subs['missing_subtitles']):
continue
diff --git a/bazarr/get_subtitle/mass_download/series.py b/bazarr/get_subtitle/mass_download/series.py
index 68888e5af..2809247bd 100644
--- a/bazarr/get_subtitle/mass_download/series.py
+++ b/bazarr/get_subtitle/mass_download/series.py
@@ -68,7 +68,10 @@ def series_download_subtitles(no):
confirmed_missing_subs = TableEpisodes.select(TableEpisodes.missing_subtitles) \
.where(TableEpisodes.sonarrEpisodeId == episode['sonarrEpisodeId']) \
.dicts() \
- .get()
+ .get_or_none()
+ if not confirmed_missing_subs:
+ continue
+
if language not in ast.literal_eval(confirmed_missing_subs['missing_subtitles']):
continue
@@ -159,7 +162,10 @@ def episode_download_subtitles(no, send_progress=False):
confirmed_missing_subs = TableEpisodes.select(TableEpisodes.missing_subtitles) \
.where(TableEpisodes.sonarrEpisodeId == episode['sonarrEpisodeId']) \
.dicts() \
- .get()
+ .get_or_none()
+ if not confirmed_missing_subs:
+ continue
+
if language not in ast.literal_eval(confirmed_missing_subs['missing_subtitles']):
continue
diff --git a/bazarr/get_subtitle/processing.py b/bazarr/get_subtitle/processing.py
index d8a1b1990..989c72bed 100644
--- a/bazarr/get_subtitle/processing.py
+++ b/bazarr/get_subtitle/processing.py
@@ -51,7 +51,9 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
TableEpisodes.sonarrEpisodeId) \
.where(TableEpisodes.path == path_mappings.path_replace_reverse(path)) \
.dicts() \
- .get()
+ .get_or_none()
+ if not episode_metadata:
+ return
series_id = episode_metadata['sonarrSeriesId']
episode_id = episode_metadata['sonarrEpisodeId']
sync_subtitles(video_path=path, srt_path=downloaded_path,
@@ -64,7 +66,9 @@ def process_subtitle(subtitle, media_type, audio_language, path, max_score, is_u
movie_metadata = TableMovies.select(TableMovies.radarrId) \
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path)) \
.dicts() \
- .get()
+ .get_or_none()
+ if not movie_metadata:
+ return
series_id = ""
episode_id = movie_metadata['radarrId']
sync_subtitles(video_path=path, srt_path=downloaded_path,
diff --git a/bazarr/get_subtitle/refiners/ffprobe.py b/bazarr/get_subtitle/refiners/ffprobe.py
index 033c8eade..3a35d257c 100644
--- a/bazarr/get_subtitle/refiners/ffprobe.py
+++ b/bazarr/get_subtitle/refiners/ffprobe.py
@@ -15,14 +15,14 @@ def refine_from_ffprobe(path, video):
file_id = TableMovies.select(TableMovies.movie_file_id, TableMovies.file_size)\
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path))\
.dicts()\
- .get()
+ .get_or_none()
else:
file_id = TableEpisodes.select(TableEpisodes.episode_file_id, TableEpisodes.file_size)\
.where(TableEpisodes.path == path_mappings.path_replace_reverse(path))\
.dicts()\
- .get()
+ .get_or_none()
- if not isinstance(file_id, dict):
+ if not file_id:
return video
if isinstance(video, Movie):
diff --git a/bazarr/get_subtitle/upload.py b/bazarr/get_subtitle/upload.py
index e2109faa7..457f0896f 100644
--- a/bazarr/get_subtitle/upload.py
+++ b/bazarr/get_subtitle/upload.py
@@ -99,7 +99,9 @@ def manual_upload_subtitle(path, language, forced, hi, title, scene_name, media_
episode_metadata = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId) \
.where(TableEpisodes.path == path_mappings.path_replace_reverse(path)) \
.dicts() \
- .get()
+ .get_or_none()
+ if not episode_metadata:
+ return
series_id = episode_metadata['sonarrSeriesId']
episode_id = episode_metadata['sonarrEpisodeId']
sync_subtitles(video_path=path, srt_path=subtitle_path, srt_lang=uploaded_language_code2, media_type=media_type,
@@ -109,7 +111,9 @@ def manual_upload_subtitle(path, language, forced, hi, title, scene_name, media_
movie_metadata = TableMovies.select(TableMovies.radarrId) \
.where(TableMovies.path == path_mappings.path_replace_reverse_movie(path)) \
.dicts() \
- .get()
+ .get_or_none()
+ if not movie_metadata:
+ return
series_id = ""
episode_id = movie_metadata['radarrId']
sync_subtitles(video_path=path, srt_path=subtitle_path, srt_lang=uploaded_language_code2, media_type=media_type,
diff --git a/bazarr/get_subtitle/wanted/movies.py b/bazarr/get_subtitle/wanted/movies.py
index 282803250..eeef7ed23 100644
--- a/bazarr/get_subtitle/wanted/movies.py
+++ b/bazarr/get_subtitle/wanted/movies.py
@@ -32,7 +32,10 @@ def _wanted_movie(movie):
confirmed_missing_subs = TableMovies.select(TableMovies.missing_subtitles) \
.where(TableMovies.radarrId == movie['radarrId']) \
.dicts() \
- .get()
+ .get_or_none()
+ if not confirmed_missing_subs:
+ continue
+
if language not in ast.literal_eval(confirmed_missing_subs['missing_subtitles']):
continue
diff --git a/bazarr/get_subtitle/wanted/series.py b/bazarr/get_subtitle/wanted/series.py
index 8af878738..6450e9c04 100644
--- a/bazarr/get_subtitle/wanted/series.py
+++ b/bazarr/get_subtitle/wanted/series.py
@@ -32,7 +32,10 @@ def _wanted_episode(episode):
confirmed_missing_subs = TableEpisodes.select(TableEpisodes.missing_subtitles) \
.where(TableEpisodes.sonarrEpisodeId == episode['sonarrEpisodeId']) \
.dicts() \
- .get()
+ .get_or_none()
+ if not confirmed_missing_subs:
+ continue
+
if language not in ast.literal_eval(confirmed_missing_subs['missing_subtitles']):
continue
diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py
index 756e568ac..d71912b9b 100644
--- a/bazarr/list_subtitles.py
+++ b/bazarr/list_subtitles.py
@@ -18,7 +18,6 @@ from helper import path_mappings, get_subtitle_destination_folder
from embedded_subs_reader import embedded_subs_reader
from event_handler import event_stream, show_progress, hide_progress
from charamel import Detector
-from peewee import DoesNotExist
gc.enable()
@@ -32,12 +31,11 @@ def store_subtitles(original_path, reversed_path, use_cache=True):
if os.path.exists(reversed_path):
if settings.general.getboolean('use_embedded_subs'):
logging.debug("BAZARR is trying to index embedded subtitles.")
- try:
- item = TableEpisodes.select(TableEpisodes.episode_file_id, TableEpisodes.file_size)\
- .where(TableEpisodes.path == original_path)\
- .dicts()\
- .get()
- except DoesNotExist:
+ item = TableEpisodes.select(TableEpisodes.episode_file_id, TableEpisodes.file_size)\
+ .where(TableEpisodes.path == original_path)\
+ .dicts()\
+ .get_or_none()
+ if not item:
logging.exception(f"BAZARR error when trying to select this episode from database: {reversed_path}")
else:
try:
@@ -141,12 +139,11 @@ def store_subtitles_movie(original_path, reversed_path, use_cache=True):
if os.path.exists(reversed_path):
if settings.general.getboolean('use_embedded_subs'):
logging.debug("BAZARR is trying to index embedded subtitles.")
- try:
- item = TableMovies.select(TableMovies.movie_file_id, TableMovies.file_size)\
- .where(TableMovies.path == original_path)\
- .dicts()\
- .get()
- except DoesNotExist:
+ item = TableMovies.select(TableMovies.movie_file_id, TableMovies.file_size)\
+ .where(TableMovies.path == original_path)\
+ .dicts()\
+ .get_or_none()
+ if not item:
logging.exception(f"BAZARR error when trying to select this movie from database: {reversed_path}")
else:
try:
diff --git a/bazarr/notifier.py b/bazarr/notifier.py
index 7a24303ee..b205740ef 100644
--- a/bazarr/notifier.py
+++ b/bazarr/notifier.py
@@ -50,7 +50,10 @@ def get_series(sonarr_series_id):
data = TableShows.select(TableShows.title, TableShows.year)\
.where(TableShows.sonarrSeriesId == sonarr_series_id)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not data:
+ return
return {'title': data['title'], 'year': data['year']}
@@ -59,7 +62,10 @@ def get_episode_name(sonarr_episode_id):
data = TableEpisodes.select(TableEpisodes.title, TableEpisodes.season, TableEpisodes.episode)\
.where(TableEpisodes.sonarrEpisodeId == sonarr_episode_id)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not data:
+ return
return data['title'], data['season'], data['episode']
@@ -68,7 +74,10 @@ def get_movie(radarr_id):
data = TableMovies.select(TableMovies.title, TableMovies.year)\
.where(TableMovies.radarrId == radarr_id)\
.dicts()\
- .get()
+ .get_or_none()
+
+ if not data:
+ return
return {'title': data['title'], 'year': data['year']}
@@ -76,6 +85,8 @@ def get_movie(radarr_id):
def send_notifications(sonarr_series_id, sonarr_episode_id, message):
providers = get_notifier_providers()
series = get_series(sonarr_series_id)
+ if not series:
+ return
series_title = series['title']
series_year = series['year']
if series_year not in [None, '', '0']:
@@ -83,6 +94,8 @@ def send_notifications(sonarr_series_id, sonarr_episode_id, message):
else:
series_year = ''
episode = get_episode_name(sonarr_episode_id)
+ if not episode:
+ return
asset = apprise.AppriseAsset(async_mode=False)
@@ -102,6 +115,8 @@ def send_notifications(sonarr_series_id, sonarr_episode_id, message):
def send_notifications_movie(radarr_id, message):
providers = get_notifier_providers()
movie = get_movie(radarr_id)
+ if not movie:
+ return
movie_title = movie['title']
movie_year = movie['year']
if movie_year not in [None, '', '0']: