Skip to content

Commit

Permalink
feat!: import aria2c from motrix
Browse files Browse the repository at this point in the history
  • Loading branch information
itsHenry35 committed Feb 7, 2024
1 parent 149f762 commit c432ff3
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Build and rename the artifact
run: |
pyinstaller --noconfirm --onefile --windowed --icon "D:/a/ledu/ledu/ledu.ico" --add-data "D:/a/ledu/ledu/bin/aria2c_win.exe;bin/" "D:/a/ledu/ledu/main.py"
pyinstaller --noconfirm --onefile --windowed --icon "D:/a/ledu/ledu/ledu.ico" --add-data "D:/a/ledu/ledu/bin/aria2c_win32_x64.exe;bin/" --add-data "D:/a/ledu/ledu/bin/aria2_win32.conf;bin/" "D:/a/ledu/ledu/main.py"
ren D:\a\ledu\ledu\dist\main.exe D:\a\ledu\ledu\dist\ledu_download_win64_${{ github.event.release.tag_name }}.exe
- name: Release
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Build and rename the artifact
run: |
pyinstaller --noconfirm --onefile --windowed --icon "/home/runner/work/ledu/ledu/ledu.ico" --add-data "/home/runner/work/ledu/ledu/bin/aria2c_linux_amd64:bin/" "/home/runner/work/ledu/ledu/main.py"
pyinstaller --noconfirm --onefile --windowed --icon "/home/runner/work/ledu/ledu/ledu.ico" --add-data "/home/runner/work/ledu/ledu/bin/aria2c_linux_x64:bin/" --add-data "/home/runner/work/ledu/ledu/bin/aria2_linux.conf:bin/" "/home/runner/work/ledu/ledu/main.py"
mv /home/runner/work/ledu/ledu/dist/main /home/runner/work/ledu/ledu/dist/ledu_download_linux_amd64_${{ github.event.release.tag_name }}
- name: Release
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Build and compress the artifact
run: |
pyinstaller --noconfirm --onefile --windowed --icon "/Users/runner/work/ledu/ledu/ledu.ico" --add-data "/Users/runner/work/ledu/ledu/bin/aria2c_macos:bin/" "/Users/runner/work/ledu/ledu/main.py"
pyinstaller --noconfirm --onefile --windowed --icon "/Users/runner/work/ledu/ledu/ledu.ico" --add-data "/Users/runner/work/ledu/ledu/bin/aria2c_darwin_x64:bin/" --add-data "/Users/runner/work/ledu/ledu/bin/aria2_darwin.conf:bin/" "/Users/runner/work/ledu/ledu/main.py"
rm /Users/runner/work/ledu/ledu/dist/main
mv /Users/runner/work/ledu/ledu/dist/main.app/ /Users/runner/work/ledu/ledu/dist/ledu_download_macos_${{ github.event.release.tag_name }}.app/
mv /Users/runner/work/ledu/ledu/dist/ /Users/runner/work/ledu/ledu/ledu_download_macos/
Expand Down
3 changes: 3 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# aria2

Source code: https://github.com/agalwood/aria2
60 changes: 60 additions & 0 deletions bin/aria2_darwin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
###############################
# Motrix macOS Aria2 config file
#
# @see https://aria2.github.io/manual/en/html/aria2c.html
#
###############################


################ RPC ################
# Enable JSON-RPC/XML-RPC server.
enable-rpc=true
# Add Access-Control-Allow-Origin header field with value * to the RPC response.
rpc-allow-origin-all=true
# Listen incoming JSON-RPC/XML-RPC requests on all network interfaces.
rpc-listen-all=true
# Set the RPC listening port. If this option is used, the default port is 6800.
rpc-listen-port=6800


################ File system ################
# Save a control file(*.aria2) every SEC seconds.
auto-save-interval=10
# Enable disk cache.
disk-cache=64M
# Specify file allocation method.
file-allocation=none
# No file allocation is made for files whose size is smaller than SIZE
no-file-allocation-limit=64M
# Save error/unfinished downloads to a file specified by --save-session option every SEC seconds.
save-session-interval=10


################ Task ################
# Verify the peer using certificates specified in --ca-certificate option.
check-certificate=false
# If aria2 receives "file not found" status from the remote HTTP/FTP servers NUM times
# without getting a single byte, then force the download to fail.
max-file-not-found=10
# Set number of tries.
max-tries=5
# Set the seconds to wait between retries. When SEC > 0, aria2 will retry downloads when the HTTP server returns a 503 response.
retry-wait=10
# Set the connect timeout in seconds to establish connection to HTTP/FTP/proxy server. After the connection is established, this option makes no effect and --timeout option is used instead.
connect-timeout=10
# Set timeout in seconds.
timeout=10
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Send Accept: deflate, gzip request header.
http-accept-gzip=true
# Retrieve timestamp of the remote file from the remote HTTP/FTP server and if it is available, apply it to the local file.
remote-time=true
# Set interval in seconds to output download progress summary. Setting 0 suppresses the output.
summary-interval=0
# Handle quoted string in Content-Disposition header as UTF-8 instead of ISO-8859-1, for example, the filename parameter, but not the extended version filename*.
content-disposition-default-utf8=true
#max connection per server
max-connection-per-server=16
#max concurrent downloads
max-concurrent-downloads=64
60 changes: 60 additions & 0 deletions bin/aria2_linux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
###############################
# Motrix Linux Aria2 config file
#
# @see https://aria2.github.io/manual/en/html/aria2c.html
#
###############################


################ RPC ################
# Enable JSON-RPC/XML-RPC server.
enable-rpc=true
# Add Access-Control-Allow-Origin header field with value * to the RPC response.
rpc-allow-origin-all=true
# Listen incoming JSON-RPC/XML-RPC requests on all network interfaces.
rpc-listen-all=true
# Set the RPC listening port. If this option is used, the default port is 6800.
rpc-listen-port=6800


################ File system ################
# Save a control file(*.aria2) every SEC seconds.
auto-save-interval=10
# Enable disk cache.
disk-cache=64M
# Specify file allocation method.
file-allocation=trunc
# No file allocation is made for files whose size is smaller than SIZE
no-file-allocation-limit=64M
# Save error/unfinished downloads to a file specified by --save-session option every SEC seconds.
save-session-interval=10


################ Task ################
# Verify the peer using certificates specified in --ca-certificate option.
check-certificate=false
# If aria2 receives "file not found" status from the remote HTTP/FTP servers NUM times
# without getting a single byte, then force the download to fail.
max-file-not-found=10
# Set number of tries.
max-tries=5
# Set the seconds to wait between retries. When SEC > 0, aria2 will retry downloads when the HTTP server returns a 503 response.
retry-wait=10
# Set the connect timeout in seconds to establish connection to HTTP/FTP/proxy server. After the connection is established, this option makes no effect and --timeout option is used instead.
connect-timeout=10
# Set timeout in seconds.
timeout=10
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Send Accept: deflate, gzip request header.
http-accept-gzip=true
# Retrieve timestamp of the remote file from the remote HTTP/FTP server and if it is available, apply it to the local file.
remote-time=true
# Set interval in seconds to output download progress summary. Setting 0 suppresses the output.
summary-interval=0
# Handle quoted string in Content-Disposition header as UTF-8 instead of ISO-8859-1, for example, the filename parameter, but not the extended version filename*.
content-disposition-default-utf8=true
#max connection per server
max-connection-per-server=16
#max concurrent downloads
max-concurrent-downloads=64
59 changes: 59 additions & 0 deletions bin/aria2_win32.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
###############################
# Motrix Windows Aria2 config file
#
# @see https://aria2.github.io/manual/en/html/aria2c.html
#
###############################


################ RPC ################
# Enable JSON-RPC/XML-RPC server.
enable-rpc=true
# Add Access-Control-Allow-Origin header field with value * to the RPC response.
rpc-allow-origin-all=true
# Listen incoming JSON-RPC/XML-RPC requests on all network interfaces.
rpc-listen-all=true
# Set the RPC listening port. If this option is used, the default port is 6800.
rpc-listen-port=6800


################ File system ################
# Save a control file(*.aria2) every SEC seconds.
auto-save-interval=10
# Enable disk cache.
disk-cache=64M
# Specify file allocation method.
file-allocation=falloc
# No file allocation is made for files whose size is smaller than SIZE
no-file-allocation-limit=64M
# Save error/unfinished downloads to a file specified by --save-session option every SEC seconds.
save-session-interval=10


################ Task ################
check-certificate=false
# If aria2 receives "file not found" status from the remote HTTP/FTP servers NUM times
# without getting a single byte, then force the download to fail.
max-file-not-found=10
# Set number of tries.
max-tries=5
# Set the seconds to wait between retries. When SEC > 0, aria2 will retry downloads when the HTTP server returns a 503 response.
retry-wait=10
# Set the connect timeout in seconds to establish connection to HTTP/FTP/proxy server. After the connection is established, this option makes no effect and --timeout option is used instead.
connect-timeout=10
# Set timeout in seconds.
timeout=10
# aria2 does not split less than 2*SIZE byte range.
min-split-size=1M
# Send Accept: deflate, gzip request header.
http-accept-gzip=true
# Retrieve timestamp of the remote file from the remote HTTP/FTP server and if it is available, apply it to the local file.
remote-time=true
# Set interval in seconds to output download progress summary. Setting 0 suppresses the output.
summary-interval=0
# Handle quoted string in Content-Disposition header as UTF-8 instead of ISO-8859-1, for example, the filename parameter, but not the extended version filename*.
content-disposition-default-utf8=true
#max connection per server
max-connection-per-server=16
#max concurrent downloads
max-concurrent-downloads=64
Binary file added bin/aria2c_darwin_arm64
Binary file not shown.
Binary file added bin/aria2c_darwin_x64
Binary file not shown.
Binary file modified bin/aria2c_linux_arm64
Binary file not shown.
Binary file added bin/aria2c_linux_armv7l
Binary file not shown.
Binary file renamed bin/aria2c_linux_amd64 → bin/aria2c_linux_x64
Binary file not shown.
Binary file removed bin/aria2c_macos
Binary file not shown.
Binary file removed bin/aria2c_win.exe
Binary file not shown.
Binary file added bin/aria2c_win32_x64.exe
Binary file not shown.
6 changes: 2 additions & 4 deletions gui/download2.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def get_cram_class(course, user_id, access_token):
}


def download2(course_list, user_id, access_token, aria2_path, custom_down_path, now, all):
def download2(course_list, user_id, access_token, aria2_path, aria2_config, custom_down_path, now, all):
global aria2process
if custom_down_path == '':
custom_down_path = "乐读-下载"
Expand Down Expand Up @@ -215,9 +215,7 @@ def switchpauseresume(button):
root = ttk.Window(title='乐读视频下载器-下载', themename="morph")
root.geometry("")
if now==1:
aria2process = subprocess.Popen(
aria2_path + ' --enable-rpc --rpc-listen-port=6800 --max-connection-per-server=16 --file-allocation=none --max-concurrent-downloads=64',
shell=True)
aria2process = subprocess.Popen([aria2_path, "--conf-path", aria2_config])
time.sleep(1)
jsonrpc = Aria2RPC()
lecturers = get_lecturers(course_list, user_id, access_token)
Expand Down
68 changes: 34 additions & 34 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,39 @@ def login():

def download():
result, custom_down_path = download1(uid, token)
aria2_path = get_platform_info()
aria2_path, aria2_config = get_aria2c_path_conf()
for count, course in enumerate(result):
download2(course, uid, token, aria2_path, custom_down_path, count + 1, len(result))


def get_platform_info():
download2(course, uid, token, aria2_path, aria2_config, custom_down_path, count + 1, len(result))


def get_aria2c_path_conf():
arch_map = {
"amd64": "x64",
"AMD64": "x64",
"x86_64": "x64",
"x64": "x64",
"aarch64": "arm64",
"arm64": "arm64",
}
os_map = {
"Windows": "win32",
"Linux": "linux",
"Darwin": "darwin"
}
bundle_dir = sys._MEIPASS if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
platform_ = platform.system()
aria2c_path = ""

if platform_ == 'Windows':
aria2c_path = f"\"{bundle_dir}\\bin\\aria2c_win.exe\""
elif platform_ == 'Linux':
if platform.machine == 'x86_64':
aria2c_path = bundle_dir + '/bin/aria2c_linux_amd64'
if platform.machine in ('armv8', 'armv8l'):
aria2c_path = bundle_dir + '/bin/aria2c_linux_arm64'
elif platform_ == 'Darwin':
aria2c_path = bundle_dir + '/bin/aria2c_macos'
else:
raise Exception(f'暂不支持的系统!请使用Windows、Linux、MacOSX或Android系统(测试中)!你的系统是:{platform_}')

return aria2c_path


try:
login()
download()
except Exception as e:
sentry_sdk.capture_exception(e)
mb.showerror('错误', '错误:' + str(e))
alertdialog = mb.askyesno('错误反馈', '是否打开错误反馈页面?')
if alertdialog:
mb.showinfo('错误反馈', '请在弹出的网页底部评论区中或在GitHub上将错误反馈给开发者!')
webbrowser.open("https://blog.itshenryz.com/2022/06/01/ledu-playback-download/")
sys.exit()
platform_string = os_map[platform.system()]
arch = arch_map[platform.machine()]
return os.path.join(bundle_dir, "bin", f"aria2c_{platform_string}_{arch}" + (".exe" if platform_string == "win32" else "")), os.path.join(bundle_dir, "bin", f"aria2_{platform_string}.conf")


# try:
login()
download()
# except Exception as e:
# sentry_sdk.capture_exception(e)
# mb.showerror('错误', '错误:' + str(e))
# alertdialog = mb.askyesno('错误反馈', '是否打开错误反馈页面?')
# if alertdialog:
# mb.showinfo('错误反馈', '请在弹出的网页底部评论区中或在GitHub上将错误反馈给开发者!')
# webbrowser.open("https://blog.itshenryz.com/2022/06/01/ledu-playback-download/")
# sys.exit()

0 comments on commit c432ff3

Please sign in to comment.