diff --git a/jellyfin_kodi/downloader.py b/jellyfin_kodi/downloader.py index 0dd37da9..90ead9f1 100644 --- a/jellyfin_kodi/downloader.py +++ b/jellyfin_kodi/downloader.py @@ -20,8 +20,6 @@ from helper import LazyLogger ################################################################################################# LOG = LazyLogger(__name__) -LIMIT = min(int(settings('limitIndex') or 50), 50) -DTHREADS = int(settings('limitThreads') or 3) ################################################################################################# @@ -246,6 +244,9 @@ def _get_items(query, server_id=None): 'RestorePoint': {} } + limit = min(int(settings('limitIndex') or 50), 50) + dthreads = int(settings('limitThreads') or 3) + url = query['url'] query.setdefault('params', {}) params = query['params'] @@ -270,16 +271,16 @@ def _get_items(query, server_id=None): return params_copy query_params = [ - get_query_params(params, offset, LIMIT) + get_query_params(params, offset, limit) for offset - in range(params['StartIndex'], items['TotalRecordCount'], LIMIT) + in range(params['StartIndex'], items['TotalRecordCount'], limit) ] # multiprocessing.dummy.Pool completes all requests in multiple threads but has to # complete all tasks before allowing any results to be processed. ThreadPoolExecutor # allows for completed tasks to be processed while other tasks are completed on other # threads. Dont be a dummy.Pool, be a ThreadPoolExecutor - p = concurrent.futures.ThreadPoolExecutor(DTHREADS) + p = concurrent.futures.ThreadPoolExecutor(dthreads) results = p.map(lambda params: _get(url, params, server_id=server_id), query_params)