Skip to content

Instantly share code, notes, and snippets.

@Paaskehare
Created October 24, 2012 22:17
Show Gist options
  • Save Paaskehare/3949299 to your computer and use it in GitHub Desktop.
Save Paaskehare/3949299 to your computer and use it in GitHub Desktop.
Script for downloading all screencasts on Destroy All Software
#!/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)
@AshwinRamesh
Copy link

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