Last active
February 27, 2023 03:18
-
-
Save michaelskyba/2e04107265d4255671bb597581afd76a to your computer and use it in GitHub Desktop.
Allow symbolic links for playlist functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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