dotfiles/.config/shell/music

94 lines
2.8 KiB
Plaintext

export DATA="$(test -d $HOME/data && echo $HOME/data || $HOME/daten)"
export MUSIC="$DATA/music"
export AUDIO="$DATA/audio"
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() {
find -regextype posix-extended -maxdepth 1 -type f -regex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n"
}
addmix() {
mv -v "$1.cue" "$AUDIO/recordings/cues"
addsong "$1.flac" Mixes
}
addsong() {
test "$1" = "-q" && shift && quick="true"
local raw="${1%.*}"
local isflac=$(case "$1" in *.flac) echo "true";; esac)
test "$isflac" || (echo "Converting to flac..." && flac "$1" --totally-silent)
test "$quick" || (echo "Press ENTER when the metadata of the flac file is correct..." && read)
echo "Converting to mp3..."
lame -V0 "$1" --silent
mkdir -p "$MUSIC/$2"
mkdir -p "$MUSIC_RAW/$2"
local destination="$MUSIC/$2/$raw.mp3"
echo "Moving mp3 with metadata to $destination"
ffmpeg -i "$raw.mp3" -i "$raw.flac" -c copy -map_metadata 1 "$destination" -v warning "${@:3}" && rm "$raw.mp3"
test ! "$PWD" -ef "$MUSIC_RAW/$2" && mv -v "$raw.flac" "$MUSIC_RAW/$2" && (test "$isflac" || rm -v "$1")
}
addalbum() {
mkdir -p "$MUSIC/$1"
mkdir -p "$MUSIC_RAW/$1"
f1 -regextype posix-extended -type f -regex "\./(cover|folder)\.(png|jpg|jpeg)" | while read cover; do
foundcover="true"
cp -v "$cover" "$MUSIC/$1" &&
mv -v "$cover" "$MUSIC_RAW
/$1"
done
test "$foundcover" || f1 -regextype posix-extended -type f -regex ".*\.(png|jpg|jpeg)" | while read cover; do
cp -v "$cover" "$MUSIC/$1" &&
mv -v "$cover" "$MUSIC_RAW
/$1"
done
IFS=$'\n'
for s in $(findsongs ".*\.(flac|wav)"); do
highlight "$s"
addsong -q "$s" "$1" "${@:2}"
done
unset IFS
}
formatsongs() {
_pwd="$PWD"
find "$PWD" "$@" -type d | while read d; do cd $d; findsongs | while read song; do
new="$(formatsong "$song")"
test "$new" != "$song" && mv -v "$song" "$new"
done; done
cd "$_pwd"
IFS=$'\n'
for f in $(find "$@" -name "*.wav"); do
echo "Converting $f to ${f%.*}.flac"
ffmpeg -i "$f" "${f%.*}.flac" -v warning && rm -v $f
done
unset IFS
}
formatsong() {
echo "$1" | sed -e 's/\([ ([]\)\(ft\|Ft\|Feat\)\([ .]\)/\1feat\3/;s/\([ ([]\)feat /\1feat. /;s/ \((Original Mix)\|(Original)\|(Full Stream)\|.NCS Release.\)//i;s/ \(\..\{2,4\}\)$/\1/;s/---/ - /;s/^[0-9]\{6\}_//;s/ / /g;s/\(\w\)+\(\w\)/\1 \2/g' -
}