bin: add pl script

This commit is contained in:
xeruf 2021-09-29 18:36:17 +02:00
parent fed6f76808
commit f6e4122d77
2 changed files with 32 additions and 17 deletions

View File

@ -3,23 +3,6 @@ export MUSIC="$DATA/music"
export AUDIO="$DATA/audio" export AUDIO="$DATA/audio"
MUSIC_RAW="$AUDIO/songs/_raw" MUSIC_RAW="$AUDIO/songs/_raw"
edpl() {
$EDITOR $(find $MUSIC/Playlists -iname "$1\.*" | grep . || find $MUSIC/Playlists -iname "$1*")
}
makePl() { echo ${2:-empty} >$1.m3u8 }
makePls() {
i=1; while test $i -le ${1:-9}; do makePl "${2:-Ω}$i" "empty$i"; ((i++)); done
}
fixPl() {
sed -i 's/.*\/musi[kc]/../g' *
}
plCd() {
dir=${2:-cd}
mkdir $dir
cat $1 | python -c "import sys, urllib as ul; [sys.stdout.write(ul.unquote_plus(l)) for l in sys.stdin]" | sed '=' | sed -r 's/^[0-9]$/0\0/' | sed -r "N; s/(.*)\n(.*\/[0-9 ]*(.*))/'\2'\n'$dir\/\1 \3'/" | xargs -L 2 cp
}
findsongs() { findsongs() {
find -regextype posix-extended -maxdepth 1 -type f -regex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n" find -regextype posix-extended -maxdepth 1 -type f -regex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n"
} }

32
.local/bin/scripts/pl Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
# Playlist utilities
# optdepends: highlight python
# env: MUSIC
test $# -gt 0 && command=$1 && shift
case $command in
(update)
for pl; do
highlight $pl
cat $pl | rev | cut -d'/' -f-2 | rev | while read f; do
test -n "$f" || continue
find -path "*${f#../}" -prune | grep --color=never . || find -path "*${f##* - }" -o -path "*${f##*/}" | head -1 | grep --color=never . || echo $f
done | tee $pl
done;;
(edit) ${EDITOR:-nano} $(find $MUSIC/Playlists -iname "$1\.*" | grep . || find $MUSIC/Playlists -iname "$1*");;
(make)
if test $1 = d
then shift && i=1; while test $i -le ${1:-9}; do $0 make "${2:-Ω}$i" "empty$i"; ((i++)); done
else echo ${2:-empty} >$1.m3u8
fi;;
(fix) sed -i 's/.*\/musi[kc]/../g';;
(cd) dir=${2:-cd}
mkdir $dir
cat $1 | python -c "import sys, urllib as ul; [sys.stdout.write(ul.unquote_plus(l)) for l in sys.stdin]" | sed '=' | sed -r 's/^[0-9]$/0\0/' | sed -r "N; s/(.*)\n(.*\/[0-9 ]*(.*))/'\2'\n'$dir\/\1 \3'/" | xargs -L 2 cp;;
(*) echo "Unknown subcommand '$1' - Possible subcommands:
update - update file paths for moved songs in a playlist
edit - open playlist in default editor
make - create an empty playlist with given name in current directory (optional second arg provides content)
> d - creates up to 9 dummy files
fix - replace absolute by relative paths for all given files (assumes library root at musi[kc] and playlist file one level below)
cd - copy all songs of a playlist into a folder with indexed names, so they can easily be burned to a CD"
esac