Compare commits

...

4 Commits

4 changed files with 76 additions and 56 deletions

View File

@ -1,10 +1,16 @@
#!/bin/sh
set -euf
# TODO: maybe make it so we're in an "updating" or "not" state?
# would have to keep tabs with an existing description file and go from there
# for now we don't gotta worry about it too much
BN="${0##*/}"
NL='
'
OSTYPE=linux-gnu . "$HOME/.local/python-venv/bin/activate"
# HELPER FUNCTIONS #
errecho() {
>&2 echo "$*"
}
@ -15,10 +21,14 @@ fail() {
}
clean() {
[ -f "$FILE" ] && rm -f "$FILE"
trap 'exit' INT HUP QUIT TERM EXIT
[ -f "$HTML_FILE" ] && rm -f "$HTML_FILE"
[ -f "$json" ] && rm -f "$json"
exit
}
trap 'clean' INT HUP QUIT TERM EXIT
# OPTIONS #
no_download=""
while getopts :n OPT; do
case $OPT in
@ -32,28 +42,34 @@ case $1 in
*.bandcamp.com*) : ;;
*) fail 'Please use the *.bandcamp.com link instead of any custom domains!' ;;
esac
IFS="/" read -r _ _ FILE _ <<-EOF
IFS="/" read -r _ _ BANDCAMP_DOMAIN _ <<-EOF
$1
EOF
mkdir -p "$FILE"; cd "$FILE"
logdir="${XDG_DATA_HOME:-$HOME/.local/share}/discogarchive/$FILE"
mkdir -p "$BANDCAMP_DOMAIN"; cd "$BANDCAMP_DOMAIN"
logdir="${XDG_DATA_HOME:-$HOME/.local/share}/discogarchive"
mkdir -p "$logdir"
FILE="/tmp/$FILE.html"
BASEURL="${1%/*}" # always evaluates to the domain without trailing /, /music or not
HTML_FILE="/tmp/$BANDCAMP_DOMAIN.html"
BASEURL="https://$BANDCAMP_DOMAIN"
# 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'
common shorthands:
web=website, sc=soundcloud, yt=youtube, tw=twitch, tr=twitter, mx=mixcloud,
ig=instagram, sp=spotify, lt=Linktree, ch=Cohost'
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 ;;
web) key=Website ;;
sc) key=SoundCloud ;;
yt) key=YouTube ;;
tw) key=Twitch ;;
tr) key=Twitter ;;
m) key=Mixcloud ;;
mx) key=Mixcloud ;;
ig) key=Instagram ;;
sp) key=Spotify ;;
lt) key=Linktree ;;
ch) key=Cohost ;;
"") break ;;
*) : ;;
esac
@ -62,56 +78,53 @@ done
socials="$(printf '%s' "$socials" | sort)$NL"
errecho 'Moving on!'
trap 'clean' INT HUP QUIT EXIT
curl -L -s -o "$FILE" "$1"
# HTML/JSON PARSING #
curl -L -s -o "$HTML_FILE" "$1"
tmplog="" look_closer="" uncontained_albums="" uncontained_tracks="" contained_albums="" contained_tracks=""
tmplog="" look_closer="" uncontained_releases="" contained_releases=""
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.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.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"
while read -r url; do
# if rg -q -F "$url" "$logdir/log" 2>/dev/null; then
# errecho "ALREADY CONTAINED $type: $url"
# tmplog="$tmplog$url CONTAINED$NL"
# continue
# fi
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.0" ]; then
look_closer="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>$NL$look_closer"
errecho "LOOK CLOSER: $url"
elif [ "$(jq 'if (.inAlbum) then .inAlbum.albumRelease[0].offers.price else .albumRelease[0].offers.price end' < "$json")" = "0.0" ]; then
contained_releases="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>${NL}${contained_releases}"
errecho "CONTAINED RELEASE: $artist - $name"
if ! rg -q -F "$url" "$logdir/log" 2>/dev/null; then
echo "$url" >> "$logdir/log"
fi
done <<-EOF
$(rg -e '"(/'"$type"'/.+)"' -or "$BASEURL"'$1' "$FILE")
EOF
done
echo "$tmplog" > "$logdir/log"
else
uncontained_releases="<a href=\"$url\" rel=\"nofollow\">$artist - $name</a><br>${NL}${uncontained_releases}"
errecho "UNCONTAINED RELEASE: $artist - $name"
fi
done <<-EOF
$(rg -e '"(/(album|track)/.+)"' -or "$BASEURL"'$1' "$HTML_FILE")
EOF
# 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"
if [ -n "${uncontained_releases}" ]; then
uncontained_releases="$NL<br><div><b>Uncontained Releases</b></div>$NL$uncontained_releases"
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"
contained_releases="$NL<br><div><b>Contained Releases</b></div>$NL$contained_releases"
printf '%s%s%s%s%s%s' \
"${look_closer:+$look_closer$NL}" "$socials" "$uncontained_albums" "$uncontained_tracks" "$contained_albums" "$contained_tracks" > DESCRIPTION.html
printf '%s%s%s%s' \
"${look_closer:+$look_closer$NL}" "$socials" "$uncontained_releases" "$contained_releases" > 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")"
img="$(pup 'img.band-photo' 'attr{src}' < "$HTML_FILE")"
if [ -n "$img" ]; then
ext="${img##*.}"
curl -s -o ./files/artist."$ext" "${img%_*}_0.$ext"
@ -119,8 +132,9 @@ if [ ! "$no_download" ]; then
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
set +f
if [ ./files/*.flac != "./files/*.flac" ]; then
mkdir ./files/TRACKS
mv ./files/*.flac ./files/TRACKS
fi
fi

View File

@ -28,18 +28,17 @@ for resrec; do
curl -s "$asseturi" | tail -c +10 | brotli -d | bson2json > "$tmp_json"
while read -r argline; do
echo "$argline"
eval "set -- $argline"
outfile="$outdir/$timestamp.webp"
imguri=$1
echo "downloading image $timestamp.webp"
curl -s -o "$tmpfile" "$imguri"
aria2c -q -d / --allow-overwrite=true --auto-file-renaming=false -o "$tmpfile" "$imguri"
if [ $# -gt 1 ]; then
meta_place=$2
meta_host=$3
meta_photographer=$4
meta_time=$(date -u -d "@$5" +'%Y:%m:%d %H:%M:%S')
shift 4
shift 5
meta_presentusers=$(sed 's/ /, /g' <<-EOF
$*
EOF
@ -79,7 +78,14 @@ Present Users: $meta_presentusers" "$tmpfile" \
select(.Type=="FrooxEngine.PhotoMetadata").Data.TimeTaken.Data/1000,
select(.Type=="FrooxEngine.PhotoMetadata").Data.UserInfos.Data[].User._userId.Data
]
| select(. != []) | @sh' < "$tmp_json")
| select(. != []) | @sh' < "$tmp_json" \
|| jq -r '.Object.Children | .. | objects | .Components.Data | select(. != null)
| [ .[]
| ( select(.Type=="FrooxEngine.StaticTexture2D").Data.URL.Data
| sub("@(resdb:///(?<x>[^.]+))?.*";"https://assets.resonite.com/\(.x)")
)
]
| select(. != []) | @sh' < "$tmp_json")
EOF
done

View File

@ -1,7 +1,7 @@
#!/bin/sh
# DEFAULT OPTIONS
INSTANCE="https://translate.slipfox.xyz"
INSTANCE="https://translate.bus-hit.me"
ENGINE="google"
FLANG="auto"
TLANG="en"

View File

@ -14,7 +14,7 @@ shift $((OPTIND - 1))
for url; do
filename="$(yt-dlp -O '%(upload_date>%Y-%m-%d)s %(title)s.%(ext)s' "$url" | sed 's/\//_/g')"
if [ -z "${novod:-}" ]; then
yt-dlp ${quality:+-f "$quality"} -o "$filename" "$url"
yt-dlp ${quality:+-f "$quality"} -o "$filename" "$url"
fi
if [ -z "${nochat:-}" ]; then