So I have written a bash script (named music.sh) for a Raspberry Pi to perform the following functions:
- When executed, look into one single directory (Music folder) and select a random folder to look into. (Note: none of these folders here have subdirectories)
- Once a folder within "Music" has been selected, then play all mp3 files IN ORDER until the last mp3 file has been reached
- At this point, the script would go back to the folders in the "Music" directory and select another random folder
- Then it would again play all mp3 files in that folder in order
- Loop indefinitely until input from user
I have this code which does all of the above EXCEPT for the following items:
- I would like to NOT play any other "album" that has been played before
- Once all albums played once, then shutdown the system
Here is my code so far that is working (WITH duplicates allowed):
#!/bin/bash
folderarray=($(ls -d /home/alphekka/Music/*/))
for i in "${folderarray[@]}";
do
folderitems=(${folderarray[RANDOM % ${#folderarray[@]}]})
for j in "${folderitems[@]}";
do
echo `ls $j`
cvlc --play-and-exit "${j[@]}"
done
done
exit 0
Please note that there isn't a single folder or file that has a space in the name. If there is a space, then I face some issues with this code working.
Anyways, I'm getting close, but I'm not quite there with the entire functionality I'm looking for. Any help would be greatly appreciated! Thank you kindly! :)