lundi 29 juin 2015

How do I write a bash script to pass random files from all sublevels of a directory into an executable one by one?

I'm trying to feed random files from my iTunes Library into mpv, to shuffle my music without iTunes. Initially I tried to pass all the files into mpv using '**' and use mpv's '--shuffle' option, but mpv cannot take that many arguments. Instead, I want to generate the list of files in my own script and pass random elements from it into mpv.

Here is my code:

RANDOM=$$$(date +%s)

FILES=(~/Music/iTunes/iTunes\ Media/Music/**/**/*)

while [ 1 ]
do
    # Get random song
    nextsong=${FILES[$RANDOM % ${#FILES[@]} ]}

    # Play song
    mpv $nextsong --audio-display=no
done

When I run this, something is wrong with the list of files, mpv tries to play incomplete bits of filepaths.




Aucun commentaire:

Enregistrer un commentaire