Even better progress indication
This commit is contained in:
parent
b249277fb5
commit
12612a5008
36
download.sh
36
download.sh
|
@ -4,7 +4,7 @@
|
||||||
# BASE64_BEARER_TOKEN='<literal base64 encoded string>'
|
# BASE64_BEARER_TOKEN='<literal base64 encoded string>'
|
||||||
source .env
|
source .env
|
||||||
|
|
||||||
OUTFILE_PATTERN="./videos/video_INDEX.mp4"
|
OUTDIR="./videos"
|
||||||
|
|
||||||
read -r -d '' API_URL <<- 'EOM'
|
read -r -d '' API_URL <<- 'EOM'
|
||||||
https://euwe-1.api.microsoftstream.com/api/videos?
|
https://euwe-1.api.microsoftstream.com/api/videos?
|
||||||
|
@ -42,24 +42,34 @@ API_URL="$(
|
||||||
tr -d '\n'
|
tr -d '\n'
|
||||||
)"
|
)"
|
||||||
|
|
||||||
mkdir -p "$(dirname "${OUTFILE_PATTERN}")" || { printf '\033[31m%s\033[m\n' 'Aborting'; exit; }
|
mkdir -p "${OUTDIR}" || { printf '\033[31m%s\033[m\n' 'Aborting'; exit; }
|
||||||
|
|
||||||
m3u8_manifest_urls=$(
|
# '>' without quotes is delimiter, since it's one of the few chars disallowed in a URL. Title must not include this char
|
||||||
wget --no-verbose --quiet -O- --header="authorization: Bearer ${BASE64_BEARER_TOKEN}" "${API_URL}" | \
|
# https://www.ietf.org/rfc/rfc2396.txt
|
||||||
jq -r '.value[].playbackUrls | map(select(.mimeType == "application/vnd.apple.mpegurl")) | .[].playbackUrl'
|
# 2.4.3. Excluded US-ASCII Characters
|
||||||
|
m3u8_manifest_urls_and_metadata=$(
|
||||||
|
wget --no-verbose --quiet -O- --header="authorization: Bearer ${BASE64_BEARER_TOKEN}" "${API_URL}" |
|
||||||
|
jq -r '.value[] | .name + ">" + .media.duration[2:] + ">" + (.playbackUrls | map(select(.mimeType == "application/vnd.apple.mpegurl")) | .[].playbackUrl)'
|
||||||
)
|
)
|
||||||
|
|
||||||
if [ -z "${m3u8_manifest_urls}" ]; then
|
if [ -z "${m3u8_manifest_urls_and_metadata}" ]; then
|
||||||
printf '\033[31m%s\033[m\n' 'Error GETting manifest urls (response empty) or Bearer token invalid/expired. Exiting.'
|
printf '\033[31m%s\033[m\n' 'Error GETting manifest urls (response empty) or Bearer token invalid/expired. Exiting.'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
idx=1
|
idx=1
|
||||||
total=$(printf '%s\n' "${m3u8_manifest_urls}" | wc -l)
|
total="$(printf '%s\n' "${m3u8_manifest_urls_and_metadata}" | wc -l)"
|
||||||
|
|
||||||
ISF="\n"
|
ISF="\n"
|
||||||
for m3u8_manifest_url in ${m3u8_manifest_urls}; do
|
for m3u8_manifest_url_and_metadata in ${m3u8_manifest_urls_and_metadata}; do
|
||||||
m3u8_highest_res_url=$(
|
IFS='>' read -ra META <<< "${m3u8_manifest_url_and_metadata}"
|
||||||
|
|
||||||
|
title="${META[0]}"
|
||||||
|
length="${META[1]}"
|
||||||
|
length="$(echo "${length}" | sed -e 's/\..*S/S/g' -e 's/M/:/g' -e 's/H/:/g')"
|
||||||
|
m3u8_manifest_url="${META[2]}"
|
||||||
|
|
||||||
|
m3u8_highest_res_url="$(
|
||||||
curl --silent "${m3u8_manifest_url}" |
|
curl --silent "${m3u8_manifest_url}" |
|
||||||
tail -n1 |
|
tail -n1 |
|
||||||
rev |
|
rev |
|
||||||
|
@ -68,13 +78,13 @@ for m3u8_manifest_url in ${m3u8_manifest_urls}; do
|
||||||
cut -d'&' -f2 |
|
cut -d'&' -f2 |
|
||||||
cut -c13- |
|
cut -c13- |
|
||||||
sed 's/keyframes/fragments/g'
|
sed 's/keyframes/fragments/g'
|
||||||
)
|
)"
|
||||||
|
|
||||||
outfile="$(printf '%s' "${OUTFILE_PATTERN}" | sed "s/INDEX/${idx}/g")"
|
filepath="${OUTDIR}/${title}.mp4"
|
||||||
|
|
||||||
printf '\033[32m%s\033[m\n' "Download '${outfile}' (${idx}/${total})"
|
printf '\033[32m%s\033[m\n' "Download '${filepath}' (${idx}/${total})"
|
||||||
|
|
||||||
ffmpeg -hide_banner -loglevel error -headers "authorization: Bearer ${BASE64_BEARER_TOKEN}" -i "${m3u8_highest_res_url}" -progress - -c copy "${outfile}" | grep --line-buffered 'out_time=' | sed -u -e 's/out_time=//g' | xargs -I{} printf '{}\r'
|
ffmpeg -hide_banner -loglevel error -headers "authorization: Bearer ${BASE64_BEARER_TOKEN}" -i "${m3u8_highest_res_url}" -progress - -c copy "${filepath}" | grep --line-buffered 'out_time=' | sed -u -e 's/out_time=//g' -e 's/\..*//g' -e 's/^-//g' | xargs -I{} printf "{} of ${length} \r"
|
||||||
|
|
||||||
printf '\n\033[33m%s\033[m\n' "Done"
|
printf '\n\033[33m%s\033[m\n' "Done"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue