diff --git a/README.md b/README.md index 5296381..5918dda 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ if no problem or error, You can use `screen` or other software like `supervisor` | force_judge_dupe_loc | Boolean | False | Judge torrent is dupe or not in location before post it to PT-site. | | get_clone_id_from_db | Boolean | True | Enable to get clone torrent's id from database first, then search. | | allow_cat | List | None | Used to limit the reseed torrent category | +| download_torrent | Boolean | False | Download Torrent to temp folder then add to transmission or feed the link | - class extractors.byrbt.Byrbt(NexusPHP) diff --git a/extractors/base/nexusphp.py b/extractors/base/nexusphp.py index 7121a29..64d2bb1 100644 --- a/extractors/base/nexusphp.py +++ b/extractors/base/nexusphp.py @@ -4,6 +4,7 @@ import re +import requests from bs4 import BeautifulSoup from extractors.base.site import Site @@ -34,6 +35,7 @@ def __init__(self, status, cookies, passkey, **kwargs): 4. _FORCE_JUDGE_DUPE_LOC : default False, Judge torrent is dupe or not in location before post it to PT-site. 5. _GET_CLONE_ID_FROM_DB : default True, Enable to get clone torrent's id from database first, then search. 6. _ALLOW_CAT : default None, Used to limit the reseed torrent category + 7. _DOWNLOAD_TORRENT : default False, Download Torrent to temp folder then add to transmission """ self._UPLVER = "yes" if kwargs.setdefault("anonymous_release", True) else "no" @@ -42,6 +44,7 @@ def __init__(self, status, cookies, passkey, **kwargs): self._FORCE_JUDGE_DUPE_LOC = kwargs.setdefault("force_judge_dupe_loc", False) self._GET_CLONE_ID_FROM_DB = kwargs.setdefault("get_clone_id_from_db", True) self._ALLOW_CAT = kwargs.setdefault("allow_cat", None) + self._DOWNLOAD_TORRENT = kwargs.setdefault("download_torrent", False) # -*- Check login's info -*- def session_check(self): @@ -54,7 +57,13 @@ def session_check(self): return self.status def torrent_link(self, tid): - return self.url_host + "/download.php?id={tid}&passkey={pk}".format(tid=tid, pk=self.passkey) + torrent_link = self.url_host + "/download.php?id={tid}&passkey={pk}".format(tid=tid, pk=self.passkey) + if self._DOWNLOAD_TORRENT: + tmp_file = "/tmp/[{}].{}.torrent".format(self.name, tid) + with open(tmp_file, "wb") as torrent: + r = requests.get(torrent_link) + torrent.write(r.content) + return tmp_file # -*- Torrent's download, upload and thank -*- def torrent_download(self, tid, **kwargs): diff --git a/extractors/npubits.py b/extractors/npubits.py index 72c44f3..c483433 100644 --- a/extractors/npubits.py +++ b/extractors/npubits.py @@ -6,6 +6,8 @@ import base64 import re +import requests + from extractors.base.nexusphp import NexusPHP from utils.constants import ubb_clean, episode_eng2chs from utils.load.handler import rootLogger as Logger diff --git a/extractors/ourbits.py b/extractors/ourbits.py index c73fdde..c840e8b 100644 --- a/extractors/ourbits.py +++ b/extractors/ourbits.py @@ -15,14 +15,6 @@ class OurBits(NexusPHP): url_host = "https://ourbits.club" db_column = "ourbits.club" - def torrent_link(self, tid): - torrent_link = self.url_host + "/download.php?id={tid}&passkey={pk}".format(tid=tid, pk=self.passkey) - tmp_file = "/tmp/[OurBits].{}.torrent".format(tid) - with open(tmp_file, "wb") as torrent: - r = requests.get(torrent_link) - torrent.write(r.content) - return tmp_file - def exist_torrent_title(self, tag): torrent_page = self.page_torrent_detail(tid=tag, bs=True) torrent_title = re.search("\[OurBits\]\.(?P.+?)\.torrent", torrent_page.text).group("name") diff --git a/extractors/tjupt.py b/extractors/tjupt.py index 5c36799..f15cb0e 100644 --- a/extractors/tjupt.py +++ b/extractors/tjupt.py @@ -38,14 +38,6 @@ def __init__(self, status, cookies, passkey, **kwargs): super().__init__(status, cookies, passkey, **kwargs) - def torrent_link(self, tid): - torrent_link = self.url_host + "/download.php?id={tid}&passkey={pk}".format(tid=tid, pk=self.passkey) - tmp_file = "/tmp/[TJUPT].{}.torrent".format(tid) - with open(tmp_file, "wb") as torrent: - r = requests.get(torrent_link) - torrent.write(r.content) - return tmp_file - def exist_torrent_title(self, tag): torrent_file_page = self.page_torrent_info(tid=tag, bs=True) if re.search("你没有该权限!", torrent_file_page.text):