43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
|
|
import libtorrent as lt
|
|
import time
|
|
import os
|
|
|
|
ses = lt.session()
|
|
ses.listen_on(6881, 6891)
|
|
|
|
magnet_uri = "magnet:?xt=urn:btih:19223321411e27f51213a2407842d773f0f8ac4e"
|
|
params = {'save_path': './downloads/'}
|
|
|
|
handle = lt.add_magnet_uri(ses, magnet_uri, params)
|
|
|
|
print("Fetching metadata (torrent info)...")
|
|
while not handle.has_metadata():
|
|
time.sleep(1)
|
|
print(".", end="", flush=True)
|
|
|
|
print("\nMetadata received!")
|
|
|
|
torrent_info = handle.get_torrent_info()
|
|
|
|
print("\nFiles in torrent:")
|
|
for idx, f in enumerate(torrent_info.files()):
|
|
print(f"[{idx}] {f.path} ({f.size / 1_000_000:.2f} MB)")
|
|
|
|
selected_indexes = [0, 2]
|
|
|
|
file_priorities = [0] * torrent_info.num_files()
|
|
for i in selected_indexes:
|
|
file_priorities[i] = 1
|
|
|
|
handle.prioritize_files(file_priorities)
|
|
|
|
print("\nDownloading selected files only...")
|
|
while handle.status().state != lt.torrent_status.seeding:
|
|
s = handle.status()
|
|
print(f"\rProgress: {s.progress * 100:.2f}% | Down: {s.download_rate / 1000:.1f} kB/s | Peers: {s.num_peers}", end=" ")
|
|
time.sleep(1)
|
|
|
|
print("\nDownload complete!")
|
|
|