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

Playing files directly from NAS via symlink #199

Closed gizmo21 closed 5 years ago

gizmo21 commented 6 years ago

I thought instead of needing to move all of the music to the SDCard I could play some over smb-share from my NAS. But even though I can see all files in bash and browser under "show files - Contains the following file(s): file1.mp3 " and I can press play, they are not played.

I used the following setup: /etc/fstab: //192.168.0.212/music /home/pi/shares/synomusic cifs credentials=/root/.smbcredentials,iocharset=utf8,x-systemd.requires=network-online.target 0 0

So after reboot I can see in ls /home/pi/shares/nasmusic all mp3 in the music root of my NAS and can navigate to all subfolder.

Now I create a symbolic link to a subfolder 'f' of the nas-share containing an mp3 file (but even /home/pi/shares/synomusic/=root of Nas-share has same results) ln -sf /home/pi/shares/synomusic/f/ /home/pi/RPi-Jukebox-RFID/shared/audiofolders/nas and even chmod -h pi:www-data /home/pi/RPi-Jukebox-RFID/shared/audiofolders/nas

In browser index.php I can now see "nas" as "Available audio folder" and even "show files" lists the correct files and it even created the folder.conf on the NAS folder. But pressing play seems to do something (folder.conf says playing) but doesn't play.

sudo tail -f /var/log/lighttpd/error.log

2018-09-13 22:39:50: (mod_fastcgi.c.2543) FastCGI-stderr: PHP message: PHP Notice:  Undefined offset: 1 in /home/pi/RPi-Jukebox-RFID/htdocs/inc.playerStatus.php on line 23
2018-09-13 22:39:50: (mod_fastcgi.c.2543) FastCGI-stderr: PHP message: PHP Notice:  Undefined offset: 1 in /home/pi/RPi-Jukebox-RFID/htdocs/inc.playerStatus.php on line 26
2018-09-13 22:39:50: (mod_fastcgi.c.2543) FastCGI-stderr: PHP message: PHP Notice:  Undefined offset: 1 in /home/pi/RPi-Jukebox-RFID/htdocs/inc.playerStatus.php on line 29

sudo tail -f /var/log/auth.log

Sep 13 22:49:22 raspberrypi sudo: www-data : TTY=unknown ; PWD=/home/pi/RPi-Jukebox-RFID/htdocs ; USER=root ; COMMAND=/home/pi/RPi-Jukebox-RFID/scripts/rfid_trigger_play.sh -d=nas
Sep 13 22:49:22 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 13 22:49:22 raspberrypi sudo:     root : TTY=unknown ; PWD=/home/pi/RPi-Jukebox-RFID/shared/audiofolders ; USER=root ; COMMAND=/bin/echo nas
Sep 13 22:49:22 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 13 22:49:22 raspberrypi sudo: pam_unix(sudo:session): session closed for user root
Sep 13 22:49:22 raspberrypi sudo:     root : TTY=unknown ; PWD=/home/pi/RPi-Jukebox-RFID/shared/audiofolders ; USER=root ; COMMAND=/bin/chmod 777 /home/pi/RPi-Jukebox-RFID/scripts/../settings/Latest_Folder_Played
Sep 13 22:49:23 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Sep 13 22:49:23 raspberrypi sudo: pam_unix(sudo:session): session closed for user root
Sep 13 22:49:24 raspberrypi sudo: pam_unix(sudo:session): session closed for user root

sudo tail -f /var/log/daemon.log:

Sep 14 02:09:15 raspberrypi python2[284]: loading: nas
Sep 14 02:09:15 raspberrypi python2[284]: OK MPD 0.19.0
Sep 14 02:09:15 raspberrypi python2[284]: OK
Sep 14 02:09:16 raspberrypi python2[284]: volume:  0%   repeat: off   random: off   single: off   consume: off

cat /home/pi/RPi-Jukebox-RFID/logs/debug.log

## SCRIPT rfid_trigger_play.sh (2018-09-14.02:06:32) ##
VAR CARDID: 00002188888
VAR FOLDER:
Card ID '00002188888' was used
This ID has been used before.
The shortcut points to audiofolder 'nas'.
# Attempting to play: /home/pi/RPi-Jukebox-RFID/shared/audiofolders/nas
VAR FOLDER: nas
VAR PLAYLISTPATH: /tmp/nas.m3u
VAR SPECIALFORMAT:
CHECK Something special to do?
Nothing special /tmp/nas.m3u

^/tmp/nas.m3u is empty wheras the other there have the correct files incl. path

It seems "find" command does not find symlinked files, so i worked around to try if it could play and it does it well that hardcoded way (adding an smb.txt as switch:

  "livestream.txt")
                # mpd can't read from .txt, so we have to write the livestream URL into playlist
                cat "$AUDIOFOLDERSPATH/$FOLDER/livestream.txt" > "$PLAYLISTPATH"
                if [ $DEBUG == "true" ]; then echo "Livestream $PLAYLISTPATH"   >> $PATHDATA/../logs/debug.log; fi
            ;;
            "smb.txt")
              cd $AUDIOFOLDERSPATH
              echo "file:////home/pi/shares/synomusic/f/file.mp3" > "$PLAYLISTPATH"

            ;;
            *)
                # Nothing special to do, folder with audio files
                # write playlist to file using the same name as the folder with ending .m3u
                # wrap $PLAYLIST string in "" to keep line breaks
                # cd to $AUDIOFOLDERSPATH as mpd accepts only filepaths relative to its music folder
                # or starting with file:// (e.g. file:///home/pi...)
                cd $AUDIOFOLDERSPATH
                find "$FOLDER" -type f | sort -f > "$PLAYLISTPATH"
                if [ $DEBUG == "true" ]; then echo "Nothing special $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi
            ;;

That of course is not the way ;) but I'm out of options to parse this correctly into the m3u.

gizmo21 commented 6 years ago

I managed it. The problem was that mpd only likes paths relative to /audiofolders OR absolute paths, as you already wrote in rfid_trigger_play.sh. Your relative path m3u generation does not work with symlinked content so the absolute path had to be resolved at first and then I struggled with spaces in the NAS-mp3 files. My iteration went this way:

   "smb.txt") # put an empty smb.txt into the NAS-folder you want to be played
              cd $AUDIOFOLDERSPATH
              # echo "file:////home/pi/shares/synomusic/f/file.mp3" > "$PLAYLISTPATH" # hardcoded for test
              # readlink -f $(find -L "$FOLDER" | sort -f ) >  "$PLAYLISTPATH"        # works with non spaced filenames
              #realpath $(find -L "$FOLDER" | sort -f) >  "$PLAYLISTPATH"              # works with non spaced filenames
              find  $(realpath  "$FOLDER") -type f | sort -f >  "$PLAYLISTPATH"      # also works with spaced filenames

            ;;

In the end I came up with this minimal alteration of your original code which then works with symlinked files via SMB AND the usual local files in audiofolder/ . So no special smb case or smb.txt file needed:

  *)
                # Nothing special to do, folder with audio files
                # write playlist to file using the same name as the folder with ending .m3u
                # wrap $PLAYLIST string in "" to keep line breaks
                # cd to $AUDIOFOLDERSPATH as mpd accepts only filepaths relative to its music folder
                # or starting with file:// (e.g. file:///home/pi...)
                cd $AUDIOFOLDERSPATH
            #   find "$FOLDER" -type f | sort -f > "$PLAYLISTPATH"
                 find "$(realpath  "$FOLDER")" -type f | sort -f >  "$PLAYLISTPATH"    #works with localfiles and local spaced folders, but also with symlinked folders and spaced cifs filenam$
   if [ $DEBUG == "true" ]; then echo "Nothing special $PLAYLISTPATH" >> $PATHDATA/../logs/debug.log; fi
            ;;

Only "drawback" I saw so far is that the /tmp/*.m3u fles get a bit larger as always absolute path is saved instead of relative to audiofolders - hop that doesn't break something else.

But of course for the cifs function you need mounting of smb-share (automatically via fstab) and the once per folder manual symlinking for every sub-folder you want to play: ln -sf <local-cifs-mountdir>/<optional-subdir-on-nas>/ /home/pi/RPi-Jukebox-RFID/shared/audiofolders/<symlink-foldername>

So just in case for anyone who also wants to play remote SMB-files, this one worked for me. Guess there are tons of possibilities to get it also going - so please enhance it.

MiczFlor commented 6 years ago

Hi @gizmo21 really nice workaround. I will take it as inspiration for the near future. I just changed the way playlists are created to improve subfolder playout - so I can‘t use it as is :/

gizmo21 commented 6 years ago

No problem, this just works for me and was only a suggestion. But it would be nice if you would take "symlinked CIFS-shares" support into consideration in the future generation of playlists. Of course the share-mount and symlinked has to be done by every user manually.

bubble1999 commented 5 years ago

Thank you very much for this great project! I also would like to play files from a shared network drive. Could you please comment where (which file) to implement the mentioned workaround? Code search did not give me an indication. Thank you!

gizmo21 commented 5 years ago

Well so far I haven't tried it on any newer version than 1.0.0 again, as they are all to unstable or with too slow web-interface for me.

I don't know if @MiczFlor changed the way m3u are created in a manner the symlink "ln -sf" is still working.

@bubble1999:

  1. do you use classic or Spotify edition? I used only classic so far and Spotify uses different player then mpd afaik and I can't tell anything about that one?

  2. have you already mounted your networkdrive and symlinked it to shared/audiofolders as mentioned above?

  3. Does folder then show up in the webinterface?

  4. does it show the files in the playlist?

Those three worked for me without changing anything in code.

  1. does play work now, and if not what do the log files and m3u files say (see post 1 here)?
bubble1999 commented 5 years ago

Thank you very much for your answer.

0) I am using classic edition 1+2) I tried two scenarios:

debug.log: ` ######### SCRIPT inc.readArgsFromCommandLine.sh (2018-12-04.20:49:51) ## VAR CARDID: 21415520026159 VAR COMMAND: createDefaultFolderConf VAR FOLDER: 30Kinderlieder VAR VALUE: ########### SCRIPT inc.writeFolderConfig.sh (2018-12-04.20:49:51) ## VAR COMMAND: createDefaultFolderConf VAR FOLDER: 30Kinderlieder VAR AUDIOFOLDERSPATH: /home/pi/RPi-Jukebox-RFID/shared/audiofolders CHECK FOLDER EXISTS: /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder !!!setting default vars for raw create!!! KEEP NEW VARS IN MIND VAR NEWCURRENTFILENAME: filename content of /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/folder.conf REPLACE VALUES FROM THE CONFIG FILE WITH NEW ONES VAR CURRENTFILENAME: filename WRITE THE VALUES INTO THE NEWLY CREATED RAW CONFIG Var $LASTFOLDER: 30Kinderlieder Var $LASTPLAYLIST: 30Kinderlieder Checking 'recursive' list? VAR $VALUE: /home/pi/RPi-Jukebox-RFID/scripts/playlist_recursive_by_folder.php folder="30Kinderlieder" > "/home/pi/RPi-Jukebox-RFID/playlists/30Kinderlieder.m3u" Var $SECONDSWIPE: RESTART Var $PLAYLISTNAME: 30Kinderlieder Second Swipe DID happen: $LASTPLAYLIST == $PLAYLISTNAME We must play the playlist no matter what: $PLAYPLAYLIST == yes VAR FOLDER: 30Kinderlieder VAR PLAYLISTPATH: /home/pi/RPi-Jukebox-RFID/playlists/30Kinderlieder.m3u Command: /home/pi/RPi-Jukebox-RFID/scripts/playout_controls.sh -c=playlistaddplay -v="30Kinderlieder" -d="30Kinderlieder" ######### SCRIPT inc.readArgsFromCommandLine.sh (2018-12-04.20:49:52) ## VAR CARDID: VAR COMMAND: createDefaultFolderConf VAR FOLDER: 30Kinderlieder VAR VALUE: ########### SCRIPT inc.writeFolderConfig.sh (2018-12-04.20:49:52) ## VAR COMMAND: createDefaultFolderConf VAR FOLDER: 30Kinderlieder VAR AUDIOFOLDERSPATH: /home/pi/RPi-Jukebox-RFID/shared/audiofolders CHECK FOLDER EXISTS: /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder !!!setting default vars for raw create!!! KEEP NEW VARS IN MIND VAR NEWCURRENTFILENAME: filename content of /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/folder.conf REPLACE VALUES FROM THE CONFIG FILE WITH NEW ONES VAR CURRENTFILENAME: filename WRITE THE VALUES INTO THE NEWLY CREATED RAW CONFIG

~/RPi-Jukebox-RFID/playlists$ cat 30Kinderlieder.m3u: /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/01_-_Lamp und Leute_-_Hallo, hallo, schön, dass du da bist.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/02_-_Lamp und Leute_-_Meine Hände sind verschwunden.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/03_-_Lamp und Leute_-_Rommel-Bommel.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/04_-_Lamp und Leute_-_Wir gehen jetzt im Kreise.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/05_-_Lamp und Leute_-_Ich bin die kleine hexe und habe rote Schuh'.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/06_-_Lamp und Leute_-_Das ist grade, das ist schief.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/07_-_Lamp und Leute_-_Häschen in der Grube.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/08_-_Lamp und Leute_-_Das Lied über mich.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/09_-_Lamp und Leute_-_Aramsamsam.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/10_-_Lamp und Leute_-_Hoch am Himmel.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/11_-_Lamp und Leute_-_Die Räder vom Bus.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/12_-_Lamp und Leute_-_Das rote Pferd.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/13_-_Lamp und Leute_-_Ein großer, ein runder, ein roter Luftballon.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/14_-_Lamp und Leute_-_Zehn kleine Zappelmänner.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/15_-_Lamp und Leute_-_Zeigt her eure Füße.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/16_-_Lamp und Leute_-_Große Uhren machen tick tack.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/17_-_Lamp und Leute_-_Wir Fröschelein.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/18_-_Lamp und Leute_-_Die Maus auf Weltraumreise.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/19_-_Lamp und Leute_-_Hände waschen.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/20_-_Lamp und Leute_-_Wo ist der Daumen_.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/21_-_Lamp und Leute_-_Ich bin ein dicker Tanzbär.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/22_-_Lamp und Leute_-_1, 2, 3 im Sauseschritt.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/23_-_Lamp und Leute_-_Igellied.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/24_-_Lamp und Leute_-_Der Apfelbaum.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/25_-_Lamp und Leute_-_Unser kleiner Bär im Zoo.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/26_-_Lamp und Leute_-_Brüderchen, komm tanz mit mir.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/27_-_Lamp und Leute_-_Was müssen das für Bäume sein_.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/28_-_Lamp und Leute_-_Auf der grünen Wiese (Karussell-Lied).mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/29_-_Lamp und Leute_-_Es tanzt ein Bi-Ba-Butzemann.mp3 /home/pi/RPi-Jukebox-RFID/shared/audiofolders/30Kinderlieder/30_-_Lamp und Leute_-_Alle Leut'.mp3

=> this seems to me that the files are found, but no playback is started. Is there another file to find more information?

gizmo21 commented 5 years ago

Have you tried it with a different single file in that folder or other folder with simplefilename.mp3 without Umlauts, dashes, spaces, comma...

Do same files play in same named folder if copied locally?

Please try different foldername without numbers, just in case that problem here https://github.com/MiczFlor/RPi-Jukebox-RFID/issues/331#issuecomment-440515110 is not only ' and - problem but also a number problem.

Do the ln'ed files play manually on bash?

Checked the accessrights in that folder compared to others local folder/files there?

Is folder.conf in that folder available with useful entries?

After that I'm out of options until I tried that newer version for myself.

bubble1999 commented 5 years ago

This helped:

Thank you very much for your help!

Best regards

gizmo21 commented 5 years ago

OK so only foldernames with ' (issue #331) and & (issue #324) are a problem but not numbers. And yes write-permission is needed to create folder.conf (that's why perhaps always log said: "VAR NEWCURRENTFILENAME: filename" instead on a realfilename).

Thanks for testing it all, so I know now that symlinking is still working on newer versions without my own patch above ;)

@bubble1999 could you perhaps document your settings e.g. fstab mounting line or which "ln"-line you used so others could set it up quickly, cause not everybody is a smb-pro.

bubble1999 commented 5 years ago

configuration line in /etc/fstab: [SERVERNAME]:/[FOLDERNAME] /[TARGETFOLDERNAME]/ nfs rw 0 0

and the ln-code I used was ln -s /[MOUNTEDMP3DIRECTORY] ~/RPi-Jukebox-RFID/shared/audiofiles/30Kinderlieder