File size: 1,562 Bytes
4f989ff
 
 
22ba115
03d5549
4f989ff
 
 
 
 
 
f15e553
4f989ff
099be0a
f15e553
 
 
 
099be0a
 
 
03d5549
4f989ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0329f70
4f989ff
 
 
 
22ba115
03d5549
 
22ba115
03d5549
 
 
 
 
 
 
22ba115
03d5549
 
22ba115
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
import libtorrent as lt
import time
import streamlit as st
import os
import shutil

st.title('磁力链接 BT 下载器')

magnet_link = st.text_input('请输入磁力链接:')

if magnet_link:
    # 创建一个会话并配置设置
    ses = lt.session()
    settings = {
        'connections_limit': 500,  # 增加连接数限制
        'download_rate_limit': 0,  # 不限制下载速度
        'upload_rate_limit': 0,    # 不限制上传速度
        # ... 其他设置
    }
    ses.apply_settings(settings)

    h = lt.add_magnet_uri(ses, magnet_link, {'save_path': './downloads'})
    st.write('开始下载...')

    while not h.is_seed():
        s = h.status()
        state_str = [
            "queued",
            "checking",
            "downloading metadata",
            "downloading",
            "finished",
            "seeding",
            "allocating",
            "checking fastresume",
        ]
        st.write(
            f"进度: {s.progress * 100:.2f}%,速度: {s.download_rate / 1000000:.2f} KB/s,状态:{state_str[s.state]}"
        )
        time.sleep(1)

    st.write('下载完成')

    # 获取下载的文件路径
    save_path = './downloads'

    # 压缩文件夹为 zip 文件
    shutil.make_archive('downloads', 'zip', save_path)

    # 提供一个下载按钮给用户下载 zip 文件
    with open('downloads.zip', 'rb') as file:
        st.download_button(
            label='下载文件',
            data=file,
            file_name='downloads.zip',
            mime='application/zip'
        )