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 |
But what about playlists?
Just make a separate directory where you add symbolic links of existing music in other directories
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
msk_music
msk_music: minimal music player
Uses mpv as the backend
Usage
msk_music <base audio directory> <songs file>
For example, if your audio directory looks like this
, the "base audio directory" would be /home/michael/music, assuming that you want all four tracks to be included.
The songs file keeps track of the queued audio files. You might use e.g
alias music="msk_music /home/michael/music $XDG_DATA_HOME/songs_list"
.