Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How I got everything working #69

Open
xenon0054 opened this issue Dec 10, 2022 · 193 comments
Open

How I got everything working #69

xenon0054 opened this issue Dec 10, 2022 · 193 comments

Comments

@xenon0054
Copy link

xenon0054 commented Dec 10, 2022

Installing SpotifyPod (The code is modified for Ricardo's Alternate Build)

What you need to do before installing SpotifyPod

You need raspberry pi lite os legacy version We will also be using raspotify version 0.14 which we will be installing later

IMPORTANT This code works 2inch LCD Module ST7789V controller 240 x 320 Pixels For more hardware instructions please follow Ricardo's Alternate Build)

Installing updates

sudo apt-get update -y
sudo apt-get upgrade -y

Install Required Packages

sudo apt install python-setuptools python3-setuptools -y

sudo apt install python3-pip -y

sudo wget https://github.com/dtcooper/raspotify/releases/download/0.14.0/raspotify_0.14.0.librespot.20200130T014147Z.3672214_armhf.deb

sudo apt-get install python3-tk -y

sudo apt-get install redis-server -y

sudo apt-get install openbox -y

sudo apt install xorg -y

sudo apt-get install lightdm -y

sudo apt-get install x11-xserver-utils -y

sudo apt-get install git -y

Change directory to home

cd ~

Clone this repo and Install Dependencies

sudo dpkg -i raspotify_0.14.0.librespot.20200130T014147Z.3672214_armhf.deb

git clone https://github.com/dupontgu/retro-ipod-spotify-client

cd retro-ipod-spotify-client/frontend

pip3 install -r requirements.txt

Installing Pi-btaudio

git clone https://github.com/bablokb/pi-btaudio.git

cd pi-btaudio

sudo tools/install

Install PigPio

wget https://github.com/joan2937/pigpio/archive/master.zip

unzip master.zip

cd pigpio-master

make

sudo make install

Setup spotify API

Create a Spotify Developer Account, then create an app where you will get your Client ID, Client Secret, and create a Redirect URI

https://developer.spotify.com/dashboard/applications/
Create_app

Add an app name and description can be anything

Add_app_name
Add_host_uri
Add_uri_2
add_uri_3
add_rui_4

Save Client id and Save Secret id

Secret_and_client

Disable screen blanking

sudo raspi-config
Display Option > Screen Blanking > OFF / Disable

Disable Cursor and Screen Savers

Add or Create and Add this:

sudo nano ~/.bash_profile

Then:

'#!/bin/bash'

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor

# Disable any form of screen saver / screen blanking / power management

xset s off

xset s noblank

export SPOTIPY_CLIENT_ID='your_SPOTIPY_CLIENT_ID'

export SPOTIPY_CLIENT_SECRET='your_SPOTIPY_CLIENT_SECRET'

export SPOTIPY_REDIRECT_URI='http://localhost:8080'

export DISPLAY=:0.0

Configure Xintric

sudo nano /etc/X11/xinit/xinitrc

#!/bin/sh

# /etc/X11/xinit/xinitrc
# global xinitrc file, used by all X sessions started by xinit (startx)
# invoke global X session script 
#. /etc/X11/Xsession' 

exec openbox-session #-> This is the one that launches Openbox ;)`

Run "spotifypod.py" with Autostart

sudo nano /etc/xdg/openbox/autostart

Then paste this before exit

#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 &

Please comment this out until I remind you to uncomment it, save the file and exit, then we are now going to make the the program that makes the clickwheel work an executable

cd /home/pi/retro-ipod-spotify-client/clickwheel
nano click.c

change #define DATA_PIN 25 to #define DATA_PIN 5

gcc -Wall -pthread -o click click.c -lpigpio -lrt

when were running "gcc -Wall -pthread -o click click.c -lpigpio -lrt" just leave it alone till you see a blinking text box

sudo chmod +x click

Spotify credentials

sudo nano /etc/xdg/openbox/environment

export SPOTIPY_CLIENT_ID='your_SPOTIPY_CLIENT_ID'

export SPOTIPY_CLIENT_SECRET='your_SPOTIPY_CLIENT_SECRET'

export SPOTIPY_REDIRECT_URI='http://localhost:8080'

Synchronize Spotify Data

Synchronizing Spotify data! Last but not least, if you want to make sure all your playlists artists, etc are synchronized every time you turn on your Spotypod, you can simply modify the script view_model.py

sudo nano view_model.py

go to line 16

#spotify_manager.refresh_devices()

spotify_manager.refresh_data()

Configure Raspotify

sudo nano /etc/default/raspotify

Uncomment and fill the following line:

OPTIONS="--username XXXXXXXX --password XXXXXXXXX"

Enter your spotify login details, In the first XXX add your email address, and in the second XXX add your password

Ex:

OPTIONS="--username email_address@hotmail.com --password thisismypassword"

Paste the following

# The displayed device type in Spotify clients.
# Can be "unknown", "computer", "tablet", "smartphone", "speaker", "tv",
# "avr" (Audio/Video Receiver), "stb" (Set-Top Box), and "audiodongle".
DEVICE_TYPE="smartphone"

Entering Device id

To obtain your device id you first have to go to https://developer.spotify.com/console/get-users-available-devices/
when you go the the website your ipod may not appear connect to it using the spotify app on the device list then retry the website and it should show up

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

nano spotify_manager.py

Go to line 173 using ctrl+shift+_ and type 173 You can comment out the entire refresh_device def and replace it with

def refresh_devices():
    device = UserDevice('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx','raspotify', True)
    DATASTORE.setUserDevice(device)

Replace the XXXXXXX with your device id
Ex:
def refresh_devices():
device = UserDevice(‘123456789','raspotify', True)
DATASTORE.setUserDevice(device)
After that you want to go save and exit the file then

cd ~/.local/lib/python3.7/site-packages/spotipy/

nano client.py

Go to line 1734 using ctrl+shift+_
Paste this in:

data = {"device_ids": ["xxxxxxxxxxxxxxxxxxxxxxxxxx"], "play": force_play}
    return self._put("me/player", payload=data)

Replace the xxxxxx with your device id

Post Install

Generate .cache files

sudo apt install midori

cd ~

git clone https://github.com/perelin/spotipy_oauth_demo

cd ~/spotipy_oauth_demo

sudo apt-get install python-pip python-dev

sudo apt-get install python3-pip python-dev

pip install -r requirements.txt

Before running it modify the client id and secret also your scopes in with:

nano spotipy_oauth_demo.py

Scope:

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-modify," \
        "playlist-read-private," \
        "playlist-read-collaborative," \
        "playlist-modify-public," \
        "playlist-modify-private," \
        "streaming," \
        "user-follow-modify," \
        "user-follow-read"

Now you can save and exit the file

before reboot do the following:

sudo raspi-config

system options --> boot / auto login --> console autologin

Turn on vnc or connect a mouse to the pi, then reboot

Then you can run this program:

python spotipy_oauth_demo.py

Recommend using a Pi 4 or anything faster than a zero w, but if this is the only pi you have you should be fine but it will take a while. Your pi should be displaying a black screen then right click and click on browser then go to internet/ browser (midori). Once you did that go to http://localhost:8080/ There should be a spotify sign in page, sign in, once signed in it should redirect you to a page with gibberish code and spotify credits. Once you're on that screen exit the page and in your terminal stop running the program.

Now move your cache file to the one in spotifypod

cp ~/spotipy_oauth_demo/.spotipyoauthcache ~/retro-ipod-spotify-client/frontend/.cache

chmod 777 ~/retro-ipod-spotify-client/frontend/.cache

Once your done you can turn off vnc
If you get ERNO98 already in use go to issue 30

Install Display code

ssh into the pi and edit the config file

sudo nano /boot/config.txt

Add the code below:

DIsplay code

hdmi_group=2
hdmi_mode=87
hdmi_cvt=320 240 60 1 0 0 0
hdmi_force_hotplug=1

Also you have to comment out this code:

dtoverlay=vc4-kms-v3d

Then save it, after that download the display code:

sudo apt install cmake git
cd ~
git clone https://github.com/juj/fbcp-ili9341.git
cd fbcp-ili9341

Then we want to change the native resolution to take advantage of the whole display.

nano st7735r.h

Go to line 18 which is ST7789
Change DISPLAY_NATIVE_HEIGHT from 240 to 320
After that save it and then nano into st7735r.cpp

nano st7735r.cpp

Go to line 95 with ctrl+shift+_
Comment out the line beginning with SPI_TRANSFER with // then below it add this:

SPI_TRANSFER(0x37, 0, 0);

Then exit the file then run this command:

mkdir build

cd build

cmake -DST7789=ON -DGPIO_TFT_DATA_CONTROL=24 -DGPIO_TFT_RESET_PIN=25 -DSPI_BUS_CLOCK_DIVISOR=30 -DSTATISTICS=0 -DDISPLAY_BREAK_ASPECT_RATIO_WHEN_SCALING=ON -DUSE_DMA_TRANSFERS=OFF ..

Once finished run:

make -j

After that is finished we want to make it run on boot:

sudo nano /etc/rc.local

Enter this before exit:

sudo /home/pi/fbcp-ili9341/build/fbcp-ili9341 &

Uncomment the Autostart things:

sudo nano /etc/xdg/openbox/autostart

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 &

Bluetooth

For bluetooth I these instructions:
To install blue-alsa link
To set up auto connect link

Use this to pair bluetooth device:

pairing

Please only follow the configuration instructions you already downloaded it in the previous link. link

When Done

Reboot and whenever you need to use the pod connect to it from your phone/ computer on the device list as if it were a speaker. It might take a while but it should connect eventually then you're free to exit the app and play songs from the pod.

Issues

Trying to recreate the Bluetooth settings (If you want to try and figure it out, I suggest going to #66 near the bottom there should be some links doris put)
If you have any issues please feel free to comment them below 😄

Resources:

Couldn't have done this without doris, they've helped me out so much.
https://hackaday.io/project/177034-spot-spotify-in-a-4th-gen-ipod-2004
https://github.com/dupontgu/retro-ipod-spotify-client
https://www.youtube.com/watch?v=KciKqGX8g94
#41
#22
#34
#65
#23
#66
http://rsflightronics.com/spotifypod
https://sigmdel.ca/michel/ha/rpi/bluetooth_n_buster_01_en.html
https://github.com/dtcooper/raspotify/wiki/Play-via-Bluetooth-Speaker
https://github.com/bablokb/pi-btaudio

@webmarco78
Copy link

Did you use Adafrit Display with composite video?

@fisjingtool
Copy link

Hi, XEROxMEXICANO, thank you for your detailed instructions!
I have been tinkering this week on trying to get the pi to work as it should for this project and it has been allot of fun. I had not really used linux before so learning as I go.

I use an newer version of raspotify that seems to run smoothly https://github.com/dtcooper/raspotify/releases/tag/0.31.3

I previously had a 2inch screen running but found it easier to try to get it to work on a big screen and now have sPOT running and autostarting on my hdmi screen!

Thank you for showing the detailed way you can get your Device id from spotify and where to type them in the spotify_manager.py and client.py files, also learning the keyboard shortcuts to get to a certain line in nano is very helpful :)

I have a thing that I really don't really understand though when starting spotifypod.py
When I use sudo -H -u pi python3 spotifypod.py & (or the line with all the variables in it, makes no difference in my case)
I do get spotipy.oauth2.SpotifyOauthError: No client_id. Pass it or set a SPOTIPY_CLIENT_ID environment variable.

If I use sudo python3 spotifypod.py &
I get a ModuleNotFoundError on import spotipy . Which has something to do with PATH and maybe not installing python with sudo? (I really understand this part)

And when I use python3 spotifypod.py & I get no error message and the program runs fine.
Could this mean I might have not intsalled python3 under sudo?

If I leave the sudo command out of the /etc/xdg/openbox/autostart It boots up fine, but I am still curious what I did wrong here. Hoping to learn what this could be.

Thanks again for putting so much effort in how you got everything to work, it is really appreciated.

Greetings!

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

Hi XEROxMEXICANO,

What nice work you did organizing and illustrating the "sPots" installation instructions ... again Nice Work!
I'm sure these instructions will help make many others successful !!! again Nice Work!

Hi fisjingtool:

May I ask

  1. Which version of Raspbian Pi OS your using?
  2. Is your "sPot working and playing Tracks"?

Thanks

@fisjingtool
Copy link

Hi Doris,

I am using Buster 10 (installed the lite images)
My sPot is indeed working and playing (full) tracks. The sound was over hdmi on my monitor.
But only if I leave out the sudo command..

I am now trying to get bluetooth to work using all the helpful pages you provided.

Thanks

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

If you need help getting Bluetooth working, follow XEROxMEXICANO's above excellent narrative.
Again, Nice Work!

Is that the recent Legacy Raspberry Pi Os Buster 10.

@fisjingtool
Copy link

the image is from
2021-01-11-raspios-buster-armhf-lite is see now there is a newer one from 22-nov 2022, but I didn't use that one

pi@raspberrypi:~$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian

pi@raspberrypi:~$ cat /proc/version
Linux version 5.10.103+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1529 Tue Mar 8 1 2:19:18 GMT 2022

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

Thank You ... I couldn't get raspotify 0.31.3 to work I'm using version 0.14.0 0 ...16.0 works as well perhaps it was because I was using the newer Legacy Buster 10
when your "sPot" boots is it ready to play music or do you have to first Authenticate with your phone/computer Spotify App. or make an http request?
And do you find that process difficult?

@fisjingtool
Copy link

I tried this yesterday two or three times, I have go to my spotifyApp on my phone and select raspotify, it would then begin to play on spot pretty fast.
It is possible to let the sPot autoconnect to the SpotifyConnect server? I didn't think about this yet, to happy to see a screen after 3 days ;) I will start it up to see if it autoconnects now.

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

I cannot auto connect either checkout in issue #41 below:

paulomurray commented on May 28, 2021
After a quick search in the code, I would guess this is the section, where you could do something like this:

retro-ipod-spotify-client/frontend/spotify_manager.py

Line 146 in 1c26cc6

device = UserDevice(item['id'], item['name'], item['is_active'])
def refresh_devices():
# results = sp.devices()
DATASTORE.clearDevices()
device = UserDevice("your-device-id", "your-device-name", True)
DATASTORE.setUserDevice(device)
I’m not sure if you pass a boolean value as is_active parameter and if it really matters.

this totally works
and resolves that issue of having first use my iphone or desktop to SELECT the Spotify Connect iPod device
with this hardcoding - it goes to the ipod device straight away

thanks

"HOWEVER THE ABOVE NEVER WORKED FOR ME"! - doris

@fisjingtool
Copy link

Hi,

I just checked this, it does autoconnect for me. Strangely yesterday I was able to play full songs but they stop now after a few seconds. I have been reading this somewhere in the issues as well.
I'll try to connect with my phone first to see if this helps solve the 2 seconds playing issue.

My idea was to use the newest raspotify version possible to avoid maybe these kinds of issues, not sure if it matters

thanks

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

I think it does matter!

Read completely issue #66 in regards to the 2- or 3-seconds play issue and let me know what you think?
And at the command prompt in terminal type "sudo systemctl status raspotify" without the quotes press enter what returns do you get?

@fisjingtool
Copy link

running and authenticated, no errors. I see now that when I exit my SpotifyApp on the phone, the sPot stops/pauses so I will try to autoconnect first.
When I stop sPot (sudo killall python3) I see a 404 code. https://api.spotify.com/v1/me/player/play?device_id=(my-device id):Device not found, reason: None. That would be the issue I think

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

Yes,
Can you try booting your "sPot" from off and then at the command prompt in terminal type "sudo systemctl status raspotify" without the quotes press enter what returns do you get?
copy/paste and post!

@fisjingtool
Copy link

● raspotify.service - Raspotify (Spotify Connect Client)
Loaded: loaded (/lib/systemd/system/raspotify.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-12-11 15:10:09 GMT; 1min 48s ago
Docs: https://github.com/dtcooper/raspotify
https://github.com/librespot-org/librespot
https://github.com/dtcooper/raspotify/wiki
https://github.com/librespot-org/librespot/wiki/Options
Main PID: 669 (librespot)
Tasks: 2 (limit: 2059)
CGroup: /system.slice/raspotify.service
└─669 /usr/bin/librespot --name raspotify --device-type smartphone --backend alsa --bitrate 160 --disable-audio-cache --enable-volume-normalisation --volume-ctrl linear --initial volume 100

Dec 11 15:10:09 raspberrypi systemd[1]: Started Raspotify (Spotify Connect Client).
Dec 11 15:10:09 raspberrypi librespot[669]: [2022-12-11T15:10:09Z INFO librespot] librespot 0.3.1 bbd575e (Built on 2021-11-26, Build ID: a6e0Ery3, Profile: release)
Dec 11 15:10:09 raspberrypi librespot[669]: [2022-12-11T15:10:09Z WARN libmdns] Failed to register IPv6 receiver: Os { code: 97, kind: Uncategorized, message: "Address family not supported
Dec 11 15:10:09 raspberrypi librespot[669]: [2022-12-11T15:10:09Z INFO librespot_core::session] Connecting to AP "ap-gew4.spotify.com:4070"
Dec 11 15:10:10 raspberrypi librespot[669]: [2022-12-11T15:10:10Z INFO librespot_core::session] Authenticated as "fisjingtool" !
Dec 11 15:10:10 raspberrypi librespot[669]: [2022-12-11T15:10:10Z INFO librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Linear
Dec 11 15:10:10 raspberrypi librespot[669]: [2022-12-11T15:10:10Z INFO librespot_playback::convert] Converting with ditherer: tpdf
Dec 11 15:10:10 raspberrypi librespot[669]: [2022-12-11T15:10:10Z INFO librespot_playback::audio_backend::alsa] Using AlsaSink with format: S16
Dec 11 15:10:10 raspberrypi librespot[669]: [2022-12-11T15:10:10Z INFO librespot_core::session] Country: "NL"
~

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

Did you first need to select "raspotify" with your phones Spotify app. ?

@fisjingtool
Copy link

No i didn't need to do that, it loads playlists etc. but stops playback after 2 seconds. I seems to me that the raspotify on the pi is doing what it should.

@fisjingtool
Copy link

You still have the same problem, that the sPot wil only play two seconds or so? And you can't autoconnect?

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

No, my spot plays perfectly all tracks however only after I select "raspotify" via my phone or computer or make an http:// request and that takes many tries, once I'm successful I can close the Spotify app. and use my "sPot" without any issues however I have to do all the above again after rebooting !

From where did you download your version of Raspbian Buster 10?

@fisjingtool
Copy link

that is great! So you first startup the Pi (I swapped the zero out for a Pi3 for now as it is much faster) and let everything and sPot startup. You then use you phone to connect to raspotify and from then on your sPot works spotlessly? (pun intended ;)
I am not sure where I got it to be honest i see now that I also have the newest img in my dowload list, so It might be that it used the newer one, not really sure, but I updated everthing so they should be the same then

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

I'm using the Zero 2W (boots fast, poor on power consumption) my spot is closed and finished in its case, I just would like to not need to select with the Spotify app. first like you!
Perhaps your image of: 2021-01-11-raspios-buster-armhf-lite would help.
If I could find it on the web

@fisjingtool
Copy link

http://debian.rutgers.edu/raspios_images/raspios_lite/raspios_lite_armhf-2021-01-12/
this is it, despite the link the os is from 2021-01-11

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

Thank You so much ... I'll let you know if it works!

@fisjingtool
Copy link

no problem, hopefully it does, it means strarting from (almost) scratch again right? I hope you make an image copy of your sd to fall back to?

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

I've done it so often that I'm extremely fast at doing it from scratch!
Did you ever try any of the newer versions of Raspotify?

Thanks Again!

@fisjingtool
Copy link

fisjingtool commented Dec 11, 2022

No, i read that this was the last version with the same file structure in issue #61 raspotify no longer supported

I figured out this part. you need to use a much older version of Raspotify, I used this one:

raspotify_0.31.3.librespot.v0.3.1-19-gbbd575e_armhf.deb

It looks like they changed the file structure in the newer one. /etc/default/raspotify does not exist.

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

Correct I know that, however the new config might work in my zero 2W and your pi3 not the zero 1W

@fisjingtool
Copy link

fisjingtool commented Dec 11, 2022

Ah yes I see what you mean, but I only swapped it out temporarily for speed purpose while trying to get things to work.
I would try a newer version if you have a zero2W then I think? If you get the new version of raspotify to work correctly getting it to "talk" to the the Spotifypod.py app that would be it right? I might be way to optimistic, and I know very little about this..sorry! so I would play it safe

@doris1347
Copy link
Collaborator

doris1347 commented Dec 11, 2022

However, the newer versions of Raspotify may require a 64bit RPI-OS which seems to create a conflict and dependency problem with the "sPot App."!

A host of dependencies were updated in November of 2021 that the sPot couldn't keep up with, which is why Buster 10 and Raspotify 14. 15. and 16 were recommended all three have the /etc/default/raspotify configuration so does 0.31.3 however I could not get 0.31.3 to work on the 1W or the 2W I was really surprised that you could ... perhaps due to the older version of Buster 10 that you're using 0.31.3 worked

Raspotify FYI:
0.31.4 is a breaking release. It is not compatible with previous versions of Raspotify. Special care needs to be taken when updating from =< 0.31.3 to 0.31.4+ or Raspotify may end up in a broken state.

Beginning with version 0.31.4 dtcooper/raspotify#470 librespot-org/librespot#886. The most obvious user facing change is that Raspotify's configuration file will change places (from /etc/default/raspotify to /etc/raspotify/conf) and change formats. Where as before the sections were basically "arg dumpsters" that you could put pretty much anything into, the new conf format will be closer to a traditional configuration file that sets environment variables that map 1 to 1 to librespot's options and flags.

After you take note of your old config values and/or back your old config to a new location you should run sudo apt purge raspotify to completely remove purge Raspotify and then reinstall with sudo apt install raspotify.

You can than migrate your settings to the new config.

/etc/raspotify/conf will contain a non-exhaustive list of librespot options and flags. If you don't see the option or flag that you normally use you can add it and so long as it's valid it will work. To avoid name collisions environment variables must be prepended with LIBRESPOT_, so option/flag foo-bar becomes LIBRESPOT_FOO_BAR. If you look at the rest of /etc/raspotify/conf it should not be difficult to understand.

@fisjingtool
Copy link

Ah yes, I get it now, the sPot app is not for 64bit os

@doris1347
Copy link
Collaborator

doris1347 commented Apr 10, 2023

Any Luck Jacob?

I use Legacy Buster 10 Desktop version.
Once I obtained my .cache file I connected a monitor, mouse and keyboard and in sudo raspi-config I configured the pi to boot to desktop with auto login I then copied the .cache file from either the home directory or the demo directory (can't remember which) over to the frontend folder, I am using a Zero 2W which handles the browser operation smoother and faster.

I saved my .cache file on a usb thumb drive for any future copying & pasting to the pi Zero.

I do remember now having the same or similar login issue and used the 10 digit username (not my e-mail address) and my password for logging into Spotify (try it both ways) best not to use VNC for this (use a monitor, keyboard and mouse connected to the pi Zero.

I purchased a micro usb to usb "A" adapter with extra usb "A" ports and Ethernet port for that purpose off eBay.

When all was correct I used sudo raspi-config to configure to boot to command line with auto login instead of booting to desktop with auto login.

When doing the above disable (comment out in autostart #python3 spotifypod.py and in Xintric comment out #exec openbox-session ... uncomment (return both to normal) when your done.

Be sure in sudo nano /etc/default/raspotify all is correct and exactly the same in your developer app. !!!

Yes you can do everything on a pi Zero 2W, 3, 4 or 4B and then move the SD card to your Zero 1W.

Re-read "The Post Install" concerning the .cache file generation!

Also read all of including member comments in open issue #41 ,#22 and closed issue #30.

@JacobMadian
Copy link

Hi Doris!

Thanks for pointing me at the various issue threads, but still no luck. I am unable to get past the spotify login page to get my .cache file. Today I tried fresh installs of Legacy Buster 10 Desktop & Lite versions, and confirmed that:

My zero W seems to slow down heavily once opening midori, so I also have an ethernet to usb adapter coming tomorrow since I've been working off my phone hotspot (only 2.4GHz network available).

I'll also keep an eye out for any in-stock Pi 3's or 4's that may be able to get the .cache file then transfer to zero W.

Where did you locate your 10 digit user ID? I tried logging in with my user id (no email) and email addresses with no success.

  • Jake

@doris1347
Copy link
Collaborator

doris1347 commented Apr 11, 2023

Hi Jake the below is a mistake ... I used the below for making a copy of an entire SD card so only use it for doing the above or moving or copying the .cache file via the desktop instead of using the command line!

"When doing the above disable (comment out in autostart:
#python3 spotifypod.py
and in Xintric comment out:
#exec openbox-session
... uncomment (return both to normal) when your done".

You could try requesting a new password from your regular Spotify account and I believe you will receive the 10 digit username as well as the new password in an email.

You can also search for your Premium Receipt e-mail if you still have it the 10 digit username should be in that email!

I just used my iphone to look at my Spotify account settings via the dedicated Spotify app. and the 10 digit username is there under account settings !!!

Can be seen when logging in via a web browser as well you will see the 10 digit username again under account settings !!!

The 10 digit username can be used in sudo nano /etc/default/raspotify as well ... instead of your e-mail address!

You want to login with your 10 digit username and your actual password!

VNC server will slow down your pi ... if you have a monitor, keyboard and mouse connected to your pi you can stop VNC server via sudo raspi-config the midori browser should run better ... the zero w1 has a slow cpu compared to the Zero 2w both have 500mb of ram.

Or stop/start VNC server via the command line:

sudo service vncserver-x11-serviced stop

or

sudo service vncserver-x11-serviced start

@viktor1234678
Copy link

Hey is that method for getting the device id obsolete? I can't get it to work and can't find any other way online that does work.

@doris1347
Copy link
Collaborator

You really do not need a device ID just follow the above instructions

@viktor1234678
Copy link

Thanks for the quick reply! But how do I do the whole Entering Device ID step? I thought I have to add it into the refresh devices function.

@doris1347
Copy link
Collaborator

doris1347 commented Jul 30, 2023

Which versions of Raspberry Pi OS and Raspotify are you using?

@viktor1234678
Copy link

I am using Raspotify 0.14.0, that's installed in the instructions. I am currently using the newest Raspberry Pi OS Lite Legacy, which I think might be a problem. I have tried the Image linked here but I had a problem with installing the requirements I think. But I will try it again if you think that could help.

@doris1347
Copy link
Collaborator

doris1347 commented Jul 30, 2023

You must have a Spotify Premium Account!
You must have a working .cache file!

You should be okay with the above versions you have installed, be sure that you:

  1. Use the same exact spot application name that you set up in your Developer app & in:

  2. sudo nano /etc/default/raspotify

sudo nano /etc/default/raspotify
Uncomment and fill the following line:

OPTIONS="--username XXXXXXXX --password XXXXXXXXX"
Enter your spotify login details, In the first XXX add your email address, and in the second XXX add your password

Ex:

OPTIONS="--username 10 digit user ID or email_address@hotmail

And in:

  1. nano spotify_manager.py

Go to line 173 using ctrl+shift+_ and type 173 You can comment out the entire refresh_device def and replace it with

def refresh_devices():
device = UserDevice('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx','raspotify', True)
DATASTORE.setUserDevice(device)
Replace the XXXXXXX with your device id
Ex:
def refresh_devices():
device = UserDevice(‘123456789','raspotify', True)
DATASTORE.setUserDevice(device)
After that you want to go save and exit the file.

Doing so will forgo the need for a device ID

To obtain your device ID:

You have to be logged-in to the Developer Dashboard Console then Click get token then copy all the terminal information in the lower black box then paste that into you computer's terminal and press enter

"but I had a problem with installing the requirements I think. But I will try it again if you think that could help."

pip3 install -r requirements.txt

You must run from the frontend folder !

@viktor1234678
Copy link

I think the method of obtaining the device ID is outdated. I can't find get token anywhere. Also I am facing a problem I had everytime. When generating the cache files, I am supposed to paste something in, but the URL doesn't change from localhost anymore.

@viktor1234678
Copy link

I do have a Spotify Premium Account and am currently trying to build it on a Pi 4 4gb. I used Raspberry Pi OS Lite Legacy, so command line, but I am already far enough for openbox to kick in as the Desktop enviroment.

@doris1347
Copy link
Collaborator

doris1347 commented Aug 3, 2023

Viktor ... didn't you already have the project working once before using the "Vpod" fork ?

I use a Pi 2w and the desktop lite version of Rpios legacy this way I can copy and paste when needed, I also saved my .cache file so i wouldn't. need to go through all the fuss whenever I needed it again it's been a long time since I originally generated the .cache file and I can't remember exactly how I obtained it other then following the instructions.

The .cache file once created can & should be moved or preferably copied from the home or demo directory into the frontend folder!

Read & Do Completely and Correctly the "Post Install" of this thread's installation instructions for the .cache file!

To obtain your device ID:

You have to be logged-in to the Developer Dashboard Console then Click get token then copy all the terminal information in the lower black box then paste that into you pi's terminal and press enter

@viktor1234678
Copy link

Thanks for being so patient. No that fork doesn't change anything, I created it when still figuring stuff out. I'll retry generating the cache now. Are you still able to get the device ID right now? When visiting my dashboard I don't have get token anywhere, I know the Layout was different like a year ago.

@doris1347
Copy link
Collaborator

doris1347 commented Aug 3, 2023

You are so right !!!
I logged on to my developer account and the "Dashboard" is no longer the same, with no apparent way of obtaining device ID's.

Not sure if obtaining .cache files have also been affected and I do not want to screw around with anything trying to find out and possibly render my spot device useless.

I have been successful in the past achieving an operational "sPot" without using a device ID by making sure that the developer app name is exactly the same in:

  1. spotify_manager.py
  2. etc/default/raspotify

@viktor1234678
Copy link

I checked and I have the same device name at both spots. Right now I am trying to generate the cache and it tells me that it Found a cached token. Do you know how I can remove the Token again? Right now entering the localhost site I see the data I am supposed to, but the link I am supposed to paste into the terminal doesn't show up.

@doris1347
Copy link
Collaborator

doris1347 commented Aug 3, 2023

When using the Spotipy Authorization Demo ... If I remember correctly the .cache file ends up in the "Home" directory or the directory of the "Authorization Demo" and you have to copy it (don't move it or you might lose it) to the front end directory ... I installed the desktop lite version for copy/paste ability.

https://github.com/perelin/spotipy_oauth_demo

@viktor1234678
Copy link

Yes but I don't have a .cache file to copy. I am stuck on it finding the cached token and expecting me to paste a link. I think if I had that link it would generate the file, but when opening localhost on my browser the link doesn't change anymore.

@doris1347
Copy link
Collaborator

doris1347 commented Aug 6, 2023

Post Install
Generate .cache file.

sudo apt install midori

cd ~

git clone https://github.com/perelin/spotipy_oauth_demo

cd ~/spotipy_oauth_demo

sudo apt-get install python-pip python-dev

sudo apt-get install python3-pip python-dev

pip install -r requirements.txt

Before running it modify the client id and secret also your scopes in with:

nano spotipy_oauth_demo.py

Scope:

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-modify,"
"playlist-read-private,"
"playlist-read-collaborative,"
"playlist-modify-public,"
"playlist-modify-private,"
"streaming,"
"user-follow-modify,"
"user-follow-read"

Now you can save and exit the file

python spotipy_oauth_demo.py

Recommend using a Pi 4 or anything faster than a zero w, but if this is the only pi you have you should be fine but it will take a while. Your pi should be displaying a black screen then right click and click on browser then go to internet/ browser (midori). Once you did that go to http://localhost:8080/ There should be a spotify sign in page, sign in, once signed in it should redirect you to a page with gibberish code and spotify credits. Once you're on that screen exit the page and in your terminal stop running the program.
Now move your cache file to the frontend directory by doing the below.

cp ~/spotipy_oauth_demo/.spotipyoauthcache ~/retro-ipod-spotify-client/frontend/.cache

The below will grant all permissions

chmod 777 ~/retro-ipod-spotify-client/frontend/.cache

The .cache file is derived when you copy over .spotipyoauthcache it will become .cache in the frontend folder.

My "sPot" is fully operational without using a device ID, however you absolutly must have an authentic .cache file!

FYI:
When you make a track selection (http request) with the "sPoT" you will see it as being selected in the Spotify app. device list of your phone or computer (and your selection will start playing) ### as long as your audio endpoint (bluetooth) is configured and working if not your selected track will only increment 3 seconds and dropout. the same will happen if you first select your device using another authorized Spotify client, if your audio endpoint (bluetooth) isn't up and running your connection will dropout after approx. 3 seconds no audio!

When editing bash profile ... '#!/bin/bash' should be ... #!/bin/bash without the accent marks !!!
sudo nano ~/.bash_profile - this is a typo in the #69 instructions!

Be sure to run ... pip3 install -r requirements.txt ... from the frontend folder
cd retro-ipod-spotify-client/frontend

Be sure to remove the <> symbols from your user name and password credentials
sudo nano /etc/default/raspotify
OPTIONS="--username XXXXXXXX --password XXXXXXXXX"

@Joris-23
Copy link

After getting to the spotify login screen for the cache thing i cant seem to click on the login button. I can enter my login info (the email and the password) but not click the login button, nothing happens when i do. I am using vnc on the rpi zero w.

@doris1347
Copy link
Collaborator

doris1347 commented Sep 12, 2023

Recommend using a Pi 4 or anything faster than a pi zero w for obtaining the .cache file ... using vnc can slow thing's down on a zero w, I used the desktop version of Raspberry Pi lite legacy so I could copy/paste and not need vnc.

Once you secure your .cache file you can use the same existing SD card from the greater pi and return it to the pi zero w.

I also used a pi zero 2w for speed.

@Joris-23
Copy link

Thank you for responding so fast. I will try to maybe use a monitor or get a cheap pi from somewhere as I don't have another pi laying around.

@doris1347
Copy link
Collaborator

doris1347 commented Sep 14, 2023

On a faster pi the browser works faster and you will be able to click/select sign in.

Once the .cache file is obtained you can copy it to a usb stick and paste/transfer it to the zero of choice and save it on the stick for any future needs.

@Joris-23
Copy link

On a faster pi the browser works faster and you will be able to click/select sign in.

Once the .cache file is obtained you can copy it to a usb stick and paste/transfer it to the zero of choice and save it on the stick for any future needs.

I must thank you so much for just always helping here. I suddenly got it working on my pi zero w. It was just all a test of patience.

@doris1347
Copy link
Collaborator

doris1347 commented Sep 18, 2023

Your right ... I found that a Big part of the fun is solving the issues that arise regardless of how long it might take. 😊
Your Welcome!

@henschelm
Copy link

henschelm commented Nov 12, 2023

Uploading IMG_8367.JPG…
Dear Doris,
I just wanna thank you again. After a few more tries and our of sock issues with the power boost module I got the IPod to work. Have a great day! Marcus

@henschelm
Copy link

python3 testit.py

This testit.py script workes perfectly for me in the past. Could it be that spotify changed something in their API ? When I run the sript I get this output:

pi@spotifypod:~/retro-ipod-spotify-client/frontend$ python3 testit.py
Spotify tracks fetched
Spotify artists fetched: 56
Traceback (most recent call last):
File "testit.py", line 3, in
spotify_manager.refresh_data()
File "/home/pi/retro-ipod-spotify-client/frontend/spotify_manager.py", line 250, in refresh_data
tracks = get_playlist_tracks(item['id'])
File "/home/pi/retro-ipod-spotify-client/frontend/spotify_manager.py", line 153, in get_playlist_tracks
tracks.append(UserTrack(track['name'], track['artists'][0]['name'], track['album']['name'], track['uri']))
TypeError: 'NoneType' object is not subscriptable

Does some have the same issue? In that past it worked perfectly to update my playlists, etc.

Thanks for your support and feedback!

@doris1347
Copy link
Collaborator

doris1347 commented Nov 13, 2023

Perhaps the device ID has changed.
I did have this problem once, unfortunately, I can't remember how it was corrected.

Synchronize Spotify Data

Synchronizing Spotify data! Last but not least, if you want to make sure all your playlists artists, etc are synchronized every time you turn on your Spotifypod, you can simply modify the script view_model.py

instead of calling refresh_device, you can execute refresh_data. This will sync all your data and then will execute refresh.devices. This will make the boot up way slower! but it will synchronize every single time you switch on :).
If you dont run at least once refresh_data() no playlist, artist or anything related with your account will be displayed!

cd retro-ipod-spotify-client/frontend

Then

sudo nano view_model.py
go to line 16

#spotify_manager.refresh_devices()

spotify_manager.refresh_data()

Comment out the first existing below line:
#spotify_manager.refresh_devices()

add a second non existing below line un-commented:
spotify_manager.refresh_data()

Then reboot!

Be sure you throughly read issue 21 & 69.

Another suggestion is to create a file called testit.py with the following 3 lines:

import spotify_manager
from functools import lru_cache
spotify_manager.refresh_data()

Place it in the frontend folder,

and then run it from the command line:

cd retro-ipod-spotify-client/frontend

Then at the command prompt run:

python3 testit.py

This will only work if you created a .cache file, But if you're good to go you should see output to the screen as it downloads playlists, artists, etc.

FYI:
When you make a track selection (http request) with the "sPoT" you will see it as being selected in the Spotify app. device list of your phone or computer (and your selection will start playing) ### as long as your audio endpoint (bluetooth) is configured and working if not your selected track will only increment 3 seconds and dropout. the same will happen if you first select your device using another authorized Spotify client, if your audio endpoint (bluetooth) isn't up and running your connection will dropout after approx. 3 seconds no audio!

@henschelm
Copy link

Perhaps the device ID has changed.

But for tracks and artists it worked:
Spotify tracks fetched
Spotify artists fetched: 56

But I will check. Thanks!

@Petengy
Copy link

Petengy commented May 30, 2024

I'm also experiencing the same problem, a chat with GPT tells me that perhaps there are indeed problems with the Spotify API. Is this happening to you too?

Below error messages (part) when running testit.py

`Max Retries reached
urllib3.exceptions.ResponseError: too many 502 error responses

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/requests/adapters.py", line 497, in send
chunked=chunked,
File "/home/pi/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 961, in urlopen
**response_kw,
File "/home/pi/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 961, in urlopen
**response_kw,
File "/home/pi/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 961, in urlopen
**response_kw,
File "/home/pi/.local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 936, in urlopen
retries = retries.increment(method, url, response=response, _pool=self)
File "/home/pi/.local/lib/python3.7/site-packages/urllib3/util/retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/playlists/3xxXXxxxxxXXxxyyyyYYyyXg/tracks?limit=50&offset=0&additional_types=track (Caused by ResponseError('too many 502 error responses'))
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants