From e9e1c637b95f609a3053c243f2f5837d5214f3c0 Mon Sep 17 00:00:00 2001 From: Loic Coyle Date: Sat, 22 Aug 2020 18:46:58 +0200 Subject: add url attribute to Torrent --- tpblite/models/torrents.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tpblite/models/torrents.py b/tpblite/models/torrents.py index ada282f..5145289 100644 --- a/tpblite/models/torrents.py +++ b/tpblite/models/torrents.py @@ -33,6 +33,7 @@ class Torrent: self._getFileInfo() ) self.magnetlink = self._getMagnetLink() + self.url = self._getUrl() def __str__(self): return "{0}, S: {1}, L: {2}, {3}".format( @@ -63,10 +64,14 @@ class Torrent: uploader = unicodedata.normalize("NFKD", t[2].replace("ULed by ", "").strip()) return uptime, size, byte_size, uploader + def _getUrl(self): + tag = self.html_row.find("a", class_="detLink") + return tag.get("href") + class Torrents: """ - Torrent object, takes query response and parses into + Torrent object, takes query response and parses into torrent list or dict. Has methods to select items from torrent list. """ -- cgit v1.2.3 From 1b8e16b6cf68fd73b84bbd876ff9a20d43466992 Mon Sep 17 00:00:00 2001 From: Loic Coyle Date: Sun, 23 Aug 2020 15:26:58 +0200 Subject: add missing typing --- tpblite/tpblite.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tpblite/tpblite.py b/tpblite/tpblite.py index b4028b6..9365c7e 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,7 +70,7 @@ 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 -- cgit v1.2.3 From 5c0bec4d7595be3503f43e3e4bd1427d36610e5a Mon Sep 17 00:00:00 2001 From: Loic Coyle Date: Sun, 23 Aug 2020 15:28:51 +0200 Subject: black --- tpblite/__init__.py | 2 +- tpblite/models/constants.py | 23 +++++++++++++++-------- tpblite/models/torrents.py | 9 ++++++--- tpblite/tpblite.py | 1 - 4 files changed, 22 insertions(+), 13 deletions(-) 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 5145289..2a9bffb 100644 --- a/tpblite/models/torrents.py +++ b/tpblite/models/torrents.py @@ -29,9 +29,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 9365c7e..00c3849 100644 --- a/tpblite/tpblite.py +++ b/tpblite/tpblite.py @@ -75,4 +75,3 @@ class TPB: q = QueryParser.top(self.base_url, category, last_48) self._search_url = q.url return Torrents(q.html_source) - -- cgit v1.2.3 From 47bcaca5004b08667368cd3d9d4e01f1ef998343 Mon Sep 17 00:00:00 2001 From: Loic Coyle Date: Wed, 26 Aug 2020 15:34:09 +0200 Subject: add url attribute to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 22e725f..38cfaab 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,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 -- cgit v1.2.3