Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
automatically downloads nptel videos from youtube
from __future__ import unicode_literals
import sys
import urllib.request
import youtube_dl
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print('Done downloading, now converting ...')
ydl_opts = {
'format': '18',
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
Urls = sys.stdin.read()
urls = list(filter(None, Urls.split("\n")))
for url in urls:
response = urllib.request.urlopen(url)
print(url)
webContent = response.read().decode("iso-8859-1")
s_i = webContent.find("v/", webContent.find("youtube.com"))
e_i = webContent.find("?", s_i)
youtube_url = "youtube.com/watch?v=" + webContent[s_i+2:e_i]
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([youtube_url])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.