Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import libtorrent as lt
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
-
import shutil
|
| 6 |
|
| 7 |
def download_magnet(magnet_uri, download_path):
|
| 8 |
# 创建会话
|
|
@@ -24,12 +23,16 @@ def download_magnet(magnet_uri, download_path):
|
|
| 24 |
# 创建进度条
|
| 25 |
progress_bar = st.progress(0)
|
| 26 |
# 下载文件
|
| 27 |
-
|
|
|
|
| 28 |
s = handle.status()
|
| 29 |
progress = s.total_done / total_size
|
|
|
|
|
|
|
|
|
|
| 30 |
progress_bar.progress(progress)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
# 下载完成,返回文件路径
|
| 34 |
return os.path.join(download_path, handle.name())
|
| 35 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import libtorrent as lt
|
| 3 |
import os
|
| 4 |
+
import time
|
|
|
|
| 5 |
|
| 6 |
def download_magnet(magnet_uri, download_path):
|
| 7 |
# 创建会话
|
|
|
|
| 23 |
# 创建进度条
|
| 24 |
progress_bar = st.progress(0)
|
| 25 |
# 下载文件
|
| 26 |
+
start_time = time.time()
|
| 27 |
+
while not handle.is_seed():
|
| 28 |
s = handle.status()
|
| 29 |
progress = s.total_done / total_size
|
| 30 |
+
download_rate = s.download_rate / 1000 # 转换为 KB/s
|
| 31 |
+
elapsed_time = time.time() - start_time
|
| 32 |
+
remaining_time = (total_size - s.total_done) / (s.download_rate or 1)
|
| 33 |
progress_bar.progress(progress)
|
| 34 |
+
st.write(f"下载进度:{progress * 100:.2f}% 下载速率:{download_rate:.2f} KB/s 剩余时间:{remaining_time:.2f} 秒")
|
| 35 |
+
time.sleep(1)
|
| 36 |
# 下载完成,返回文件路径
|
| 37 |
return os.path.join(download_path, handle.name())
|
| 38 |
|