This commit is contained in:
Lukas Schulz 2020-12-19 23:09:12 +01:00
parent a6a86bbe8d
commit 846673157b

12
main.py
View file

@ -9,8 +9,7 @@ import threading
import requests
from io import BytesIO
import time
import requests
import shutil
import urllib.request
@ -45,11 +44,12 @@ def get_track():
print('getting image')
#urlretrieve(track['item']['album']['images'][0]['url'], 'thumbnail.jpg')
#imageString = requests.get(track['item']['album']['images'][0]['url'])
image_url=track['item']['album']['images'][0]['url']
opener=urllib.request.build_opener()
opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36')]
urllib.request.install_opener(opener)
filename = "thumbnail.jpg"
r = requests.get(track['item']['album']['images'][0]['url'], stream = True)
r.raw.decode_content = True
with open(filename,'wb') as f:
shutil.copyfileobj(r.raw, f)
urllib.request.urlretrieve(image_url, filename)
image = Image.open('thumbnail.jpg')
print('resizing image')
image = image.resize((32,32))