Added download auto retry on unstable connections
This commit is contained in:
parent
4933e01034
commit
98b67fa70a
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
__version__ = "1.2.16"
|
__version__ = "1.2.17"
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os.path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from requests import get
|
from requests import get
|
||||||
from requests.exceptions import HTTPError, ConnectionError
|
from requests import exceptions as request_exception
|
||||||
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from os import makedirs, remove, system as execute
|
from os import makedirs, remove, system as execute
|
||||||
|
@ -57,7 +57,7 @@ def downloadImage(url, path, overwrite="n"):
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
f.write(image.content)
|
f.write(image.content)
|
||||||
return path
|
return path
|
||||||
except HTTPError:
|
except request_exception.HTTPError:
|
||||||
if 'cdns-images.dzcdn.net' in url:
|
if 'cdns-images.dzcdn.net' in url:
|
||||||
urlBase = url[:url.rfind("/")+1]
|
urlBase = url[:url.rfind("/")+1]
|
||||||
pictureUrl = url[len(urlBase):]
|
pictureUrl = url[len(urlBase):]
|
||||||
|
@ -454,7 +454,7 @@ class DownloadJob:
|
||||||
except DownloadCancelled:
|
except DownloadCancelled:
|
||||||
remove(writepath)
|
remove(writepath)
|
||||||
raise DownloadCancelled
|
raise DownloadCancelled
|
||||||
except (HTTPError, DownloadEmpty):
|
except (request_exception.HTTPError, DownloadEmpty):
|
||||||
remove(writepath)
|
remove(writepath)
|
||||||
if track.fallbackId != "0":
|
if track.fallbackId != "0":
|
||||||
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available, using fallback id")
|
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Track not available, using fallback id")
|
||||||
|
@ -473,12 +473,13 @@ class DownloadJob:
|
||||||
raise DownloadFailed("notAvailableNoAlternative")
|
raise DownloadFailed("notAvailableNoAlternative")
|
||||||
else:
|
else:
|
||||||
raise DownloadFailed("notAvailable")
|
raise DownloadFailed("notAvailable")
|
||||||
except ConnectionError as e:
|
except (request_exception.ConnectionError, request_exception.ChunkedEncodingError) as e:
|
||||||
logger.exception(str(e))
|
remove(writepath)
|
||||||
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, trying again in 5s...")
|
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, trying again in 5s...")
|
||||||
sleep(5)
|
sleep(5)
|
||||||
return downloadMusic(track, trackAPI_gw)
|
return downloadMusic(track, trackAPI_gw)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
remove(writepath)
|
||||||
logger.exception(str(e))
|
logger.exception(str(e))
|
||||||
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, you should report this to the developers")
|
logger.warn(f"[{track.mainArtist['name']} - {track.title}] Error while downloading the track, you should report this to the developers")
|
||||||
raise e
|
raise e
|
||||||
|
@ -559,7 +560,7 @@ class DownloadJob:
|
||||||
try:
|
try:
|
||||||
request.raise_for_status()
|
request.raise_for_status()
|
||||||
return format_num
|
return format_num
|
||||||
except HTTPError: # if the format is not available, Deezer returns a 403 error
|
except request_exception.HTTPError: # if the format is not available, Deezer returns a 403 error
|
||||||
pass
|
pass
|
||||||
if fallback:
|
if fallback:
|
||||||
continue
|
continue
|
||||||
|
@ -573,7 +574,7 @@ class DownloadJob:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request = get(track.downloadUrl, headers=self.dz.http_headers, stream=True, timeout=30)
|
request = get(track.downloadUrl, headers=self.dz.http_headers, stream=True, timeout=30)
|
||||||
except ConnectionError:
|
except request_exception.ConnectionError:
|
||||||
sleep(2)
|
sleep(2)
|
||||||
return self.streamTrack(stream, track)
|
return self.streamTrack(stream, track)
|
||||||
request.raise_for_status()
|
request.raise_for_status()
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="deemix",
|
name="deemix",
|
||||||
version="1.2.16",
|
version="1.2.17",
|
||||||
description="A barebone deezer downloader library",
|
description="A barebone deezer downloader library",
|
||||||
long_description=README,
|
long_description=README,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|
Loading…
Reference in New Issue