Skip to content

Instantly share code, notes, and snippets.

@bibby
Created July 29, 2017 13:43
Show Gist options
  • Save bibby/2db8ffe89b8b2364dfc5849ea34db7c6 to your computer and use it in GitHub Desktop.
Save bibby/2db8ffe89b8b2364dfc5849ea34db7c6 to your computer and use it in GitHub Desktop.
C-SPAN mp4 downloader
#!/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"
@mbonaci
Copy link

mbonaci commented Sep 21, 2020

Seems that the c-span player link is no longer OK.

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