From c5033b318adffb4247b168f6d45ddf7524108552 Mon Sep 17 00:00:00 2001 From: tosu Date: Sun, 26 Feb 2023 17:57:43 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + download.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .gitignore create mode 100755 download.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/download.sh b/download.sh new file mode 100755 index 0000000..4792cce --- /dev/null +++ b/download.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +source .env +OUTFILE_PATTERN="./videos/video_INDEX.mp4" +API_URL='https://euwe-1.api.microsoftstream.com/api/videos?'\ +'$top=100&'\ +'$skip=0&'\ +'$orderby=metrics/trendingScore desc&'\ +'$filter=published and ((state eq %27Completed%27 and contentSource ne %27livestream%27) or (contentSource eq %27livestream%27 and not (state eq %27Completed%27 and not liveEvent/LiveEventOptions/OnDemandOptions/EnablePlayback)))&'\ +'api-version=1.4-private' + +mkdir -p "$(dirname "${OUTFILE_PATTERN}")" || { echo -e '\033[31mAborting\033[m'; exit; } +m3u8_manifest_urls=$(wget --no-verbose --quiet -O- --header="authorization: Bearer ${BASE64_ENCODED_BEARER_TOKEN}" "${API_URL}" | jq -r '.value[].playbackUrls | map(select(.mimeType == "application/vnd.apple.mpegurl")) | .[].playbackUrl') + +idx=1 +total=$(echo "${m3u8_manifest_urls}" | wc -l) +echo "${m3u8_manifest_urls}" | while IFS= read -r m3u8_manifest_url; do + +m3u8_highest_res_url=$(curl -s "${m3u8_manifest_url}" | tail -n1 | rev | cut -c3- | rev | cut -d'&' -f2 | cut -c13- | sed 's/keyframes/fragments/g') + +echo -e "\033[32mDownload video ${idx} of ${total}\033[m" + +outfile="$(echo "${OUTFILE_PATTERN}" | sed "s/idx/${idx}/g")" + +# This doesn't work for some reason +# ffmpeg -loglevel 24 -headers "authorization: Bearer ${BASE64_ENCODED_BEARER_TOKEN}" -i "${m3u8_highest_res_url}" -c copy "${outfile}" +# Don't know what the f is going on, but it only works this hacky way +echo 'ffmpeg -loglevel 24 -headers "authorization: Bearer '${BASE64_ENCODED_BEARER_TOKEN}'" -i "'${m3u8_highest_res_url}'" -c copy "'${outfile}'"' | sh +echo -e "\033[33mDone\033[m" + +idx=$((idx+1)) + +done