Skip to main content

TCP and UDP bittorrent tracker scraping abstraction.

Project description

Bittorrent Tracker Scraping

https://img.shields.io/pypi/v/bittorrent_tracker_scraping.svg https://img.shields.io/travis/1elie1/bittorrent_tracker_scraping.svg

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}]

History

0.1.0 (2018-11-10)

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bittorrent-tracker-scraping, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size bittorrent_tracker_scraping-0.1.0-py3-none-any.whl (12.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size bittorrent_tracker_scraping-0.1.0.tar.gz (8.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page