54 lines
1.7 KiB
Bash
Executable File
54 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -euf
|
|
|
|
BN="${0##*/}"
|
|
NL='
|
|
'
|
|
|
|
errecho() {
|
|
>&2 echo "$*"
|
|
}
|
|
|
|
fail() {
|
|
errecho "error: $BN: $*"
|
|
exit 1
|
|
}
|
|
|
|
clean() {
|
|
rm -f "$FILE"
|
|
rm -f "$tmpfile"
|
|
}
|
|
|
|
FILE="/tmp/$(printf '%s' "$1" | cut -d '/' -f 3).html"
|
|
BASEURL="${1%/*}"
|
|
trap 'clean' INT HUP QUIT EXIT
|
|
curl -s "$1" -o "$FILE"
|
|
|
|
tmpfile="$(mktemp -u)"
|
|
# albums and tracks
|
|
for type in album track; do
|
|
while IFS= read -r url; do
|
|
curl -s -o "$tmpfile" "$url"
|
|
artist="$(pup 'script[type="application/ld+json"]' 'text{}' <"$tmpfile" | jq -r '.byArtist.name')"
|
|
name="$(pup 'script[type="application/ld+json"]' 'text{}' <"$tmpfile" | jq -r '.name')"
|
|
if [ "$(pup 'span:contains("name your price"), button:contains("Free Download")' <"$tmpfile")" ]; then
|
|
eval 'contained_'"$type"'s="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>${NL}${contained_'"$type"'s:-}"'
|
|
echo "CONTAINED $type: $artist - $name"
|
|
else
|
|
eval 'uncontained_'"$type"'s="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>${NL}${uncontained_'"$type"'s:-}"'
|
|
echo "UNCONTAINED $type: $artist - $name"
|
|
fi
|
|
done <<-EOF
|
|
$(rg -e '"(/'"$type"'/.+)"' -or "$BASEURL"'$1' "$FILE")
|
|
EOF
|
|
done
|
|
|
|
if [ "${uncontained_albums:-}" ] || [ "${uncontained_tracks:-}" ]; then
|
|
printf '<div><b>Uncontained Releases</b></div>\n%s\n%s\n<div><b>Contained Releases</b></div>\n%s\n%s\n' \
|
|
"${uncontained_albums:+$uncontained_albums<br>}" "${uncontained_tracks:+<u>SINGLES</u><br>$uncontained_tracks<br>}" \
|
|
"${contained_albums:+$contained_albums}" "${contained_tracks:+<br><u>SINGLES</u><br>$NL$contained_tracks}"
|
|
else
|
|
printf '<div><b>Contained Releases</b></div>\n%s\n%s\n' \
|
|
"${contained_albums:+$contained_albums}" "${contained_tracks:+<br><u>SINGLES</u><br>$NL$contained_tracks}"
|
|
fi
|