dupontgu / retro-ipod-spotify-client

The software that powers the sPot: a 4th generation "Click Wheel" iPod with a full Spotify client.
Apache License 2.0
892 stars 90 forks source link

Just boots to command line #21

Open zburhop opened 3 years ago

zburhop commented 3 years ago

I have been over this very carefully and my ipod just boots to a command line. I cant get it to run anything else. Anyone have any ideas?

HeartWaker000 commented 3 years ago

I can't make openbox auto run spotifypod.py either. In .bash_profile I can take the '-- - no cursor' argument out and then the black screen boots with a cursor. I can then right click on the black screen and open a terminal window from there where I can run python3 spotifypod.py . This will get the UI up and going and I can choose songs and play them etc. the only thing that fails is the search function. Maybe the search function needs another Scooe?

zburhop commented 3 years ago

quick question. where can i find .bash_profile i created one in root but am wondering if that is not correct.

HeartWaker000 commented 3 years ago

I believe it's correct. .bash_profile is a hidden file so it's probably in your root folder if you created it. Type ls -a in whatever directory you created .bash_profile in and you should see it. If you sudo nano .bash_profile you can edit the file your created.

doctorleach commented 3 years ago

I just discovered today the reason why my Pi wasn't entering the spotifypod.py program automatically on boot. Although I set the environment for openbox to have my Spotify user id, secret and redirect URI, it didn't seem to be visible to the spotifypod.py script.

The line sudo -H -u pi python3 spotifypod.py & executes the script as the user pi, but doesn't incorporate the environment for the pi user. It is possible to pass a list of environment variables that do carry over when using sudo. I'm not sure how others were able to boot into spotifypod.py, and I know some people couldn't, so if you're in the latter camp, here's what worked for me.

Here's how my /etc/xdg/openbox/autostart now reads:

cd /home/pi/retro-ipod-spotify-client/frontend/

sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py &

sudo /home/pi/retro-ipod-spotify-client/clickwheel/click &

3urobeat commented 3 years ago

This works for me too! Great idea, I hadn't thought of the --preserve-env flag...

Edit: So if anyone is wondering - I think these are all the changes I did that aren'tin the readme as of now to get everything running:

Install the midori browser, start the script, the browser will open with spotify.com, login and accept, copy the url you are redirected to and paste it into the console. The browser will be very very slow so if you have a full size Raspberry Pi laying around try to do this step with it instead of the Pi Zero. frontend/spotify_manager.py line 143, change 'Spotifypod' to the name you set in /etc/default/raspotify. Otherwise you can't select a song to play.
Compile clickwheel/click.c with gcc -Wall -pthread -o click click.c -lpigpio -lrt
Make the change from the comment above to autostart the UI

I think that is everything

The UI isn't perfect, it doesn't perfectly fit on my 320x240 screen, when scrolling some Playlist names appear like 10 times and afaik you can't change the volume so it is clever to change the volume arguments in /etc/default/raspotify to start with a volume of 50 or something like that. Other than that I hope I get the hardware to work now and that everything will fit.

zburhop commented 3 years ago

pi@raspberrypi:~$ cd /home/pi/home/pi/fork/retro-ipod-spotify-client/frontend pi@raspberrypi:~/home/pi/fork/retro-ipod-spotify-client/frontend$ ls datastore.py pod_arrow_blk.ppm pod_arrow_grn_2.bmp pod_arrow_grn.png pod_pause.png pod_space.png prog_frame.png rand_circle.png requirements.txt spotifypod.py pod_arrow_blk.png pod_arrow_empty.png pod_arrow_grn_2.png pod_arrow_grn.ppm pod_play.png pod_wifi.png __pycache__ README.md spotify_manager.py view_model.py pi@raspberrypi:~/home/pi/fork/retro-ipod-spotify-client/frontend$ sudo python3 spotifypod.py Traceback (most recent call last): File "spotifypod.py", line 12, in <module> from view_model import * File "/home/pi/home/pi/fork/retro-ipod-spotify-client/frontend/view_model.py", line 1, in <module> import spotify_manager File "/home/pi/home/pi/fork/retro-ipod-spotify-client/frontend/spotify_manager.py", line 79, in <module> sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) File "/usr/local/lib/python3.7/dist-packages/spotipy/oauth2.py", line 276, in __init__ self.client_id = client_id File "/usr/local/lib/python3.7/dist-packages/spotipy/oauth2.py", line 92, in client_id self._client_id = _ensure_value(val, "client_id") File "/usr/local/lib/python3.7/dist-packages/spotipy/oauth2.py", line 71, in _ensure_value raise SpotifyOauthError(msg) spotipy.oauth2.SpotifyOauthError: No client_id. Pass it or set a SPOTIPY_CLIENT_ID environment variable. pi@raspberrypi:~/home/pi/fork/retro-ipod-spotify-client/frontend$ sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py Enter the URL you were redirected to: http://127.0.0.0:8888 Enter the URL you were redirected to: no ints

So i cant get the spotifypod.py to run manually either. It appears to be communicating with spotify but something is wrong with my credentials. But all of that information is correct. Any ideas?

zburhop commented 3 years ago

That post made a mess of the code.... i typed this . pi@raspberrypi:~/home/pi/fork/retro-ipod-spotify-client/frontend$ sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py

and end up with it asking for Enter the URL you were redirected to: I type this http://127.0.0.0:8888 and it replys with this.... Enter the URL you were redirected to: no ints

doctorleach commented 3 years ago

OK, I think you actually are making good progress, because your program is communicating with Spotify.

As an aside, I'm not sure it matters but you have 127.0.0.0 (probably an invalid address) whereas localhost is 127.0.0.1. When you set up your project on the Spotify administration page, they asked you to type in the redirect URI. Did you type in "http://127.0.0.0:8888" (without the quotes)?

Matching the URI exactly is very important. Everywhere it appears, including in the /etc/xdg/openbox/environment file.

But back to the main story. I think this is the point I got to before I installed a browser on the Pi Zero. From your comments in the thread for Issue #22, however, I gather you did install Midori? Do you have a .cache file in your frontend subdirectory where spotifypod.py is? [According to @rsappia: "You'll need to authenticate with Spotify to get an access token, which will sit in a file called .cache. If you try to run the app without .cache present, one will be generated for you, BUT it will not contain a real access token. " Perhaps you should delete your .cache file if it is not correct, which you may be able to tell upon inspection.]

If you have Midori on the Pi, perhaps you should just open it and paste this in the URL box (substituting your correct credentials):

https://accounts.spotify.com/authorize?client_id=XXX&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1&scope=user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20app-remote-control%20streaming%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative%20user-library-modify%20user-library-read%20streaming (replace XXX with client_id and make sure the redirect URI exactly matches the one in your Spotify project setup on spotify.com, although in this browser address box using URL escape codes like %3A for : and %2F for / )

I believe that once the .cache file is created then the browser is never needed again and you will not see "Enter the URL you were redirected to" either.

I've been where you are now and I fought my way through.

zburhop commented 3 years ago

Oh i think i may get it now. The screen started automatically taking me to the spotify page to login. Maybe thats why VNC is recomended. So i can authenticate there? Im goning to try that now. Thanks for the help.

zburhop commented 3 years ago

So i setup VNC went in and tried to login to spotify as it requests it gives me a "there was an error please try again" meanwhile on the pc with the exact same username and password it logs in and out fine. Ive rebooted and everything. Is that not wierd?

doctorleach commented 3 years ago

I just noticed your comment (either you're up early for an American or you're in Europe). I would suggest very carefully checking each occurrence of the REDIRECT_URI to make sure they are all absolutely identical. Also, look at the .cache file in the frontend subdirectory to see if it seems sensible; mine looks like this (incriminating details removed):

{"access_token": "[very long string of upper and lower case letters and numbers]", "token_type": "Bearer", "expires_in": 3600, "scope": "user-follow-read,user-library-read,user-library-modify,user-modify-playback-state,user-read-playback-state,user-read-currently-playing,app-remote-control,playlist-read-private,playlist-read-collaborative,playlist-modify-public,playlist-modify-private,streaming", "expires_at": 1615833272, "refresh_token": "[fairly long string of upper and lower case letters and numbers]"}

If yours looks like that but with random strings between the square brackets, then it is probably good.

You said you used VNC to go to the Pi Zero and "tried to login to spotify as it requests"--can you be more precise? You ran the spotifypod.py script? Did the browser come up? Is that what you mean by login to Spotify?

Once you get a valid .cache access_token, the browser becomes irrelevant I think.

zburhop commented 3 years ago

Lol I like to work until like 5 am, you get a lot done when everyone is asleep. I did check the uri and I did have it mismatched as you thought. But now it appears that the Spotifypod.py is now running at boot. The py is now automatically loading the browser at the Spotify page asking me to login to Spotify for permissions. So I setup vnc to be able to do that from my desktop. The problem is that it will not let me login. It gives me an error. Not a password incorrect error but just a general error. I can login in my desktop no problem. I’m 100 percent certain I’ve got the right login credentials. Can you thing if a reason why Spotify would stop only the pi from logging in? Sent from my iPhone

On Mar 15, 2021, at 11:37 AM, doctorleach @.***> wrote:

 I just noticed your comment (either you're up early for an American or you're in Europe). I would suggest very carefully checking each occurrence of the REDIRECT_URI to make sure they are all absolutely identical. Also, look at the .cache file in the frontend subdirectory to see if it seems sensible; mine looks like this (incriminating details removed):

{"access_token": "[very long string of upper and lower case letters and numbers]", "token_type": "Bearer", "expires_in": 3600, "scope": "user-follow-read,user-library-read,user-library-modify,user-modify-playback-state,user-read-playback-state,user-read-currently-playing,app-remote-control,playlist-read-private,playlist-read-collaborative,playlist-modify-public,playlist-modify-private,streaming", "expires_at": 1615833272, "refresh_token": "[fairly long string of upper and lower case letters and numbers]"}

If yours looks like that but with random strings between the square brackets, then it is probably good.

You said you used VNC to go to the Pi Zero and "tried to login to spotify as it requests"--can you be more precise? You ran the spotifypod.py script? Did the browser come up? Is that what you mean by login to Spotify?

Once you get a valid .cache access_token, the browser becomes irrelevant I think.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

doctorleach commented 3 years ago

OK. As you probably know, the spotifypod.py script runs at boot if you have the line:

sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py &

in the file /etc/xdg/openbox/autostart

and you can disable it for testing by commenting it out.

It calls the browser, though, which is progress. You didn't tell me whether your .cache file exists in the retro-ipod-spotify-client/frontend directory and if it does whether it looks sorta like mine. If you do have one and it looks nice, you might compare it to the one created on your desktop; you may even be able to copy it to the Pi, but that's just a guess.

Maybe the fact that you logged in from your desktop is confusing Spotify. Somebody else mentioned in some comment that you want to close any other instances of Spotify (including the client app) running on any other computers/phones/tablets so you might try that too.

Other than that, if everything checks out I would suggest looking through log files to see if there is a better description of the error. If you disable the autostart of the spotifypod.py script on boot and run it from a terminal (in VNC so you are literally on the Pi), you might see some errors in the terminal.

If you have a Pi 4 you might want to do all this on it (put your SD card in it from the Zero) because things go much faster, although you wouldn't have the tiny display to give a fully realistic test.

I am listening to jazz on Spotify from my bluetooth speaker connected to my iPod/Spotipy splayed open on my desk. So I'm sure you'll get there, hopefully soon.

zburhop commented 3 years ago

When I do "ls" the only cache file in that directory is a folder called pycache It contains 3 .pyc files. Other then that there are no other files relating to cache that I can see.

doctorleach commented 3 years ago

ls -a will show hidden files (those beginning with a . )

zburhop commented 3 years ago

aside from pycache there is nothing else.

zburhop commented 3 years ago

I got spotify to authenticate in the web browser. I linked my facebook to the spotify account.... then instead of using spotify themselves i elected to login via facebook and that worked. The site popped up with authentication status : successful. Before i close the window I'm sort of confused with what I'm supposed to do next. As this was not really documented in the github.

doctorleach commented 3 years ago

[your message just popped up when I was typing this:]

The pycache subdirectory contains compiled byte code versions of the Python code that you ran, which is normal. If you don't have a .cache file in frontend, then the authorization has not been given from Spotify, which is probably not news to you.

So the trick is to get the authorization. If you disable the autostart and run spotifypod.py from a terminal (using VNC), I take it that the Midori browser (or whichever one you installed on the Pi) starts up and takes you to the accounts.spotify.com page? And there are no errors shown in the terminal? And you've shutdown any connections to Spotify you might have on other devices?

If still no clues, grep librespot in /var/log/daemon.log

[ok, now for your latest message]

If you got the successful authentication, now run "ls -a" in the terminal in the frontend subdirectory and see if there is a .cache file

doctorleach commented 3 years ago

Although I'm a little nervous about the Facebook login angle . . . it's different from the methods discussed in these pages.

zburhop commented 3 years ago

It is kind of is news to me lol I expected I fixed it considering I have a giant page saying successful.

doctorleach commented 3 years ago

well check for .cache

if you have it then you shouldn't need the browser again, I think

zburhop commented 3 years ago

did ls-a and theres no .cache file

zburhop commented 3 years ago

Also my pi no longer boots to the web browser but instead is back to my old friend the empty black screen.

doctorleach commented 3 years ago

did you try pasting into the browser on the Pi:

https://accounts.spotify.com/authorize?client_id=XXX&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1&scope=user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20app-remote-control%20streaming%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative%20user-library-modify%20user-library-read%20streaming

(replace XXX with client_id and make sure the redirect URI exactly matches the one in your Spotify project setup on spotify.com, although in this browser address box using URL escape codes like %3A for : and %2F for / )

doctorleach commented 3 years ago

Also my pi no longer boots to the web browser but instead is back to my old friend the empty black screen.

I would comment out the line in /etc/xdg/openbox/autostart that calls the script spotifypod.py

And it sounds like you are back to an authentication issue

doctorleach commented 3 years ago

By the way, are you still using the REDIRECT_URI http://127.0.0.0:8888 ?

zburhop commented 3 years ago

no im using http://127.0.0.1:8888

zburhop commented 3 years ago

so if i try to manually run it again its asks me "enter the Url you were redirected to: what is it wanting from me here?

doctorleach commented 3 years ago

at some point mine just worked without asking me that; try http://127.0.0.1:8888

doctorleach commented 3 years ago

but it's probably not right

zburhop commented 3 years ago

That was my first instinct too. it replys no ints

doctorleach commented 3 years ago

ah, are either of these lines uncommented in view_model.py:

spotify_manager.refresh_devices() spotify_manager.refresh_data()

zburhop commented 3 years ago

I only see refresh devices and it is uncommented

doctorleach commented 3 years ago

this is so annoying--I think you must be very close

doctorleach commented 3 years ago

when you were asked "enter the URL you were redirected to," what was showing in the browser URL box? If you can't remember, try running the python script again

zburhop commented 3 years ago

Its not graphical. That is via command line. I type this. sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py and it replys with asking about the url

doctorleach commented 3 years ago

so the browser didn't open

zburhop commented 3 years ago

no the browser no longer opens. Just black screen

doctorleach commented 3 years ago

if you execute in the terminal:

env | grep SPOTIPY

are the 3 SPOTIPY_ variables in there?

I suspect not, so you might want to run the 3 export commands from the terminal and try again

doctorleach commented 3 years ago

because if you execute the sudo line you just showed me it can't find the variables in the environment for the user pi

zburhop commented 3 years ago

there are but for some reason its picking up on 127.0.0.0:8002 not what i changed it all to http://127.0.0.1:8888 i bet theres multiple places and its getting it from somwehere else

doctorleach commented 3 years ago

try

export SPOTIPY_REDIRECT_URI='http://127.0.0.1:8888'

doctorleach commented 3 years ago

and go to developer.spotify.com on your desktop edit settings; make sure the RedirectURI is correct

doctorleach commented 3 years ago

I know my files at one point had http://127.0.0.1:8002, which is close to what you said, so you might have gotten it from me and miscopied it slightly; but who knows

doctorleach commented 3 years ago

you might also grep for 8002 in the frontend directory to see if it's in any script

doctorleach commented 3 years ago

also, check /etc/xdg/openbox/environment for the correct redirect uri

zburhop commented 3 years ago

so here's the deal. I used yours first and it didn't work so I switched to 8888 I have a bad habit of forgetting the 1.... so i guarantee i entered it wrong somewhere. its correct on spotifys developer site. im trying to figure out all the places I was supposed to enter it on the pi. Im definite i just messed the redirect up somewhere.

doctorleach commented 3 years ago

look to see if you added it to /home/pi/.bash_profile or some other configuration file in /home/pi

zburhop commented 3 years ago

Thats what i did. I fixed it. Now when i run the sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py

it just says "no ints" over and over and over

doctorleach commented 3 years ago

so if you execute

env | grep SPOTIPY you get the 3 variables with correct values?

also add the line

spotify_manager.refresh_data()

to view_model_py and see if that makes a difference (I doubt it because of authorization failure)

and still no .cache?

try rebooting?

very frustrating