Last active
August 29, 2015 14:02
-
-
Save liyong03/d973b18abf9879b7237e to your computer and use it in GitHub Desktop.
WWDC2014 video download
This file contains hidden or 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
#!/usr/bin/python | |
import urllib2 | |
from xml.dom import minidom | |
from bs4 import BeautifulSoup | |
import json | |
import os | |
import subprocess | |
#read download session | |
videoList = [] | |
if os.path.exists("/tmp/wwdc_download"): | |
print "Find list!" | |
f = open("/tmp/wwdc_download", "rw") | |
videoList = json.load(f) | |
f.close() | |
else: | |
page = urllib2.urlopen("https://developer.apple.com/videos/wwdc/2014/") | |
print "Downloading list..." | |
print "Get the page!" | |
soup = BeautifulSoup(page) | |
videos = soup.body.find_all("li", attrs={"class": "session"}) | |
for video in videos: | |
sessionID = video.attrs['id'] | |
name = video.find("li", attrs={"class" : "title"}).string | |
pDownload = video.find("p", attrs={"class" : "download"}) | |
links = pDownload.find_all("a") | |
urls = {} | |
for link in links: | |
urls[link.string] = link.attrs["href"] | |
print "%s: %s" %(sessionID, name) | |
#print urls["HD"] | |
obj = {} | |
obj["ID"] = sessionID | |
obj["name"] = name | |
obj["urls"] = urls | |
obj["isdone"] = 0 | |
videoList.append(obj) | |
f = open("/tmp/wwdc_download", "w") | |
json.dump(videoList, f) | |
f.close() | |
for obj in videoList: | |
if obj["isdone"] == 0: | |
url = obj["urls"]["HD"] | |
print "Downloading %s: %s" %(obj["ID"], obj["name"]) | |
output = ""+obj["ID"]+": "+obj["name"]+".mov" | |
subprocess.call(['wget', '-c', '-P', '~/wwdc2014/', url, "-O", output]) | |
obj["isdone"] = 1 | |
#save new data to disk | |
f = open("/tmp/wwdc_download", "w") | |
json.dump(videoList, f) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment