Skip to content

Instantly share code, notes, and snippets.

@5j9
Created December 25, 2017 07:45
Show Gist options
  • Save 5j9/b0589f8cb657b405242eac00663a250e to your computer and use it in GitHub Desktop.
Save 5j9/b0589f8cb657b405242eac00663a250e to your computer and use it in GitHub Desktop.
A script to download WorldScienceU coarse videos
"""Download WorldScienceYou coarse videos.
Requirements:
* python 3.6+
* pip install youtube-dl requests
* create a config.py file with USERNAME and PASSWORD variables.
Running the script:
Make sure the coarse number at the last line of the script is correct and
then run...
"""
import re
from requests import Session
from subprocess import check_call
from config import USERNAME, PASSWORD
def login():
session = Session()
login_response = session.get('http://www.worldscienceu.com/login')
authenticity_token = re.search(
r'<input name="authenticity_token" type="hidden" value="(.*?)" />',
login_response.text
).group(1)
session.post(
'http://www.worldscienceu.com/login',
{
'authenticity_token': authenticity_token,
'commit': '',
'user[email]': USERNAME,
'user[password]': PASSWORD,
'utf8': '✓',
},
)
return session
def download_youtube(url, num):
check_call(['youtube-dl', '--output', f'{num}.%(title)s.%(ext)s', url])
def download_videos(course_num):
session = login()
elements = session.get(
f'http://www.worldscienceu.com/courses/{course_num}/elements/',
).json()
vidoe_number = 1
for element in elements:
url = (
f'http://www.worldscienceu.com/courses/{course_num}/elements/'
+ element['token']
)
youtube_urls = re.findall(
'url="(http://youtu.be/.*?)"',
session.get(url).text,
)
for url in youtube_urls:
download_youtube(url, vidoe_number)
vidoe_number += 1
if __name__ == '__main__':
# 6 is Special Relativity coarse
# 6 is Space, Time and Einstein coarse
download_videos(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment