mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-04-24 06:37:16 -04:00
Revert "Merged the series and episodes sync process. Episodes are only synced if series sizeOnDisk reported by Sonarr changes."
This reverts commit 5aadcea8
This commit is contained in:
parent
47157f81b7
commit
97caf44a5a
9 changed files with 40 additions and 54 deletions
|
@ -77,7 +77,8 @@ defaults = {
|
|||
'full_update_day': '6',
|
||||
'full_update_hour': '4',
|
||||
'only_monitored': 'False',
|
||||
'series_sync': '5',
|
||||
'series_sync': '1',
|
||||
'episodes_sync': '5',
|
||||
'excluded_tags': '[]',
|
||||
'excluded_series_types': '[]'
|
||||
},
|
||||
|
|
|
@ -102,7 +102,6 @@ def db_upgrade():
|
|||
['table_shows', 'seriesType', 'text', ''],
|
||||
['table_shows', 'imdbId', 'text', ''],
|
||||
['table_shows', 'profileId', 'integer'],
|
||||
['table_shows', 'sizeOnDisk', 'integer'],
|
||||
['table_episodes', 'format', 'text'],
|
||||
['table_episodes', 'resolution', 'text'],
|
||||
['table_episodes', 'video_codec', 'text'],
|
||||
|
|
|
@ -16,30 +16,22 @@ def update_all_episodes():
|
|||
logging.info('BAZARR All existing episode subtitles indexed from disk.')
|
||||
|
||||
|
||||
def sync_episodes(series_id=None):
|
||||
def sync_episodes():
|
||||
logging.debug('BAZARR Starting episodes sync from Sonarr.')
|
||||
apikey_sonarr = settings.sonarr.apikey
|
||||
|
||||
# Get current episodes id in DB
|
||||
current_episodes_db = database.execute("SELECT sonarrEpisodeId, path, sonarrSeriesId FROM table_episodes")
|
||||
|
||||
if series_id:
|
||||
current_episodes_db_list = [x['sonarrEpisodeId'] for x in current_episodes_db if x['sonarrSeriesId'] == series_id]
|
||||
else:
|
||||
current_episodes_db_list = [x['sonarrEpisodeId'] for x in current_episodes_db]
|
||||
current_episodes_db_list = [x['sonarrEpisodeId'] for x in current_episodes_db]
|
||||
|
||||
current_episodes_sonarr = []
|
||||
episodes_to_update = []
|
||||
episodes_to_add = []
|
||||
altered_episodes = []
|
||||
|
||||
if series_id and isinstance(series_id, int):
|
||||
# Get sonarrId for each series from database
|
||||
seriesIdList = database.execute("SELECT sonarrSeriesId, title FROM table_shows WHERE sonarrSeriesId = ?",
|
||||
(series_id,))
|
||||
else:
|
||||
# Get sonarrId for each series from database
|
||||
seriesIdList = database.execute("SELECT sonarrSeriesId, title FROM table_shows")
|
||||
# Get sonarrId for each series from database
|
||||
seriesIdList = database.execute("SELECT sonarrSeriesId, title FROM table_shows")
|
||||
|
||||
for i, seriesId in enumerate(seriesIdList):
|
||||
# Get episodes data for a series from Sonarr
|
||||
|
|
|
@ -11,7 +11,6 @@ from database import database, dict_converter
|
|||
from utils import get_sonarr_version
|
||||
from helper import path_mappings
|
||||
from event_handler import event_stream
|
||||
from get_episodes import sync_episodes
|
||||
|
||||
|
||||
def update_series():
|
||||
|
@ -57,7 +56,6 @@ def update_series():
|
|||
current_shows_sonarr = []
|
||||
series_to_update = []
|
||||
series_to_add = []
|
||||
episodes_to_sync = []
|
||||
|
||||
series_list_length = len(r.json())
|
||||
for i, show in enumerate(r.json(), 1):
|
||||
|
@ -89,13 +87,6 @@ def update_series():
|
|||
# Add shows in Sonarr to current shows list
|
||||
current_shows_sonarr.append(show['id'])
|
||||
|
||||
# Get sizeOnDisk for show
|
||||
sizeOnDisk = show['sizeOnDisk'] if 'sizeOnDisk' in show else 0
|
||||
show_size_in_db = database.execute('SELECT sizeOnDisk FROM table_shows WHERE sonarrSeriesId = ?', (show['id'],))
|
||||
if len(show_size_in_db):
|
||||
if sizeOnDisk != show_size_in_db[0]['sizeOnDisk']:
|
||||
episodes_to_sync.append(show['id'])
|
||||
|
||||
if show['id'] in current_shows_db_list:
|
||||
series_to_update.append({'title': show["title"],
|
||||
'path': show["path"],
|
||||
|
@ -110,8 +101,7 @@ def update_series():
|
|||
'alternateTitles': alternate_titles,
|
||||
'tags': str(tags),
|
||||
'seriesType': show['seriesType'],
|
||||
'imdbId': imdbId,
|
||||
'sizeOnDisk': sizeOnDisk})
|
||||
'imdbId': imdbId})
|
||||
else:
|
||||
series_to_add.append({'title': show["title"],
|
||||
'path': show["path"],
|
||||
|
@ -127,22 +117,19 @@ def update_series():
|
|||
'tags': str(tags),
|
||||
'seriesType': show['seriesType'],
|
||||
'imdbId': imdbId,
|
||||
'profileId': serie_default_profile,
|
||||
'sizeOnDisk': sizeOnDisk})
|
||||
'profileId': serie_default_profile})
|
||||
|
||||
# Remove old series from DB
|
||||
removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr))
|
||||
|
||||
for series in removed_series:
|
||||
database.execute("DELETE FROM table_shows WHERE sonarrSeriesId=?", (series,))
|
||||
database.execute("DELETE FROM table_episodes WHERE sonarrSeriesId=?", (series,))
|
||||
database.execute("DELETE FROM table_shows WHERE sonarrSeriesId=?",(series,))
|
||||
event_stream(type='series', action='delete', series=series)
|
||||
|
||||
# Update existing series in DB
|
||||
series_in_db_list = []
|
||||
series_in_db = database.execute("SELECT title, path, tvdbId, sonarrSeriesId, overview, poster, fanart, "
|
||||
"audio_language, sortTitle, year, alternateTitles, tags, seriesType, imdbId, "
|
||||
"sizeOnDisk FROM table_shows")
|
||||
"audio_language, sortTitle, year, alternateTitles, tags, seriesType, imdbId FROM table_shows")
|
||||
|
||||
for item in series_in_db:
|
||||
series_in_db_list.append(item)
|
||||
|
@ -155,9 +142,6 @@ def update_series():
|
|||
query.values + (updated_series['sonarrSeriesId'],))
|
||||
event_stream(type='series', action='update', series=updated_series['sonarrSeriesId'])
|
||||
|
||||
if updated_series['sonarrSeriesId'] in episodes_to_sync:
|
||||
sync_episodes(series_id=updated_series['sonarrSeriesId'])
|
||||
|
||||
# Insert new series in DB
|
||||
for added_series in series_to_add:
|
||||
query = dict_converter.convert(added_series)
|
||||
|
@ -166,15 +150,13 @@ def update_series():
|
|||
query.question_marks + ''')''', query.values)
|
||||
if result:
|
||||
list_missing_subtitles(no=added_series['sonarrSeriesId'])
|
||||
event_stream(type='series', action='insert', id=added_series['sonarrSeriesId'])
|
||||
|
||||
if added_series['sonarrSeriesId'] in episodes_to_sync:
|
||||
sync_episodes(series_id=added_series['sonarrSeriesId'])
|
||||
else:
|
||||
logging.debug('BAZARR unable to insert this series into the database:',
|
||||
path_mappings.path_replace(added_series['path']))
|
||||
|
||||
logging.debug('BAZARR All series synced from Sonarr into database.')
|
||||
event_stream(type='series', action='insert', series=added_series['sonarrSeriesId'])
|
||||
|
||||
logging.debug('BAZARR All series synced from Sonarr into database.')
|
||||
|
||||
|
||||
def get_profile_list():
|
||||
|
|
|
@ -163,9 +163,6 @@ if settings.analytics.visitor:
|
|||
with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini')), 'w+') as handle:
|
||||
settings.remove_option('general', 'throtteled_providers')
|
||||
settings.remove_option('general', 'update_restart')
|
||||
settings.remove_option('sonarr', 'episodes_sync')
|
||||
if settings.sonarr.series_sync == '1':
|
||||
settings.sonarr.series_sync = '5'
|
||||
settings.write(handle)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# coding=utf-8
|
||||
|
||||
from get_episodes import update_all_episodes
|
||||
from get_episodes import sync_episodes, update_all_episodes
|
||||
from get_movies import update_movies, update_all_movies
|
||||
from get_series import update_series
|
||||
from config import settings
|
||||
|
@ -143,14 +143,18 @@ class Scheduler:
|
|||
if settings.general.getboolean('use_sonarr'):
|
||||
self.aps_scheduler.add_job(
|
||||
update_series, IntervalTrigger(minutes=int(settings.sonarr.series_sync)), max_instances=1,
|
||||
coalesce=True, misfire_grace_time=15, id='update_series', name='Sync with Sonarr',
|
||||
coalesce=True, misfire_grace_time=15, id='update_series', name='Update Series list from Sonarr',
|
||||
replace_existing=True)
|
||||
self.aps_scheduler.add_job(
|
||||
sync_episodes, IntervalTrigger(minutes=int(settings.sonarr.episodes_sync)), max_instances=1,
|
||||
coalesce=True, misfire_grace_time=15, id='sync_episodes', name='Sync episodes with Sonarr',
|
||||
replace_existing=True)
|
||||
|
||||
def __radarr_update_task(self):
|
||||
if settings.general.getboolean('use_radarr'):
|
||||
self.aps_scheduler.add_job(
|
||||
update_movies, IntervalTrigger(minutes=int(settings.radarr.movies_sync)), max_instances=1,
|
||||
coalesce=True, misfire_grace_time=15, id='update_movies', name='Sync with Radarr',
|
||||
coalesce=True, misfire_grace_time=15, id='update_movies', name='Update Movie list from Radarr',
|
||||
replace_existing=True)
|
||||
|
||||
def __cache_cleanup_task(self):
|
||||
|
@ -253,6 +257,7 @@ scheduler = Scheduler()
|
|||
if 'BAZARR_AUDIO_PROFILES_MIGRATION' in os.environ:
|
||||
if settings.general.getboolean('use_sonarr'):
|
||||
scheduler.aps_scheduler.modify_job('update_series', next_run_time=datetime.now())
|
||||
scheduler.aps_scheduler.modify_job('sync_episodes', next_run_time=datetime.now())
|
||||
if settings.general.getboolean('use_radarr'):
|
||||
scheduler.aps_scheduler.modify_job('update_movies', next_run_time=datetime.now())
|
||||
del os.environ['BAZARR_AUDIO_PROFILES_MIGRATION']
|
||||
|
|
1
frontend/src/@types/settings.d.ts
vendored
1
frontend/src/@types/settings.d.ts
vendored
|
@ -128,6 +128,7 @@ namespace Settings {
|
|||
full_update_hour: number;
|
||||
only_monitored: boolean;
|
||||
series_sync: number;
|
||||
episodes_sync: number;
|
||||
excluded_tags: string[];
|
||||
excluded_series_types: SonarrSeriesType[];
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
import {
|
||||
dayOptions,
|
||||
diskUpdateOptions,
|
||||
episodesSyncOptions,
|
||||
moviesSyncOptions,
|
||||
seriesSyncOptions,
|
||||
upgradeOptions,
|
||||
|
@ -27,13 +28,19 @@ const SettingsSchedulerView: FunctionComponent = () => {
|
|||
return (
|
||||
<SettingsProvider title="Scheduler - Bazarr (Settings)">
|
||||
<Group header="Sonarr/Radarr Sync">
|
||||
<Input name="Sync with Sonarr">
|
||||
<Input name="Update Series List from Sonarr">
|
||||
<Selector
|
||||
options={seriesSyncOptions}
|
||||
settingKey="settings-sonarr-series_sync"
|
||||
></Selector>
|
||||
</Input>
|
||||
<Input name="Sync with Radarr">
|
||||
<Input name="Update Episodes List from Sonarr">
|
||||
<Selector
|
||||
options={episodesSyncOptions}
|
||||
settingKey="settings-sonarr-episodes_sync"
|
||||
></Selector>
|
||||
</Input>
|
||||
<Input name="Update Movies List from Radarr">
|
||||
<Selector
|
||||
options={moviesSyncOptions}
|
||||
settingKey="settings-radarr-movies_sync"
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
export const seriesSyncOptions: SelectorOption<number>[] = [
|
||||
{ label: "1 Minute", value: 1 },
|
||||
{ label: "5 Minutes", value: 5 },
|
||||
{ label: "15 Minutes", value: 15 },
|
||||
{ label: "1 Hour", value: 60 },
|
||||
{ label: "3 Hours", value: 180 },
|
||||
];
|
||||
|
||||
export const episodesSyncOptions: SelectorOption<number>[] = [
|
||||
{ label: "5 Minutes", value: 5 },
|
||||
{ label: "15 Minutes", value: 15 },
|
||||
{ label: "1 Hour", value: 60 },
|
||||
|
@ -6,13 +14,7 @@ export const seriesSyncOptions: SelectorOption<number>[] = [
|
|||
{ label: "6 Hours", value: 360 },
|
||||
];
|
||||
|
||||
export const moviesSyncOptions: SelectorOption<number>[] = [
|
||||
{ label: "5 Minutes", value: 5 },
|
||||
{ label: "15 Minutes", value: 15 },
|
||||
{ label: "1 Hour", value: 60 },
|
||||
{ label: "3 Hours", value: 180 },
|
||||
{ label: "6 Hours", value: 360 },
|
||||
];
|
||||
export const moviesSyncOptions = episodesSyncOptions;
|
||||
|
||||
export const diskUpdateOptions: SelectorOption<string>[] = [
|
||||
{ label: "Manually", value: "Manually" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue