-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_track_album_art.py
95 lines (79 loc) · 2.89 KB
/
get_track_album_art.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import sys
import json
import spotipy
import webbrowser
import spotipy.util as util
from json.decoder import JSONDecodeError
import oauth
username = 'd5gqzzfewfdefoiyrwa6yvgq7'
token = util.prompt_for_user_token(username, oauth.scope, oauth.client_id, oauth.client_secret, oauth.redirect_uri)
#Create our spotifyObject
spotifyObject = spotipy.Spotify(auth=token)
#Get user informations
user = spotifyObject.current_user()
#print(json.dumps(user, sort_keys=True, indent=4))
display_name = user['display_name']
followers = user['followers']['total']
#Get user playlists
while True:
print()
print(">>> Welcome to Spotify " + display_name + "!")
print(">>> You have " + str(followers) + " followers.")
print()
print("0 - Search for an artist")
print("1 - exit")
choice = input("Your choice: ")
#Search for the artist
if choice == "0":
print()
searchQuery = input("Ok, what's their name?: ")
print()
# Get seach result
searchResults = spotifyObject.search(searchQuery,1,0,"artist")
#print(json.dumps(searchResults, sort_keys=True, indent=4))
# Artist details
artist = searchResults['artists']['items'][0]
print(artist['name'])
print(str(artist['followers']['total']) + " followers")
print(artist['genres'][0])
print()
webbrowser.open(artist['images'][0]['url'])
artistID = artist['id']
# Albums and Tracks
trackURIs = []
trackArt = []
z = 0
# Extract album data
albumResults = spotifyObject.artist_albums(artistID)
#print(json.dumps(albumResult, sort_keys=True, indent=4))
# OR a btterr version is to automate the json dumps methode by creting a json file
#f = open("album_search.json", "w+")
#f.write(json.dumps(albumResults, sort_keys=True, indent=4))
#f.close()
albumResults = albumResults['items']
for item in albumResults:
print("ALBUM " + item['name'])
albumID = item['id']
albumArt = item['images'][0]['url']
# Extract track data
trackResults = spotifyObject.album_tracks(albumID)
#f = open("track_search.json", "w+")
#f.write(json.dumps(trackResults, sort_keys=True, indent=4))
#f.close()
trackResults = trackResults['items']
for item in trackResults:
print(str(z) + ": " + item['name'])
trackURIs.append(item['uri'])
trackArt.append(albumArt)
z+=1
print()
# See album art
while True:
SongSelection = input("Enter a song number to see the album art associated with it (x to exit): ")
if SongSelection == "x":
break
webbrowser.open(trackArt[int(SongSelection)])
#End the program
if choice == "1":
break