Here's a a way to listen to music randomly:
Code:
(SHUF='shuf'$'\n''--random-data=/dev/urandom'; IFS=$'\n'; exec mpv $(find -L ~/Music -type f | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | grep -iE 'mp3$|m4a$|ogg$|flac$|wav$|wma$|opus$|oga$'))
This will cause mpv - or theoretically any other player - to play any regular files (or symbolic links that point to regular files) with certain extensions. (Namely, those passed as arguments to grep. More could be added if desired.) I like to put make a SHUF command, and save it as a script, so that I can call it whenever I need it, but since I'm too lazy to post said script here, I made a simplified version as a shell variable.
Here's another method that requires mpv (it might also work with mplayer, but since I don't use mplayer, I'm not incentivized to test it):
Code:
SHUF='shuf --random-data=/dev/urandom'; find -L ~/Music -type f | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | grep -i mp3\$ | mpv --playlist=-
This makes a randomly-generated list of files, and passes it to mpv via stdin. From there, mpv won't recognize this list without the
--playlist=- argument. If you use relative paths, mpv will resolve those paths relative to the current working directory.
Here's a similar way to randomize your mp3s:
Code:
mpv --playlist=<(SHUF='shuf --random-data=/dev/urandom'; find -L Music -type f | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | grep -i mp3\$)
Unlike the above, mpv will resolve any relative paths from /dev/fd. So, if you're in your HOME directory, you'll probably get bunch of error that say something like this: "[file] Cannot open file /dev/fd/Music/(blablabla)/file.mp3: no such file or directory" before mpv exits. Thus, it's probably better to use command substitutions (such as
$(command)) than process substitutions (such as
<(command)) in this case.
Here's yet another way to do this:
Code:
SHUF='shuf --random-data=/dev/urandom'; find -L ~/Music -type f | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | $SHUF | xargs -0 -d \\n -s 1234567890 mpv
Do note that xargs will print a message to stderr saying like "value 1234567890 for -s option should be <= 2092657". I've seen that latter number change from one instance to another, and thus I don't even bother to memorize it. Honestly, this error can be safely ignored, and mpv (or any other player) should start playing regardless. This is probably the least graceful way of doing this, but it works well enough.
I also like resetting both my terminal and my shell by typing:
Code:
printf \\ec && exec bash
I love one-liners.
Happy Hacking!