From d08d0a8914d06587ba9430a007d616a2084a9d05 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:38:29 +0200 Subject: [PATCH] "booru": waifu.im support --- .../modules/sidebarLeft/anime/BooruImage.qml | 7 ++- .../sidebarLeft/anime/BooruResponse.qml | 3 +- .config/quickshell/services/Booru.qml | 43 +++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml b/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml index 3160b1b58..f869d059d 100644 --- a/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml +++ b/.config/quickshell/modules/sidebarLeft/anime/BooruImage.qml @@ -22,10 +22,10 @@ Button { Process { id: downloadProcess running: false - command: ["bash", "-c", `curl '${imageData.preview_url}' -o '${previewDownloadPath}/${root.fileName}' && echo 'done'`] + command: ["bash", "-c", `curl '${root.imageData.preview_url ?? root.imageData.sample_url}' -o '${root.previewDownloadPath}/${root.fileName}' && echo 'done'`] stdout: SplitParser { onRead: (data) => { - console.log("Download output:", data) + // console.log("Download output:", data) if(data.includes("done")) { imageObject.source = `${previewDownloadPath}/${root.fileName}` } @@ -35,6 +35,9 @@ Button { Component.onCompleted: { if (root.manualDownload) { + // console.log("Manual download triggered") + // console.log("Image data:", JSON.stringify(root.imageData)) + // console.log("Download command:", downloadProcess.command.join(" ")) downloadProcess.running = true } } diff --git a/.config/quickshell/modules/sidebarLeft/anime/BooruResponse.qml b/.config/quickshell/modules/sidebarLeft/anime/BooruResponse.qml index 681906b16..780e3fe9a 100644 --- a/.config/quickshell/modules/sidebarLeft/anime/BooruResponse.qml +++ b/.config/quickshell/modules/sidebarLeft/anime/BooruResponse.qml @@ -207,9 +207,10 @@ Rectangle { Repeater { model: modelData.images delegate: BooruImage { + required property var modelData imageData: modelData rowHeight: imageRow.rowHeight - manualDownload: root.responseData.provider == "danbooru" + manualDownload: ["danbooru", "waifu.im"].includes(root.responseData.provider) previewDownloadPath: root.previewDownloadPath downloadPath: root.downloadPath nsfwPath: root.nsfwPath diff --git a/.config/quickshell/services/Booru.qml b/.config/quickshell/services/Booru.qml index d22985a23..5523fcae6 100644 --- a/.config/quickshell/services/Booru.qml +++ b/.config/quickshell/services/Booru.qml @@ -27,7 +27,7 @@ Singleton { } property var defaultUserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" - property var providerList: ["yandere", "konachan", "zerochan", "danbooru", "gelbooru"] + property var providerList: ["yandere", "konachan", "zerochan", "danbooru", "gelbooru", "waifu.im"] property var providers: { "system": { "name": "System" }, "yandere": { @@ -155,7 +155,32 @@ Singleton { } }) } - } + }, + "waifu.im": { + "name": "waifu.im", + "url": "https://waifu.im", + "api": "https://api.waifu.im/search", + "listAccess": ["images"], + "mapFunc": (response) => { + return response.map(item => { + return { + "id": item.image_id, + "width": item.width, + "height": item.height, + "aspect_ratio": item.width / item.height, + "tags": item.tags.map(tag => {return tag.name}).join(" "), + "rating": item.is_nsfw ? "e" : "s", + "is_nsfw": item.is_nsfw, + "md5": item.md5, + "preview_url": item.sample_url ?? item.url, // preview_url just says access denied (maybe i fucked up and sent too many requests idk) + "sample_url": item.url, + "file_url": item.url, + "file_ext": item.extension, + "source": getWorkingImageSource(item.source) ?? item.url, + } + }) + } + }, } property var currentProvider: ConfigOptions.sidebar.booru.defaultProvider @@ -189,7 +214,7 @@ Singleton { var provider = providers[currentProvider] var baseUrl = provider.api var tagString = tags.join(" ") - if (!nsfw && currentProvider !== "zerochan") { + if (!nsfw && !(["zerochan", "waifu.im"].includes(currentProvider))) { tagString += " rating:safe" } var params = [] @@ -201,6 +226,14 @@ Singleton { params.push("t=" + 1) params.push("p=" + page) } + else if (currentProvider === "waifu.im") { + var tagsArray = tagString.split(" "); + tagsArray.forEach(tag => { + params.push("included_tags=" + encodeURIComponent(tag)); + }); + params.push("limit=" + Math.min(limit, 30)) // Only admin can do > 30 + params.push("is_nsfw=" + (nsfw ? "null" : "false")) // null is random + } else { params.push("tags=" + encodeURIComponent(tagString)) params.push("limit=" + limit) @@ -230,12 +263,14 @@ Singleton { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { try { // console.log("[Booru] Raw response length: " + xhr.responseText.length) - console.log("[Booru] Raw response: " + xhr.responseText) + // console.log("[Booru] Raw response: " + xhr.responseText) var response = JSON.parse(xhr.responseText) // Access nested properties based on listAccess var accessList = providers[currentProvider].listAccess for (var i = 0; i < accessList.length; ++i) { + // console.log("[Booru] Accessing property: " + accessList[i]) + // console.log("[Booru] Current response: " + JSON.stringify(response)) if (response && response.hasOwnProperty(accessList[i])) { response = response[accessList[i]] } else {