Created
January 20, 2012 06:17
-
-
Save pao/1645701 to your computer and use it in GitHub Desktop.
Script to batch download additional digital materials for Artificial Heart Level 4.
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
''' | |
Usage: python getHeart.py YOURCODE [email protected] someregex | |
The "someregex" matches against the link text. | |
For instance: | |
* "flac" will get all the FLAC downloads | |
* "flac|VIDEO" will get FLAC and video | |
and so on. | |
''' | |
import os | |
import re | |
import sys | |
from urllib import url2pathname | |
import mechanize | |
CHUNK = 16 * 1024 | |
br = mechanize.Browser() | |
br.open('http://www.atozmedia.com/soundcard') | |
br.select_form([f for f in br.forms()][0].name) | |
br['downloadCode'] = sys.argv[1] | |
br['email'] = sys.argv[2] | |
br.submit() | |
for link in list(br.links(text_regex=sys.argv[3])): | |
# Run `watch ls -l' in the folder you're downloading to for status | |
resp = br.follow_link(link) | |
filename = url2pathname(resp.geturl().split('/')[-1]) | |
if os.path.exists(filename) and os.path.getsize(filename) == int(resp.info()['content-length']): | |
br.back() | |
continue | |
with open(filename, 'wb') as dlfile: | |
for chunk in iter(lambda: resp.read(CHUNK), ''): | |
if not chunk: break | |
dlfile.write(chunk) | |
br.back() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment