Skip to content

Commit

Permalink
Add artist and album fetching scripts with image and track saving fun…
Browse files Browse the repository at this point in the history
…ctionality
  • Loading branch information
sillyangel committed Nov 20, 2024
1 parent c434616 commit 56e8613
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
Binary file added public/artistprofile/billieeilish.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/artistprofile/childishgambino.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/artistprofile/frankocean.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/artistprofile/kanyewest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
47 changes: 47 additions & 0 deletions spotifyalbumfetch/artistspotifypicfetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import json
import re

token = 'BQAcX7bZr8qfz8vPZmzfd1E49Vl40YEt5IwxyxG5vMtJlsWPTdatq1aaMhIF-sGKn7fGKLaAAui9zHj_lxGZgsXp9B9HDvYLqu3M5h049EWgqfyBoIsOgQvzr6G7SGc1oz3norKCAwY6kvnzVrkK1EymEJ3E9358FzZA2ItFJs95rED1dUoo0jMEd6Yn9vxPSme0Ba37qsTiqGsWGoRhQFOTaFWFREacl3-4yoSdjKQbjzcD_GqiFCtZqFRxWBK-_GpSIe0a84Gn';

# Set headers with authorization token
headers = {
"Authorization": f"Bearer {token}"
}

# Function to fetch and save artist picture
def fetch_and_save_artist_picture(artist_id):
# Base URL for artist details
artist_url = f"https://api.spotify.com/v1/artists/{artist_id}"

# Get artist details
artist_response = requests.get(artist_url, headers=headers)
if artist_response.status_code == 200:
artist_data = json.loads(artist_response.text)
artist_name = artist_data["name"]
artist_picture_url = artist_data["images"][0]["url"] if artist_data["images"] else None

if artist_picture_url:
# Remove special characters and spaces from artist name for filename
filename = re.sub(r'\W+', '', artist_name).lower() + ".jpg"

# Fetch the artist picture
picture_response = requests.get(artist_picture_url)
if picture_response.status_code == 200:
# Save the picture to a file
with open(filename, "wb") as outfile:
outfile.write(picture_response.content)
print(f"Artist picture saved to {filename}")
else:
print(f"Error fetching artist picture: {picture_response.status_code}")
else:
print(f"No picture found for artist: {artist_name}")
else:
print(f"Error fetching artist details: {artist_response.status_code}")

# Prompt user for artist IDs
artist_ids = input("Enter artist IDs separated by commas: ").split(',')

# Fetch and save picture for each artist
for artist_id in artist_ids:
fetch_and_save_artist_picture(artist_id.strip())

0 comments on commit 56e8613

Please sign in to comment.