Skip to content

Instantly share code, notes, and snippets.

@printminion
Last active August 29, 2015 14:00
Show Gist options
  • Save printminion/11236362 to your computer and use it in GitHub Desktop.
Save printminion/11236362 to your computer and use it in GitHub Desktop.
Script for getting youtube_id of udacity course videos. Set proper cookie value ans run it like ./get_course.sh cs255
#!/bin/bash
COURCEID=$1
mkdir $COURCEID
#set your udacity cookie here - just in case
MY_COOKIE='cookie: __unam=bla-bla-bla; optimizelyEndUserId=bla;'
#read course data
curl 'https://www.udacity.com/api/nodes/'$COURCEID'?depth=1&fresh=false&required_behavior=view&projection=navigation' \
-H 'accept-encoding: gzip,deflate,sdch' \
-H 'accept-language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4,uk;q=0.2' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36' \
-H 'x-udacity-client: udacity.com; version=3e62f5a' \
-H 'accept: application/json, text/plain, */*' \
-H 'x-xsrf-token: 23e411849b78bd10ff02d6256fa6ba2424502f21/1398292535' \
-H 'cache-control: max-age=0' \
-H "$MY_COOKIE" \
-H 'referer: https://www.udacity.com/course/viewer' --compressed | sed s/\)\]\}\'//g | python -mjson.tool > ./$COURCEID/nodes.json
cat "./$COURCEID/nodes.json" | json "references.Node.$COURCEID.steps_refs" | json -a key > ./$COURCEID/nodes.txt
#read nodes
while read NODEID
do
#echo "$NODEID"
curl 'https://www.udacity.com/api/nodes/'$NODEID'?depth=2&fresh=false&required_behavior=view&projection=classroom' \
-H 'accept-encoding: gzip,deflate,sdch' \
-H 'accept-language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4,uk;q=0.2' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36' \
-H 'x-udacity-client: udacity.com; version=3e62f5a' -H 'accept: application/json, text/plain, */*' \
-H 'x-xsrf-token: 2d81dc0805d502b4a032e7a35d4f4434aa91fe4f/1398288749' \
-H 'cache-control: max-age=0' \
-H "$MY_COOKIE" \
-H 'referer: https://www.udacity.com/course/viewer' --compressed > ./$COURCEID/node_$NODEID.json
cat "./$COURCEID/node_$NODEID.json" | sed s/\)\]\}\'//g | python -mjson.tool > "./$COURCEID/node_$NODEID.clean.json"
done < "./$COURCEID/nodes.txt"
find ./$COURCEID/ -name "*.clean.json" -exec grep --color=auto 'youtube_id' {} \; | sed s/"youtube_id"//g | sed s/\"//g | sed s/://g | sed s/" "//g > "youtube_id_$COURCEID.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment