aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md82
-rw-r--r--setup.py32
-rw-r--r--tpblite/__init__.py2
-rw-r--r--tpblite/models/torrents.py20
4 files changed, 109 insertions, 27 deletions
diff --git a/README.md b/README.md
index e69de29..d47db7d 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,82 @@
+Unofficial Lightweight Python API for ThePirateBay
+
+Installation
+=============
+```sh
+$ pip install tpblite
+```
+
+Dependencies:
+ - BeautifulSoup
+ - purl
+
+Usage
+==========
+
+```python
+from tpblite import TPB
+
+# Create a TPB object with a domain name
+t = TPB('https://thepiratebay.org')
+
+# Or create a TPB object with default domain
+t = TPB()
+```
+## Search
+```python
+# Quick search for torrents, returns a Torrents object
+torrents = t.search('public domain')
+
+# See how many torrents were found
+print('There were {0} torrents found.'.format(len(torrents))
+
+# Iterate through list of torrents and print info for Torrent object
+for torrent in torrents:
+ print(torrent)
+
+# Customize your search
+from tpb import CATEGORIES, ORDERS
+torrents = t.search('public domain', page=2, order=ORDERS.NAME.DEC, category=CATEGORIES.VIDEO.MOVIES)
+
+# Get the most seeded torrent based on a filter
+torrent = torrents.getBestTorrent(min_seeds=30, min_filesize='500 MiB', max_filesize='4 GiB')
+
+# Or select a particular torrent by indexing
+torrent = torrents[3]
+
+# Get the magnet link for a torrent
+print(torrent.magnetlink)
+```
+## Torrents object
+The search function returns a `Torrents` object, which is a *list-like* collection of the torrents found.
+
+You can also iterate over the `Torrents` object just by calling it in a for loop (see example above).
+
+You can see how many `Torrent` objects your query has returned, by using the `len()` function
+
+## Torrent object
+`Torrent` objects represent each torrent found in the `Torrents` class, they have the following attributes
+### Attributes
+- `Torrent.title` - The name of the torrent (str)
+- `Torrent.seeds` - The number of seeders (int)
+- `Torrent.leeches` - The number of leechers (int)
+- `Torrent.upload_date` - Date the torrent was uploaded (str)
+- `Torrent.uploader` - Name of user who uploaded torrent (str)
+- `Torrent.filesize` - The filesize in *iB format, eg. 5 GiB (str)
+- `Torrent.byte_size` - The filesize in bytes of the torrent (int)
+- `Torrent.magnetlink` - magnetlink of the torrent (str)
+
+
+Example Workflow
+==========
+
+With a commandline torrent client such as [aria2](), you can automate search and downloading of torrents like so:
+```python
+import subprocess
+from tpblite import TPB
+
+t = TPB()
+torrents = t.search('GIMP 2.10.8')
+torrent = torrents.getBestTorrent()
+subprocess.call(['aria2c', torrent.magnetlink])
+``` \ No newline at end of file
diff --git a/setup.py b/setup.py
index 9c98f92..14f35f3 100644
--- a/setup.py
+++ b/setup.py
@@ -2,21 +2,25 @@
from setuptools import setup, find_packages
-setup(name='tpblite',
- version='0.1.3',
- description='The Unofficial Pirate Bay Lightweight Python API',
- author='Matt Lyon',
- author_email='matthewlyon18@gmail.com',
- python_requires='>=3.6',
- license='MIT License',
- packages=['tpblite', 'tpblite/models'],
- install_requires=[
+setup(name = 'tpblite',
+ version = '0.2.0',
+ description = 'The Unofficial Pirate Bay Lightweight Python API',
+ author = 'Matt Lyon',
+ author_email = 'matthewlyon18@gmail.com',
+ python_requires = '>=3.6',
+ url = 'https://github.com/mattlyon93/tpb-lite',
+ license = 'MIT License',
+ packages = ['tpblite', 'tpblite/models'],
+ install_requires = [
'beautifulsoup4',
- 'purl',
- ],
- classifiers=[
+ 'purl'],
+ classifiers = [
+ 'Development Status :: 3 - Alpha',
'Programming Language :: Python',
'Operating System :: Unix',
- 'Operating System :: MacOS'
- ],
+ 'Operating System :: MacOS',
+ 'Topic :: Internet :: WWW/HTTP :: Browsers',
+ 'Topic :: Internet :: WWW/HTTP :: Indexing/Search',
+ 'Topic :: Utilities'],
+ keywords = ['ThePirateBay', 'PirateBay', 'torrent']
) \ No newline at end of file
diff --git a/tpblite/__init__.py b/tpblite/__init__.py
index e69de29..6a397d1 100644
--- a/tpblite/__init__.py
+++ b/tpblite/__init__.py
@@ -0,0 +1,2 @@
+from tpblite.tpblite import TPB
+from tpblite.models.constants import ORDERS, CATEGORIES \ No newline at end of file
diff --git a/tpblite/models/torrents.py b/tpblite/models/torrents.py
index 87a3b6b..eb007cb 100644
--- a/tpblite/models/torrents.py
+++ b/tpblite/models/torrents.py
@@ -2,7 +2,6 @@ import re
import unicodedata
from bs4 import BeautifulSoup
-#TODO: implement a pretty print for Torrents object
#TODO: write better comments
def fileSizeStrToInt(size_str):
@@ -73,7 +72,7 @@ class Torrents(object):
self.__search_set = None
self.html_source = html_source
- self.list = self._createTorrentListMod()
+ self.list = self._createTorrentList()
def __str__(self):
return 'Torrents object: {} torrents'.format(len(self.list))
@@ -87,21 +86,16 @@ class Torrents(object):
def __len__(self):
return len(self.list)
+ def __getitem__(self,index):
+ return self.list[index]
+
@property
- def search_set(self):
+ def _search_set(self):
if self.__search_set == None:
self.__search_set = set(filter(None, re.split(r'[\s.|\(|\)]',self.search_str.lower())))
return self.__search_set
-
- def _createTorrentList(self):
- soup = BeautifulSoup(self.html_source, features='html.parser')
- rows = self.__getRows(soup)
- torrents = []
- for row in rows:
- torrents.append(Torrent(row))
- return torrents
- def _createTorrentListMod(self):
+ def _createTorrentList(self):
soup = BeautifulSoup(self.html_source, features='html.parser')
rows = soup.body.find_all('tr')
torrents = []
@@ -109,7 +103,7 @@ class Torrents(object):
# Get the lowercase unique set from the row text
text_set = set(filter(None, re.split(r'[\s.|\(|\)]',row.text.lower())))
# Check if search string is subset
- if self.search_set.issubset(text_set):
+ if self._search_set.issubset(text_set):
torrents.append(Torrent(row))
return torrents