Spaces:
Build error
Build error
Commit
·
03d5549
1
Parent(s):
22ba115
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import libtorrent as lt
|
|
| 2 |
import time
|
| 3 |
import streamlit as st
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
st.title('磁力链接 BT 下载器')
|
| 7 |
|
|
@@ -9,7 +10,7 @@ magnet_link = st.text_input('请输入磁力链接:')
|
|
| 9 |
|
| 10 |
if magnet_link:
|
| 11 |
ses = lt.session()
|
| 12 |
-
h = lt.add_magnet_uri(ses, magnet_link, {'save_path': './'})
|
| 13 |
st.write('开始下载...')
|
| 14 |
|
| 15 |
while not h.is_seed():
|
|
@@ -31,16 +32,17 @@ if magnet_link:
|
|
| 31 |
|
| 32 |
st.write('下载完成')
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
files = torrent_info.files()
|
| 37 |
-
filepath = f"./{files.file_path(0)}"
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
data=file,
|
| 44 |
-
file_name=
|
| 45 |
-
mime=
|
| 46 |
)
|
|
|
|
| 2 |
import time
|
| 3 |
import streamlit as st
|
| 4 |
import os
|
| 5 |
+
import shutil
|
| 6 |
|
| 7 |
st.title('磁力链接 BT 下载器')
|
| 8 |
|
|
|
|
| 10 |
|
| 11 |
if magnet_link:
|
| 12 |
ses = lt.session()
|
| 13 |
+
h = lt.add_magnet_uri(ses, magnet_link, {'save_path': './downloads'})
|
| 14 |
st.write('开始下载...')
|
| 15 |
|
| 16 |
while not h.is_seed():
|
|
|
|
| 32 |
|
| 33 |
st.write('下载完成')
|
| 34 |
|
| 35 |
+
# 获取下载的文件路径
|
| 36 |
+
save_path = './downloads'
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# 压缩文件夹为 zip 文件
|
| 39 |
+
shutil.make_archive('downloads', 'zip', save_path)
|
| 40 |
+
|
| 41 |
+
# 提供一个下载按钮给用户下载 zip 文件
|
| 42 |
+
with open('downloads.zip', 'rb') as file:
|
| 43 |
+
st.download_button(
|
| 44 |
+
label='下载文件',
|
| 45 |
data=file,
|
| 46 |
+
file_name='downloads.zip',
|
| 47 |
+
mime='application/zip'
|
| 48 |
)
|