From 8a6afd969c6b27e7de8a1d10eae6504f8cf6a1c6 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 22:30:12 +0100 Subject: [PATCH] added multi-threaded downloading --- deemix/app/downloader.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 7775406..4d978c5 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -7,6 +7,7 @@ from os import makedirs from requests import get from requests.exceptions import HTTPError from tempfile import gettempdir +from concurrent.futures import ThreadPoolExecutor dz = Deezer() TEMPDIR = os.path.join(gettempdir(), 'deezloader-imgs') @@ -346,10 +347,11 @@ def download_album(id, settings, overwriteBitrate=False): downloadTrackObj(trackAPI, settings, overwriteBitrate) else: tracksArray = dz.get_album_tracks_gw(id) - for trackAPI in tracksArray: - trackAPI['_EXTRA_ALBUM'] = albumAPI - trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate'] - downloadTrackObj(trackAPI, settings, overwriteBitrate) + with ThreadPoolExecutor(settings['queueConcurrency']) as executor: + for trackAPI in tracksArray: + trackAPI['_EXTRA_ALBUM'] = albumAPI + trackAPI['FILENAME_TEMPLATE'] = settings['albumTracknameTemplate'] + executor.submit(downloadTrackObj, trackAPI, settings, overwriteBitrate) def download_playlist(id, settings, overwriteBitrate=False): playlistAPI = dz.get_playlist(id)