Skip to content

Instantly share code, notes, and snippets.

@mitnk
Last active December 15, 2015 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitnk/5214298 to your computer and use it in GitHub Desktop.
Save mitnk/5214298 to your computer and use it in GitHub Desktop.
Download all Pycon 2013 Video
from urllib2 import urlopen
from subprocess import Popen, PIPE
from bs4 import BeautifulSoup
page = urlopen('http://pyvideo.org/category/33/pycon-us-2013')
soup = BeautifulSoup(page)
video_url_list = []
count = 0
tags = soup.find_all('div', {'class': 'section'})
for t in tags:
url_page = 'http://pyvideo.org' + t.find('a')['href']
soup_inner = BeautifulSoup(urlopen(url_page))
for a in soup_inner.find_all('a'):
if 'www.youtube.com/watch' in a.get('href', ''):
video_url_list.append(a['href'])
break
for url in video_url_list:
p1 = Popen(["youtube-dl", "-F", url], stdout=PIPE)
p2 = Popen(["grep", "-i", "mp4"], stdin=p1.stdout, stdout=PIPE)
p3 = Popen(["head", "-n", "1"], stdin=p2.stdout, stdout=PIPE)
p4 = Popen(["grep", "-o", r"^[0-9]*"], stdin=p3.stdout, stdout=PIPE)
output = p4.communicate()[0]
code_format = output.strip()
print 'youtube-dl -o "%%(title)s.%%(ext)s" --restrict-filenames -f %s %s' % (code_format, url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment