From 7b92d12d42fe0cfcd86a4bb983d9d2641701db5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Sun, 12 May 2024 18:00:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(scripts):=20avoid?= =?UTF-8?q?=20harcoding=20values=20in=20downloadSpotify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .local/bin/downloadSpotify | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.local/bin/downloadSpotify b/.local/bin/downloadSpotify index 1eae26ad..ec695908 100755 --- a/.local/bin/downloadSpotify +++ b/.local/bin/downloadSpotify @@ -9,23 +9,19 @@ if ! command -v spotdl &>/dev/null; then exit 1 fi -FOLDERS=( - "EDM-House" - "Metal-Rock" - "Synth-Chill" - "Lofi-Sleppy" - "Space-Cyberpunk" - "Cyberpunk-Darksynth" -) +MUSIC_FOLDER="$HOME/Musica/Listen-To" notify "Started syncing..." -for FOLDER in "${FOLDERS[@]}"; do - cd "$HOME/Musica/Listen-To/$FOLDER" || continue +while IFS= read -r -d '' FOLDER; do + FOLDER_NAME=$(basename "$FOLDER") - spotdl sync "${FOLDER,,}.spotdl" - - notify "$FOLDER synced" -done + SPOTDL_FILE=$(find "$FOLDER" -maxdepth 1 -type f -name '*.spotdl' -print -quit) + if [ -n "$SPOTDL_FILE" ]; then + cd "$(dirname "$SPOTDL_FILE")" || continue + spotdl sync "$(basename "$SPOTDL_FILE")" + notify "Synced $FOLDER_NAME" + fi +done < <(find "$MUSIC_FOLDER" -mindepth 1 -maxdepth 1 -type d -print0) notify "Spotdl Sync Complete"