diff --git a/data/example-config.py b/data/example-config.py index 89d9acbe..dd9b0d78 100644 --- a/data/example-config.py +++ b/data/example-config.py @@ -38,6 +38,10 @@ # Play the bell sound effect when asking for confirmation "sfx_on_prompt": True, + # Run an API search after upload to find the permalink and insert as comment in torrent + # Needs a 5 second wait to ensure the API is updated + "get_permalink": False, + }, "TRACKERS": { diff --git a/src/trackers/ACM.py b/src/trackers/ACM.py index 1970a8e1..71e3d3c3 100644 --- a/src/trackers/ACM.py +++ b/src/trackers/ACM.py @@ -7,6 +7,7 @@ from str2bool import str2bool from src.trackers.COMMON import COMMON from src.console import console +import bencodepy class ACM(): @@ -374,3 +375,42 @@ async def edit_desc(self, meta): descfile.write(self.signature) descfile.close() return + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/AITHER.py b/src/trackers/AITHER.py index d58d1428..027fb0a6 100644 --- a/src/trackers/AITHER.py +++ b/src/trackers/AITHER.py @@ -5,6 +5,7 @@ from str2bool import str2bool import platform import re +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -224,3 +225,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/AL.py b/src/trackers/AL.py index dcc7b677..50c0f1d5 100644 --- a/src/trackers/AL.py +++ b/src/trackers/AL.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -179,3 +180,42 @@ async def search_existing(self, meta, disctype): async def edit_name(self, meta): name = meta['uuid'].replace('.mkv', '').replace('.mp4', '').replace(".", " ").replace("DDP2 0", "DDP2.0").replace("DDP5 1", "DDP5.1").replace("H 264", "x264").replace("H 265", "x265").replace("DD+7 1", "DDP7.1").replace("AAC2 0", "AAC2.0").replace('DD5 1', 'DD5.1').replace('DD2 0', 'DD2.0').replace('TrueHD 7 1', 'TrueHD 7.1').replace('DTS-HD MA 7 1', 'DTS-HD MA 7.1').replace('DTS-HD MA 5 1', 'DTS-HD MA 5.1').replace("TrueHD 5 1", "TrueHD 5.1").replace("DTS-X 7 1", "DTS-X 7.1").replace("DTS-X 5 1", "DTS-X 5.1").replace("FLAC 2 0", "FLAC 2.0").replace("FLAC 2 0", "FLAC 2.0").replace("FLAC 5 1", "FLAC 5.1").replace("DD1 0", "DD1.0").replace("DTS ES 5 1", "DTS ES 5.1").replace("DTS5 1", "DTS 5.1").replace("AAC1 0", "AAC1.0").replace("DD+5 1", "DDP5.1").replace("DD+2 0", "DDP2.0").replace("DD+1 0", "DDP1.0") return name + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/BLU.py b/src/trackers/BLU.py index 6ce0dba5..f88da21b 100644 --- a/src/trackers/BLU.py +++ b/src/trackers/BLU.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -218,3 +219,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/CBR.py b/src/trackers/CBR.py index c090e80a..e7c3c240 100644 --- a/src/trackers/CBR.py +++ b/src/trackers/CBR.py @@ -4,6 +4,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -177,3 +178,42 @@ async def edit_name(self, meta): name = meta['uuid'].replace('.mkv', '').replace('.mp4', '').replace(".", " ").replace("DDP2 0", "DDP2.0").replace("DDP5 1", "DDP5.1").replace("H 264", "H.264").replace("H 265", "H.265").replace("DD+7 1", "DDP7.1").replace("AAC2 0", "AAC2.0").replace('DD5 1', 'DD5.1').replace('DD2 0', 'DD2.0').replace('TrueHD 7 1', 'TrueHD 7.1').replace('DTS-HD MA 7 1', 'DTS-HD MA 7.1').replace('DTS-HD MA 5 1', 'DTS-HD MA 5.1').replace("TrueHD 5 1", "TrueHD 5.1").replace("DTS-X 7 1", "DTS-X 7.1").replace("DTS-X 5 1", "DTS-X 5.1").replace("FLAC 2 0", "FLAC 2.0").replace("FLAC 5 1", "FLAC 5.1").replace("DD1 0", "DD1.0").replace("DTS ES 5 1", "DTS ES 5.1").replace("DTS5 1", "DTS 5.1").replace("AAC1 0", "AAC1.0").replace("DD+5 1", "DDP5.1").replace("DD+2 0", "DDP2.0").replace("DD+1 0", "DDP1.0") return name + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/FNP.py b/src/trackers/FNP.py index eb6ebaa4..9d9baf50 100644 --- a/src/trackers/FNP.py +++ b/src/trackers/FNP.py @@ -4,6 +4,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -166,3 +167,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/HP.py b/src/trackers/HP.py index 76acbb83..609fa066 100644 --- a/src/trackers/HP.py +++ b/src/trackers/HP.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -169,3 +170,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/HUNO.py b/src/trackers/HUNO.py index 558d4b23..afd3d463 100644 --- a/src/trackers/HUNO.py +++ b/src/trackers/HUNO.py @@ -6,6 +6,7 @@ import os import re import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -285,3 +286,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/JPTV.py b/src/trackers/JPTV.py index 76e8e78f..fe28e3df 100644 --- a/src/trackers/JPTV.py +++ b/src/trackers/JPTV.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -198,3 +199,42 @@ async def edit_name(self, meta): name = name.replace("DD+ ", "DD+") return name + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/LCD.py b/src/trackers/LCD.py index 5b7397d3..d4c0a1d4 100644 --- a/src/trackers/LCD.py +++ b/src/trackers/LCD.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -179,3 +180,42 @@ async def edit_name(self, meta): name = meta['uuid'].replace('.mkv', '').replace('.mp4', '').replace(".", " ").replace("DDP2 0", "DDP2.0").replace("DDP5 1", "DDP5.1").replace("H 264", "H.264").replace("H 265", "H.264").replace("DD+7 1", "DD+7.1").replace("AAC2 0", "AAC2.0").replace('DD5 1', 'DD5.1').replace('DD2 0', 'DD2.0').replace('TrueHD 7 1', 'TrueHD 7.1').replace('DTS-HD MA 7 1', 'DTS-HD MA 7.1').replace('-C A A', '-C.A.A'), return name + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/LST.py b/src/trackers/LST.py index a9e55e38..bcc54123 100644 --- a/src/trackers/LST.py +++ b/src/trackers/LST.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -195,3 +196,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/LT.py b/src/trackers/LT.py index c6e0e4be..100af0a0 100644 --- a/src/trackers/LT.py +++ b/src/trackers/LT.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -191,3 +192,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/OE.py b/src/trackers/OE.py index e536179f..08ffd3e6 100644 --- a/src/trackers/OE.py +++ b/src/trackers/OE.py @@ -10,6 +10,7 @@ from src.bbcode import BBCODE from src.trackers.COMMON import COMMON from src.console import console +import bencodepy class OE(): @@ -322,3 +323,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/OTW.py b/src/trackers/OTW.py index 766ebd76..1835c10d 100644 --- a/src/trackers/OTW.py +++ b/src/trackers/OTW.py @@ -4,6 +4,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -166,3 +167,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/PSS.py b/src/trackers/PSS.py index 0f0fde00..e6abcb19 100644 --- a/src/trackers/PSS.py +++ b/src/trackers/PSS.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -168,3 +169,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/R4E.py b/src/trackers/R4E.py index 82a8c808..c2f73f50 100644 --- a/src/trackers/R4E.py +++ b/src/trackers/R4E.py @@ -5,6 +5,7 @@ from str2bool import str2bool import tmdbsimple as tmdb import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -164,3 +165,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/RF.py b/src/trackers/RF.py index 5b9e6b83..463ea981 100644 --- a/src/trackers/RF.py +++ b/src/trackers/RF.py @@ -5,6 +5,7 @@ import platform import re from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -180,3 +181,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/SHRI.py b/src/trackers/SHRI.py index 6862b431..ff254cd2 100644 --- a/src/trackers/SHRI.py +++ b/src/trackers/SHRI.py @@ -4,6 +4,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -166,3 +167,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/STC.py b/src/trackers/STC.py index fb17b2c0..8451a526 100644 --- a/src/trackers/STC.py +++ b/src/trackers/STC.py @@ -3,6 +3,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -182,3 +183,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/STT.py b/src/trackers/STT.py index 2f8ee800..008dd8ad 100644 --- a/src/trackers/STT.py +++ b/src/trackers/STT.py @@ -4,6 +4,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -163,3 +164,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/TDC.py b/src/trackers/TDC.py index b2dd45c8..54f7a98f 100644 --- a/src/trackers/TDC.py +++ b/src/trackers/TDC.py @@ -3,6 +3,7 @@ import asyncio import requests from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -168,3 +169,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/TIK.py b/src/trackers/TIK.py index 6a8b9d98..20659b14 100644 --- a/src/trackers/TIK.py +++ b/src/trackers/TIK.py @@ -10,6 +10,7 @@ import urllib.request import click from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -593,3 +594,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/ULCX.py b/src/trackers/ULCX.py index 2b1b816c..ee708cb4 100644 --- a/src/trackers/ULCX.py +++ b/src/trackers/ULCX.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -161,3 +162,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/UNIT3D_TEMPLATE.py b/src/trackers/UNIT3D_TEMPLATE.py index d3bc0677..4c242f34 100644 --- a/src/trackers/UNIT3D_TEMPLATE.py +++ b/src/trackers/UNIT3D_TEMPLATE.py @@ -4,6 +4,7 @@ import requests import platform from str2bool import str2bool +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -176,3 +177,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/src/trackers/UTP.py b/src/trackers/UTP.py index 30d16fea..c962efe2 100644 --- a/src/trackers/UTP.py +++ b/src/trackers/UTP.py @@ -4,6 +4,7 @@ import requests from str2bool import str2bool import platform +import bencodepy from src.trackers.COMMON import COMMON from src.console import console @@ -165,3 +166,42 @@ async def search_existing(self, meta, disctype): await asyncio.sleep(5) return dupes + + async def search_torrent_page(self, meta, disctype): + torrent_file_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{self.tracker}]{meta['clean_name']}.torrent" + Name = meta['name'] + quoted_name = f'"{Name}"' + + params = { + 'api_token': self.config['TRACKERS'][self.tracker]['api_key'].strip(), + 'name': quoted_name + } + + try: + response = requests.get(url=self.search_url, params=params) + response.raise_for_status() + response_data = response.json() + + if response_data['data'] and isinstance(response_data['data'], list): + details_link = response_data['data'][0]['attributes'].get('details_link') + + if details_link: + with open(torrent_file_path, 'rb') as open_torrent: + torrent_data = open_torrent.read() + + torrent = bencodepy.decode(torrent_data) + torrent[b'comment'] = details_link.encode('utf-8') + updated_torrent_data = bencodepy.encode(torrent) + + with open(torrent_file_path, 'wb') as updated_torrent_file: + updated_torrent_file.write(updated_torrent_data) + + return details_link + else: + return None + else: + return None + + except requests.exceptions.RequestException as e: + print(f"An error occurred during the request: {e}") + return None diff --git a/upload.py b/upload.py index 023a4ddd..aee32010 100644 --- a/upload.py +++ b/upload.py @@ -235,8 +235,9 @@ async def do_the_thing(base_dir): ####### Upload to Trackers ####### # noqa #F266 #################################### common = COMMON(config=config) - api_trackers = ['BLU', 'AITHER', 'STC', 'R4E', 'STT', 'RF', 'ACM', 'LCD', 'HUNO', 'SN', 'LT', 'NBL', 'ANT', 'JPTV', 'TDC', 'OE', 'BHDTV', 'RTF', - 'OTW', 'FNP', 'CBR', 'UTP', 'AL', 'SHRI', 'LST', 'BHD', 'TL', 'TIK', 'PSS', 'ULCX'] + api_trackers = ['BLU', 'AITHER', 'STC', 'R4E', 'STT', 'RF', 'ACM', 'LCD', 'HUNO', 'LT', 'JPTV', 'TDC', 'OE', + 'OTW', 'FNP', 'CBR', 'UTP', 'AL', 'SHRI', 'LST', 'BHD', 'TIK', 'PSS', 'ULCX'] + other_api_trackers = ['SN', 'NBL', 'ANT', 'BHDTV', 'RTF', 'TL'] http_trackers = ['HDB', 'TTG', 'FL', 'PTER', 'HDT', 'MTV'] tracker_class_map = { 'BLU': BLU, 'BHD': BHD, 'AITHER': AITHER, 'STC': STC, 'R4E': R4E, 'THR': THR, 'STT': STT, 'HP': HP, 'PTP': PTP, 'RF': RF, 'SN': SN, 'TIK': TIK, @@ -286,6 +287,51 @@ async def check_mod_q_and_draft(tracker_class, meta, debug, disctype): if tracker in api_trackers: tracker_class = tracker_class_map[tracker](config=config) + if meta['unattended']: + upload_to_tracker = True + else: + try: + upload_to_tracker = cli_ui.ask_yes_no( + f"Upload to {tracker_class.tracker}? {debug}", + default=meta['unattended'] + ) + except (KeyboardInterrupt, EOFError): + sys.exit(1) # Exit immediately + + if upload_to_tracker: + # Get mod_q, draft, or draft/live depending on the tracker + modq, draft = await check_mod_q_and_draft(tracker_class, meta, debug, disctype) + + # Print mod_q and draft info if relevant + if modq is not None: + console.print(f"(modq: {modq})") + if draft is not None: + console.print(f"(draft: {draft})") + + console.print(f"Uploading to {tracker_class.tracker}") + + # Check if the group is banned for the tracker + if check_banned_group(tracker_class.tracker, tracker_class.banned_groups, meta): + continue + + dupes = await tracker_class.search_existing(meta, disctype) + dupes = await common.filter_dupes(dupes, meta) + meta = dupe_check(dupes, meta) + + # Proceed with upload if the meta is set to upload + if meta.get('upload', False): + await tracker_class.upload(meta, disctype) + perm = config['DEFAULT'].get('get_permalink', False) + if perm: + # need a wait so we don't race the api + await asyncio.sleep(5) + await tracker_class.search_torrent_page(meta, disctype) + await asyncio.sleep(0.5) + await client.add_to_client(meta, tracker_class.tracker) + + if tracker in other_api_trackers: + tracker_class = tracker_class_map[tracker](config=config) + if meta['unattended']: upload_to_tracker = True else: