TCP和UDP BitTorrent跟踪器抓取抽象。
bittorrent-tracker-scraping的Python项目详细描述
BitTorrent跟踪器抓取
用于抓取UDP和TCP BitTorrent跟踪器的Python包。
功能
- udptracker:
- []执行超时
- [X]为一个URL收集信息哈希值
- [X]用多个URL擦掉信息散列
- tcptracker:
- [X]实现了scrape方法
- [X]用多个URL擦掉信息散列
- []执行超时
使用量
最高抽象级别:
>>> from asyncio import get_event_loop >>> from aiohttp import ClientSession >>> import bittorrent_tracker_scraping as scraping >>> >>> l = get_event_loop() >>> client = ClientSession() >>> urls = ['http://torrent.ubuntu.com:6969/announce', 'http://torrent.nwps.ws:80/announce', ... 'udp://tracker.coppersurfer.tk:6969/announce', 'udp://explodie.org:6969/announce'] >>> >>> info_hashes = ['5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609'] >>> >>> >>> results = l.run_until_complete(scraping.scrape_trackers(urls, info_hashes, client)) >>> print(results) [{'seeders': 13, 'info_hash': '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', 'completed': 326, 'leechers': 3, 'complete': 1535, 'downloaded': 34534, 'incomplete': 69, 'name': 'ubuntu-18.10-desktop-amd64.iso'}, {'seeders': 7, 'info_hash': '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609', 'completed': 52, 'leechers': 1, 'complete': 619, 'downloaded': 3893, 'incomplete': 26, 'name': 'ubuntu-18.10-live-server-amd64.iso'}]
创建TCP跟踪器:
>>> from asyncio import get_event_loop >>> from bittorrent_tracker_scraping import TCPTracker >>> from aiohttp import ClientSession >>> >>> l = get_event_loop() >>> client = ClientSession() >>> >>> url = 'http://torrent.ubuntu.com:6969/announce' >>> tracker = TCPTracker(url, client)
抓取跟踪器就像将信息散列传递给scrape方法一样简单。 scrape方法返回一个包含none或dictionary的列表:
>>> info_hashes = ['5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609'] >>> data = l.run_until_complete(tracker.scrape(info_hashes)) >>> >>> print(data) [{'complete': 1473, 'downloaded': 34524, 'incomplete': 50, 'name': 'ubuntu-18.10-desktop-amd64.iso', 'info_hash': '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67'}, {'complete': 594, 'downloaded': 3892, 'incomplete': 21, 'name': 'ubuntu-18.10-live-server-amd64.iso', 'info_hash': '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609'}]
或
>>> from asyncio import get_event_loop >>> from bittorrent_tracker_scraping import TCPTracker >>> from aiohttp import ClientSession >>> >>> l = get_event_loop() >>> client = ClientSession() >>> urls = 'http://torrent.ubuntu.com:6969/announce', 'http://torrent.nwps.ws:80/announce' >>> info_hashes = ['5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', ... '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609'] >>> >>> coroutine = TCPTracker.scrape_urls(urls, info_hashes, client) >>> data = l.run_until_complete(coroutine) >>> >>> print(data) [{'complete': 1418, 'downloaded': 33553, 'incomplete': 57, 'name': 'ubuntu-18.10-desktop-amd64.iso', 'info_hash': '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67'}, {'complete': 581, 'downloaded': 3780, 'incomplete': 11, 'name': 'ubuntu-18.10-live-server-amd64.iso', 'info_hash': '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609'}]
创建一个udp跟踪器:
>>> from asyncio import get_event_loop >>> from bittorrent_tracker_scraping import UDPTracker >>> >>> l = get_event_loop() >>> >>> url = 'udp://tracker.coppersurfer.tk:6969/announce' >>> info_hashes = '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609' >>> >>> tracker = UDPTracker(url=url) >>> data = l.run_until_complete(tracker.scrape(info_hashes)) >>> print(data) [{'seeders': 7, 'info_hash': '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', 'completed': 150, 'leechers': 0}, {'seeders': 3, 'info_hash': '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609', 'completed': 25, 'leechers': 1}]
或
>>> from asyncio import get_event_loop >>> >>> l = get_event_loop() >>> >>> urls = 'udp://tracker.coppersurfer.tk:6969/announce', 'udp://explodie.org:6969/announce' >>> info_hashes = '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609' >>> >>> data = l.run_until_complete(UDPTracker.scrape_urls(urls, info_hashes)) >>> print(data) [{'seeders': 12, 'info_hash': '5a8ce26e8a19a877d8ccc927fcc18e34e1f5ff67', 'completed': 326, 'leechers': 3}, {'seeders': 7, 'info_hash': '8c4adbf9ebe66f1d804fb6a4fb9b74966c3ab609', 'completed': 52, 'leechers': 1}]
历史记录
0.1.0(2018-11-10)
- 初次发布。