Closed TimStewartJ closed 1 year ago
I'm really excited about this new auth flow. I'm hoping it will lead the way to non-programmers being able to use the app, via a webapp or something.
Yeah, the new auth flow doesn't require a user ID anymore, making things a little easier for first time setup. Users won't have to dig around their spotify settings to find their ID, which is harder than it should be.
Not much else has changed in terms of interaction for this PR. I've tried to preserve as much of the original functionality as possible, just focusing on readability and clean up. A webapp interface for spotnik sounds really interesting. Maybe we could make a discussion for it to figure out how we want to approach it? It seems like a longer-term overhaul that would benefit from focused development.
There are still some chunks of code and comments that seem to be left over from earlier states of development, but I've left most of them intact in case any useful information could be garnered from them. Other than that, I'd say this is good to merge, barring any comments from anyone else.
@TimStewartJ hmm...without passing my Spotify username as a parameter, I get this error in get_spotify()
. Do I have to get a new set of Spotify developer creds maybe?
Getting tracks from the playlists earmarked for the Spotnik Example Playlist 1 playlist...
- sampling a maximum of 8 Spotify tracks from the playlist 'albumsImCheckingOut'...
Traceback (most recent call last):
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\oauth2.py", line 588, in refresh_access_token
response.raise_for_status()
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\aethe\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\aethe\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\RC Dropbox\Rivers Cuomo\Apps\spotnik\spotnik\__main__.py", line 117, in <module>
main()
File "C:\RC Dropbox\Rivers Cuomo\Apps\spotnik\spotnik\__main__.py", line 53, in main
tracks = get_all_tracks(data, job, spotify)
File "C:\RC Dropbox\Rivers Cuomo\Apps\spotnik\spotnik\get_all_tracks.py", line 37, in get_all_tracks
new_tracks = sample_playlist_tracks(
File "C:\RC Dropbox\Rivers Cuomo\Apps\spotnik\spotnik\api.py", line 64, in sample_playlist_tracks
all_tracks = get_playlist_tracks(spotify, playlist_id)
File "C:\RC Dropbox\Rivers Cuomo\Apps\spotnik\spotnik\api.py", line 74, in get_playlist_tracks
results = spotify.playlist_tracks(playlist_id)
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\client.py", line 649, in playlist_tracks
return self.playlist_items(playlist_id, fields, limit, offset,
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\client.py", line 673, in playlist_items
return self._get(
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\client.py", line 297, in _get
return self._internal_call("GET", url, payload, kwargs)
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\client.py", line 221, in _internal_call
headers = self._auth_headers()
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\client.py", line 212, in _auth_headers
token = self.auth_manager.get_access_token(as_dict=False)
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\oauth2.py", line 525, in get_access_token
token_info = self.validate_token(self.cache_handler.get_cached_token())
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\oauth2.py", line 380, in validate_token
token_info = self.refresh_access_token(
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\oauth2.py", line 596, in refresh_access_token
self._handle_oauth_error(http_error)
File "C:\RC Dropbox\Rivers Cuomo\Apps\.G\lib\site-packages\spotipy\oauth2.py", line 146, in _handle_oauth_error
raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: error: invalid_client, error_description: Invalid client
@riverscuomo That's really odd... I'm trying to reproduce it but I can't. In the meantime I would recommend the following steps:
.cache
and rerun.@TimStewartJ Thanks. I deleted .cache
and .cache-rcuomo
and then it ran successfully. I saw no sign of the program reaching oauthStepTwo()
, so I'm not sure how it worked. But work, it did.
Great, glad to hear it. Yeah I don't think oauthStepTwo() is necessary any more, spotipy should handle login in most situations that require it, like when the cached token expires, or if access to the app is revoked.
os.path.join
for the random facts path to work on any system.SpotifyOAuth
to authenticate the spotipy instance. This is more robust and will generally prompt for re-authentication when necessary so we don't have to.bans
functions under a single class that holds references to the current job and audio features of all of the tracks. Also condensed calls to the class into a single function that calls the old ones.get_audio_features
now returns a dict where the track's id is the key. We no longer need to iterate through the entire track list every time we want to check if we should ban a track in_is_banned_by_low_energy()
.newmusicdescription.py
. It was unused and all of its functionality has been replaced bygetFact()
inpost_description.py
.