Skip to content

Instantly share code, notes, and snippets.

@abbaspour
Last active August 1, 2019 05:51
Show Gist options
  • Save abbaspour/70a71e83c75fc50b3a93fa8a0e9965eb to your computer and use it in GitHub Desktop.
Save abbaspour/70a71e83c75fc50b3a93fa8a0e9965eb to your computer and use it in GitHub Desktop.
download videos from wistia.com
#!/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}"
@abbaspour
Copy link
Author

improve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment