diff options
-rw-r--r-- | README.md | 17 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | tpblite/__init__.py | 2 | ||||
-rw-r--r-- | tpblite/models/constants.py | 23 | ||||
-rw-r--r-- | tpblite/models/torrents.py | 9 | ||||
-rw-r--r-- | tpblite/tpblite.py | 5 |
6 files changed, 41 insertions, 17 deletions
@@ -1,5 +1,7 @@ Unofficial Lightweight Python API for ThePirateBay +[![PyPI version](https://badge.fury.io/py/tpblite.png)](https://badge.fury.io/py/tpblite) + Installation ============= ```sh @@ -54,6 +56,18 @@ torrents = t.browse(category=CATEGORIES.VIDEOS) torrents = t.browse(category=CATEGORIES.VIDEO.MOVIES, page=1, order=ORDERS.UPLOADED.DES) ``` +## Top +```python +from tpblite import TPB, CATEGORIES +t = TPB() + +# Get the top recent torrents +torrents = t.top(CATEGORIES.GAMES.ALL) + +# Customize with category and restriction to torrents from the last 48h +torrents = t.top(category=CATEGORIES.GAMES.ALL, last_48=True) +``` + ## Categories and Sort Order ```python # To print all available categories, use the classmethod printOptions @@ -73,6 +87,7 @@ You can see how many `Torrent` objects your query has returned, by using the `le ## 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) @@ -82,7 +97,7 @@ You can see how many `Torrent` objects your query has returned, by using the `le - `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) - +- `Torrent.url` - url of the torrent page (str) Example Workflow ========== @@ -7,7 +7,7 @@ this_dir = path.abspath(path.dirname(__file__)) with open(path.join(this_dir, 'README.md'), encoding='utf-8') as f: long_description = f.read() -version = '0.3.0' +version = '0.5.0' setup(name = 'tpblite', version = version, diff --git a/tpblite/__init__.py b/tpblite/__init__.py index 6a397d1..47116c6 100644 --- a/tpblite/__init__.py +++ b/tpblite/__init__.py @@ -1,2 +1,2 @@ from tpblite.tpblite import TPB -from tpblite.models.constants import ORDERS, CATEGORIES
\ No newline at end of file +from tpblite.models.constants import ORDERS, CATEGORIES diff --git a/tpblite/models/constants.py b/tpblite/models/constants.py index 214b379..be65286 100644 --- a/tpblite/models/constants.py +++ b/tpblite/models/constants.py @@ -1,16 +1,23 @@ - class OPTION: @classmethod def printOptions(cls): - for opt in [x for x in cls.__dict__.keys() if not (x.startswith('__') or x.startswith('printOptions'))]: - if hasattr(getattr(cls,opt),'__dict__'): - for sub_opt in [y for y in getattr(cls,opt).__dict__.keys() if not (y.startswith('__') or y.startswith('printOptions'))]: - print('{}.{}'.format(opt,sub_opt)) + for opt in [ + x + for x in cls.__dict__.keys() + if not (x.startswith("__") or x.startswith("printOptions")) + ]: + if hasattr(getattr(cls, opt), "__dict__"): + for sub_opt in [ + y + for y in getattr(cls, opt).__dict__.keys() + if not (y.startswith("__") or y.startswith("printOptions")) + ]: + print("{}.{}".format(opt, sub_opt)) else: print(opt) -class ORDERS(OPTION): +class ORDERS(OPTION): class NAME(OPTION): DES = 1 ASC = 2 @@ -42,7 +49,7 @@ class ORDERS(OPTION): class CATEGORIES(OPTION): ALL = 0 - + class AUDIO(OPTION): ALL = 100 MUSIC = 101 @@ -102,4 +109,4 @@ class CATEGORIES(OPTION): PICTURES = 603 COVERS = 604 PHYSIBLES = 605 - OTHER = 699
\ No newline at end of file + OTHER = 699 diff --git a/tpblite/models/torrents.py b/tpblite/models/torrents.py index 4eb5a16..1c2b32d 100644 --- a/tpblite/models/torrents.py +++ b/tpblite/models/torrents.py @@ -28,9 +28,12 @@ class Torrent: self.html_row = html_row self.title = self._getTitle() self.seeds, self.leeches = self._getPeers() - self.upload_date, self.filesize, self.byte_size, self.uploader = ( - self._getFileInfo() - ) + ( + self.upload_date, + self.filesize, + self.byte_size, + self.uploader, + ) = self._getFileInfo() self.magnetlink = self._getMagnetLink() self.url = self._getUrl() diff --git a/tpblite/tpblite.py b/tpblite/tpblite.py index b4028b6..00c3849 100644 --- a/tpblite/tpblite.py +++ b/tpblite/tpblite.py @@ -61,7 +61,7 @@ class TPB: self._search_url = q.url return Torrents(q.html_source) - def top(self, category: int = 0, last_48: bool = False): + def top(self, category: int = 0, last_48: bool = False) -> Torrents: """Get the top torrents of a category and return a list of Torrents Args: @@ -70,9 +70,8 @@ class TPB: last_48: wether to fetch the top torrent in the last 48 hours or the overall top Return: - Torrent object + Torrents object """ q = QueryParser.top(self.base_url, category, last_48) self._search_url = q.url return Torrents(q.html_source) - |