Added some sleep to long for loop to prevent blocking other stuff during that time. Some more could be required in the future.

pull/1419/head
morpheus65535 4 years ago
parent 0ea03e0008
commit 8e6275513b

@ -3,8 +3,9 @@
import os import os
import requests import requests
import logging import logging
from database import get_exclusion_clause, TableEpisodes, TableShows from gevent import sleep
from database import get_exclusion_clause, TableEpisodes, TableShows
from config import settings, url_sonarr from config import settings, url_sonarr
from helper import path_mappings from helper import path_mappings
from list_subtitles import store_subtitles, series_full_scan_subtitles from list_subtitles import store_subtitles, series_full_scan_subtitles
@ -42,6 +43,7 @@ def sync_episodes(series_id=None, send_event=True):
series_count = len(seriesIdList) series_count = len(seriesIdList)
for i, seriesId in enumerate(seriesIdList, 1): for i, seriesId in enumerate(seriesIdList, 1):
sleep()
if send_event: if send_event:
show_progress(id='episodes_progress', show_progress(id='episodes_progress',
header='Syncing episodes...', header='Syncing episodes...',
@ -56,6 +58,7 @@ def sync_episodes(series_id=None, send_event=True):
continue continue
else: else:
for episode in episodes: for episode in episodes:
sleep()
if 'hasFile' in episode: if 'hasFile' in episode:
if episode['hasFile'] is True: if episode['hasFile'] is True:
if 'episodeFile' in episode: if 'episodeFile' in episode:
@ -82,6 +85,7 @@ def sync_episodes(series_id=None, send_event=True):
removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr)) removed_episodes = list(set(current_episodes_db_list) - set(current_episodes_sonarr))
for removed_episode in removed_episodes: for removed_episode in removed_episodes:
sleep()
episode_to_delete = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId)\ episode_to_delete = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId)\
.where(TableEpisodes.sonarrEpisodeId == removed_episode)\ .where(TableEpisodes.sonarrEpisodeId == removed_episode)\
.dicts()\ .dicts()\
@ -114,6 +118,7 @@ def sync_episodes(series_id=None, send_event=True):
episodes_to_update_list = [i for i in episodes_to_update if i not in episode_in_db_list] episodes_to_update_list = [i for i in episodes_to_update if i not in episode_in_db_list]
for updated_episode in episodes_to_update_list: for updated_episode in episodes_to_update_list:
sleep()
TableEpisodes.update(updated_episode).where(TableEpisodes.sonarrEpisodeId == TableEpisodes.update(updated_episode).where(TableEpisodes.sonarrEpisodeId ==
updated_episode['sonarrEpisodeId']).execute() updated_episode['sonarrEpisodeId']).execute()
altered_episodes.append([updated_episode['sonarrEpisodeId'], altered_episodes.append([updated_episode['sonarrEpisodeId'],
@ -122,6 +127,7 @@ def sync_episodes(series_id=None, send_event=True):
# Insert new episodes in DB # Insert new episodes in DB
for added_episode in episodes_to_add: for added_episode in episodes_to_add:
sleep()
result = TableEpisodes.insert(added_episode).on_conflict(action='IGNORE').execute() result = TableEpisodes.insert(added_episode).on_conflict(action='IGNORE').execute()
if result > 0: if result > 0:
altered_episodes.append([added_episode['sonarrEpisodeId'], altered_episodes.append([added_episode['sonarrEpisodeId'],
@ -135,6 +141,7 @@ def sync_episodes(series_id=None, send_event=True):
# Store subtitles for added or modified episodes # Store subtitles for added or modified episodes
for i, altered_episode in enumerate(altered_episodes, 1): for i, altered_episode in enumerate(altered_episodes, 1):
sleep()
store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1])) store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1]))
logging.debug('BAZARR All episodes synced from Sonarr into database.') logging.debug('BAZARR All episodes synced from Sonarr into database.')

@ -5,6 +5,7 @@ import requests
import logging import logging
import operator import operator
from functools import reduce from functools import reduce
from gevent import sleep
from config import settings, url_radarr from config import settings, url_radarr
from helper import path_mappings from helper import path_mappings
@ -64,6 +65,7 @@ def update_movies(send_event=True):
# Build new and updated movies # Build new and updated movies
movies_count = len(movies) movies_count = len(movies)
for i, movie in enumerate(movies, 1): for i, movie in enumerate(movies, 1):
sleep()
if send_event: if send_event:
show_progress(id='movies_progress', show_progress(id='movies_progress',
header='Syncing movies...', header='Syncing movies...',
@ -103,6 +105,7 @@ def update_movies(send_event=True):
removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr)) removed_movies = list(set(current_movies_db_list) - set(current_movies_radarr))
for removed_movie in removed_movies: for removed_movie in removed_movies:
sleep()
TableMovies.delete().where(TableMovies.tmdbId == removed_movie).execute() TableMovies.delete().where(TableMovies.tmdbId == removed_movie).execute()
# Update movies in DB # Update movies in DB
@ -135,6 +138,7 @@ def update_movies(send_event=True):
movies_to_update_list = [i for i in movies_to_update if i not in movies_in_db_list] movies_to_update_list = [i for i in movies_to_update if i not in movies_in_db_list]
for updated_movie in movies_to_update_list: for updated_movie in movies_to_update_list:
sleep()
TableMovies.update(updated_movie).where(TableMovies.tmdbId == updated_movie['tmdbId']).execute() TableMovies.update(updated_movie).where(TableMovies.tmdbId == updated_movie['tmdbId']).execute()
altered_movies.append([updated_movie['tmdbId'], altered_movies.append([updated_movie['tmdbId'],
updated_movie['path'], updated_movie['path'],
@ -143,6 +147,7 @@ def update_movies(send_event=True):
# Insert new movies in DB # Insert new movies in DB
for added_movie in movies_to_add: for added_movie in movies_to_add:
sleep()
result = TableMovies.insert(added_movie).on_conflict(action='IGNORE').execute() result = TableMovies.insert(added_movie).on_conflict(action='IGNORE').execute()
if result > 0: if result > 0:
altered_movies.append([added_movie['tmdbId'], altered_movies.append([added_movie['tmdbId'],
@ -157,6 +162,7 @@ def update_movies(send_event=True):
# Store subtitles for added or modified movies # Store subtitles for added or modified movies
for i, altered_movie in enumerate(altered_movies, 1): for i, altered_movie in enumerate(altered_movies, 1):
sleep()
store_subtitles_movie(altered_movie[1], path_mappings.path_replace_movie(altered_movie[1])) store_subtitles_movie(altered_movie[1], path_mappings.path_replace_movie(altered_movie[1]))
logging.debug('BAZARR All movies synced from Radarr into database.') logging.debug('BAZARR All movies synced from Radarr into database.')

@ -3,6 +3,7 @@
import os import os
import requests import requests
import logging import logging
from gevent import sleep
from config import settings, url_sonarr from config import settings, url_sonarr
from list_subtitles import list_missing_subtitles from list_subtitles import list_missing_subtitles
@ -49,6 +50,7 @@ def update_series(send_event=True):
series_count = len(series) series_count = len(series)
for i, show in enumerate(series, 1): for i, show in enumerate(series, 1):
sleep()
if send_event: if send_event:
show_progress(id='series_progress', show_progress(id='series_progress',
header='Syncing series...', header='Syncing series...',
@ -81,6 +83,7 @@ def update_series(send_event=True):
removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr)) removed_series = list(set(current_shows_db_list) - set(current_shows_sonarr))
for series in removed_series: for series in removed_series:
sleep()
TableShows.delete().where(TableShows.sonarrSeriesId == series).execute() TableShows.delete().where(TableShows.sonarrSeriesId == series).execute()
if send_event: if send_event:
event_stream(type='series', action='delete', payload=series) event_stream(type='series', action='delete', payload=series)
@ -108,6 +111,7 @@ def update_series(send_event=True):
series_to_update_list = [i for i in series_to_update if i not in series_in_db_list] series_to_update_list = [i for i in series_to_update if i not in series_in_db_list]
for updated_series in series_to_update_list: for updated_series in series_to_update_list:
sleep()
TableShows.update(updated_series).where(TableShows.sonarrSeriesId == TableShows.update(updated_series).where(TableShows.sonarrSeriesId ==
updated_series['sonarrSeriesId']).execute() updated_series['sonarrSeriesId']).execute()
if send_event: if send_event:
@ -115,6 +119,7 @@ def update_series(send_event=True):
# Insert new series in DB # Insert new series in DB
for added_series in series_to_add: for added_series in series_to_add:
sleep()
result = TableShows.insert(added_series).on_conflict(action='IGNORE').execute() result = TableShows.insert(added_series).on_conflict(action='IGNORE').execute()
if result: if result:
list_missing_subtitles(no=added_series['sonarrSeriesId']) list_missing_subtitles(no=added_series['sonarrSeriesId'])

@ -8,6 +8,7 @@ import re
from guess_language import guess_language from guess_language import guess_language
from subliminal_patch import core, search_external_subtitles from subliminal_patch import core, search_external_subtitles
from subzero.language import Language from subzero.language import Language
from gevent import sleep
from database import get_profiles_list, get_profile_cutoff, TableEpisodes, TableShows, TableMovies from database import get_profiles_list, get_profile_cutoff, TableEpisodes, TableShows, TableMovies
from get_languages import alpha2_from_alpha3, language_from_alpha2, get_language_set from get_languages import alpha2_from_alpha3, language_from_alpha2, get_language_set
@ -284,6 +285,7 @@ def list_missing_subtitles(no=None, epno=None, send_event=True):
use_embedded_subs = settings.general.getboolean('use_embedded_subs') use_embedded_subs = settings.general.getboolean('use_embedded_subs')
for episode_subtitles in episodes_subtitles: for episode_subtitles in episodes_subtitles:
sleep()
missing_subtitles_text = '[]' missing_subtitles_text = '[]'
if episode_subtitles['profileId']: if episode_subtitles['profileId']:
# get desired subtitles # get desired subtitles
@ -394,6 +396,7 @@ def list_missing_subtitles_movies(no=None, send_event=True):
use_embedded_subs = settings.general.getboolean('use_embedded_subs') use_embedded_subs = settings.general.getboolean('use_embedded_subs')
for movie_subtitles in movies_subtitles: for movie_subtitles in movies_subtitles:
sleep()
missing_subtitles_text = '[]' missing_subtitles_text = '[]'
if movie_subtitles['profileId']: if movie_subtitles['profileId']:
# get desired subtitles # get desired subtitles
@ -493,6 +496,7 @@ def series_full_scan_subtitles():
count_episodes = len(episodes) count_episodes = len(episodes)
for i, episode in enumerate(episodes, 1): for i, episode in enumerate(episodes, 1):
sleep()
show_progress(id='episodes_disk_scan', show_progress(id='episodes_disk_scan',
header='Full disk scan...', header='Full disk scan...',
name='Episodes subtitles', name='Episodes subtitles',
@ -516,6 +520,7 @@ def movies_full_scan_subtitles():
count_movies = len(movies) count_movies = len(movies)
for i, movie in enumerate(movies, 1): for i, movie in enumerate(movies, 1):
sleep()
show_progress(id='movies_disk_scan', show_progress(id='movies_disk_scan',
header='Full disk scan...', header='Full disk scan...',
name='Movies subtitles', name='Movies subtitles',
@ -541,6 +546,7 @@ def series_scan_subtitles(no):
.dicts() .dicts()
for episode in episodes: for episode in episodes:
sleep()
store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) store_subtitles(episode['path'], path_mappings.path_replace(episode['path']))
@ -551,6 +557,7 @@ def movies_scan_subtitles(no):
.dicts() .dicts()
for movie in movies: for movie in movies:
sleep()
store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path'])) store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))

Loading…
Cancel
Save