mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-02-25 07:15:56 +08:00
Fixed some queries trowing exception when no existing row were found #1425
This commit is contained in:
parent
57080eda11
commit
8d570fd3b7
3 changed files with 32 additions and 14 deletions
|
@ -4,6 +4,7 @@ import os
|
|||
import requests
|
||||
import logging
|
||||
from gevent import sleep
|
||||
from peewee import DoesNotExist
|
||||
|
||||
from database import get_exclusion_clause, TableEpisodes, TableShows
|
||||
from config import settings, url_sonarr
|
||||
|
@ -151,10 +152,13 @@ def sync_one_episode(episode_id):
|
|||
logging.debug('BAZARR syncing this specific episode from Sonarr: {}'.format(episode_id))
|
||||
|
||||
# Check if there's a row in database for this episode ID
|
||||
existing_episode = TableEpisodes.select(TableEpisodes.path)\
|
||||
.where(TableEpisodes.sonarrEpisodeId == episode_id)\
|
||||
.dicts()\
|
||||
.get()
|
||||
try:
|
||||
existing_episode = TableEpisodes.select(TableEpisodes.path)\
|
||||
.where(TableEpisodes.sonarrEpisodeId == episode_id)\
|
||||
.dicts()\
|
||||
.get()
|
||||
except DoesNotExist:
|
||||
existing_episode = None
|
||||
|
||||
try:
|
||||
# Get episode data from sonarr api
|
||||
|
@ -186,23 +190,23 @@ def sync_one_episode(episode_id):
|
|||
TableEpisodes.update(episode).where(TableEpisodes.sonarrEpisodeId == episode_id).execute()
|
||||
event_stream(type='episode', action='update', payload=int(episode_id))
|
||||
logging.debug('BAZARR updated this episode into the database:{}'.format(path_mappings.path_replace(
|
||||
episode.path)))
|
||||
episode['path'])))
|
||||
|
||||
# Insert new episodes in DB
|
||||
elif episode and not existing_episode:
|
||||
TableEpisodes.insert(episode).on_conflict(action='IGNORE').execute()
|
||||
event_stream(type='episode', action='update', payload=int(episode_id))
|
||||
logging.debug('BAZARR inserted this episode into the database:{}'.format(path_mappings.path_replace(
|
||||
episode.path)))
|
||||
episode['path'])))
|
||||
|
||||
# Storing existing subtitles
|
||||
logging.debug('BAZARR storing subtitles for this episode: {}'.format(path_mappings.path_replace(
|
||||
episode.path)))
|
||||
store_subtitles(episode.path, path_mappings.path_replace(episode.path))
|
||||
episode['path'])))
|
||||
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['path'])))
|
||||
episode_download_subtitles(episode_id)
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import operator
|
||||
from functools import reduce
|
||||
from gevent import sleep
|
||||
from peewee import DoesNotExist
|
||||
|
||||
from config import settings, url_radarr
|
||||
from helper import path_mappings
|
||||
|
@ -172,7 +173,13 @@ 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
|
||||
existing_movie = TableMovies.get_or_none(TableMovies.radarrId == movie_id)
|
||||
try:
|
||||
existing_movie = TableMovies.select(TableMovies.path)\
|
||||
.where(TableMovies.radarrId == movie_id)\
|
||||
.dicts()\
|
||||
.get()
|
||||
except DoesNotExist:
|
||||
existing_movie = None
|
||||
|
||||
# Remove movie from DB
|
||||
if action == 'deleted':
|
||||
|
@ -180,7 +187,7 @@ def update_one_movie(movie_id, action):
|
|||
TableMovies.delete().where(TableMovies.radarrId == movie_id).execute()
|
||||
event_stream(type='movie', action='delete', payload=int(movie_id))
|
||||
logging.debug('BAZARR deleted this movie from the database:{}'.format(path_mappings.path_replace_movie(
|
||||
existing_movie.path)))
|
||||
existing_movie['path'])))
|
||||
return
|
||||
|
||||
radarr_version = get_radarr_version()
|
||||
|
@ -225,7 +232,7 @@ def update_one_movie(movie_id, action):
|
|||
TableMovies.delete().where(TableMovies.radarrId == movie_id).execute()
|
||||
event_stream(type='movie', action='delete', payload=int(movie_id))
|
||||
logging.debug('BAZARR deleted this movie from the database:{}'.format(path_mappings.path_replace_movie(
|
||||
existing_movie.path)))
|
||||
existing_movie['path'])))
|
||||
return
|
||||
|
||||
# Update existing movie in DB
|
||||
|
|
|
@ -4,6 +4,7 @@ import os
|
|||
import requests
|
||||
import logging
|
||||
from gevent import sleep
|
||||
from peewee import DoesNotExist
|
||||
|
||||
from config import settings, url_sonarr
|
||||
from list_subtitles import list_missing_subtitles
|
||||
|
@ -137,7 +138,13 @@ def update_one_series(series_id, action):
|
|||
logging.debug('BAZARR syncing this specific series from RSonarr: {}'.format(series_id))
|
||||
|
||||
# Check if there's a row in database for this series ID
|
||||
existing_series = TableShows.get_or_none(TableShows.sonarrSeriesId == series_id)
|
||||
try:
|
||||
existing_series = TableShows.select(TableShows.path)\
|
||||
.where(TableShows.sonarrSeriesId == series_id)\
|
||||
.dicts()\
|
||||
.get()
|
||||
except DoesNotExist:
|
||||
existing_series = None
|
||||
|
||||
sonarr_version = get_sonarr_version()
|
||||
serie_default_enabled = settings.general.getboolean('serie_default_enabled')
|
||||
|
@ -184,7 +191,7 @@ def update_one_series(series_id, action):
|
|||
TableShows.delete().where(TableShows.sonarrSeriesId == series_id).execute()
|
||||
event_stream(type='series', action='delete', payload=int(series_id))
|
||||
logging.debug('BAZARR deleted this series from the database:{}'.format(path_mappings.path_replace(
|
||||
existing_series.path)))
|
||||
existing_series['path'])))
|
||||
return
|
||||
|
||||
# Update existing series in DB
|
||||
|
|
Loading…
Reference in a new issue