2016-12-23 00:10:40 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Delete all songs that are in the delete-pls playlist, and cleans up any empty folders
|
|
|
|
# it leaves behind.
|
|
|
|
|
2016-12-28 23:39:21 -08:00
|
|
|
set -e
|
2017-02-28 16:04:35 -08:00
|
|
|
shopt -s nullglob
|
2016-12-28 23:39:21 -08:00
|
|
|
|
2017-02-28 16:04:35 -08:00
|
|
|
playlistdir=$(grep playlist_directory "$HOME/.config/mpd/mpd.conf" | awk '{ print $2; }')
|
2017-01-05 22:30:22 -08:00
|
|
|
playlistdir="${playlistdir//\"/}"
|
2017-02-28 16:04:35 -08:00
|
|
|
playlistfile="${playlistdir/#\~/$HOME}/1-star.m3u"
|
|
|
|
songs=$(cat "$playlistfile")
|
2016-12-23 00:10:40 -08:00
|
|
|
|
|
|
|
# Delete designated songs
|
|
|
|
IFS="
|
|
|
|
"
|
2017-02-28 16:04:35 -08:00
|
|
|
declare -a to_delete=()
|
|
|
|
for song in "${songs[@]}"; do
|
2016-12-23 00:10:40 -08:00
|
|
|
fpath="$HOME/music/$song"
|
|
|
|
if [[ -f $fpath ]]; then
|
2017-02-28 16:04:35 -08:00
|
|
|
to_delete+=("$fpath")
|
|
|
|
# echo "Deleting: $song"
|
|
|
|
# rm -f "$fpath"
|
2016-12-23 00:10:40 -08:00
|
|
|
fi
|
|
|
|
done
|
2017-02-28 16:04:35 -08:00
|
|
|
|
|
|
|
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
|
2016-12-23 00:10:40 -08:00
|
|
|
:>"$playlistfile"
|
|
|
|
|
2017-01-05 22:30:30 -08:00
|
|
|
# Remove duplicates in playlists
|
|
|
|
for playlist in "$playlistdir"/*.m3u; do
|
2017-02-28 16:04:35 -08:00
|
|
|
awk '!seen[$0]++' "${playlist}" > "${playlist}.tmp"
|
2017-01-05 22:30:30 -08:00
|
|
|
if [[ -f "${playlist}.tmp" ]]; then
|
|
|
|
rm -f "$playlist"
|
|
|
|
mv "${playlist}.tmp" "$playlist"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-12-28 23:39:21 -08:00
|
|
|
# Remove empty directories
|
|
|
|
find "$HOME/music" -type d -empty -delete
|