Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import spotipy
- import requests
- import webbrowser
- def clean_filename(filename):
- replacer_map = {"#": "no.", "%": "percent", "&": "and", "{": "(", "}": ")", "\\": "-", "<": "(", ">": ")", "*": "X", "?": "", "!": "", "$": "", " ": "_", "/": "-", "'": "", '"': "", ":": "_-", "@": "at", "+": "plus", "|": "-", "=": "equals", "`": "",}
- for symbol in replacer_map.keys():
- filename = filename.replace(symbol, replacer_map[symbol])
- return filename
- sp = spotipy.Spotify(client_credentials_manager = spotipy.oauth2.SpotifyClientCredentials())
- uri = str(sys.argv[1]).split("/")[-1]
- album = sp.album(uri)
- album_title = album["name"]
- cover_url = album["images"][0]["url"]
- webbrowser.get("/usr/bin/firefox").open(cover_url)
- album_filename = clean_filename(album_title)
- full_save_path = os.path.join("/home/tomo/Downloads/cover_art/", uri + "_" + album_filename + ".jpg")
- if not os.path.isfile(full_save_path):
- response = requests.get(cover_url)
- with open(full_save_path, "wb") as f:
- f.write(response.content)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement