Esempio n. 1
0
def parse_torrent(torrent: bytes) -> Torrent:
    """Returns Torrent object from torrent contents.

    :param torrent: Torrent file contents.

    """
    return Torrent.from_string(torrent)
Esempio n. 2
0
def parse_torrent(torrent: bytes) -> Optional[Torrent]:
    """Returns Torrent object from torrent contents.

    :param torrent: Torrent file contents.

    """
    try:
        return Torrent.from_string(torrent)

    except BencodeDecodingError as e:
        LOGGER.error(f'Unable to parse torrent: {e}')
        return None
Esempio n. 3
0
def parse_torrent(torrent):
    """Returns a dictionary with basic information from torrent contents.

    :param torrent:
    :return: torrent info dict - keys: hash; name; files; torrent (torrent file contents just from input).
    :rtype: dict
    """
    torrent_info = Torrent.from_string(torrent)
    files_from_torrent = [a_file[0] for a_file in torrent_info.files]
    info = {
        'hash': str(torrent_info.info_hash),
        'name': torrent_info.name,
        'files': files_from_torrent,
        'torrent': torrent
    }
    return info
Esempio n. 4
0
def parse_torrent(torrent):
    """Returns a dictionary with basic information from torrent contents.

    :param torrent:
    :return: torrent info dict - keys: hash; name; files; torrent (torrent file contents just from input).
    :rtype: dict
    """
    torrent_info = Torrent.from_string(torrent)
    files_from_torrent = [a_file[0] for a_file in torrent_info.files]
    info = {
        'hash': str(torrent_info.info_hash),
        'name': torrent_info.name,
        'files': files_from_torrent,
        'torrent': torrent
    }
    return info
Esempio n. 5
0
File: utils.py Progetto: alv1r/torrt
def parse_torrent(torrent: bytes) -> dict:
    """Returns a dictionary with basic information from torrent contents.

        keys:
            * hash;
            * name;
            * files;
            * torrent (torrent file contents just from input).

    :param torrent:

    """
    torrent_info = Torrent.from_string(torrent)

    files_from_torrent = [a_file[0] for a_file in torrent_info.files]
    info = {
        'hash': str(torrent_info.info_hash),
        'name': torrent_info.name,
        'files': files_from_torrent,
        'torrent': torrent
    }
    return info
Esempio n. 6
0
def test_from_string():
    torrstr = '4:spam'
    t = Torrent.from_string(torrstr)
    assert t._struct == 'spam'
Esempio n. 7
0
def test_from_string():
    torrstr = '4:spam'
    t = Torrent.from_string(torrstr)
    assert t._struct == 'spam'