From 5ec4ebb8742db514b55784828f247ea4790377b7 Mon Sep 17 00:00:00 2001 From: dotnet Date: Fri, 13 Oct 2023 17:50:15 -0400 Subject: [PATCH] Ensure pixiv urls are correct. --- gelbooru_poster.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gelbooru_poster.py b/gelbooru_poster.py index f406349..511d138 100644 --- a/gelbooru_poster.py +++ b/gelbooru_poster.py @@ -12,6 +12,19 @@ from PIL import Image from io import BytesIO import urllib.parse +def gelboorusource_urlcleaner(url): + # Split out all urls in the string + url = url.split(" ")[0] + + #Check if the url matches the old pixiv url format + if url.startswith("http://www.pixiv.net/member_illust.php?mode=medium&illust_id="): + #Extract the id from the url + url = url.replace("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=", "") + #Return the new url + return "https://www.pixiv.net/en/artworks/" + url + + return url + class BotInstance: # Gelbooru API URL gelbooru_url = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=100&tags=" @@ -66,7 +79,7 @@ class BotInstance: if 'source' not in gelbooru_json['post'][image_number] or gelbooru_json['post'][image_number]["source"] == "": image_src = image_url else: - image_src = gelbooru_json['post'][image_number]["source"] + image_src = gelboorusource_urlcleaner(gelbooru_json['post'][image_number]["source"]) # Get the image rating image_rating = gelbooru_json['post'][image_number]["rating"]