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

Unable to start spotifyd with local build #82

Closed
James-C-000 opened this issue Feb 9, 2025 · 5 comments
Closed

Unable to start spotifyd with local build #82

James-C-000 opened this issue Feb 9, 2025 · 5 comments

Comments

@James-C-000
Copy link

Running setup.sh without the --no-build flag causes spotifyd to crash on start with the following error: /usr/local/bin/spotifyd: error while loading shared libraries: libasound.so.2: cannot open shared object file: No such file or directory. There is no error when running with the --no-build flag, but this causes other issues (see #80).

Entering the Docker container I see that libasound2-dev is installed and libasound.so.2 is located under /usr/lib/aarch64-linux-gnu/libasound.so.2.

I tried specifying the library location before running spotifyd without any success:

root@raspberrypi:/app# LD_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/:$LD_LIBRARY_PATH /usr/local/bin/spotifyd 
/usr/local/bin/spotifyd: error while loading shared libraries: libasound.so.2: wrong ELF class: ELFCLASS64

The binary should match my architecture (uname -m = aarch64). Regardless, I've tried downloading the spotifyd binaries compiled for other architectures to no avail.

@James-C-000
Copy link
Author

libasound.so.2 seems to be compiled for the correct architecture too:

root@raspberrypi:/app# file /usr/lib/aarch64-linux-gnu/libasound.so.2
/usr/lib/aarch64-linux-gnu/libasound.so.2: symbolic link to libasound.so.2.0.0
root@raspberrypi:/app# file /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0 
/usr/lib/aarch64-linux-gnu/libasound.so.2.0.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=1a12e660fd56f3de2836b83b9841f0cc59f181e4, stripped

@James-C-000
Copy link
Author

James-C-000 commented Feb 9, 2025

Fixed it! The issue is that every spotifyd binary (even the spotifyd-linux-armv6-slim.tar.gz build) is compiled for 32 bit architectures. To get a working spotifyd I followed these steps:

1. Enter the docker container: docker exec -it gpt-home bash
2. Update apt sources: apt update
3. Install these packages: apt install libasound2-dev:armhf libasound2-data:armhf libasound2-plugins:armhf
4. Download the armv6 build: wget https://github.com/Spotifyd/spotifyd/releases/download/v0.3.5/spotifyd-linux-armv6-slim.tar.gz (re: https://docs.spotifyd.rs/installation/Raspberry-Pi.html)
5. Untar the build: tar xzf spotifyd-linux-armv6-slim.tar.gz
6. Run: ./spotifyd --no-daemon

I'll look into updating the dockerfile/setup.sh and submit a pull request.

Getting alsamixer crashes now. I'm going to look into building a 64bit spotifyd from source.

@James-C-000
Copy link
Author

James-C-000 commented Feb 10, 2025

I've found a stable fix:

  1. Download the spotifyd-linux-armv6-slim.tar.gz v0.3.5 build of spotifyd from here: https://github.com/Spotifyd/spotifyd/releases
  2. Untar
  3. Overwrite the spotifyd binary in /usr/local/bin/ with the extracted spotifyd binary
  4. Download the libasound2-plugin and jq packages: sudo apt install libasound2-plugins:armhf jq

I was getting a bad credentials error when starting spotifyd and also had to do the following:

  1. Download spotify-player on another machine (as the URI redirect to my Pi wasn't working for me) - https://github.com/aome510/spotify-player
  2. Sign in to your Spotify account through spotify-player
  3. After signing in, exit and locate the credentials.json file created by spotify-player
  4. Copy this file to the local gpt-home directory on your Raspberry Pi (or whatever gpt-home is running on)
  5. Enter the gpt-home container and move credentials.json to /root/.spotifyd/cache/
  6. Edit /root/.config/spotifyd/spotifyd.conf and insert the following lines (removing the username and password fields if they exist):
username_cmd = "jq -r .username /root/.spotifyd/cache/credentials.json"
cache_path = "/root/.spotifyd/cache/"
  1. Edit src/backend.py by deleting this entire block under if name == "spotify": (line 367)
spotify_username = fields.get("USERNAME")
            spotify_password = fields.get("PASSWORD")
            os.environ["SPOTIFY_USERNAME"] = spotify_username
            
            if spotify_username and spotify_password:
                # Update the spotifyd configuration dynamically
                config_path = "/root/.config/spotifyd/spotifyd.conf"
                whoami = subprocess.run(["whoami"], capture_output=True).stdout.decode().strip()
                with open(config_path, "w") as file:
                    file.write("[global]\n")
                    file.write(f"username = \"{spotify_username}\"\n")
                    file.write(f"password = \"{spotify_password}\"\n")
                    file.write("backend = \"alsa\"\n")
                    file.write("device_name = \"GPT Home\"\n")
                    file.write("bitrate = 320\n")
                    file.write(f"cache_path = \"/home/{whoami}/.spotifyd/cache\"\n")
                    file.write("discovery = false\n")
                
                # Restart spotifyd to apply changes
                subprocess.run(["supervisorctl", "restart", "spotifyd"], check=True)
  1. Exit the container and restart the Pi
  2. Navigate to the WebUI and connect to Spotify. Neither of the redirect URIs would work for me. I ended up having to use the gpt-home.local one then replacing gpt-home.local with the PI's IP address in my browser after it failed to connect the first time.

@judahpaul16
Copy link
Owner

judahpaul16 commented Feb 17, 2025

Good work! I experimented with spotify-player but I did manage at one point to get everything working with spotifyd. The redirect issue is a separate spotify oauth2 integration. For me the redirect works but the device list shows empty because spotifyd is failing.

@James-C-000
Copy link
Author

I didn't run into any issues (device list or otherwise) after doing all those steps above. I can cast music to the Pi from my laptop or ask the Pi to play something directly. I'd look into fixing this and submitting another pull request but I ended up switching back to my Echo Dot as wake word detection wasn't great (especially when there's background music, which is pretty much a constant in my house). Hopefully the steps I listed above help though! Good luck.

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

2 participants