Ensure pixiv urls are correct.

This commit is contained in:
dotnet 2023-10-13 17:50:15 -04:00
parent 53a09f91cd
commit 5ec4ebb874
1 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,19 @@ from PIL import Image
from io import BytesIO from io import BytesIO
import urllib.parse 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: class BotInstance:
# Gelbooru API URL # Gelbooru API URL
gelbooru_url = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=100&tags=" 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"] == "": if 'source' not in gelbooru_json['post'][image_number] or gelbooru_json['post'][image_number]["source"] == "":
image_src = image_url image_src = image_url
else: else:
image_src = gelbooru_json['post'][image_number]["source"] image_src = gelboorusource_urlcleaner(gelbooru_json['post'][image_number]["source"])
# Get the image rating # Get the image rating
image_rating = gelbooru_json['post'][image_number]["rating"] image_rating = gelbooru_json['post'][image_number]["rating"]