-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathleccap_dl.py
68 lines (51 loc) · 1.97 KB
/
leccap_dl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python2
import argparse
import urllib
import getpass
from selenium import webdriver
FILE_EXT = ".mp4"
LOGIN_URL = "https://weblogin.umich.edu/"
LECCAP_BASE_URL = "https://leccap.engin.umich.edu/leccap/viewer/s/"
def parse_args():
parser = argparse.ArgumentParser(\
description="An automated leccap recording downloader",\
epilog="example: python leccap_dl.py hsfrlzcioe7xc71tu1w eecs482_lecture")
parser.add_argument("course_uid",\
help="the unique leccap course identifier")
parser.add_argument("file_prefix",\
help="the file prefix for downloaded lecture recordings")
return parser.parse_args()
def main():
args = parse_args()
uniqname = raw_input("Uniqname: ")
password = getpass.getpass("Password: ")
# initialize browser
browser = webdriver.Chrome(executable_path = './chromedriver')
browser.implicitly_wait(60) # seconds
# attempt login
browser.get(LOGIN_URL)
browser.find_element_by_id("login").send_keys(uniqname)
browser.find_element_by_id("password").send_keys(password)
browser.find_element_by_id("loginSubmit").click()
# go to course leccap page
leccap_course_url = LECCAP_BASE_URL + args.course_uid
browser.get(leccap_course_url)
# scrape lecture urls
lecture_urls = []
for rec_btn in browser.find_elements_by_class_name("recording-button"):
lec_url = rec_btn.get_attribute("href")
lecture_urls.append(lec_url)
# scrape video urls from lectures
video_urls = []
for lec_url in lecture_urls:
browser.get(lec_url)
vid_url = browser.find_element_by_tag_name("video").get_attribute("src")
video_urls.append(vid_url)
browser.quit()
# download videos
for i in range(len(video_urls)):
filename = args.file_prefix + str(i + 1) + FILE_EXT
print("downloading " + filename + " from " + video_urls[i])
urllib.urlretrieve(video_urls[i], filename)
if __name__ == '__main__':
main()