Skip to content

Instantly share code, notes, and snippets.

@vimagick
Last active March 30, 2024 05:21
Show Gist options
  • Save vimagick/a74d08c46126e364d11acfd624b75542 to your computer and use it in GitHub Desktop.
Save vimagick/a74d08c46126e364d11acfd624b75542 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/bash
#
# Background Music / Sound Effects Downloader
#
BASE_URL=https://www.tukuppt.com
IDX_URL=$BASE_URL/peiyueso/shipin5097/__zonghe_0_0_0_0_0_0_%d.html
#IDX_URL=$BASE_URL/yinxiaomuban/shipin/__zonghe_0_0_0_0_0_0_%d.html
API_URL=$BASE_URL/api/audio
TOTAL_PAGES=46
#TOTAL_PAGES=50
HTTP_PROXY=
OUTPUT_FILE=tukuppt-background-music.jsonl
#OUTPUT_FILE=tukuppt-sound-effects.jsonl
declare -a SEEN
readarray -t SEEN < <(jq -r '.id' $OUTPUT_FILE)
echo "### Previous Downloaded: ${#SEEN[@]} ###" >&2
for ((page=1;page<=$TOTAL_PAGES;page++)); do
url=$(printf "$IDX_URL" $page)
html=$(curl -s "$url")
count=0
paste <(echo "$html" | pup 'dl i attr{value}') \
<(echo "$html" | pup 'dl dt .title text{}') \
<(echo "$html" | pup 'dl dt .title attr{href}') \
<(echo "$html" | pup 'dl .end-time text{}') |
while IFS=$'\t' read id title url time; do
echo -n "#$page.$((++count)): $title ($time) " >&2
if printf '%s\0' "${SEEN[@]}" | grep -qFxz -- "$id"; then
echo "☑️" >&2
continue
fi
duration=$(date -d "1970-01-01T00:${time} UTC" "+%s")
download=$(curl -s -m5 ${HTTP_PROXY:+-x $HTTP_PROXY} -e $BASE_URL $API_URL -d value=$id | jq -r '.data.swf')
if (($? == 0)); then
jq -n -c --arg id "$id" \
--arg title "$title" \
--argjson duration "$duration" \
--arg url "$BASE_URL$url" \
--arg download "$download" '{$id, $title, $duration, $url, $download}' >> $OUTPUT_FILE
echo "✅" >&2
else
echo "❌" >&2
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment