shell/music: update playlist dir

This commit is contained in:
xeruf 2025-01-15 11:36:47 +01:00
parent de874c9604
commit cf33fa7b79
5 changed files with 21 additions and 17 deletions

View file

@ -1,25 +1,20 @@
export AUDIO="$DATA/audio" # See also scripts/pl
MUSIC_RAW="$AUDIO/songs/_raw"
alias scbra='scpr zebra "/srv/funkwhale/data/music${PWD/$MUSIC}"'
# Finds common music files in the current directory, optionally taking a regex
findsongs() { findsongs() {
find -regextype posix-extended -maxdepth 1 -type f \ find -regextype posix-extended -maxdepth 1 -type f \
-iregex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n" -iregex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n"
} }
addtopl() {
pl=$1
shift
playlists=$MUSIC/Playlists
realpath --relative-to $playlists "$@" | tee -a $playlists/$pl*
}
addmix() { addmix() {
AUDIO="$DATA/audio"
mv -v "$1.cue" "$AUDIO/recordings/cues" mv -v "$1.cue" "$AUDIO/recordings/cues"
addsong "$1.flac" Mixes addsong "$1.flac" Mixes
} }
# Used to keep music directory small, pretty much obsolete now
MUSIC_RAW="$d4/songs/_raw"
addsong() { addsong() {
test "$1" = "-q" && shift && quick="true" test "$1" = "-q" && shift && quick="true"
@ -41,6 +36,7 @@ addsong() {
test ! "$PWD" -ef "$MUSIC_RAW/$2" && mv -v "$raw.flac" "$MUSIC_RAW/$2" && (test "$isflac" || rm -v "$1") test ! "$PWD" -ef "$MUSIC_RAW/$2" && mv -v "$raw.flac" "$MUSIC_RAW/$2" && (test "$isflac" || rm -v "$1")
} }
# Execute inside an album folder with the desired target path
addalbum() { addalbum() {
mkdir -p "$MUSIC/$1" mkdir -p "$MUSIC/$1"
mkdir -p "$MUSIC_RAW/$1" mkdir -p "$MUSIC_RAW/$1"
@ -86,8 +82,10 @@ updatemusic() {
formatsongs() { formatsongs() {
( (
find -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | formatin find -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | formatin
find "$@" "$PWD" -type d | while read d; find "${@:-$PWD}" -type d | while read d;
do builtin cd "$d" && findsongs | formatin do builtin cd "$d" && findsongs | formatin
test $(find -maxdepth 1 -name '01 *' | wc -l) -gt 1 -a $(find -maxdepth 1 -name '02 *' | wc -l) -eq 0 &&
zmv -W '01 *' '*'
done done
) )
# fd --no-ignore-vcs --type f --extension opus --exec opusdec --quiet "{}" "{.}.wav" \; ".*" "$@" # fd --no-ignore-vcs --type f --extension opus --exec opusdec --quiet "{}" "{.}.wav" \; ".*" "$@"

View file

@ -5,7 +5,7 @@
# args: either a playlist file name, or a list of terms which all have to match # args: either a playlist file name, or a list of terms which all have to match
# TODO fails on "Alchemy" # TODO fails on "Alchemy"
# TODO implement finding by tags # TODO implement finding by tags
PLAYLISTS="${PLAYLISTS:-$MUSIC/Playlists}" PLAYLISTS="${PLAYLISTS:-$MUSIC/playlists}"
mpc -q clear || mpdr mpc -q clear || mpdr
if test -z "$1" if test -z "$1"
then mp -q "$PLAYLISTS/focus.m3u" then mp -q "$PLAYLISTS/focus.m3u"

View file

@ -4,9 +4,15 @@
# depends: xargs realpath mpc # depends: xargs realpath mpc
# env: MUSIC # env: MUSIC
# TODO auto-convert unknown types with ffmpeg to flac rather than linking (wav, opus, ...) # TODO auto-convert unknown types with ffmpeg to flac rather than linking (wav, opus, ...)
if test $# -eq 0
then echo "Usage: $0 [files...]"
mpdr
mpc play
exit 0
fi
MPD_CONF=${XDG_CONFIG_HOME:-$HOME/.config}/mpd/mpd.conf MPD_CONF=${XDG_CONFIG_HOME:-$HOME/.config}/mpd/mpd.conf
MUSIC="${MUSIC:-$(cat $MPD_CONF | grep music_directory | cut -d'"' -f2 | sed "s|~|$HOME|")}" MUSIC="${MUSIC:-$(cat $MPD_CONF | grep music_directory | cut -d'"' -f2 | sed "s|~|$HOME|")}"
PLAYLISTS="$(cat $MPD_CONF | grep playlist_directory | cut -d'"' -f2 | sed "s|~|$HOME|" || echo "$MUSIC/Playlists")" PLAYLISTS="$(cat $MPD_CONF | grep playlist_directory | cut -d'"' -f2 | sed "s|~|$HOME|" || echo "$MUSIC/playlists")"
LINKS="$MUSIC/.links" LINKS="$MUSIC/.links"
if test "$1" = "-r" if test "$1" = "-r"
then shift then shift
@ -16,7 +22,7 @@ then shift
do do
matchname="$(basename -- "$arg" | sed 's|\(\[.*\)\]|\\\1\\]|;s|\?|\\?|')" matchname="$(basename -- "$arg" | sed 's|\(\[.*\)\]|\\\1\\]|;s|\?|\\?|')"
filepath="$({ find "$(dirname -- "$arg")" -maxdepth 1 -name "$matchname" -exec realpath {} + || filepath="$({ find "$(dirname -- "$arg")" -maxdepth 1 -name "$matchname" -exec realpath {} + ||
find "$(dirname -- "$arg")" "$MUSIC/$(dirname -- "$arg")" "$MUSIC/Playlists/$(dirname -- "$arg")" -maxdepth 1 \ find "$(dirname -- "$arg")" "$MUSIC/$(dirname -- "$arg")" "$PLAYLISTS/$(dirname -- "$arg")" -maxdepth 1 \
-name "$matchname*" -exec realpath {} +; } 2>/dev/null)" -name "$matchname*" -exec realpath {} +; } 2>/dev/null)"
test -n "$verbose" && echo "Scanning path '$filepath' $( test -n "$verbose" && echo "Scanning path '$filepath' $(
test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2

View file

@ -1,7 +1,7 @@
#!/bin/sh -e #!/bin/sh -e
# Reload mpd with appropriate config # Reload mpd with appropriate config
yadm alt yadm alt
cd $XDG_CONFIG_HOME/mpd cd ${XDG_CONFIG_HOME:-/home/janek/.config}/mpd
mv *template .. mv *template ..
mv ../*template . mv ../*template .
systemctl --user restart mpd systemctl --user restart mpd

View file

@ -1,5 +1,5 @@
#!/bin/sh -e #!/bin/sh -e
# MPC add file to queue # Add file to mpd queue
for arg for arg
do fullpath=$(realpath "$arg") do fullpath=$(realpath "$arg")
mpc insert "${fullpath/$MUSIC\//}" mpc insert "${fullpath/$MUSIC\//}"