shell/mpd/bin/cleanup-music.sh: ask for confirmation
This commit is contained in:
parent
e372294911
commit
78b6ced011
|
@ -4,27 +4,50 @@
|
||||||
# it leaves behind.
|
# it leaves behind.
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
playlistdir="$(grep playlist_directory $HOME/.config/mpd/mpd.conf | awk '{ print $2; }')"
|
playlistdir=$(grep playlist_directory "$HOME/.config/mpd/mpd.conf" | awk '{ print $2; }')
|
||||||
playlistdir="${playlistdir//\"/}"
|
playlistdir="${playlistdir//\"/}"
|
||||||
playlistfile="$playlistdir/1-star.m3u"
|
playlistfile="${playlistdir/#\~/$HOME}/1-star.m3u"
|
||||||
songs=$(<"$playlistfile")
|
songs=$(cat "$playlistfile")
|
||||||
|
|
||||||
# Delete designated songs
|
# Delete designated songs
|
||||||
IFS="
|
IFS="
|
||||||
"
|
"
|
||||||
for song in ${songs[@]}; do
|
declare -a to_delete=()
|
||||||
|
for song in "${songs[@]}"; do
|
||||||
fpath="$HOME/music/$song"
|
fpath="$HOME/music/$song"
|
||||||
if [[ -f $fpath ]]; then
|
if [[ -f $fpath ]]; then
|
||||||
echo "Deleting: $song"
|
to_delete+=("$fpath")
|
||||||
rm -f "$fpath"
|
# echo "Deleting: $song"
|
||||||
|
# rm -f "$fpath"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if (( ${#to_delete[@]} == 0 )); then
|
||||||
|
echo "Nothing to delete"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Deleting %s songs:\n\n%s\n\nConfirm? (y/n) " \
|
||||||
|
"${#to_delete[@]}" \
|
||||||
|
"$(IFS=$'\n'; printf "%s" "${to_delete[*]}")"
|
||||||
|
read -r confirm
|
||||||
|
case $confirm in
|
||||||
|
y|Y)
|
||||||
|
echo "Deleting..."
|
||||||
|
for file in ${to_delete[@]}; do
|
||||||
|
rm -fv "$file"
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
n|N) echo "Aborted"; exit ;;
|
||||||
|
*) echo "Invalid" ;;
|
||||||
|
esac
|
||||||
:>"$playlistfile"
|
:>"$playlistfile"
|
||||||
|
|
||||||
# Remove duplicates in playlists
|
# Remove duplicates in playlists
|
||||||
for playlist in "$playlistdir"/*.m3u; do
|
for playlist in "$playlistdir"/*.m3u; do
|
||||||
awk '!seen[$0]++' "$playlist" > "${playlist}.tmp"
|
awk '!seen[$0]++' "${playlist}" > "${playlist}.tmp"
|
||||||
if [[ -f "${playlist}.tmp" ]]; then
|
if [[ -f "${playlist}.tmp" ]]; then
|
||||||
rm -f "$playlist"
|
rm -f "$playlist"
|
||||||
mv "${playlist}.tmp" "$playlist"
|
mv "${playlist}.tmp" "$playlist"
|
||||||
|
|
Loading…
Reference in a new issue