Created
December 14, 2014 18:52
-
-
Save iKlsR/d3704abebab9083dd1f5 to your computer and use it in GitHub Desktop.
download all the videos on vimcasts.org in mp4 format
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
import json, urllib2 | |
response = urllib2.urlopen("http://media.vimcasts.org/videos/index.json") | |
data = json.load(response) | |
number_of_videos = data.keys() | |
number_of_videos.sort(key=int) | |
urls = [] | |
file_names = [] | |
for i in range(1, int(number_of_videos[-1]) + 1): | |
file_n = (data[str(i)]["quicktime"]["url"])[(data[str(i)]["quicktime"]["url"]) | |
.find("videos/") + 7:] # videos/ | |
urls.append(data[str(i)]["quicktime"]["url"]) | |
num = file_n[:file_n.find("/")] | |
file_name = (file_n[file_n.find("/") + 1:]) | |
file_names.append(num + "-" + file_name) | |
for count, url in enumerate(urls): | |
file_name = file_names[count] | |
u = urllib2.urlopen(url) | |
f = open(file_name, 'wb') | |
meta = u.info() | |
file_size = int(meta.getheaders("Content-Length")[0]) | |
# massive overkill.. heh | |
print "Downloading: %s Bytes: %s" % (file_name, file_size) | |
file_size_dl = 0 | |
block_sz = 8192 | |
while True: | |
buffer = u.read(block_sz) | |
if not buffer: | |
break | |
file_size_dl += len(buffer) | |
f.write(buffer) | |
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) | |
status = status + chr(8)*(len(status)+1) | |
print status, | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment