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 \
|
2022-11-09 11:45:38 +00:00
|
|
|
-iregex "${1:-.*\.(mp3|flac|wav|m4a)}" -printf "%P\n"
|
2020-06-08 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 06:31:13 +00:00
|
|
|
addtopl() {
|
|
|
|
pl=$1
|
|
|
|
shift
|
|
|
|
playlists=$MUSIC/Playlists
|
|
|
|
realpath --relative-to $playlists "$@" | tee -a $playlists/$pl*
|
|
|
|
}
|
|
|
|
|
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"
|
2022-11-09 11:45:38 +00:00
|
|
|
f1 -regextype posix-extended -type f -iregex "\./(cover|folder)\.(png|jpg|jpeg)" |
|
2021-11-16 09:20:13 +00:00
|
|
|
while read cover; do
|
|
|
|
foundcover="true"
|
|
|
|
cp -v "$cover" "$MUSIC/$1" &&
|
|
|
|
mv -v "$cover" "$MUSIC_RAW/$1"
|
|
|
|
done
|
2022-11-09 11:45:38 +00:00
|
|
|
test "$foundcover" || f1 -regextype posix-extended -type f -iregex ".*\.(png|jpg|jpeg)" |
|
2021-11-16 09:20:13 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-06-28 19:32:19 +00:00
|
|
|
|
|
|
|
updatemusic() {
|
|
|
|
for dir in $(find "$MUSIC" -mindepth 1 -maxdepth 1 -type d -name "[A-Z]*")
|
|
|
|
do builtin cd "$dir"
|
|
|
|
find -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read dir
|
|
|
|
do target="$(echo ${dir} | tr -d ' ')"
|
|
|
|
find -maxdepth 1 \( -name "$dir" -o -iname "$(echo ${target} | sed 's/\([a-z]\)\([A-Z][a-z]\)/\1*\2/g')*" \) -not -name "$target" -exec mv -nv {} $target/ \;
|
|
|
|
done
|
|
|
|
done
|
|
|
|
cd "$MUSIC"
|
|
|
|
find -mindepth 4 -type d -not -path '*/Hip-Hop/*' -not -path '*/Movies/*' -not -path '*/LeagueOfLegends/*' -exec sh -c 'mv -vn "{}" "$(echo "{}" | cut -d/ -f2-3)/"' \; -prune
|
|
|
|
find -mindepth 4 -type d -exec sh -c 'test $(find "{}" -type f | grep -vE "(.jpe?g|.png)" | wc -l) -eq 1 && name="$(ls "{}" | grep -vE "(.jpe?g|.png)")" && mv -vi "{}/$name" "$(dirname "{}")/$(echo "$name" | sed "s|^01 ||")" && rm -rv "{}"' \; -prune
|
|
|
|
# TODO delete folders with only images: find -type d -exec sh -c 'test $(find "{}" -type f | grep -vE "(.jpe?g|.png)" | wc -l) -eq 0 && rm -r "{}"' \; -prune
|
|
|
|
find -empty -delete
|
|
|
|
formatsongs
|
|
|
|
printf "=== DONE RENAMING ===\n\n"
|
|
|
|
beet import -AC "$MUSIC"
|
|
|
|
}
|
|
|
|
|
2020-06-08 09:41:03 +00:00
|
|
|
formatsongs() {
|
2021-11-16 09:20:13 +00:00
|
|
|
(
|
2023-01-31 17:58:36 +00:00
|
|
|
find -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | formatin
|
2021-11-16 09:20:13 +00:00
|
|
|
find "$@" "$PWD" -type d | while read d;
|
2023-01-09 23:47:53 +00:00
|
|
|
do builtin cd "$d" && findsongs | formatin
|
2021-11-16 09:20:13 +00:00
|
|
|
done
|
|
|
|
)
|
2022-01-05 17:42:20 +00:00
|
|
|
# fd --no-ignore-vcs --type f --extension opus --exec opusdec --quiet "{}" "{.}.wav" \; ".*" "$@"
|
2022-11-09 11:45:38 +00:00
|
|
|
find "$@" -type f -iname "*.wav" -exec sh -c '
|
2022-01-05 17:42:20 +00:00
|
|
|
f="{}" &&
|
|
|
|
echo "Converting $f to ${f%.*}.flac" &&
|
|
|
|
ffmpeg -i "$f" "${f%.*}.flac" -v warning &&
|
|
|
|
mv -v "$f" /tmp' \;
|
2020-06-08 09:41:03 +00:00
|
|
|
}
|
|
|
|
|
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")"
|
2023-01-31 17:58:36 +00:00
|
|
|
if test "$new" && test "$new" != "$song"
|
|
|
|
then mkdir -p "$(dirname "$new")" && mv -iv "$song" "$new"
|
|
|
|
fi
|
2021-11-16 09:20:13 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-11-19 11:01:04 +00:00
|
|
|
# Normalize the given filename
|
2020-06-08 09:41:03 +00:00
|
|
|
formatsong() {
|
2024-05-31 08:57:17 +00:00
|
|
|
# Qobuz folders /^[A-z0-9_-]\+$/{s|_| |g;s|-|/|g};
|
|
|
|
echo "$1" | sed -e '
|
2023-01-31 17:58:36 +00:00
|
|
|
s/\b\(ft\|Ft\|Feat\|featuring\)\([ .]\)/feat\2/;
|
2021-11-16 09:20:13 +00:00
|
|
|
s/\bfeat /feat. /;
|
2023-01-09 23:47:53 +00:00
|
|
|
s/)(/) (/g;
|
2024-05-31 08:57:17 +00:00
|
|
|
s/ [[(]\(None\|Free Download\|Original Mix\|Original\|Full Stream\|NCS Release\)[])]//i;
|
2023-01-09 23:47:53 +00:00
|
|
|
s/ (\(Acoustic\|Live|.* Remix\))/ [\1]/i;
|
2021-04-11 20:47:51 +00:00
|
|
|
s/ \[\(feat.*\)\]/ (\1)/i;
|
2021-03-20 10:02:53 +00:00
|
|
|
s/ \(\..\{2,4\}\)$/\1/;
|
|
|
|
s/---/ - /;
|
2022-06-13 13:47:47 +00:00
|
|
|
s/-LLS\././;
|
2021-03-20 10:02:53 +00:00
|
|
|
s/^[0-9]\{6\}_//;
|
2022-01-05 17:42:20 +00:00
|
|
|
s/\([^/]\)_/\1 /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' -
|
2024-06-28 19:32:19 +00:00
|
|
|
#s/^\([A-z]\+\) The \([^-]\+\)$/\1, the \2/g;
|
2020-06-08 09:41:03 +00:00
|
|
|
}
|