86 lines
2.3 KiB
Bash
86 lines
2.3 KiB
Bash
|
|
# --- Bandcamp ----------------------------------------------------------------
|
|
|
|
# bandcampdl <url>: 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 <bandcamp-url>"
|
|
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 <file>: 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 <url-file>"
|
|
return 1
|
|
fi
|
|
|
|
while IFS= read -r url; do
|
|
[[ -z "$url" || "$url" == \#* ]] && continue
|
|
bandcampdl "$url"
|
|
done < "$file"
|
|
}
|
|
|
|
# bandcamplist <https://band.bandcamp.com/music> [output.txt]:
|
|
# write all album/track URLs of an artist to a file
|
|
# (default: bandcamp-<band>.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 <https://band.bandcamp.com/music> [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."
|
|
}
|