Пример #1
0
async def download(t_file : str, download_loc : str, loop=None):
    '''Entry point for client, initializes `Peers` and `DownloadSession` according to 
    configureation present in `t_file` which is the .torrent file and saves the 
    downloaded file to `download_loc` directory'''

    torrent = Torrent(t_file)
    LOG.info('Torrent : {}'.format(torrent))

    torrent_writer = FileSaver(download_loc, torrent) 
    session = DownloadSession(torrent, torrent_writer.get_received_blocks_queue())

    tracker = Tracker(torrent) # implement Tracker class
    peer_info = await tracker.get_peers()

    seen_peers = set()
    peers = [Peer(session, host, port) for host, port in peer_info]
    seen_peers.update([str(p) for p in peers])
    LOG.info('Peers : {}'.format(seen_peers))

    asyncio.gather([peer.download() for peer in peers])