tmp
This commit is contained in:
parent
c690162983
commit
7df0c0a0ff
49 changed files with 1439861 additions and 169 deletions
45
loadArtwork.py
Normal file
45
loadArtwork.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import requests
|
||||
import os
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
|
||||
from common import *
|
||||
|
||||
|
||||
def save_image_from_url(url, name, image_dir="playlist_covers"):
|
||||
response = requests.get(url)
|
||||
|
||||
if response.status_code != 200:
|
||||
raise "Cannot fetch the playlist cover"
|
||||
|
||||
image = Image.open(BytesIO(response.content))
|
||||
|
||||
directory = os.path.join(data_dir, image_dir)
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
file_path = os.path.join(directory, f"{name}.jpg")
|
||||
print(f"Image saved {file_path}")
|
||||
image.save(file_path)
|
||||
|
||||
|
||||
def load_playlist_covers():
|
||||
playlists = get_data('playlists')
|
||||
|
||||
for pl in playlists:
|
||||
if len(pl['images']):
|
||||
url = pl['images'][0]['url']
|
||||
save_image_from_url(url, pl['name'])
|
||||
|
||||
|
||||
def load_user_cover():
|
||||
user_data = get_data("user_data")
|
||||
url = user_data['images'][1]['url']
|
||||
save_image_from_url(url, "user", ".")
|
||||
|
||||
|
||||
def load():
|
||||
load_user_cover()
|
||||
load_playlist_covers()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
load()
|
||||
Loading…
Add table
Add a link
Reference in a new issue