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

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

$ pwd
/home/michael/music
$ tree
.
└── main-playlist
    ├── 1
    │   ├── track1.webm
    │   └── track2.webm
    └── 2
        ├── track3.webm
        └── track4.webm

3 directories, 4 files

, 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" .

@michaelskyba
Copy link
Author

michaelskyba commented Aug 27, 2022

But what about playlists?

Just make a separate directory where you add symbolic links of existing music in other directories

@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