jeudi 27 août 2015

How to randomly select a song I haven't heard in a while and play it

Shuffling mp3 files often results in hearing a track that recently played. So I decided to use the 'touch' command to update the 'last modified' date & time of a file. I want my script to randomly select a song from the 10 songs that I haven't heard in the longest amount of time.

I came up with this: ls -t $music_folder | tail -n 10 | sort -R | tail -n 1 | while read file; do echo $music_folder$file mplayer $music_folder$file done

I have not yet added the 'touch' line to update the song that's about to play.

This lists the files in $music_folder sorted by time last modified, looks only at the 10 that haven't been touched in the longest time, randomizes the sort order of those ten, then grabs the one at the bottom of the list...

The 'echo' line works perfectly. However, when I try to play the song with mplayer, it tries to play several files where each word of the results is a different file name. Why is it not passing $file as a single string of text? and how can I get mplayer to play the file shown in the echo line?

Thank you!




Aucun commentaire:

Enregistrer un commentaire