conor-f / spotibar

Polybar plugin for Spotify
15 stars 2 forks source link

Need help getting this to work #17

Closed gldtn closed 2 years ago

gldtn commented 2 years ago

I've been trying to get this to work, but have not had any luck..

I created the .json file, create the app under spotify dev and added the URI..

When I run spotibar --auth I get a link in my terminal which was directing me to an error page due to invalid URL. Until I saw that my terminal was messing up the URL with weird characters:

https://accounts.spotify.com/authorize?client_id=*&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080&scope=playlist-read-private+playlist-modify-private+user-read-playback-state+user-modify-playback-state+playlist-modify-public

Like so: redirect_uri=http%3A%2F%2F127.0.0.1

So, I manually edited it to redirect_uri=http://127.0.0.1

And it redirect me to what seem to be correct: 127.0.0.1/?code=AQAXeggpUbU8QgtqeT4OKEUJohPNimVFlQMi1n0kNWQB-T0YLOmEz7Ikx1IIsCbJuAlUiyC90GXEZuwa-yJtHsfrRLFLs_z7XPo_BE9iCFD24ajIgIi-vi1prUgt1BE3bzofVypRwgJFoWoavA9A500SHInuCTicWSTLRWXpcPccRF8WPa7GDtCnCLqvq-QcHAqMaeT6Xisza3Q7MSrTXBG_oYIYKWeOTPg-mXmKNCrwuE1NnzWsiAXmU9IXvPCMDgMLEIEEekMs_uu9as6mS1NcWJ4ulXRFanQ336Y1uUDgi2ov6zrC7lDL3d0wBojmF8Q

The first time spotify/url prompt me to accept a few things and I did.. than it redirect me to localhost(127.0.0.1)

With that code in the url, although my browser says: 127.0.0.1 refused to connect.

So I pasted back the URL: 127.0.0.1/?code=AQAXeggpUbU8QgtqeT4OKEUJohPNimVFlQMi1n0kNWQB-T0YLOmEz7Ikx1IIsCbJuAlUiyC90GXEZuwa-yJtHsfrRLFLs_z7XPo_BE9iCFD24ajIgIi-vi1prUgt1BE3bzofVypRwgJFoWoavA9A500SHInuCTicWSTLRWXpcPccRF8WPa7GDtCnCLqvq-QcHAqMaeT6Xisza3Q7MSrTXBG_oYIYKWeOTPg-mXmKNCrwuE1NnzWsiAXmU9IXvPCMDgMLEIEEekMs_uu9as6mS1NcWJ4ulXRFanQ336Y1uUDgi2ov6zrC7lDL3d0wBojmF8Q

I also tried without the http and just the code alone... they all return: Successfully authenticated.

But I cannot control it with the bar module, nothing happens when I click on the play/pause icon

Oddly enough when I try to run in my terminal: spotibar --toggle-playback

It tells me to go to the URL 3 different times and eventually returns: Traceback (most recent call last): File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/oauth2.py", line 559, in get_access_token response.raise_for_status() File "/usr/lib/python3.10/site-packages/requests/models.py", line 960, 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 "/home/gldtn/.local/bin/spotibar", line 8, in sys.exit(main()) File "/home/gldtn/.local/lib/python3.10/site-packages/spotibar/client.py", line 378, in main spotibar_client.toggle_playback() File "/home/gldtn/.local/lib/python3.10/site-packages/spotibar/client.py", line 116, in toggle_playback self.play() File "/home/gldtn/.local/lib/python3.10/site-packages/spotibar/client.py", line 102, in play self.client.start_playback(device_id=self.get_current_device_id()) File "/home/gldtn/.local/lib/python3.10/site-packages/spotibar/client.py", line 88, in get_current_device_id devices = self.client.devices() File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/client.py", line 1694, in devices return self._get("me/player/devices") File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get return self._internal_call("GET", url, payload, kwargs) File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/client.py", line 221, in _internal_call headers = self._auth_headers() File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/client.py", line 212, in _auth_headers token = self.auth_manager.get_access_token(as_dict=False) File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/oauth2.py", line 565, in get_access_token self._handle_oauth_error(http_error) File "/home/gldtn/.local/lib/python3.10/site-packages/spotipy/oauth2.py", line 146, in _handle_oauth_error raise SpotifyOauthError( spotipy.oauth2.SpotifyOauthError: error: invalid_request, error_description: code must be supplied

Any idea of what might be happening here? Also I'm unsure if I should paste the whole URL or just the code itself after 127.0.0.1/?code= and if I need to include http://, I tried all 3 ways with no luck so I'm assuming there is something else in my config that might be causing an error.

Thanks,

conor-f commented 2 years ago

Thanks for the bug report. I'll take a look into this now.

The install process is very messy so I'll try clean it all up! Will update this issue with details as I find them.

conor-f commented 2 years ago

So due to library limitations the install process has to remain this awkward for the time being unfortunately.

I made some changes that may have fixed the issue you were having, so if you could run the following and let me know how it goes, that'd be great!

rm -fr ~/.spotibar*
python3 -m pip install spotibar --upgrade
spotibar --init

It should have an easier install process. I have just installed it all again from scratch and it's worked fine, so let me know if you have any more issues!

gldtn commented 2 years ago

The upgrade and auth part went smooth and everything seems to work until I try to use it.. at first only the toggle module is showing up and I cannot get it to play from the bar.. so I tried once again opening a terminal and running spotibar --toggle-playback and all other spotibar --COMMAND and Spotify responds with no problem.

As I was trying to figure out what was happening I decided to take a look what the modules was doing, so I comment out the exec-if just to see if I can get everything to show and it does, but does not respond to click-left... Although I did notice if I comment out the exec-if from the following module I get a error on the polybar:

[module/spotibar-currently-playing] type = custom/script exec = spotibar --get-currently-playing click-left = i3-msg '[class="Spotify"] focus' ;exec-if = [ $(spotibar --is-live) = "True" ] format-underline = #1db954 format-padding = 2

Error; /bin/sh line1: spotibar: command not found

Do I need to copy the src/spotibar here from github to a script/ folder or something or am I missing something else here?

Thanks for the reply!

conor-f commented 2 years ago

so I tried once again opening a terminal and running spotibar --toggle-playback and all other spotibar --COMMAND and Spotify responds with no problem.

Okay this is great. All the API authentication etc is set up and being read correctly. Looks like this will be an issue in your i3 config/surrounding environment.

The error /bin/sh line1: spotibar: command not found indicates Polybar is running where it might not have spotibar on it's PATH.

If you can try the following we should be able to get closer to solving the issue:

1) What shell are you running where spotibar commands work (echo $SHELL)? 2) Where is spotibar installed (which spotibar)? 3) Do spotibar commands work when you run them within the sh shell (sh <Enter> spotibar --is-live)? 4) What is the output when you add the following module to your polybar config?

[module/spotibar-currently-playing-debug]
type = custom/script
exec = echo $PATH >> /tmp/polybar.log
click-left = i3-msg '[class="Spotify"] focus'
format-underline = #1db954
format-padding = 2
conor-f commented 2 years ago

Hey @gldtn any news on this?

If I don't hear back from you this week I'll probably just close the issue!

conor-f commented 2 years ago

Closing as there hasn't been any update! Any further issues let me know in a new issue (or reopen this).