# --- Bandcamp ---------------------------------------------------------------- # bandcampdl : download an album/track as MP3 (best quality) with # metadata and cover art, sorted into Artist/Year - Album/ bandcampdl() { if [[ -z "$1" ]]; then echo "Usage: bandcampdl " return 1 fi yt-dlp \ -x \ --audio-format mp3 \ --audio-quality 0 \ --embed-metadata \ --embed-thumbnail \ --convert-thumbnails jpg \ -o "%(album_artist)s/%(release_year)s - %(album)s/%(album_artist)s - %(album)s - %(track_number)02d - %(title)s.%(ext)s" \ "$1" } # bandcampbatch : run bandcampdl for every URL in a file # (empty lines and lines starting with # are skipped) bandcampbatch() { local file="$1" url if [[ ! -r "$file" ]]; then echo "Usage: bandcampbatch " return 1 fi while IFS= read -r url; do [[ -z "$url" || "$url" == \#* ]] && continue bandcampdl "$url" done < "$file" } # bandcamplist [output.txt]: # write all album/track URLs of an artist to a file # (default: bandcamp-.txt) - input for bandcampbatch bandcamplist() { local url outfile tmpfile band count if (( ! $+commands[yt-dlp] )); then echo "Fehler: yt-dlp wurde nicht gefunden." return 1 fi if (( $# < 1 || $# > 2 )); then echo "Usage:" echo " bandcamplist [output.txt]" return 1 fi url="$1" # zsh stores capture groups of =~ in $match if [[ ! "$url" =~ ^https?://([^.]+)\.bandcamp\.com/music/?$ ]]; then echo "Fehler: Keine gueltige Bandcamp-/music-URL:" echo " $url" return 1 fi band="${match[1]}" outfile="${2:-bandcamp-${band}.txt}" tmpfile=$(mktemp) if ! yt-dlp --flat-playlist --print webpage_url "$url" | sort -u > "$tmpfile"; then rm -f "$tmpfile" echo "Fehler beim Abrufen der Links." return 1 fi count=$(wc -l < "$tmpfile") if (( count == 0 )); then rm -f "$tmpfile" echo "Keine Album- oder Track-Links gefunden." return 1 fi mv "$tmpfile" "$outfile" echo "✓ $count Links nach '$outfile' geschrieben." }