aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tpblite/models/utils.py8
-rw-r--r--tpblite/tpblite.py16
2 files changed, 24 insertions, 0 deletions
diff --git a/tpblite/models/utils.py b/tpblite/models/utils.py
index 6c479d4..8043707 100644
--- a/tpblite/models/utils.py
+++ b/tpblite/models/utils.py
@@ -42,6 +42,14 @@ class QueryParser:
segments = ("browse", str(category), str(page), str(order), "0")
return cls(base_url, segments)
+ @classmethod
+ def top(cls: Type[T], base_url: str, category: int, last_48: bool) -> T:
+ if last_48:
+ segments = ("top", '48h' + str(category))
+ else:
+ segments = ("top", str(category))
+ return cls(base_url, segments)
+
def _sendRequest(self):
req = Request(self.url, headers=headers())
return urlopen(req).read()
diff --git a/tpblite/tpblite.py b/tpblite/tpblite.py
index 1ec3991..abd59ae 100644
--- a/tpblite/tpblite.py
+++ b/tpblite/tpblite.py
@@ -61,3 +61,19 @@ class TPB:
q = QueryParser.browse(self.base_url, category, page, order)
self._search_url = q.url
return Torrents(q.html_source)
+
+ def top(self, category: int=0, last_48=False):
+ """Get the top torrents of a category and return a list of Torrents
+
+ Args:
+ category: Restrict search to specific category, for list of categories see
+ tpblite.models.constants.CATEGORIES
+ last_48: wether to fetch the top torrent in the last 48 hours or the overall top
+
+ Return:
+ Torrent object
+ """
+ q = QueryParser.top(self.base_url, category, last_48)
+ self._search_url = q.url
+ return Torrents(q.html_source)
+