Created
October 24, 2012 22:17
-
-
Save Paaskehare/3949299 to your computer and use it in GitHub Desktop.
Script for downloading all screencasts on Destroy All Software
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import cookielib | |
import urllib | |
import urllib2 | |
import re | |
import os.path | |
email = '' | |
password = '' | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) | |
urllib2.install_opener(opener) | |
base = 'https://www.destroyallsoftware.com/' | |
def login(): | |
url = base + 'screencasts/users/sign_in' | |
page = urllib2.urlopen(url).read() | |
token = re.search('<input name="authenticity_token" type="hidden" value="([\w/\+=]+?)" />', page).group(1) | |
values = { | |
'utf8': '✓', | |
'authenticity_token': token, | |
'user[email]': email, | |
'user[password]': password, | |
} | |
data = urllib.urlencode(values) | |
req = urllib2.Request(url, data) | |
response = urllib2.urlopen(req) | |
return response.read() | |
page = login() | |
#page = open('screencasts.html', 'r').read() | |
screencasts = re.findall('<li class="screencast">\s+<a href="(.*?)">(.+?)</a>', page)[::-1] | |
for i in range(len(screencasts)): | |
screencast = screencasts[i] | |
url, title = screencast | |
filename = 'das-%s-%s.mov' % (str(i + 1).zfill(4), url.rsplit('/', 1)[1]) | |
url = base + url + '/download' | |
print(filename) | |
if os.path.exists(filename): | |
print('Already downloaded: ' + filename + ' skipping ...') | |
continue | |
print('Downloading "' + filename + '" ...') | |
req = urllib2.Request(url) | |
response = urllib2.urlopen(req) | |
while 1: | |
data = response.read(512) | |
if not len(data): break | |
else: | |
with open(filename, 'ab') as f: | |
f.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revised script here: https://gist.github.com/AshwinRamesh/e10af8a210f7fbe4b9463b7abbb180ea