This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
94 lines (72 loc) · 3.29 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
'''
Project :
FilePath : \OPENSOURCE\main.py
Descripttion :
Author : GDDG08
Date : 2022-11-08 02:07:44
LastEditors : GDDG08
LastEditTime : 2024-04-03 16:10:23
'''
import sys
import argparse
from gui import GUI
from yanhekt import YanHeKT
def configArgs():
parser = argparse.ArgumentParser(description='GDDG08/YanHeKT_Downloader')
parser.add_argument('courseID', type=int, help='Course ID of YanHeKT')
group_lession = parser.add_argument_group('Lesson Selection', 'IF NONE, PRINT LESSON LIST AND EXIT.')
group_lession_exc = group_lession.add_mutually_exclusive_group()
group_lession_exc.add_argument('-A', '--all', action='store_true', help='Download all lessons')
group_lession_exc.add_argument('-L', '--list', type=int, nargs='+', metavar='i', help='Select of lesson index (e.g., --list 1 2 4)')
group_lession_exc.add_argument('-R', '--range', type=int, nargs=2, action='append', metavar='i',
help='Select range of lessons (e.g., --range 3 5 for [3,5))')
group_video = parser.add_argument_group('Video Type')
group_video_exc = group_video.add_mutually_exclusive_group()
group_video_exc.add_argument('-D', '--dual', action='store_true', help='Download both VGA(PC) and Video (default)')
group_video_exc.add_argument('-G', '--vga', action='store_true', help='Download VGA(PC) only')
group_video_exc.add_argument('-V', '--video', action='store_true', help='Download Video only')
group_config = parser.add_argument_group('Configurations')
group_config.add_argument('-S', '--skip', action='store_true', help='Skip existing files')
group_config.add_argument('--dir', type=str, default='./', help='Output directory (e.g., --dir ./output)')
group_config.add_argument('--max-workers', type=int, default=32, metavar='num', help='Max workers for downloading (default: 32)')
return parser
def parseArgs(parser):
# force to show help message if no arguments provided
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
else:
args = parser.parse_args()
# merge list and range arguments
if not (args.vga or args.video):
args.dual = True
return args
def printArgs(args):
print("="*10+" YanHeKT_Downloader "+"="*10)
print(f"Course ID: {args.courseID}")
print(f"Lesson Selection: {'ALL' if args.all else args.list or args.range}")
print(f"Video Type: {'VGA & Video' if args.dual else 'VGA' if args.vga else 'Video'}")
print(f"Skip existing files: {args.skip}")
print(f"Output Directory: {args.dir}")
print("="*40+"\n")
def progressPrint(current, total):
sys.stdout.write('\r[%-25s](%d/%d)' % ("*" * (100 * current // total // 4),
current, total))
sys.stdout.flush()
def runCli():
parser = configArgs()
args = parseArgs(parser)
printArgs(args)
yanhekt = YanHeKT(args.courseID, args.all, args.list, args.range, args.dual, args.vga, args.video, args.skip, args.dir, args.max_workers)
yanhekt.download(callback_prog=progressPrint)
def runGui():
gui = GUI()
gui.event_loop()
def main():
# judge whether to run in GUI mode
if len(sys.argv) > 1 and sys.argv[1] == 'gui':
runGui()
else:
runCli()
if __name__ == "__main__":
main()