azidilofficial
@azidilofficial
Ученик

Как скачать torrent?

import warnings

from torrentp.session import Session
from torrentp import TorrentInfo

import libtorrent



# disable DeprecationWarning
warnings.filterwarnings("ignore", category=DeprecationWarning)


torrent_file = "file.torrent"

torrent_info = TorrentInfo(torrent_file, libtorrent)


session = Session(libtorrent).create_session()
_file = session.add_torrent({'ti': torrent_info(), 'save_path': torrent_file})


while(not _file.has_metadata()):
    pass
    
torinfo = _file.get_torrent_info()

for x in range(torinfo.files().num_files()):
    print(torinfo.files().file_path(x))

Этот код только показывает информацию о файлах внутри torrent, а мне нужно скачать файлы в папку save.

Код работает – только показывает имена файлов.
  • Вопрос задан
  • 308 просмотров
Пригласить эксперта
Ответы на вопрос 1
@melodyy
import warnings
import time
import libtorrent as lt

# Disable DeprecationWarning
warnings.filterwarnings("ignore", category=DeprecationWarning)

# Путь к торрент-файлу и папке для сохранения загруженных файлов
torrent_file = "file.torrent"
save_path = "/path/to/save" 

# Создаем сессию и добавляем торрент
session = lt.session()
info = lt.torrent_info(torrent_file)
params = {
    'save_path': save_path,
    'storage_mode': lt.storage_mode_t.storage_mode_sparse,
    'ti': info
}

handle = session.add_torrent(params)

print('Starting download...')

while not handle.is_seed():
    s = handle.status()
    print(f'\rDownload rate: {s.download_rate / 1000:.2f} kB/s, Progress: {s.progress * 100:.2f}%', end='')
    time.sleep(1)

print('\nDownload complete!')

# Вывод информации о загруженных файлах
for file in info.files():
    print(file.path)


маленько измени код под свою папку и пробуй
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
SpectrumData Екатеринбург
от 150 000 до 250 000 ₽
Гринатом Москва
от 150 000 ₽
DIGITAL SECTOR Краснодар
от 150 000 до 250 000 ₽
27 июн. 2024, в 10:20
1000 руб./за проект
27 июн. 2024, в 09:54
3000 руб./за проект