Skip to content

Instantly share code, notes, and snippets.

@michaelskyba
Last active February 27, 2023 03:18
Show Gist options
  • Save michaelskyba/2e04107265d4255671bb597581afd76a to your computer and use it in GitHub Desktop.
Save michaelskyba/2e04107265d4255671bb597581afd76a to your computer and use it in GitHub Desktop.
Allow symbolic links for playlist functionality
#!/bin/sh
[ -z "$1" -o -z "$2" ] && . err
music_dir=$1
tracks=$2
# Otherwise wc could error on a non-existent
[ -f "$tracks" ] || touch "$tracks"
while :
do
# Make sure there are tracks
num_of_lines=$(wc -l "$tracks")
num_of_lines=${num_of_lines%% *}
# Refresh if not
[ "$num_of_lines" = 0 ] &&
find "$music_dir" -type "f,l" | shuf > "$tracks" &&
herbe "msk_music: refreshing"
track=$(head -1 "$tracks")
mpv --no-resume-playback "$track"
# Delete first line of tracks
sed -i "1d" "$tracks"
done
@michaelskyba
Copy link
Author

michaelskyba commented Oct 7, 2022

What about mpv --shuffle <dir>?

This covers the basic functionality, but it's not as extendable. In a shell script, you are writing every line, so you can add checks and calls in between any action you want. In mpv, running a script when a file is not found, for example, is way more annoying than just adding a [ -f file ] || myscript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment