replaced urllib with requests

This commit is contained in:
uh_wot 2020-02-29 20:40:03 +01:00
parent 83821405ee
commit adc498ccde
2 changed files with 5 additions and 9 deletions

View File

@ -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)

View File

@ -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