#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'ipetrash'


import sys
from pathlib import Path

import effbot_bencode

sys.path.append(str(Path(__file__).resolve().parent.parent))
from human_byte_size import sizeof_fmt


with open('_.torrent', 'rb') as f:
    torrent_file_bytes = f.read()
    torrent_file_text = torrent_file_bytes.decode('latin1')

torrent = effbot_bencode.decode(torrent_file_text)
total_size = 0

print('Files:')
for file in torrent["info"]["files"]:
    print(f"    {'/'.join(file['path'])!r} - {file['length']:d} bytes")
    total_size += file["length"]

print()
print(f"Total size: {sizeof_fmt(total_size)} ({total_size} bytes)")
Exemplo n.º 2
0
                                                    torrent_file_url,
                                                    info_hash))

            if qb.get_torrent(info_hash):
                print('Торрент {} уже есть в списке раздачи'.format(info_hash))

            else:
                if info_hash != last_info_hash:
                    import requests

                    data = requests.get(torrent_file_url).content.decode(
                        'latin1')

                    import effbot_bencode

                    torrent = effbot_bencode.decode(data)
                    files = [
                        "/".join(file["path"])
                        for file in torrent["info"]["files"]
                    ]

                    # Использование множеств, чтобы узнать разницу списков, т.е. какие файлы были добавлены
                    # А чтобы узнать какие были удалены: list(set(last_torrent_files) - set(files))
                    new_files = list(set(files) - set(last_torrent_files))

                    if last_info_hash is None:
                        print("Добавление торрента с {} файлами: {}".format(
                            len(new_files), new_files))
                    else:
                        print('Торрент изменился, пора его перекачивать')
                        print("Добавлено {} файлов: {}".format(