From a0feed3695668e632021ac41c4e84a624f8b630a Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 17 Nov 2024 22:56:10 +0100 Subject: [PATCH] Scripts: support .png-uploads in imgur-to-panoramax script --- scripts/ImgurToPanoramax.ts | 19 +++++++++++++------ src/Logic/ImageProviders/Imgur.ts | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/ImgurToPanoramax.ts b/scripts/ImgurToPanoramax.ts index 10f16d699..dcdbad55c 100644 --- a/scripts/ImgurToPanoramax.ts +++ b/scripts/ImgurToPanoramax.ts @@ -137,6 +137,7 @@ export class ImgurToPanoramax extends Script { if (!v) { return undefined } + const isPng = v.endsWith(".png") const imageHash = v.split("/").at(-1).split(".").at(0) { @@ -151,7 +152,9 @@ export class ImgurToPanoramax extends Script { } let path: string = undefined - if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) { + if (isPng) { + path = this._imageDirectory + "/../imgur_png_images/jpg/" + imageHash + ".jpg" + } else if (existsSync(this._imageDirectory + "/" + imageHash + ".jpg")) { path = this._imageDirectory + "/" + imageHash + ".jpg" } else if (existsSync(this._imageDirectory + "/" + imageHash + ".jpeg")) { path = this._imageDirectory + "/" + imageHash + ".jpeg" @@ -164,7 +167,7 @@ export class ImgurToPanoramax extends Script { license = await this.getLicenseFor(v) } catch (e) { console.error("Could not fetch license due to", e) - if(e === 404){ + if (e === 404) { console.log("NOT FOUND") return new Tag(key, "") } @@ -174,6 +177,10 @@ export class ImgurToPanoramax extends Script { return undefined } const sequence = this.sequenceIds[license.licenseShortName?.toLowerCase()] + console.log("Reading ",path) + if(!existsSync(path)){ + return undefined + } const handle = await open(path) const stat = await handle.stat() @@ -262,12 +269,12 @@ export class ImgurToPanoramax extends Script { const bounds = new BBox([ [ - 5.051208080670676, - 45.55085138791583 + -180, + -90 ], [ - 14.998934008628453, - 55.163232765096495 + 180, + 90 ] ]) const maxcount = 10000 diff --git a/src/Logic/ImageProviders/Imgur.ts b/src/Logic/ImageProviders/Imgur.ts index 44e633057..dfa7f8b08 100644 --- a/src/Logic/ImageProviders/Imgur.ts +++ b/src/Logic/ImageProviders/Imgur.ts @@ -95,7 +95,7 @@ export class Imgur extends ImageProvider { withResponse?: (obj) => void ): Promise { const url = providedImage.url - const hash = url.substr("https://i.imgur.com/".length).split(/\.jpe?g/i)[0] + const hash = url.substr("https://i.imgur.com/".length).split(/(\.jpe?g)|(\.png)/i)[0] const apiUrl = "https://api.imgur.com/3/image/" + hash const response = await Utils.downloadJsonCached<{