Bittorrent Tracker Scraping
Python package for scraping udp and tcp bittorrent trackers.
Features
- UDPTracker:
-
- [ ] Implement Timeout
- [x] Scrape info_hashes for one url
- [x] Scrape info_hashes with multiple urls
- TCPTracker:
-
- [x] Scrape method implemented
- [x] Scrape info_hashes with multiple urls
- [ ] Implement Timeout
Usage
Highest level of abstraction:
>>> 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'}]
Create a TCP Tracker:
>>> 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)
Scraping trackers is as easy as passing the info_hashes to the scrape method. The scrape method returns a list containing None or dictionaries:
>>> 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'}]
OR
>>> 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'}]
Create a UDP Tracker:
>>> 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}]
OR
>>> 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}]