Fix bug and add inkbunny
parent
80b3fb46d8
commit
45edf27da9
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "neo-scraper",
|
"name": "neo-scraper",
|
||||||
"version": "0.4.1",
|
"version": "0.4.2",
|
||||||
"description": "Scrape a booru-like post object from the DOM.",
|
"description": "Scrape a booru-like post object from the DOM.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.js",
|
"types": "dist/index.d.js",
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export default class NeoScraper {
|
||||||
new engines.Danbooru(),
|
new engines.Danbooru(),
|
||||||
new engines.e621(),
|
new engines.e621(),
|
||||||
new engines.Gelbooru(),
|
new engines.Gelbooru(),
|
||||||
|
new engines.Inkbunny(),
|
||||||
new engines.Moebooru(),
|
new engines.Moebooru(),
|
||||||
new engines.Pixiv(),
|
new engines.Pixiv(),
|
||||||
new engines.Reddit(),
|
new engines.Reddit(),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine";
|
||||||
|
|
||||||
|
export default class Inkbunny implements ScrapeEngine {
|
||||||
|
name = "inkbunny";
|
||||||
|
|
||||||
|
canImport(url: Location): boolean {
|
||||||
|
return url.host == "inkbunny.net";
|
||||||
|
}
|
||||||
|
|
||||||
|
scrapeDocument(document: Document): ScrapeResult {
|
||||||
|
let result = new ScrapeResult(this.name);
|
||||||
|
|
||||||
|
let post = new ScrapedPost();
|
||||||
|
post.pageUrl = document.location.href;
|
||||||
|
|
||||||
|
// Set image url
|
||||||
|
const downloadEl = document.querySelector("a[download]") as HTMLAnchorElement;
|
||||||
|
|
||||||
|
if (downloadEl) {
|
||||||
|
post.contentUrl = downloadEl.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sometimes the HTML structure is different for whatever reason?
|
||||||
|
if (!post.contentUrl) {
|
||||||
|
const imgEl = document.querySelector(".widget_imageFromSubmission > img") as HTMLImageElement;
|
||||||
|
if (imgEl) {
|
||||||
|
post.contentUrl = imgEl.src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return early if we didn't find an image.
|
||||||
|
if (!post.contentUrl) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set rating
|
||||||
|
const ratingExp = new RegExp("Rating: (.*)");
|
||||||
|
const spanEls = Array.from(document.querySelectorAll("div > span"));
|
||||||
|
const ratingEls = spanEls.map((x) => x as HTMLDivElement).filter((x) => x.innerText.indexOf("Rating:") != -1);
|
||||||
|
|
||||||
|
if (ratingEls.length > 0) {
|
||||||
|
const matches = ratingEls[0].parentElement!.innerText.match(ratingExp);
|
||||||
|
if (matches && matches.length > 0) {
|
||||||
|
switch (matches[1].toLowerCase()) {
|
||||||
|
case "general":
|
||||||
|
post.rating = "safe";
|
||||||
|
break;
|
||||||
|
case "mature":
|
||||||
|
case "adult":
|
||||||
|
post.rating = "unsafe";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set tags
|
||||||
|
const metaKeywords = document.querySelector("meta[name='keywords']") as HTMLMetaElement;
|
||||||
|
const keywordsContent = metaKeywords.getAttribute("content");
|
||||||
|
|
||||||
|
if (keywordsContent) {
|
||||||
|
const keywords = keywordsContent.split(",").map((x) => x.trim());
|
||||||
|
|
||||||
|
for (const keyword of keywords) {
|
||||||
|
let tag = new ScrapedTag(keyword);
|
||||||
|
post.tags.push(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.tryAddPost(post);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ export default class e621 implements ScrapeEngine {
|
||||||
let result = new ScrapeResult(this.name);
|
let result = new ScrapeResult(this.name);
|
||||||
|
|
||||||
let post = new ScrapedPost();
|
let post = new ScrapedPost();
|
||||||
post.source = document.location.href;
|
post.pageUrl = document.location.href;
|
||||||
|
|
||||||
// Set image url
|
// Set image url
|
||||||
const downloadEl = document.querySelector("#image-download-link > a") as HTMLAnchorElement;
|
const downloadEl = document.querySelector("#image-download-link > a") as HTMLAnchorElement;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ export { default as Danbooru } from "./Danbooru";
|
||||||
export { default as e621 } from "./e621";
|
export { default as e621 } from "./e621";
|
||||||
export { default as Fallback } from "./Fallback";
|
export { default as Fallback } from "./Fallback";
|
||||||
export { default as Gelbooru } from "./Gelbooru";
|
export { default as Gelbooru } from "./Gelbooru";
|
||||||
|
export { default as Inkbunny } from "./Inkbunny";
|
||||||
export { default as Moebooru } from "./Moebooru";
|
export { default as Moebooru } from "./Moebooru";
|
||||||
export { default as Pixiv } from "./Pixiv";
|
export { default as Pixiv } from "./Pixiv";
|
||||||
export { default as Reddit } from "./Reddit";
|
export { default as Reddit } from "./Reddit";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue