2020-10-12 20:20:06 +00:00
|
|
|
export AUDIO="$DATA/audio"
|
2020-10-03 09:40:28 +00:00
|
|
|
MUSIC_RAW="$AUDIO/songs/_raw"
|
2020-06-08 09:41:03 +00:00
|
|
|
|
2021-10-13 17:15:26 +00:00
|
|
|
alias scbra='scpr zebra "/srv/funkwhale/data/music${PWD/$MUSIC}"'
|
|
|
|
|
2020-06-08 09:41:03 +00:00
|
|
|
findsongs() {
|
2021-11-16 09:20:13 +00:00
|
|
|
find -regextype posix-extended -maxdepth 1 -type f \
|
|
|
|
-regex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n"
|
2020-06-08 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addmix() {
|
2020-10-03 09:40:28 +00:00
|
|
|
mv -v "$1.cue" "$AUDIO/recordings/cues"
|
2020-06-08 09:41:03 +00:00
|
|
|
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"
|
2021-11-16 09:20:13 +00:00
|
|
|
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
|
2020-06-08 09:41:03 +00:00
|
|
|
|
|
|
|
IFS=$'\n'
|
|
|
|
for s in $(findsongs ".*\.(flac|wav)"); do
|
|
|
|
highlight "$s"
|
|
|
|
addsong -q "$s" "$1" "${@:2}"
|
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
}
|
|
|
|
|
|
|
|
formatsongs() {
|
2021-11-16 09:20:13 +00:00
|
|
|
(
|
|
|
|
find -maxdepth 1 -type d | formatin
|
|
|
|
find "$@" "$PWD" -type d | while read d;
|
|
|
|
do builtin cd $d && findsongs | formatin
|
|
|
|
done
|
|
|
|
)
|
2020-06-08 09:41:03 +00:00
|
|
|
IFS=$'\n'
|
|
|
|
for f in $(find "$@" -name "*.wav"); do
|
|
|
|
echo "Converting $f to ${f%.*}.flac"
|
2021-11-14 13:25:34 +00:00
|
|
|
ffmpeg -i "$f" "${f%.*}.flac" -v warning && mv -v $f /tmp
|
2020-06-08 09:41:03 +00:00
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
}
|
|
|
|
|
2021-11-19 11:01:04 +00:00
|
|
|
# Normalize filenames for files given from stdin
|
2021-11-16 09:20:13 +00:00
|
|
|
formatin() {
|
|
|
|
while read song; do
|
|
|
|
new="$(formatsong "$song")"
|
|
|
|
test "$new" && test "$new" != "$song" && mv -iv "$song" "$new"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-11-19 11:01:04 +00:00
|
|
|
# Normalize the given filename
|
2020-06-08 09:41:03 +00:00
|
|
|
formatsong() {
|
2021-11-16 09:20:13 +00:00
|
|
|
echo "$1" | sed -e 's/\b\(ft\|Ft\|Feat\|featuring\)\([ .]\)/feat\2/;
|
|
|
|
s/\bfeat /feat. /;
|
2021-03-20 10:02:53 +00:00
|
|
|
s/ \((Original Mix)\|(Original)\|(Full Stream)\|.NCS Release.\)//i;
|
2021-04-11 20:47:51 +00:00
|
|
|
s/ (\(Acoustic\|Live\))/ [\1]/i;
|
|
|
|
s/ \[\(feat.*\)\]/ (\1)/i;
|
2021-11-14 13:25:34 +00:00
|
|
|
s/^\([A-z]\+\) The \([^-]\+\)$/\1, the \2/g;
|
2021-03-20 10:02:53 +00:00
|
|
|
s/ \(\..\{2,4\}\)$/\1/;
|
|
|
|
s/---/ - /;
|
|
|
|
s/^[0-9]\{6\}_//;
|
2021-07-06 00:00:56 +00:00
|
|
|
s/_/ /g;
|
2021-11-14 13:25:34 +00:00
|
|
|
s/ \././g;
|
|
|
|
s/ / /g;
|
2021-03-20 10:02:53 +00:00
|
|
|
s/\(\w\)+\(\w\)/\1 \2/g' -
|
2020-06-08 09:41:03 +00:00
|
|
|
}
|