forked from prcwcy/sjtu-canvas-video-download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sjtu_canvas_video_download.py
64 lines (59 loc) · 1.96 KB
/
sjtu_canvas_video_download.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
import time
import os
import sys
import subprocess
import tkinter.messagebox
from sjtu_history import history, save_history
self_dirname = os.path.dirname(sys.argv[0])
tmp_dirname = os.path.join(self_dirname, "tmp")
os.makedirs(tmp_dirname, exist_ok=True)
aria2_exe_filename = os.path.join(
self_dirname, "aria2", "aria2c.exe"
)
def download_courses(course_links, course_filenames, video_dirname, no_record=False):
if not no_record:
history.append(
{
"time": time.time_ns(),
"course_links": course_links,
"course_filenames": course_filenames,
"video_dirname": video_dirname
}
)
save_history()
aria2_txt_filename = os.path.join(tmp_dirname, f"{time.time_ns()}.txt")
with open(aria2_txt_filename, mode="w", encoding="utf-8") as aria2_txt_file:
for course_link, course_filename in zip(course_links, course_filenames):
print(course_link, file=aria2_txt_file)
print(
f" out={course_filename}", file=aria2_txt_file
)
print(
" header=referer: https://courses.sjtu.edu.cn",
file=aria2_txt_file
)
if sys.platform == "win32":
subprocess.Popen(
[
aria2_exe_filename,
"-d", video_dirname,
"-i", aria2_txt_filename,
"-x", str(16),
"--auto-file-renaming=false"
],
creationflags=subprocess.CREATE_NEW_CONSOLE
)
else:
tkinter.messagebox.showinfo("提示", "请查看控制台输出")
try:
subprocess.run(
[
"aria2c",
"-d", video_dirname,
"-i", aria2_txt_filename,
"-x", str(16),
"--auto-file-renaming=false"
]
)
except KeyboardInterrupt:
pass