Skip to content

Instantly share code, notes, and snippets.

@pyokagan
Created May 1, 2012 13:24
Show Gist options
  • Select an option

  • Save pyokagan/2567877 to your computer and use it in GitHub Desktop.

Select an option

Save pyokagan/2567877 to your computer and use it in GitHub Desktop.
Prints list of videos in season of Youtube Show. Requires Python 3 for parsing URLs. Requires jshon for parsing JSON. Now, why didn't I write this whole thing in Python in the first place :(
#! /bin/sh
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: $0 URL SEASON" >&2
exit 1
fi
SHOW_ID=`python3 -c 'from urllib.parse import urlparse, parse_qs;from sys import argv;print(parse_qs(urlparse(argv[1]).query)["p"][0])' "$1"`
SHOW_URL="http://gdata.youtube.com/feeds/api/shows/$SHOW_ID/content?v=2&alt=json"
SEASON="$2"
SEASON_URL=`curl $SHOW_URL | jshon -e feed -e entry -a -e 'yt$season' -e season -u -p -p -e content -e src -u | sed 'N;s/\n/ /g' | awk '{ if ($1 == SEASON) print $2; exit 0 }' SEASON=$SEASON)`
if [ -z "$SEASON_URL" ]; then
echo "Season $SEASON does not exist." >&2
exit 1
fi
curl "$SEASON_URL&alt=json" | jshon -e feed -e entry -a -e content -e src -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment