# PIP Spotipy | https://spotipy.readthedocs.io/en/2.13.0/ # # # 1). Login # 2). Select playlist # 3). Iterate/Download items # 4). Use spotify metadata to ID3 tag song # 5). Songs that could not be found are listed an possible exported for later use # # This will be awesome! # from command import search, settings from helper import console, tagging import colorama as color import spotipy from spotipy.oauth2 import SpotifyOAuth from helper.settings import Settings from helper.tags.tagitem import TagItem def spotify(): if Settings.SpotifyUsername.get() == '' or Settings.SpotifyClientID.get() == '' or Settings.SpotifySecret.get() == '': console.output('You need to request a developers account at spotify. You only have to do this once.') console.output('This is very easy, quick, and free to do and this doesn\'t further affect your account') console.output('Please go to:') console.output('\thttps://developer.spotify.com/dashboard/applications') console.output('And create a new application.') console.output('Fill in a name, description and enter in the Redirect URI\'s this:') console.output('\thttp://spotify-finder') console.output('Save it and make sure you find Client ID and Client Secret on your screen') console.ask_input('Are you ready to fill in your username, client ID, and secret? [y]') settings() return True console.output('Logging in to Spotify') spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=Settings.SpotifyScope.get(), client_id=Settings.SpotifyClientID.get(), client_secret=Settings.SpotifySecret.get(), redirect_uri='http://spotify-finder', username=Settings.SpotifyUsername.get())) playlists = spotify.current_user_playlists() console.output('Found {0} spotify playlists'.format(len(playlists['items'])), console.DBG_INFO) playlist = console.option_picker("Pick a playlist that you want to download from", playlists['items'], quit=True, objects=[ '__id__', 'x[name]', 'x[description]' ], table=[ ('ID', 2), ('Name', 50), ('Description', 100) ]) if playlist is None: return True else: playlist = playlists['items'][playlist] tracks = spotify.playlist_tracks(playlist['id'], fields='items(track(album(name,images(url)),artists(name),name))') console.output('Found {0} tracks in playlist {1}'.format(len(tracks['items']), playlist['name']), console.DBG_INFO) console.output('Start finding music from playlist \'{0}\''.format(playlist['name'])) success = [] fail = [] for track in tracks['items']: track = track['track'] tag = TagItem() tag.set_title(track['name']) tag.set_artist(', '.join(list(i['name'] for i in track['artists']))) tag.set_cover_url(track['album']['images'][0]['url']) # 640x640 tag.set_album(track['album']['name']) tag.set_genre('') # unknown keywords = '{0} - {1}'.format(track['artists'][0]['name'], track['name']) console.output('Looking up {0} - {1}'.format(track['artists'][0]['name'], track['name'])) result = search(keywords=keywords, automode=True, tags=tag) if result: success.append(tag) console.output(color.Fore.GREEN + '[ OK ] {tag.artist} - {tag.title}'.format(tag=tag)) else: fail.append(tag) console.output(color.Fore.RED + '[FAIL] {tag.artist} - {tag.title}'.format(tag=tag)) console.output('Sucessfully downloaded {0} songs. {1} songs failed to download'.format(len(success), len(fail))) if len(fail) > 0: seefails = console.ask_input('Do you want to see a list of the failed songs and manually search for it? [y/n]') if seefails == 'y': while True: song = console.option_picker('Pick a song to manually download it', fail, quit=True, objects=[ '__id__', 'x.artist', 'x.title' ], table=[ ('ID', 2), ('Artist', 50), ('Title', 100) ]) if song is None: break else: keywords = '{tag.artist} - {tag.title}'.format(tag=tag) search(keywords=keywords) return True