diff --git a/bazarr/get_episodes.py b/bazarr/get_episodes.py index 4d8938731..301846677 100644 --- a/bazarr/get_episodes.py +++ b/bazarr/get_episodes.py @@ -3,8 +3,9 @@ import os import requests 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 helper import path_mappings 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) for i, seriesId in enumerate(seriesIdList, 1): + sleep() if send_event: show_progress(id='episodes_progress', header='Syncing episodes...', @@ -56,6 +58,7 @@ def sync_episodes(series_id=None, send_event=True): continue else: for episode in episodes: + sleep() if 'hasFile' in episode: if episode['hasFile'] is True: 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)) for removed_episode in removed_episodes: + sleep() episode_to_delete = TableEpisodes.select(TableEpisodes.sonarrSeriesId, TableEpisodes.sonarrEpisodeId)\ .where(TableEpisodes.sonarrEpisodeId == removed_episode)\ .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] for updated_episode in episodes_to_update_list: + sleep() TableEpisodes.update(updated_episode).where(TableEpisodes.sonarrEpisodeId == updated_episode['sonarrEpisodeId']).execute() altered_episodes.append([updated_episode['sonarrEpisodeId'], @@ -122,6 +127,7 @@ def sync_episodes(series_id=None, send_event=True): # Insert new episodes in DB for added_episode in episodes_to_add: + sleep() result = TableEpisodes.insert(added_episode).on_conflict(action='IGNORE').execute() if result > 0: 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 for i, altered_episode in enumerate(altered_episodes, 1): + sleep() store_subtitles(altered_episode[1], path_mappings.path_replace(altered_episode[1])) logging.debug('BAZARR All episodes synced from Sonarr into database.') diff --git a/bazarr/get_movies.py b/bazarr/get_movies.py index df75a1225..239839a42 100644 --- a/bazarr/get_movies.py +++ b/bazarr/get_movies.py @@ -5,6 +5,7 @@ import requests import logging import operator from functools import reduce +from gevent import sleep from config import settings, url_radarr from helper import path_mappings @@ -64,6 +65,7 @@ def update_movies(send_event=True): # Build new and updated movies movies_count = len(movies) for i, movie in enumerate(movies, 1): + sleep() if send_event: show_progress(id='movies_progress', 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)) for removed_movie in removed_movies: + sleep() TableMovies.delete().where(TableMovies.tmdbId == removed_movie).execute() # 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] for updated_movie in movies_to_update_list: + sleep() TableMovies.update(updated_movie).where(TableMovies.tmdbId == updated_movie['tmdbId']).execute() altered_movies.append([updated_movie['tmdbId'], updated_movie['path'], @@ -143,6 +147,7 @@ def update_movies(send_event=True): # Insert new movies in DB for added_movie in movies_to_add: + sleep() result = TableMovies.insert(added_movie).on_conflict(action='IGNORE').execute() if result > 0: altered_movies.append([added_movie['tmdbId'], @@ -157,6 +162,7 @@ def update_movies(send_event=True): # Store subtitles for added or modified movies for i, altered_movie in enumerate(altered_movies, 1): + sleep() store_subtitles_movie(altered_movie[1], path_mappings.path_replace_movie(altered_movie[1])) logging.debug('BAZARR All movies synced from Radarr into database.') diff --git a/bazarr/get_series.py b/bazarr/get_series.py index 1b9c6fe08..481131388 100644 --- a/bazarr/get_series.py +++ b/bazarr/get_series.py @@ -3,6 +3,7 @@ import os import requests import logging +from gevent import sleep from config import settings, url_sonarr from list_subtitles import list_missing_subtitles @@ -49,6 +50,7 @@ def update_series(send_event=True): series_count = len(series) for i, show in enumerate(series, 1): + sleep() if send_event: show_progress(id='series_progress', 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)) for series in removed_series: + sleep() TableShows.delete().where(TableShows.sonarrSeriesId == series).execute() if send_event: 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] for updated_series in series_to_update_list: + sleep() TableShows.update(updated_series).where(TableShows.sonarrSeriesId == updated_series['sonarrSeriesId']).execute() if send_event: @@ -115,6 +119,7 @@ def update_series(send_event=True): # Insert new series in DB for added_series in series_to_add: + sleep() result = TableShows.insert(added_series).on_conflict(action='IGNORE').execute() if result: list_missing_subtitles(no=added_series['sonarrSeriesId']) diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index c6f938b2e..dccedca29 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -8,6 +8,7 @@ import re from guess_language import guess_language from subliminal_patch import core, search_external_subtitles from subzero.language import Language +from gevent import sleep 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 @@ -284,6 +285,7 @@ def list_missing_subtitles(no=None, epno=None, send_event=True): use_embedded_subs = settings.general.getboolean('use_embedded_subs') for episode_subtitles in episodes_subtitles: + sleep() missing_subtitles_text = '[]' if episode_subtitles['profileId']: # 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') for movie_subtitles in movies_subtitles: + sleep() missing_subtitles_text = '[]' if movie_subtitles['profileId']: # get desired subtitles @@ -493,6 +496,7 @@ def series_full_scan_subtitles(): count_episodes = len(episodes) for i, episode in enumerate(episodes, 1): + sleep() show_progress(id='episodes_disk_scan', header='Full disk scan...', name='Episodes subtitles', @@ -516,6 +520,7 @@ def movies_full_scan_subtitles(): count_movies = len(movies) for i, movie in enumerate(movies, 1): + sleep() show_progress(id='movies_disk_scan', header='Full disk scan...', name='Movies subtitles', @@ -541,6 +546,7 @@ def series_scan_subtitles(no): .dicts() for episode in episodes: + sleep() store_subtitles(episode['path'], path_mappings.path_replace(episode['path'])) @@ -551,6 +557,7 @@ def movies_scan_subtitles(no): .dicts() for movie in movies: + sleep() store_subtitles_movie(movie['path'], path_mappings.path_replace_movie(movie['path']))