-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGather_Album_Artwork.py
51 lines (41 loc) · 1.69 KB
/
Gather_Album_Artwork.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
sys.path.insert(1, '../Spotify_Release_Pi/src/')
import General_Spotify_Helpers as gsh
import sqlite3
from PIL import Image, ImageStat
from io import BytesIO
import glob
import requests
# Grab every track from Master Playlist
# populate track_info_db
# Keep a unique set of album_id's
# Grab every unique album_id image in max resolution
SCOPE = "playlist-read-private " \
"playlist-read-collaborative "
TRACK_INFO_DB = "track_info.db"
MASTER_PLAYLIST_ID = "6kGQQoelXM2YDOSmqUUzRw"
# Smaller playlist to test with
# MASTER_PLAYLIST_ID = "196H9SeTzhVNDf5rBtTUuu"
spotify = gsh.GeneralSpotifyHelpers(SCOPE)
conn = sqlite3.connect(TRACK_INFO_DB)
conn.execute(f'''CREATE TABLE IF NOT EXISTS 'info'(
track_name TEXT NOT NULL,
artist_name TEXT NOT NULL,
album_name TEXT NOT NULL,
album_id TEXT NOT NULL);''')
tracks_data = spotify.get_playlist_tracks(MASTER_PLAYLIST_ID, track_info=['name'], album_info=['id', 'name', 'images'], artist_info=['name'])
album_ids = []
for track in tracks_data:
print(f"Getting {track['name']} - { track['artists'][0]['name']} - {track['album_name']} {track['album_id']}")
# Skip local tracks
if track['album_id'] is None:
continue
conn.execute('INSERT INTO info (track_name,artist_name,album_name,album_id) VALUES (?,?,?,?)',
(track['name'], track['artists'][0]['name'], track['album_name'], track['album_id']))
if track['album_id'] not in album_ids:
print("\t Grabbing Image")
album_ids.append(track['album_id'])
img = Image.open(BytesIO(requests.get(track["album_images"][0]['url']).content))
img.save(f"Albums/{track['album_id']}.png")
conn.commit()
conn.close()