From 1bbe60d3a237cfe99dc6d1a3aa14de542668dc6f Mon Sep 17 00:00:00 2001 From: Starscouts Date: Thu, 11 Jul 2024 00:25:16 +0200 Subject: Update intimate --- intimate/src/fetcher.js | 64 ++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) (limited to 'intimate/src') diff --git a/intimate/src/fetcher.js b/intimate/src/fetcher.js index bf80203..4375fe5 100755 --- a/intimate/src/fetcher.js +++ b/intimate/src/fetcher.js @@ -63,43 +63,24 @@ async function slideshowMain() { initiateLoad(); let pageDerpibooru = 1; - let pageE621 = 1; let pageLocal = 1; let seed = Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex"); console.log(config); - async function loadNextPageE621() { - if (!config.modules.e621 || !config._show.e621) return; - console.log("Slideshow: Loading page " + pageE621 + " from e621"); - - let res = await fetch("https://e621.net/posts.json?limit=" + Math.round(50 * config.modules.e621.proportion) + "&tags=order:random%20fav:" + encodeURIComponent(config.modules.e621.source) + "%20rating:" + (testMode ? "q" : "e") + "%20randseed:" + seed + "&page=" + pageE621); - let json = await res.json(); - - if (json["posts"].length === 0 && pageE621 !== 1) { - console.log("Slideshow: Reached the end of e621, wrapping around"); - pageE621 = 1; - await loadNextPageE621(); - return; - } - - json["posts"] = json["posts"].map(i => { - i["view_url"] = i["file"]["url"]; - i["mime_type"] = extToMime(i["file"]["ext"]); - i["_source"] = "https://e621.net/posts/" + i["id"]; - return i; - }); - - window.displayQueue.push(...json["posts"]); - window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random()); - pageE621++; - } - async function loadNextPageDerpibooru() { - if (!config.modules.derpibooru || !config._show.derpibooru) return; + if (!config.modules.derpibooru || !(config._sessionPreferences.sources === 0 || config._sessionPreferences.sources === 2)) return; console.log("Slideshow: Loading page " + pageDerpibooru + " from Derpibooru"); - let res = await fetch("https://derpibooru.org/api/v1/json/search/images/?q=" + (testMode ? "suggestive" : "explicit") + ",%20faved_by:" + encodeURIComponent(config.modules.derpibooru.source) + "&per_page=" + Math.round(50 * config.modules.derpibooru.proportion) + "&filter_id=56027&sf=random:" + seed + "&page=" + pageDerpibooru); + let res = await fetch("https://derpibooru.org/api/v1/json/search/images/?q=" + (testMode ? "suggestive" : "explicit") + ( + config._sessionPreferences.content === 0 ? + ",%20mime_type:image/*" + : (config._sessionPreferences.content === 1 ? + ",%20mime_type:video/*" + : + "" + ) + ) + ",%20faved_by:" + encodeURIComponent(config.modules.derpibooru.source) + "&per_page=" + Math.round(50 * config.modules.derpibooru.proportion) + "&filter_id=56027&sf=random:" + seed + "&page=" + pageDerpibooru); let json = await res.json(); if (json["images"].length === 0 && pageDerpibooru !== 1) { @@ -114,19 +95,24 @@ async function slideshowMain() { return i; }); - window.displayQueue.push(...json["images"]); + window.displayQueue.push(...json["images"].map(i => { + if (!config.modules.derpibooru['faunerie_cache']) return i; + if (!fs.existsSync(config.modules.derpibooru['faunerie_cache'] + "/images/" + i['sha512_hash'].substring(0, 1) + "/" + i['sha512_hash'].substring(0, 2) + "/" + i['sha512_hash'].substring(0, 3) + "/10" + i['id'] + ".bin")) return i; + i['view_url'] = "pbip://" + config.modules.derpibooru['faunerie_cache'] + "/images/" + i['sha512_hash'].substring(0, 1) + "/" + i['sha512_hash'].substring(0, 2) + "/" + i['sha512_hash'].substring(0, 3) + "/10" + i['id'] + ".bin"; + return i; + })); window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random()); pageDerpibooru++; } let fullList; - if (config.modules.local && config._show.local) { - fullList = (await getFiles(config.modules.local.source)).filter(i => extToMime(path.extname(i))); + if (config.modules.local && (config._sessionPreferences.sources === 1 || config._sessionPreferences.sources === 2)) { + fullList = (await getFiles(config.modules.local.source)).filter(i => !path.basename(i).startsWith(".") && extToMime(path.extname(i))); } async function loadNextPageLocal() { - if (!config.modules.local || !config._show.local) return; + if (!config.modules.derpibooru || !(config._sessionPreferences.sources === 1 || config._sessionPreferences.sources === 2)) return; console.log("Slideshow: Loading page " + pageLocal + " from local filesystem"); let res = fullList.slice((pageLocal - 1) * Math.round(50 * config.modules.derpibooru.proportion), pageLocal * Math.round(50 * config.modules.derpibooru.proportion)); @@ -154,19 +140,25 @@ async function slideshowMain() { }); window.displayQueue.push(...json["images"]); - window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random()); + window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random()).filter(i => { + if (config._sessionPreferences.content === 0) { + return i.mime_type.startsWith("image/"); + } else if (config._sessionPreferences.content === 1) { + return i.mime_type.startsWith("video/"); + } else { + return true; + } + }); pageLocal++; } console.log("Slideshow: Loading first page"); await loadNextPageDerpibooru(); - await loadNextPageE621(); await loadNextPageLocal(); console.log("Slideshow: Starting slideshow"); await startSlideshow(false, async () => { await loadNextPageDerpibooru(); - await loadNextPageE621(); await loadNextPageLocal(); }); -- cgit