Skip to content

Commit

Permalink
feat: support non-override
Browse files Browse the repository at this point in the history
  • Loading branch information
itsHenry35 committed Sep 28, 2024
1 parent 9a92d78 commit a56d0c9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
4 changes: 3 additions & 1 deletion bin/aria2_darwin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ content-disposition-default-utf8=true
#max connection per server
max-connection-per-server=16
#max concurrent downloads
max-concurrent-downloads=64
max-concurrent-downloads=64
#only override, no new filename
auto-file-renaming=false
4 changes: 3 additions & 1 deletion bin/aria2_linux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ content-disposition-default-utf8=true
#max connection per server
max-connection-per-server=16
#max concurrent downloads
max-concurrent-downloads=64
max-concurrent-downloads=64
#only override, no new filename
auto-file-renaming=false
4 changes: 3 additions & 1 deletion bin/aria2_win32.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ content-disposition-default-utf8=true
#max connection per server
max-connection-per-server=16
#max concurrent downloads
max-concurrent-downloads=64
max-concurrent-downloads=64
#only override, no new filename
auto-file-renaming=false
2 changes: 2 additions & 0 deletions gui/download1.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def mouse_scroll(event):

extensiveornot = ttk.Checkbutton(text='延伸课程', bootstyle="default-square-toggle", variable=var)
extensiveornot.pack(anchor='w')
override = ttk.Checkbutton(text='覆盖已下载文件', bootstyle="default-square-toggle", variable=isoverride)
override.pack(anchor='w')
submit = ttk.Button(text='提交', bootstyle="primary", command=submit)
submit.pack(anchor='w')
selectpath = ttk.Button(text='选择自定义路径(可不选,默认为程序所在目录)', bootstyle="primary-outline-toolbutton",
Expand Down
41 changes: 38 additions & 3 deletions gui/download2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def _async_raise(tid, exctype):
def stop_thread(thread):
_async_raise(thread.ident, SystemExit)

def wait_for_aria2():
print("start")
url = 'http://localhost:6800/jsonrpc'
timeout = 10
start_time = time.time()

while time.time() - start_time < timeout:
try:
response = requests.post(url, json={"jsonrpc": "2.0", "method": "aria2.getVersion", "id": "1"}, timeout=0.4)
if response.status_code == 200:
return True
except requests.ConnectionError:
print("retry")
time.sleep(1)
else:
return False


def get_lecturers(course_list, user_id, access_token):
url = "https://course-api-online.saasp.vdyoo.com/course/v1/student/course/user-live-list"
Expand Down Expand Up @@ -217,7 +234,8 @@ def switchpauseresume(button):
root.geometry("")
if now==1:
aria2process = subprocess.Popen([aria2_path, "--conf-path", aria2_config], shell=isWindows)
time.sleep(1)
if wait_for_aria2() == False:
raise Exception("Aria2c failed to start")
jsonrpc = aria2p.Client(
host="http://localhost",
port=6800
Expand All @@ -228,11 +246,25 @@ def switchpauseresume(button):
count = 1
for lecture in lecturers:
if extensive_or_not == False:
result = get_download_url(lecture, user_id, access_token)
filename = f'第{count}讲.mp4'
if isoverride == False and os.path.exists(os.path.join(custom_down_path, course_name, filename)) and not os.path.exists(os.path.join(custom_down_path, course_name, filename + '.aria2')):
result = {
"url": "",
"success": False,
"errmsg": "文件已存在",
}
else:
result = get_download_url(lecture, user_id, access_token)
if extensive_or_not == True:
result = get_cram_class(lecture, user_id, access_token)
filename = f'第{count}讲_延伸内容.mp4'
if isoverride == False and os.path.exists(os.path.join(custom_down_path, course_name, filename)) and not os.path.exists(os.path.join(custom_down_path, course_name, filename + '.aria2')):
result = {
"url": "",
"success": False,
"errmsg": "文件已存在",
}
else:
result = get_cram_class(lecture, user_id, access_token)
download_urls[filename] = result
count += 1
count = 2
Expand Down Expand Up @@ -269,6 +301,9 @@ def switchpauseresume(button):
else:
tkinterlist[filename]['percentage'].configure(text='下载失败')
tkinterlist[filename]['speed'].configure(text=download_urls[filename]['errmsg'])
if download_urls[filename]['errmsg'] == "文件已存在":
tkinterlist[filename]['percentage'].configure(text='100%')
tkinterlist[filename]['progress']['value'] = 100
thread = threading.Thread(target=update_download_status)
thread.start()
root.mainloop()
Expand Down

0 comments on commit a56d0c9

Please sign in to comment.