MiczFlor / RPi-Jukebox-RFID

A Raspberry Pi jukebox, playing local music, podcasts, web radio and streams triggered by RFID cards, web app or home automation. All plug and play via USB. GPIO scripts available.
http://phoniebox.de
MIT License
1.38k stars 397 forks source link

Play Spotify #18

Closed mec0-de closed 5 years ago

mec0-de commented 6 years ago

Hello,

thanks for the great work. Will it be possible to play songs or playlists from Spotify premium?

Thanks four your help!

Alwiz79 commented 6 years ago

Thats good News! Looking forward to the new Spotify-phoniebox:-)

princemaxwell commented 6 years ago

@Alwiz79 @MiczFlor It's done! I have a first working version of Phoniebox with spotify support ;-) The best is, that i deactivated MPD, because i preffered to use the MPD of Mopidy, so that not two instances are running. Mopidy MPD is listening on port 6600 by default, so the difference between the master branch and my version are very easy to handle.

I added the following features: -spotify integration -cover integration for spotify tracks -AJAX integration for title, album, artist, time (elapsed and overall) -playlist with title, album, artist, time -fix for songs with > 60 minutes. the time now shows hours. -advanced inc.playerStatus.php

I am testing all the functions now. I wrote a little step-by-step guide how i got it working ;-)

Alwiz79 commented 6 years ago

That’s great news! Happy to see the result next week :-)

chriwen commented 6 years ago

Thank you. That's great :-)

MiczFlor commented 6 years ago

Hi @princemaxwell six months after you solved this already for the VLC version of Phoniebox, now you did it again :) And thanks to @Alwiz79 to open the hood of the car, too on this issue. I am waiting for the pull requests and then will merge it with the develop branch for testing. The Spotifiers in the Phoniebox universe: stay tuned for testing!

princemaxwell commented 6 years ago

@MiczFlor I have made a pull request. You get my installation step-by-step guide, because i hope you can handle the installerscript integration.

MiczFlor commented 6 years ago

**Call for testers** I merged @princemaxwell 's work into the develop branch and added the howto to this document: https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/develop/docs/SPOTIFY-INTEGRATION.md Please start testing now, those of you who have been waiting for this for a long time, since we migrated to mpd from vlc. In my experience the process of making this universally working starts only now - and will take some time. So the more input and testing, the better. (Some of the older Phonieboxers might remember the second swipe* discussions :) So roll up your sleeves and create pull requests, add to the docs and discuss here.

petschni commented 6 years ago

@princemaxwell thanks for the PR - great news! What is the best way to "update" my current installation to the "develop" commit?

princemaxwell commented 6 years ago

The develop branch is under testing!! So if you want to test, make a backup of your SD-card and try (!) to use the document: https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/develop/docs/SPOTIFY-INTEGRATION.md i have pull requested a more detailed version here, so take a look there. and please read it first and then look, what steps you need...

The easiest thing would be to clone your SD card...

chriwen commented 6 years ago

@princemaxwell I made a first installation of develop branch but couldn't find where to change the Playlist_Folders_Path variable as mentioned in https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/develop/docs/SPOTIFY-INTEGRATION.md#change-playlists_folders_path-to Could you please help?

princemaxwell commented 6 years ago

Look at your settings folder in your phoniebox installation: /home/pi/RPi-Jukebox-RFID/settings/

There should be a file named "Playlists_Folders_Path"

Later we put that step into installerscript...

chriwen commented 6 years ago

Thank you. That worked out. But now I'm wondering where to type in the spotify track-url (eg. spotify:track:6ZAQxzVUL20heVoowCy...) Is the stream-url the right place? And what type should I choose? Thank you again.

princemaxwell commented 6 years ago

Have you updated to the develop branch? Then you should see it when you AddNewStream. Stream type: Spotify Stream Url: spotify:(user:username:)album/track/playlist:###

chriwen commented 6 years ago

Thank you. Its working now :-) Got my first track played via RFID from spotify 👍

princemaxwell commented 6 years ago

GREAT! Love to hear that it's working. where did you install the mopidy_spotify FIX now? can you share a git clone URL for direct installation from git??

chriwen commented 6 years ago

I used this command for installing the mopidy-spotify fix in directory: /usr/lib/python2.7/dist-packages/mopidy_spotify/

git clone -b fix/incompatible_playlists --single-branch https://github.com/BlackLight/mopidy-spotify.git

princemaxwell commented 6 years ago

did you navigate to the destination directory first? when I only use: git clone -b fix/incompatible_playlists --single-branch https://github.com/BlackLight/mopidy-spotify.git it will be installed into /home/pi

chriwen commented 6 years ago

yes, i first navigated to the destination directory. Had to say that I am an absolute noob regarding shell commands etc. just started 3 days ago getting my first raspberry ... so, there should be more convenient ways to make this work.

chriwen commented 6 years ago

maybe something went wrong. Just had a look into the /usr/lib/python2.7/dist-packages/mopidy_spotify/ directory and figured out that there are 3 mopidy_spotify directories as child-directories. So maybe there went something wrong with my git comment. The strange thing is, that spotify works - even if I probably didn't got the version with the fix... So better don't use this command until there is a better solution..

blacklight commented 6 years ago

maybe something went wrong. Just had a look into the /usr/lib/python2.7/dist-packages/mopidy_spotify/ directory and figured out that there are 3 mopidy_spotify directories as child-directories. So maybe there went something wrong with my git comment.

You have other versions installed. You can safely remove all of them and then install my fork:

[sudo] apt purge mopidy-spotify
[sudo] rm -rf /usr/lib/python2.7/dist-packages/mopidy_spotify*
[sudo] rm -rf /usr/lib/python2.7/dist-packages/Mopidy_Spotify-*
git clone -b fix/incompatible_playlists --single-branch https://github.com/BlackLight/mopidy-spotify.git
cd mopidy-spotify
[sudo] python setup.py install
princemaxwell commented 6 years ago

it would even works because you have installed original branch by sudo apt-get install Mopidy-spotify. Spotify is working here but not with playlist spotify URI

MiczFlor commented 6 years ago

To those who want to test the spotify integration, here is how to get and checkout the branch develop

How to switch to the develop branch, assuming:

cd /home/pi/RPi-Jukebox-RFID/
git checkout master
git branch -D develop
git checkout --track origin/develop

This should end with something like this:

Branch 'develop' set up to track remote branch 'develop' from 'origin'.
Switched to a new branch 'develop'

And you can check if you are on the branch by typing:

git branch

To make sure the code is really what you are looking for, typing the following:

cat htdocs/ajax.loadCover.php | grep spotify.com

Should return (at least, possibly more if the code has been changed since I wrote this):

$url = "https://open.spotify.com/oembed/?url=".$playerStatus['file']."&format=json";
MiczFlor commented 6 years ago

@BlackLight The commands

sudo rm -rf /usr/lib/python2.7/dist-packages/mopidy_spotify*
sudo rm -rf /usr/lib/python2.7/dist-packages/Mopidy_Spotify-*
cd
sudo rm -rf mopidy-spotify
git clone -b fix/incompatible_playlists --single-branch https://github.com/BlackLight/mopidy-spotify.git
cd mopidy-spotify
sudo python setup.py install

Where in the howto would you add them? Just tell me the line, I will do the editing.

And: which lines really need a sudo? I took a guess above, would that work?

blacklight commented 6 years ago

@MiczFlor sudo is only required for the commands that remove or install files outside of your home, so yeah your guess is correct. Also note that apt purge/remove might be required to cleanly uninstall mopidy-spotify if you're on Raspbian/Debian, otherwise the next apt upgrade may overwrite the directory.

Feel free to integrate those lines in the Install MOPIDY section, replacing all the part that goes from To install one of the listed package until the end of the section. Actually advising to install mopidy-spotify via apt isn't a good idea, since this fix hasn't been merged into the official package yet and apt would just install the wrong version.

kathateich commented 6 years ago

I installed and edited "everything". Spotify works - thanks a lot to everyone who contributed - but local music does not: I linked the card id with the folder in the phoniebox browserapp, but the jukebox only stops playing the Spotify music but does not start to play local files. As I checked the shortcut-file and tried to edit it manually (I thought maybe blanks in the folder name were the problem), this didn't work: After saving the file and reopening it, the file was empty. Edit: now I have one folder working. Is it possible that you need to start all folders via browser first before you can start them via RFID?

princemaxwell commented 6 years ago

@kathateich You are right! That's a issue i fixed by changing the Playlists_Folder_Path to "/home/pi/RPi-Jukebox-RFID/playlists/". If you want to manually fix ist, change it in "/home/pi/RPi-Jukebox-RFID/settings/Playlists_Folder_Path" and in /etc/mopidy/mopidy.conf put into [m3u] section:

[m3u]
playlists_dir = /home/pi/RPi-Jukebox-RFID/playlists
dnkroy commented 6 years ago

Hello im having Troubles with the install at this step sudo nano ~/.config/mopidy/mopidy.conf the file does not exists. what i am doing wrong?

Even without this, everything works fine. I tried original Album and user made Playlist.

I have one issues, when i skip a track the song starts playing but its muted. i have to scan another Card to unmute it

kathateich commented 6 years ago

The file ist created when you start mopidy the first time. So either you start mopidy 8nce or you just create it yourself.

Am Samstag, 20. Oktober 2018 schrieb dnkroy :

Hello im having Troubles with the install at this step sudo nano ~/.config/mopidy/mopidy.conf the file does not exists. what i am doing wrong?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/18#issuecomment-431617645, or mute the thread https://github.com/notifications/unsubscribe-auth/Ap_7EGCVqHfHKF2fjMBdT2VBPIiDLnJRks5um47kgaJpZM4Sk7As .

Alwiz79 commented 6 years ago

@princemaxwell could you please explain again what's to do because of the local music problem @kathateich just mentioned above?

I am currently having the same problem. spotify works great, but when i want to start local music it just stops.

besides that i am not having any issue with the spotify integration so far. great work! just a question: is there a way to save allready in the uri, that i want the playlist to be shuffled? something like :shuffle:ON :-)

princemaxwell commented 6 years ago

@Alwiz79 did you update or fresh install? In the Spotify installer there should be no problem, only the local music is loaded slower. This problem is under investigation.

For Spotify you can turn on shuffle in the web UI...

MiczFlor commented 6 years ago

Hi @princemaxwell Please make these two installs parallel for the time beimg. We need time to catch all the bugs and I would like the default install to work as it did - and spotify is a bonus. Otherwsie we are annoying all the non spotify people. So the install script should habe copies for mod.conf like „mpd-spotify.conf.sample“ Some things must wirk in both installs, like

Alwiz79 commented 6 years ago

@princemaxwell i did a fresh install with the one line script for the spotify version (obviously :-) )

Alwiz79 commented 6 years ago

@princemaxwell @MiczFlor general feeedback on the handling of spotifiy links: It seems as if the format of a e.g. playlist should be something like

spotify:user:spotify:playlist:37i9dQZF1DWUVpAXiEPK8P

My problem is (I can solve it, but probably not every user can) that the link I get out of the spotifiy webplayer or the iris frontend looks something like:

https://open.spotify.com/playlist/6mIRMg8kpuok7eS3o7uUx7

Maybe I'm just doing it wrong (copying the link), the way it entered in phoniebox and linked to an rfid card could be improved

MiczFlor commented 6 years ago

@Alwiz79 @kathateich @dnkroy
In the develop branch, I added the option to change the file ending for playlists. See here for details: https://github.com/MiczFlor/RPi-Jukebox-RFID/commit/0f31aeb0f5104cb626b0bf4e2795d1e8169b82cd By default m3u is set. Spotify / Mopidy requires m3u8. If you have the time, could you please check if this works for you - and if so, I will merge it with the master branch.

kathateich commented 6 years ago

@alwiz: Did you install the fork (Blacklight) in the home directory or the other path mentioned? In the documentation it says you need to copy them to a certain directory but it is missing that you need to install it. I think that that was my fault.

Am Montag, 22. Oktober 2018 schrieb Alwiz79 :

@princemaxwell https://github.com/princemaxwell could you please explain again what's to do because of the local music problem @kathateich https://github.com/kathateich just mentioned above?

I am currently having the same problem. spotify works great, but when i want to start local music it just stops.

besides that i am not having any issue with the spotify integration so far. great work! just a question: is there a way to save allready in the uri, that i want the playlist to be shuffled? something like :shuffle:ON :-)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/18#issuecomment-431708648, or mute the thread https://github.com/notifications/unsubscribe-auth/Ap_7EMqSUpHmZuH9uKixnQ7waPFzH_Xsks5unPC7gaJpZM4Sk7As .

Alwiz79 commented 6 years ago

@miczflor: this might sound stupid, but I’m really not familiar with github. How do I switch to develop branch?

@miczflor: where did you add the option? During the execution of the installation script (input needed) or somewhere in the phoniebox GUI ?

@kathateich: Not sure..I just used the one line command script for the Spotify version provided by miczflor

princemaxwell commented 6 years ago

@Alwiz79 with the Spotify one line script, everything should fine when you have done a fresh installation.

I tested it many times... Have you tried to start music over SSH?

Please use: mpc load "playlistname" && mpc play

playlistname without extension

Be sure the playlist is in the playlist directory, e.g. playlistname.m3u8.

What's happening?

Alwiz79 commented 6 years ago

@princemaxwell when i try to start the music over ssh I get the following:

pi@PlayPi:~ $ mpc load "chartstuff" && mpc play loading: chartstuff volume: 30% repeat: off random: off single: off consume: off

To me this looks pretty "normal", but still no audio output.

The playlist (chartstuff.m3u8) is located here: /home/pi/RPi-Jukebox-RFID/playlists The mp3 referenced in the playlist is located here: /home/pi/RPi-Jukebox-RFID/shared/audiofolders/chartstuff

princemaxwell commented 6 years ago

Should be ok. If playlist path is wrong, a error message is shown. by showing "volume: 30% repeat: off random: off single: off consume: off" the status is changed to play.

Did you check the content of M3U8 in a text editor? Are the folders and files correct there?

Alwiz79 commented 6 years ago

This is the content of the M3U8

/home/pi/RPi-Jukebox-RFID/shared/audiofolders/chartstuff/mySong.mp3

princemaxwell commented 6 years ago

@Alwiz79

This is the content of the M3U8

/home/pi/RPi-Jukebox-RFID/shared/audiofolders/chartstuff/mySong.mp3

Should be ok, else! Damn, can you please check, if "alsasink" is the correct output way for your box? In mopidy.conf, alsasink is set as standard output for mopidy... Because it look like the playlist is being played.

Otherwise check the follwing commands (the first is to load and play the playlist):

mpc load "chartstuff" && mpc play
mpc
mpc current
mpc playlist

Please post your requests here!!

just a question: is there a way to save allready in the uri, that i want the playlist to be shuffled? something like :shuffle:ON :-)

You only can shuffle by using the WebUI and press the shuffle button. To integrate this into URI would be a heavy work...

general feeedback on the handling of spotifiy links: It seems as if the format of a e.g. playlist should be something like

spotify:user:spotify:playlist:37i9dQZF1DWUVpAXiEPK8P

My problem is (I can solve it, but probably not every user can) that the link I get out of the spotifiy webplayer or the iris frontend looks something like:

https://open.spotify.com/playlist/6mIRMg8kpuok7eS3o7uUx7

Maybe I'm just doing it wrong (copying the link), the way it entered in phoniebox and linked to an rfid card could be improved

screen2

You have to right-click on album, playlist or track in Mopidy IRIS and choose Copy URI. But attention. You have to add "user:username" to this link manually!!! The better way is, to use Spotify client on Mac or Windows. There you can copy directly with user.

Alwiz79 commented 6 years ago

@princemaxwell in mopidy.conf alsasink is selected, yes. If this correct I don't know? With this raspi I'm not using a soundcard or anything but the raspi itself. So I guess it is correct. Looking at this setup guide https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/master/docs/SPOTIFY-INTEGRATION.md It says to edit this file

sudo nano ~/.config/mopidy/mopidy.conf

This file doesn't exist. in fact the whole .config/ path I cannot see. Is this maybe part of the problem?

Otherwise check the follwing commands (the first is to load and play the playlist):

mpc load "chartstuff" && mpc play mpc mpc current mpc playlist

This is the result:

pi@PlayPi:~ $ mpc load "chartstuff" && mpc play loading: chartstuff volume: 30% repeat: off random: off single: off consume: off pi@PlayPi:~ $ mpc volume: 30% repeat: off random: off single: off consume: off pi@PlayPi:~ $ mpc current pi@PlayPi:~ $ mpc playlist Amy Macdonald - Don't Tell Me That It's Over.mp3

To me this looks like the music is playing, but I cannot here it.

Concerning the URI: using the spotify client does the trick..I was always using the web player, and the links to playlist look like described above

Alwiz79 commented 6 years ago

did a fresh install, it's working now! spotify and local music playing. only issue but I don't care about this: no cover art is shown (even not for spotify). But since my phoniebox doesn't have a display that is not important to me

UPDATE: after a reboot, the covers are now loading again :-)

SmightyCrown commented 6 years ago

i did also a fresh install on rpi3 with the oneline installer . Local music is playing but spotify isnt working. I authorized my account in iris , but in in settings/services it shows "Mopidy-Spotify extension is not running - you will not be able to play any Spotify tracks". When i swipe a rfid card with a spotify url, nothing happens and when i want to play it from the playlist it shows "Mopidy: Failed to add some tracks". The mopidy.conf should be rigth in my opinion. Any idea what to do ?

princemaxwell commented 6 years ago

@Alwiz79 yeah, great news!! @SmightyCrown Do you tried to reboot? Otherwise try these commands:

sudo systemctl stop mopidy
mopidy

Then mopidy is not loaded as a service. Please post the output here.

SmightyCrown commented 6 years ago

@princemaxwell Yes i did some reboots,its always the same behaviour. This is the ouput of the command:

INFO Starting Mopidy 2.1.0 INFO Loading config from builtin defaults INFO Loading config from command line options INFO Creating dir /home/pi/.cache/mopidy INFO Creating dir /home/pi/.config/mopidy INFO Creating dir /home/pi/.local/share/mopidy INFO Loading config from builtin defaults INFO Loading config from command line options INFO Creating file /home/pi/.config/mopidy/mopidy.conf INFO Initialized /home/pi/.config/mopidy/mopidy.conf with default config INFO Disabled extension spotify: Dependency The 'pyspotify>=2.0.5' distribution was not found and is required by the application not found INFO Enabled extensions: iris, mpd, http, stream, m3u, softwaremixer, file, local-images INFO Disabled extensions: spotify, local WARNING Found local configuration errors, the extension has been automatically disabled: WARNING local/media_dir must be set. WARNING Please fix the extension configuration errors or disable the extensions to silence these messages. INFO Starting Mopidy mixer: SoftwareMixer INFO Starting Mopidy audio INFO Starting Mopidy backends: StreamBackend, M3UBackend, FileBackend INFO Creating dir /home/pi/.local/share/mopidy/m3u INFO Audio output set to "autoaudiosink" INFO Starting Mopidy core INFO Starting Mopidy frontends: IrisFrontend, MpdFrontend, HttpFrontend INFO Starting Iris 3.28.1 INFO MPD server running at [::ffff:127.0.0.1]:6600 INFO HTTP server running at [::ffff:127.0.0.1]:6680 INFO Starting GLib mainloop INFO Creating dir /home/pi/.local/share/mopidy/local-images INFO New MPD connection from [::ffff:127.0.0.1]:41644 INFO New MPD connection from [::ffff:127.0.0.1]:41642 INFO New MPD connection from [::ffff:127.0.0.1]:41650 INFO New MPD connection from [::ffff:127.0.0.1]:41654 INFO New MPD connection from [::ffff:127.0.0.1]:41658

blacklight commented 6 years ago

@SmightyCrown

INFO Disabled extension spotify: Dependency The 'pyspotify>=2.0.5' distribution was not found and is required by the application not found

princemaxwell commented 6 years ago

@SmightyCrown

You need to install pyspotify. By the way, update the extension mopidy-spotify too.

sudo apt-get install libspotify12 python-cffi python-ply python-pycparser python-spotify
sudo rm -rf /usr/lib/python2.7/dist-packages/mopidy_spotify*
sudo rm -rf /usr/lib/python2.7/dist-packages/Mopidy_Spotify-*
sudo rm -rf /usr/local/lib/python2.7/dist-packages/mopidy_spotify*
sudo rm -rf /usr/local/lib/python2.7/dist-packages/Mopidy_Spotify-*
cd
sudo rm -rf mopidy-spotify
git clone -b fix/web_api_playlists --single-branch https://github.com/princemaxwell/mopidy-spotify.git
cd mopidy-spotify
sudo python setup.py install
cd
SmightyCrown commented 6 years ago

@BlackLight @princemaxwell Thank you for the fast answer. After i installed pyspotiy and updated mopidy-spotify, it works without a error. The only thing is, that i cant add spotify albums to a card, only tracks. With spotify:track:XXXX it works, with spotify:albumXXX in the spotify.txt file, mopidy brings an error: invalid id.

dnkroy commented 6 years ago

Did YouTube Miss the : after Album? spotify:albumXXX . Maybe you got an user made album?