diff options
Diffstat (limited to 'sys')
5 files changed, 202 insertions, 58 deletions
diff --git a/sys/nixpkgs/pkgs/scripts/default.nix b/sys/nixpkgs/pkgs/scripts/default.nix index 6ef59b0e..6353e690 100644 --- a/sys/nixpkgs/pkgs/scripts/default.nix +++ b/sys/nixpkgs/pkgs/scripts/default.nix @@ -306,10 +306,28 @@ dependencies = builtins.attrValues {inherit (prev) mediainfo jq gawk;}; }; - spodi-scr = write_shell { + spodi-scr = sysLib.writeShellScriptMultiPart { name = "spodi"; - path = "wrappers"; - dependencies = builtins.attrValues {inherit (prev) gawk expect spotdl fd coreutils;}; + keepPath = false; + src = ./source/specific/spodi; + baseName = "spodi.sh"; + cmdPrefix = "sh"; + cmdNames = [ + "download.sh" + "update.sh" + ]; + dependencies = with prev; [ + gawk + expect + spotdl + fd + coreutils + ]; + generateCompletions = true; + replacementStrings = { + XDG_CACHE_HOME = config.xdg.cacheHome; + XDG_MUSIC_DIR = config.xdg.userDirs.music; + }; }; update-sys-scr = write_shell { diff --git a/sys/nixpkgs/pkgs/scripts/source/specific/spodi/sh/download.sh b/sys/nixpkgs/pkgs/scripts/source/specific/spodi/sh/download.sh new file mode 100755 index 00000000..fe9746c8 --- /dev/null +++ b/sys/nixpkgs/pkgs/scripts/source/specific/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 diff --git a/sys/nixpkgs/pkgs/scripts/source/specific/spodi/sh/update.sh b/sys/nixpkgs/pkgs/scripts/source/specific/spodi/sh/update.sh new file mode 100755 index 00000000..a289cf58 --- /dev/null +++ b/sys/nixpkgs/pkgs/scripts/source/specific/spodi/sh/update.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env dash + +update() { + UPDATE_DIRECTORY="%XDG_MUSIC_DIR/artists" + UPDATE_CONFIG_FILE="%XDG_MUSIC_DIR/artists/update.conf" + + if ! [ -f "$UPDATE_CONFIG_FILE" ]; then + error="$( + cat <<EOF +Please provide an update config file at: '$UPDATE_CONFIG_FILE'. + +The 'update.conf' file should follow this pattern: +<path_to_artist>/<artist_name>|<spotify_url> + +All comments and empty lines are ignored +EOF + )" + die "$error" + fi + + config_file="$(mktmp)" + clean "$UPDATE_CONFIG_FILE" >"$config_file" + + while IFS="|" read -r artist url; do + full_artist="$UPDATE_DIRECTORY/$artist" + [ -d "$full_artist" ] || mkdir --parents "$full_artist" + [ -d "$full_artist/update" ] || mkdir --parents "$full_artist/update" + [ -d "$full_artist/all" ] || mkdir --parents "$full_artist/all" + [ -d "$full_artist/filtered" ] || mkdir --parents "$full_artist/filtered" + + while read -r file; do + ln --symbolic --relative "$file" "$full_artist/update/$(basename "$file")" + done <"$(tmp fd --type file --extension opus . "$full_artist/all")" + + msg2 "Updating $artist with url: '$url'" + download "$url" "$full_artist/update" + + while read -r file; do + mv "$file" "$full_artist/all" + ln --symbolic --relative "$full_artist/all/$(basename "$file")" "$full_artist/filtered/$(basename "$file")" + done <"$(tmp fd --type file --extension opus . "$full_artist/update")" + + while read -r file; do + rm "$file" + done <"$(tmp fd --type symlink --extension opus . "$full_artist/update")" + + cp "$full_artist/update/spotdl.log" "$full_artist/all/spotdl.$(date +%Y_%m_%d).log" + cp "$full_artist/update/spotdl-errors.log" "$full_artist/all/spotdl-errors.$(date +%Y_%m_%d).log" + done <"$config_file" +} + +# vim: ft=sh diff --git a/sys/nixpkgs/pkgs/scripts/source/specific/spodi/spodi.sh b/sys/nixpkgs/pkgs/scripts/source/specific/spodi/spodi.sh new file mode 100755 index 00000000..a62c6e1d --- /dev/null +++ b/sys/nixpkgs/pkgs/scripts/source/specific/spodi/spodi.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="2.1.1" . %SHELL_LIBRARY_PATH + +# these are used in version() +# shellcheck disable=2034 +AUTHORS="Soispha" +# shellcheck disable=2034 +YEARS="2023" + +# load dependencies +. ./sh/update.sh +. ./sh/download.sh + +help() { + cat <<EOF +This is a small wrapper around downloading things from spotify + +USAGE: + $NAME [OPTIONS] COMMAND + +OPTIONS: + --help | -h + Display this help and exit. + + --version | -v + Display version and copyright information and exit. +COMMANDS: + update + Read the artist.conf file and download all newly released things + + download URL + Download a specific url to the DOWNLOAD_DIRECTORY +EOF +} + +for arg in "$@"; do + case "$arg" in + "--help" | "-h") + help + exit 0 + ;; + "--version" | "-v") + version + exit 0 + ;; + esac +done + +case "$1" in +"update") + shift 1 + update + exit 0 + ;; +"download") + shift 1 + download_url="$1" + [ -z "$download_url" ] && die "You need to provide a download url" + download_to_down "$download_url" + exit 0 + ;; +*) + die "Command '$1' is not know" + help + exit 1 + ;; +esac + +# vim: ft=sh diff --git a/sys/nixpkgs/pkgs/scripts/source/wrappers/spodi.sh b/sys/nixpkgs/pkgs/scripts/source/wrappers/spodi.sh deleted file mode 100755 index 09b932ce..00000000 --- a/sys/nixpkgs/pkgs/scripts/source/wrappers/spodi.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="2.1.1" . %SHELL_LIBRARY_PATH - -# This path must not contain spaces -DOWN_DIR="/home/soispha/media/music/down/spotify" - -download_url="$1" - -already_downloaded_files="$(mktmp)" -fd . "$DOWN_DIR" --exclude spotdl.log --exclude spotdl-errors.log >"$already_downloaded_files" - -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 /home/soispha/.cache/spotdl/.spotipy - -# Output options ---preload ---format opus ---output {artists}_-_{title} ---print-errors ---save-errors $DOWN_DIR/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 - -if [ -z "$NO_CHECK" ] && [ "$(wc -l <"$already_downloaded_files")" -ne 0 ]; then - die "something is already downloaded" -fi - -rm "$DOWN_DIR/spotdl.log" -cd "$DOWN_DIR" || die "BUG: no $DOWN_DIR" -touch "$DOWN_DIR/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 "$DOWN_DIR/spotdl.log" - -[ -d ~/.spotdl ] && rm -r ~/.spotdl -# vim: ft=sh |