diff --git a/data/example-config.py b/data/example-config.py index c1b37e8dc..937c227c6 100644 --- a/data/example-config.py +++ b/data/example-config.py @@ -10,13 +10,15 @@ "imgbb_api" : "imgbb api key", "ptpimg_api" : "ptpimg api key", "lensdump_api" : "lensdump api key", + "ptscreens_api" : "ptscreens api key", # Order of image hosts, and backup image hosts "img_host_1": "imgbb", "img_host_2": "ptpimg", "img_host_3": "imgbox", - "img_host_4": "pixhost", + "img_host_4": "pixhost", "img_host_5": "lensdump", + "img_host_6": "ptscreens", "screens" : "6", diff --git a/src/args.py b/src/args.py index ff93c8e0e..413b63b25 100644 --- a/src/args.py +++ b/src/args.py @@ -51,7 +51,7 @@ def parse(self, args, meta): parser.add_argument('-d', '--desc', nargs='*', required=False, help="Custom Description (string)") parser.add_argument('-pb', '--desclink', nargs='*', required=False, help="Custom Description (link to hastebin/pastebin)") parser.add_argument('-df', '--descfile', nargs='*', required=False, help="Custom Description (path to file)") - parser.add_argument('-ih', '--imghost', nargs='*', required=False, help="Image Host", choices=['imgbb', 'ptpimg', 'imgbox', 'pixhost', 'lensdump']) + parser.add_argument('-ih', '--imghost', nargs='*', required=False, help="Image Host", choices=['imgbb', 'ptpimg', 'imgbox', 'pixhost', 'lensdump', 'ptscreens']) parser.add_argument('-siu', '--skip-imagehost-upload', dest='skip_imghost_upload', action='store_true', required=False, help="Skip Uploading to an image host") parser.add_argument('-th', '--torrenthash', nargs='*', required=False, help="Torrent Hash to re-use from your client's session directory") parser.add_argument('-nfo', '--nfo', action='store_true', required=False, help="Use .nfo in directory for description") diff --git a/src/prep.py b/src/prep.py index 7bbbd970a..8fc69a101 100644 --- a/src/prep.py +++ b/src/prep.py @@ -718,6 +718,8 @@ def disc_screenshots(self, filename, bdinfo, folder_id, base_dir, use_vs, image_ i += 1 elif self.img_host == "lensdump": i += 1 + elif self.img_host == "ptscreens": + i += 1 else: console.print("[red]Image too large for your image host, retaking") time.sleep(1) @@ -2150,6 +2152,26 @@ def upload_screens(self, meta, screens, img_host_num, i, total_screens, custom_i progress.console.print("[yellow]ptpimg failed, trying next image host") progress.stop() newhost_list, i = self.upload_screens(meta, screens - i, img_host_num + 1, i, total_screens, [], return_dict) + elif img_host == "ptscreens": + url = "https://ptscreens.com/api/1/upload" + data = { + 'image': base64.b64encode(open(image, "rb").read()).decode('utf8') + } + headers = { + 'X-API-Key': self.config['DEFAULT']['ptscreens_api'], + } + try: + response = requests.post(url, data=data, headers=headers, timeout=timeout) + response = response.json() + if response.get('status_code') != 200: + progress.console.print(response) + img_url = response['data'].get('medium', response['data']['image'])['url'] + web_url = response['data']['url_viewer'] + raw_url = response['data']['image']['url'] + except Exception: + progress.console.print("[yellow]ptscreens failed, trying next image host") + progress.stop() + newhost_list, i = self.upload_screens(meta, screens - i , img_host_num + 1, i, total_screens, [], return_dict) elif img_host == "lensdump": url = "https://lensdump.com/api/1/upload" data = { @@ -2170,6 +2192,7 @@ def upload_screens(self, meta, screens, img_host_num, i, total_screens, custom_i progress.console.print("[yellow]lensdump failed, trying next image host") progress.stop() newhost_list, i = self.upload_screens(meta, screens - i , img_host_num + 1, i, total_screens, [], return_dict) + else: console.print("[bold red]Please choose a supported image host in your config") exit()