Created
July 29, 2017 13:43
-
-
Save bibby/2db8ffe89b8b2364dfc5849ea34db7c6 to your computer and use it in GitHub Desktop.
C-SPAN mp4 downloader
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 | |
# Download mp4s from C-SPAN | |
# Use: cspan CSPAN_URL [outfile] | |
# - script depends on jq and pup | |
# -- jq is a commandline json processor | |
# a precompiled binary can be obtained from https://github.com/stedolan/jq/releases | |
# -- pup is a commandline html processor (the jq of html/xml) | |
# a precompiled binary can be obtained from https://github.com/ericchiang/pup/releases | |
# TODO: clips. Right now, clip urls download the whole event. | |
# identify the unique program-id from the page | |
id=$(curl -s "$1" | pup '[type="hidden"][name="id"] attr{value}' | head -1) | |
echo "id: $id" >&2 | |
# retrive a file list from a player resource | |
url="https://www.c-span.org/assets/player/ajax-player.php?os=android&html5=program&id=${id}&html5=program" | |
echo "url: $url" >&2 | |
# pick the first. TODO: choose? | |
mp4=$(curl -sk "$url" | jq -r '.video.files[0].path["#text"]' | sed 's/&/\&/g') | |
echo "mp4: $mp4" >&2 | |
# decide an output file. TODO: name after the page-title? | |
out=${2:-"${id}.mp4"} | |
# slurp | |
curl -k "$mp4" > "$out" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems that the c-span player link is no longer OK.