-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
100 lines (88 loc) · 3.37 KB
/
main.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
92
93
94
95
96
97
98
99
100
import os
import sys
import subprocess
import time
import signal
from selenium.webdriver.firefox import webdriver
from selenium.webdriver.firefox.options import Options
import helpers
import parser_helper
HEADLESS_BROWSING = True
RECORDING_TIMEOUT_MINS = 45
SLEEP_SECONDS = 5
VERSION = 2.1
HELP_MSG = """Usage: python3 main.py [OPTIONS]...
options:
-h --help Print this message and exit
-v --version Print version and exit
-i --input Enter a course from the course list through stdin
-c=COURSE_CLASSNAME Enter a course given its html class name as found on https://live.rbg.tum.de
-m=MODULE_CODE Enter a course given its TUM module code as found on COURSE_MAP
-t=MINUTES Set minutes after which the recording will be stopped.
Default: 90
"""
COURSE_MAP = {
"IN0042": "course379", # IT Sicherheit
"IN2381": "course391", # Einführung in Quantum Computing
"IN0008": "course392", # Grundlagen Datenbanken
"IN0009": "course387", # Grundlagen: Betriebssysteme
"MA0902": "course448", # Analysis
}
GECKODRIVER_PATH = "/Library/Frameworks/Python.framework/Versions/3.10/bin/geckodriver"
if __name__ == '__main__':
# COMMAND FLAGS READING ============================================================================================
course_id: str = str()
timeout_minutes: int = RECORDING_TIMEOUT_MINS
if len(sys.argv) > 3:
print(HELP_MSG)
sys.exit(1)
for arg in sys.argv[1:]:
match arg.split("="):
case ["-h"] | ["--help"]:
print(HELP_MSG)
sys.exit(0)
case ["-v"] | ["--version"]:
print(VERSION)
sys.exit(0)
case ["-i"] | ["--input"]:
course_id = helpers.get_course_class_id(COURSE_MAP)
continue
case ["-c", id]:
course_id = id
continue
case ["-t", minutes]:
timeout_minutes = minutes
continue
case ["-m", module_id]:
course_id = COURSE_MAP[module_id]
continue
case _:
print(HELP_MSG)
sys.exit(1)
if not course_id:
course_id = helpers.get_course_class_id(COURSE_MAP)
# SETUP ============================================================================================================
options = Options()
options.headless = HEADLESS_BROWSING
browser = webdriver.WebDriver(options=options, executable_path=GECKODRIVER_PATH)
browser.get("https://live.rbg.tum.de")
parser_helper.login(browser)
parser_helper.enter_course(browser, course_id)
stream_url: str = parser_helper.get_stream_source(browser)
browser.quit()
# MAIN PROCESS =====================================================================================================
process = subprocess.Popen(
["youtube-dl", stream_url],
)
try:
print(f"Running process {process.pid}")
time.sleep(int(int(timeout_minutes) * 60))
process.send_signal(signal.SIGINT)
except Exception as exc:
print(f"Terminated with exception {exc}")
time.sleep(SLEEP_SECONDS)
if not os.path.isdir("./output"):
os.mkdir("./output")
subprocess.run(
["mv", "./playlist-playlist.mp4.part", helpers.get_filename()]
)