configs/arch-config/scripts/pieces/music-create-links.sh

77 lines
2.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# remove content of music directory
rm -rf "$HOME/Musik/"*
# change into music raw folder
2024-06-23 11:37:41 +02:00
pushd "$HOME/Nextcloud/MusikRaw"
2024-06-23 11:37:41 +02:00
# disable expansion of empty globs
shopt -s nullglob
2021-02-12 14:30:17 +01:00
2024-06-23 11:37:41 +02:00
for artdir in */; do
# FIXME remove trailing slash
artdir="${artdir%/}"
# change into artist directory
2024-06-23 12:03:06 +02:00
pushd "$artdir"
2024-06-23 11:37:41 +02:00
for dir in */; do
# FIXME remove trailing slash
dir="${dir%/}"
2021-02-12 14:30:17 +01:00
# change into directory
2024-06-23 11:37:41 +02:00
pushd "$dir"
for subdir in */; do
if [ "$subdir" != "normalized/" ]; then
# NOTE handle new paths with streaming services included
# FIXME remove trailing slash
subdir="${subdir%/}"
# go into subdirectory
pushd "$subdir"
# create directory in music
mkdir -p "$HOME/Musik/${artdir}/$subdir"
# link cover image (jpg or png)
if [ -f cover.jpg ]; then
ln -vf "$HOME/Nextcloud/MusikRaw/${artdir}/$dir/$subdir/cover.jpg" "$HOME/Musik/${artdir}/$subdir/"
elif [ -f cover.png ]; then
ln -vf "$HOME/Nextcloud/MusikRaw/${artdir}/$dir/$subdir/cover.png" "$HOME/Musik/${artdir}/$subdir/"
fi
# make symbolic link to music
# if the "normalized" directory exists, links are created
if [ -d "normalized" ]; then
ln -svf "$HOME/Nextcloud/MusikRaw/${artdir}/$dir/$subdir/normalized/"* "$HOME/Musik/${artdir}/$subdir/"
fi
popd
else
# NOTE this stays the same, without streaming services included
# create directory in music
mkdir -p "$HOME/Musik/${artdir}/$dir"
# link cover image (jpg or png)
if [ -f cover.jpg ]; then
ln -vf "$HOME/Nextcloud/MusikRaw/${artdir}/$dir/cover.jpg" "$HOME/Musik/${artdir}/$dir/"
elif [ -f cover.png ]; then
ln -vf "$HOME/Nextcloud/MusikRaw/${artdir}/$dir/cover.png" "$HOME/Musik/${artdir}/$dir/"
fi
# make symbolic link to music
# if the "normalized" directory exists, links are created
if [ -d "normalized" ]; then
ln -svf "$HOME/Nextcloud/MusikRaw/${artdir}/$dir/normalized/"* "$HOME/Musik/${artdir}/$dir/"
fi
fi
done
2024-06-23 12:03:06 +02:00
popd
2024-06-23 11:37:41 +02:00
done
2024-06-23 12:03:06 +02:00
popd
2024-06-23 11:37:41 +02:00
done
popd
echo Finished!
exit