-
Notifications
You must be signed in to change notification settings - Fork 45
/
test_khan_dl.py
91 lines (78 loc) · 3.33 KB
/
test_khan_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import unittest
import yt_dlp
import sys
sys.path.append("../khan_dl")
from khan_dl.khan_dl import *
class TestKhanDL(unittest.TestCase):
def test_get_courses(self):
print("test_get_courses")
khan_dl = KhanDL()
courses, courses_url = khan_dl.get_courses("https://www.khanacademy.org/math")
self.assertIsNotNone(courses)
self.assertIsNotNone(courses_url)
self.assertEqual(len(courses), len(courses_url))
def test_get_course_page(self):
print("test_get_course_page")
khan_dl = KhanDL()
khan_dl.course_url = "https://www.khanacademy.org/math/precalculus"
khan_dl.get_course_page()
self.assertIsNotNone(khan_dl.course_page)
def test_get_course_title(self):
print("test_get_course_title")
khan_dl = KhanDL()
khan_dl.course_url = "https://www.khanacademy.org/math/precalculus"
khan_dl.get_course_page()
khan_dl.get_course_title()
self.assertEqual(khan_dl.course_title, "Precalculus")
def test_get_course_unit_urls(self):
print("test_get_course_unit_urls")
khan_dl = KhanDL()
khan_dl.course_url = "https://www.khanacademy.org/math/precalculus"
khan_dl.get_course_page()
khan_dl.get_course_unit_urls()
self.assertEqual(len(khan_dl.course_unit_urls), 10)
def test_get_course_unit_titles(self):
print("test_get_course_unit_titles")
khan_dl = KhanDL()
khan_dl.course_url = "https://www.khanacademy.org/math/precalculus"
khan_dl.get_course_page()
khan_dl.get_course_unit_titles()
self.assertIsNotNone(khan_dl.course_unit_titles)
self.assertEqual(len(khan_dl.course_unit_titles), 10)
def test_get_course_unit_slugs(self):
print("test_get_course_unit_slugs")
khan_dl = KhanDL()
khan_dl.course_url = "https://www.khanacademy.org/math/precalculus"
khan_dl.get_course_page()
khan_dl.get_course_title()
khan_dl.get_course_unit_titles()
khan_dl.get_course_unit_slugs()
self.assertEqual(len(khan_dl.course_unit_slugs), 10)
def test_youtube_dl_down_playlist(self):
print("test_youtube_dl_down_playlist")
course_unit_url = (
"https://www.khanacademy.org/math/precalculus/x9e81a4f98389efdf:complex"
)
lesson_youtube_ids = []
youtube_dl_opts = {}
with yt_dlp.YoutubeDL(youtube_dl_opts) as ydl:
info_dict = ydl.extract_info(course_unit_url, download=False)
for video in info_dict["entries"]:
video_id = video.get("id", None)
lesson_youtube_ids.append(video_id)
self.assertIsNotNone(lesson_youtube_ids)
self.assertEqual(len(lesson_youtube_ids), 22)
def test_lesson_title_match_youtube_ids(self):
print("test_lesson_title_match_youtube_ids")
khan_dl = KhanDL()
khan_dl.course_url = "https://www.khanacademy.org/math/trigonometry"
khan_dl.get_course_page()
khan_dl.get_course_title()
khan_dl.get_course_unit_titles()
khan_dl.get_course_unit_slugs()
khan_dl.get_course_unit_urls()
khan_dl.get_course_all_slugs()
khan_dl.get_course_youtube_ids()
self.assertEqual(len(khan_dl.course_all_slugs), len(khan_dl.lesson_youtube_ids))
if __name__ == "__main__":
unittest.main()