Last active
August 1, 2019 05:51
-
-
Save abbaspour/70a71e83c75fc50b3a93fa8a0e9965eb to your computer and use it in GitHub Desktop.
download videos from wistia.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
[[ "$#" -lt 1 ]] && { echo "$0 http://someurl" && exit 1; } | |
which curl >/dev/null || { echo >&2 "Error: you need curl"; exit 2; } | |
which jq >/dev/null || { echo >&2 "Error: you need jq"; exit 2; } | |
which awk >/dev/null || { echo >&2 "Error: you need awk"; exit 2; } | |
declare pref_name=$(echo "${1}" | awk -F/ '{printf ("%s.mp4", $NF)}' ) | |
declare iframe_url=$(curl -s "${1}" | grep -E 'https://fast.wistia.net/embed/iframe/[^?"]+' -o) | |
[[ -z "$iframe_url" ]] && { | |
iframe_url='http://fast.wistia.net/embed/iframe/' | |
iframe_url+=$(curl -s "${1}" | grep -E 'https://fast.wistia.com/embed/medias/[^/]+' -o | awk -F/ '{print $NF}') | |
} | |
declare -r md_mp4_video=$(curl -s ${iframe_url} | grep "W.iframeInit([^)]*" -o | cut -c14- | jq -r '.assets[] | select(.type == "md_mp4_video") | .url' 2>/dev/null ) | |
echo "downloading ${pref_name} from: ${md_mp4_video}" | |
curl -o "${pref_name}" "${md_mp4_video}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
improve