Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PT Screens image host #352

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion data/example-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 23 additions & 0 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {
Expand All @@ -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()
Expand Down