From adc498ccdebaedd9f31f0a3b2ff4bba2fa2ed1cc Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 20:40:03 +0100 Subject: [PATCH 1/4] replaced urllib with requests --- deemix/api/deezer.py | 8 ++------ deemix/app/downloader.py | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/deemix/api/deezer.py b/deemix/api/deezer.py index 79bca07..0993afb 100755 --- a/deemix/api/deezer.py +++ b/deemix/api/deezer.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import binascii import hashlib -from urllib.request import urlopen import blowfish import pyaes @@ -268,13 +267,10 @@ class Deezer: i += 1 def stream_track(self, track_id, url, stream): - response = urlopen(url) + request = requests.get(url, stream=True) cipher = blowfish.Cipher(str.encode(self._get_blowfish_key(str(track_id)))) i = 0 - while True: - chunk = response.read(2048) - if not chunk: - break + for chunk in request.iter_content(2048): if (i % 3) == 0 and len(chunk) == 2048: chunk = b"".join(cipher.decrypt_cbc(chunk, b"\x00\x01\x02\x03\x04\x05\x06\x07")) stream.write(chunk) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index d9a9275..c32c418 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -4,8 +4,8 @@ from deemix.utils.taggers import tagID3, tagFLAC from deemix.utils.pathtemplates import generateFilename, generateFilepath import os.path from os import makedirs -from urllib.request import urlopen -from urllib.error import HTTPError +from requests import get +from requests.exceptions import HTTPError from tempfile import gettempdir dz = Deezer() @@ -264,7 +264,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False, extraTrack=None if not os.path.isfile(track['album']['picPath']): with open(track['album']['picPath'], 'wb') as f: try: - f.write(urlopen(track['album']['picUrl']).read()) + f.write(get(track['album']['picUrl']).content) except HTTPError: track['album']['picPath'] = None From 678f85fda72e8162e6c9fadd5f491d7a5b53f4e0 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 20:40:46 +0100 Subject: [PATCH 2/4] added requests to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 39ed6e3..7a4433a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ pyaes blowfish mutagen click +requests From 1a1883fabb330a00de02db2e64ed5ef157fb9359 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 20:46:42 +0100 Subject: [PATCH 3/4] removed semicolon --- deemix/app/downloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index c32c418..a49454e 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -24,7 +24,7 @@ extensions = { } def getPreferredBitrare(filesize, bitrate): - bitrateFound = False; + bitrateFound = False selectedFormat = 0 selectedFilesize = 0 if int(bitrate) == 9: From e9167ccc5440990a3acc615a4bcb16bd94f224f7 Mon Sep 17 00:00:00 2001 From: uh_wot <3631986-uh_wot@users.noreply.gitlab.com> Date: Sat, 29 Feb 2020 20:54:47 +0100 Subject: [PATCH 4/4] fixed "getPreferredBitrare" typo --- deemix/app/downloader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index a49454e..2e46dcb 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -23,7 +23,7 @@ extensions = { 13: '.mp4' } -def getPreferredBitrare(filesize, bitrate): +def getPreferredBitrate(filesize, bitrate): bitrateFound = False selectedFormat = 0 selectedFilesize = 0 @@ -249,7 +249,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False, extraTrack=None # Get the selected bitrate bitrate = overwriteBitrate if overwriteBitrate else settings['maxBitrate'] - (format, filesize) = getPreferredBitrare(track['filesize'], bitrate) + (format, filesize) = getPreferredBitrate(track['filesize'], bitrate) track['selectedFormat'] = format track['selectedFilesize'] = filesize track['album']['bitrate'] = format