def parse_torrent(torrent: bytes) -> Torrent: """Returns Torrent object from torrent contents. :param torrent: Torrent file contents. """ return Torrent.from_string(torrent)
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
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
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
def test_from_string(): torrstr = '4:spam' t = Torrent.from_string(torrstr) assert t._struct == 'spam'