File size: 795 Bytes
4f989ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import libtorrent as lt
import time
import streamlit as st

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

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

if magnet_link:
    ses = lt.session()
    h = lt.add_magnet_uri(ses, magnet_link, {'save_path': './'})
    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 / 1000:.2f} KB/s,状态:{state_str[s.state]}"
        )
        time.sleep(1)

    st.write('下载完成')