127 lines
4.0 KiB
Bash
Executable File
127 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
set -euf
|
|
|
|
BN="${0##*/}"
|
|
NL='
|
|
'
|
|
|
|
errecho() {
|
|
>&2 echo "$*"
|
|
}
|
|
|
|
fail() {
|
|
errecho "error: $BN: $*"
|
|
exit 1
|
|
}
|
|
|
|
clean() {
|
|
[ -f "$FILE" ] && rm -f "$FILE"
|
|
[ -f "$json" ] && rm -f "$json"
|
|
}
|
|
|
|
no_download=""
|
|
while getopts :n OPT; do
|
|
case $OPT in
|
|
n) no_download=1 ;; # don't download files, just make the description.html
|
|
*) fail "unknown option: -$OPTARG" ;;
|
|
esac
|
|
done
|
|
shift "$((OPTIND - 1))"
|
|
|
|
case $1 in
|
|
*.bandcamp.com*) : ;;
|
|
*) fail 'Please use the *.bandcamp.com link instead of any custom domains!' ;;
|
|
esac
|
|
IFS="/" read -r _ _ FILE _ <<-EOF
|
|
$1
|
|
EOF
|
|
mkdir -p "$FILE"; cd "$FILE"
|
|
logdir="${XDG_DATA_HOME:-$HOME/.local/share}/discogarchive/$FILE"
|
|
mkdir -p "$logdir"
|
|
|
|
FILE="/tmp/$FILE.html"
|
|
BASEURL="${1%/*}" # always evaluates to the domain without trailing /, /music or not
|
|
|
|
# SOCIALS #
|
|
errecho 'input artist socials in KEY=VALUE format. blank line to continue. bandcamp is already filled
|
|
common shorthands: w=website, s=soundcloud, y=youtube, tw=twitch, tr=twitter, m=mixcloud'
|
|
socials="<a href=\"$BASEURL\" rel=\"nofollow\">Bandcamp</a><br>$NL"
|
|
while IFS="=" read -r key val; do
|
|
case "$key" in
|
|
w) key=Website ;;
|
|
s) key=SoundCloud ;;
|
|
y) key=YouTube ;;
|
|
tw) key=Twitch ;;
|
|
tr) key=Twitter ;;
|
|
m) key=Mixcloud ;;
|
|
"") break ;;
|
|
*) : ;;
|
|
esac
|
|
socials="$socials<a href=\"$val\" rel=\"nofollow\">$key</a><br>$NL"
|
|
done
|
|
socials="$(printf '%s' "$socials" | sort)$NL"
|
|
errecho 'Moving on!'
|
|
|
|
trap 'clean' INT HUP QUIT EXIT
|
|
curl -L -s -o "$FILE" "$1"
|
|
|
|
tmplog="" look_closer="" uncontained_albums="" uncontained_tracks="" contained_albums="" contained_tracks=""
|
|
json="$(mktemp -u)"
|
|
# albums and tracks
|
|
for type in album track; do
|
|
while IFS= read -r url; do
|
|
curl -L -s -o - "$url" | pup 'script[type="application/ld+json"]' 'text{}' > "$json" || continue
|
|
artist="$(jq -r '.byArtist.name' < "$json")"
|
|
name="$(jq -r '.name' < "$json")"
|
|
if [ "$(jq '.numTracks' < "$json")" = "0" ]; then
|
|
look_closer="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>$NL$look_closer"
|
|
errecho "LOOK CLOSER: $url"
|
|
tmplog="$tmplog$url LOOK_CLOSER$NL"
|
|
elif [ "$(jq 'if (.inAlbum) then .inAlbum.albumRelease[0].offers.price else .albumRelease[0].offers.price end' < "$json")" = "0" ]; then
|
|
eval 'contained_'"$type"'s="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>${NL}${contained_'"$type"'s}"'
|
|
errecho "CONTAINED $type: $artist - $name"
|
|
tmplog="$tmplog$url CONTAINED$NL"
|
|
if rg -F "$url UNCONTAINED" "$logdir/log" >/dev/null 2>&1; then
|
|
errecho "- was updated from UNCONTAINED to CONTAINED! $url"
|
|
fi
|
|
else
|
|
eval 'uncontained_'"$type"'s="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>${NL}${uncontained_'"$type"'s}"'
|
|
errecho "UNCONTAINED $type: $artist - $name"
|
|
tmplog="$tmplog$url UNCONTAINED$NL"
|
|
fi
|
|
done <<-EOF
|
|
$(rg -e '"(/'"$type"'/.+)"' -or "$BASEURL"'$1' "$FILE")
|
|
EOF
|
|
done
|
|
echo "$tmplog" > "$logdir/log"
|
|
|
|
# formatting the description
|
|
if [ -n "${uncontained_albums}" ] || [ -n "${uncontained_tracks}" ]; then
|
|
uncontained_albums="$NL<br><div><b>Uncontained Releases</b></div>$NL$uncontained_albums"
|
|
[ -n "$uncontained_tracks" ] && uncontained_tracks="$NL<br><div><u>SINGLES</u></div>$NL$uncontained_tracks"
|
|
fi
|
|
[ -n "$contained_tracks" ] && contained_tracks="$NL<br><div><u>SINGLES</u></div>$NL$contained_tracks"
|
|
contained_albums="$NL<br><div><b>Contained Releases</b></div>$NL$contained_albums"
|
|
|
|
printf '%s%s%s%s%s%s' \
|
|
"${look_closer:+$look_closer$NL}" "$socials" "$uncontained_albums" "$uncontained_tracks" "$contained_albums" "$contained_tracks" > DESCRIPTION.html
|
|
|
|
# download shit
|
|
if [ ! "$no_download" ]; then
|
|
mkdir -p "files"
|
|
printf '%s' 'CAT.ALL' > ./files/_rules.conf
|
|
# artist img
|
|
img="$(pup 'img.band-photo' 'attr{src}' < "$FILE")"
|
|
if [ -n "$img" ]; then
|
|
ext="${img##*.}"
|
|
curl -s -o ./files/artist."$ext" "${img%_*}_0.$ext"
|
|
fi
|
|
errecho "Done with retrieving metadata! Now to download..."
|
|
bcdl-free --no-unzip -z 12345 -f FLAC -d "./files" -e auto -l "$BASEURL"
|
|
|
|
if [ "$(echo ./files/*.flac)" != "./files/*.flac" ]; then
|
|
mkdir ./files/SINGLES
|
|
mv ./files/*.flac ./files/SINGLES
|
|
fi
|
|
fi
|