about summary refs log tree commit diff stats
path: root/pkgs/by-name/sp/spodi/sh/download.sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-23 13:26:22 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-23 13:26:22 +0200
commit204731c0a69136c9cebcb54f1afecf5145e26bbe (patch)
treefc9132e5dc74e4a8e1327cdd411839a90f9410aa /pkgs/by-name/sp/spodi/sh/download.sh
parentrefactor(sys): Modularize and move to `modules/system` or `pkgs` (diff)
downloadnixos-config-204731c0a69136c9cebcb54f1afecf5145e26bbe.zip
refactor(pkgs): Categorize into `by-name` shards
This might not be the perfect way to organize a package set --
especially if the set is not nearly the size of nixpkgs -- but it is
_at_ least a way of organization.
Diffstat (limited to 'pkgs/by-name/sp/spodi/sh/download.sh')
-rwxr-xr-xpkgs/by-name/sp/spodi/sh/download.sh58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkgs/by-name/sp/spodi/sh/download.sh b/pkgs/by-name/sp/spodi/sh/download.sh
new file mode 100755
index 00000000..fe9746c8
--- /dev/null
+++ b/pkgs/by-name/sp/spodi/sh/download.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env dash
+
+download_to_down() {
+    DOWNLOAD_DIRECTORY="%XDG_MUSIC_DIR/down/spotify"
+
+    already_downloaded_files="$(mktmp)"
+    fd . "$DOWNLOAD_DIRECTORY" --exclude spotdl.log --exclude spotdl-errors.log >"$already_downloaded_files"
+    if [ -z "$NO_CHECK" ] && [ "$(wc -l <"$already_downloaded_files")" -ne 0 ]; then
+        die "something is already downloaded"
+    fi
+    # [ -e "$DOWNLOAD_DIRECTORY/spotdl.log" ] && rm "$DOWNLOAD_DIRECTORY/spotdl.log"
+
+    download "$1" "$DOWNLOAD_DIRECTORY"
+}
+
+download() {
+    download_url="$1"
+    output_path="$2"
+
+    config="$(mktmp)"
+    cat <<EOF | clean >"$config"
+# Main options
+--audio slider-kz bandcamp youtube-music piped youtube soundcloud
+--lyrics genius musixmatch azlyrics synced
+
+# FFmpeg options
+--ffmpeg ffmpeg
+--threads 16
+--bitrate 256k
+
+# Spotify options
+--cache-path %XDG_CACHE_HOME/spotdl/.spotipy
+
+# Output options
+--preload
+--format opus
+--output {artists}_-_{title}
+--print-errors
+--save-errors $output_path/spotdl-errors.log
+# TODO: Reactive whence spotdl support for these has improved <2023-12-19>
+# --generate-lrc
+--overwrite skip
+
+# Misc options
+--log-level INFO
+EOF
+
+    cd "$output_path" || die "BUG: no $output_path"
+    touch "$output_path/spotdl-errors.log"
+
+    # The sub shell needs to be unquoted, as the arguments may not be treated as one.
+    # shellcheck disable=2046
+    unbuffer spotdl $(cat "$config") download "$download_url" | tee "$output_path/spotdl.log"
+
+    [ -d ~/.spotdl ] && rm -r ~/.spotdl
+}
+
+# vim: ft=sh