Skip to content

Instantly share code, notes, and snippets.

@nishad
Last active August 29, 2015 14:23
Show Gist options
  • Save nishad/ecf58e5a43ee9d7ac746 to your computer and use it in GitHub Desktop.
Save nishad/ecf58e5a43ee9d7ac746 to your computer and use it in GitHub Desktop.
#!/bin/python
import requests
import re
def start():
chapter_links=[]
course="http://try.jquery.com/"
response=requests.get(course)
chapter_pattern=re.compile(r'(http[s]?://try.jquery.com/levels/\d)"')
for each in chapter_pattern.findall(response.content):
chapter_links.append(each)
print "Number of Chapters:", len(chapter_links)
return chapter_links
def gather_pages(chapter_links):
page_links=[]
page_pattern=re.compile(r'href=\\"(http[s]?://try.jquery.com/levels/\d+/sections/\d+)\\"')
for each in chapter_links:
response=requests.get(each)
page_links.extend(list(set(page_pattern.findall(response.content))))
return page_links
def gather_videos(page_links):
video_links={}
video_pattern=re.compile(r'\"url\":"(http://projector.codeschool.com/videos/.*?profile=720p.*?)\"')
count=0
for each in page_links:
response=requests.get(each)
video_link=video_pattern.findall(response.content)
if video_link:
count+=1
video_links[str(count)]=video_link
print "Number of videos to download:", len(video_links.keys())
return video_links
with open("downloads.txt", 'w') as f:
for k,v in gather_videos(gather_pages(start())).items():
line='url="' + ",".join(v) + '"' + '\n' + 'output="' + k + '.mp4"' + '\n'
f.write(line)
# Run downloads.txt in terminal with `curl -L -K downloads.txt`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment