forked from dinosaurfiles-zz/cybrary-video-downloader
/
cybrary-video-downloader.py
executable file
·70 lines (53 loc) · 1.78 KB
/
cybrary-video-downloader.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
69
70
#!/usr/bin/python
import os
import re
import sys
import getpass
import requests
from more_itertools import unique_everseen
# Set sys encoding to UTF-8
reload(sys)
sys.setdefaultencoding('utf-8')
# Global Variables
session = requests.session()
# Initialize Login
def login(username, password):
values = {
'log': username,
'pwd': password,
'testcookie': 1,
'wp-submit': 'Log+In',
'redirect_to': ''
}
global session
session.post('https://www.cybrary.it/wp-login.php', data=values)
# Get Lessons
def getLessonList(courselink, quality):
global session
coursehtml = (session.get(courselink)).text
lessonLinkRegex = re.compile('https?://www.cybrary.it/video/\w+(?:-[\w]+)*/')
matchedLessonLink = list(unique_everseen(lessonLinkRegex.findall(coursehtml)))
for link in matchedLessonLink:
print "Downloading "+link
downloadVideos(getVideoLink(link), quality)
# Get Video URL
def getVideoLink(lessonlink):
global session
lessonhtml = (session.get(lessonlink)).text
videoLinkRegex = re.compile('https?://player.vimeo.com/video/[\d]+')
return (list(unique_everseen(videoLinkRegex.findall(lessonhtml))))[0]
# Download Videos using youtube-dl
def downloadVideos(videoLink, quality):
command = "youtube-dl -cif http-%sp %s" % (quality, videoLink)
os.system(command)
def main():
if len(sys.argv) < 3:
print "Usage: ./cybrary-video-downloader.py <270/360/720> \"<course link>\""
print "Example: ./cybrary-video-downloader.py 360 \"https://www.cybrary.it/course/ethical-hacking/\""
else:
username = raw_input("Username: ")
passwd = getpass.getpass()
login(username, passwd)
getLessonList(sys.argv[2], sys.argv[1])
if __name__ == '__main__':
main()