diff options
author | Matt <32886639+mattlyon93@users.noreply.github.com> | 2019-12-25 16:24:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-25 16:24:25 +0000 |
commit | c0b26a45f8bf910de9f594f28003cff7dc9e37a7 (patch) | |
tree | c2aa2b2636acd81e78223284e8ad616ad250bb3a /tpblite/tpblite.py | |
parent | c45b6ca3e82a5d10e14c31c4b7d0fdaf66fff933 (diff) | |
parent | 4418d8c73b26639016733bc0a3264a96046c6ab1 (diff) | |
download | tpb-lite-c0b26a45f8bf910de9f594f28003cff7dc9e37a7.tar.gz tpb-lite-c0b26a45f8bf910de9f594f28003cff7dc9e37a7.tar.bz2 tpb-lite-c0b26a45f8bf910de9f594f28003cff7dc9e37a7.zip |
Merge pull request #2 from JPFrancoia/master
Adding a browse() method to the TPB object, to get torrents by category,
Diffstat (limited to 'tpblite/tpblite.py')
-rw-r--r-- | tpblite/tpblite.py | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/tpblite/tpblite.py b/tpblite/tpblite.py index a2a927d..3c68d62 100644 --- a/tpblite/tpblite.py +++ b/tpblite/tpblite.py @@ -1,34 +1,59 @@ +from typing import Optional + from .models.torrents import Torrents, Torrent from .models.utils import QueryParser -class TPB(object): - - def __init__(self, base_url='https://tpb.party'): - '''ThePirateBay Object + +class TPB: + + def __init__(self, base_url: str = "https://tpb.party"): + """ThePirateBay Object Args: base_url (str): PirateBay URL to use for queries - Attributes: - search_url (str): This is the compiled search string used - to query the PirateBay URL, modified when calling search - method - ''' + """ + # PirateBay URL to use for queries self.base_url = base_url - self.search_url = None - - def __str__(self): - return 'TPB Object, base URL: {}'.format(self.base_url) - - def search(self, query, page=0, order=99, category=0): - '''Search ThePirateBay and retturn list of Torrents + + # Compiled search string used to query the PirateBay URL + self._search_url: Optional[str] = None + + def __str__(self) -> str: + return "TPB Object, base URL: {}".format(self.base_url) + + def search( + self, query: str, page: int = 0, order: int = 99, category: int = 0 + ) -> Torrents: + """Search ThePirateBay and return list of Torrents Args: - query (str): Search string to query ThePirateBay - page (int): page number to grab results from + query: Search string to query ThePirateBay + page: page number to grab results from order TODO category TODO - ''' - q = QueryParser(query, self.base_url, page, order, category) - self.search_url = q.url - return Torrents(query, q.html_source)
\ No newline at end of file + + Return: + Torrents + + """ + q = QueryParser.search(query, self.base_url, page, order, category) + self._search_url = q.url + return Torrents(q.html_source) + + def browse(self, category: int = 0, page: int = 0, order: int = 99) -> Torrents: + """Browse ThePirateBay and return list of Torrents + + Args: + query: Search string to query ThePirateBay + page: page number to grab results from + order TODO + category TODO + + Return: + Torrent + + """ + q = QueryParser.browse(self.base_url, category, page, order) + self._search_url = q.url + return Torrents(q.html_source) |