Add FurAffinity

pull/9/head
neobooru 2021-08-12 23:41:39 +02:00
parent 9fa5e9e512
commit 51653d7d72
4 changed files with 62 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "neo-scraper",
"version": "0.4.4",
"version": "0.4.5",
"description": "Scrape a booru-like post object from the DOM.",
"main": "dist/index.js",
"types": "dist/index.d.js",

View File

@ -11,6 +11,7 @@ export default class NeoScraper {
new engines.AnimePictures(),
new engines.Danbooru(),
new engines.e621(),
new engines.FurAffinity(),
new engines.Gelbooru(),
new engines.Inkbunny(),
new engines.Moebooru(),

View File

@ -0,0 +1,59 @@
import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine";
import { guessContentType } from "../Utility";
export default class e621 implements ScrapeEngine {
name = "furaffinity";
canImport(url: Location): boolean {
return url.host == "www.furaffinity.net";
}
scrapeDocument(document: Document): ScrapeResult {
let result = new ScrapeResult(this.name);
let post = new ScrapedPost();
post.pageUrl = document.location.href;
// Set image url
// Could use the download button here, but as far as I can tell it doesn't matter.
const downloadEl = document.querySelector("#submissionImg") as HTMLImageElement;
post.contentUrl = downloadEl?.src;
if (post.contentUrl == undefined) {
return result;
}
// Set content type
post.contentType = guessContentType(post.contentUrl);
// Set rating
const ratingEls = Array.from(document.querySelectorAll("div.rating > span.rating-box")).map(
(x) => x as HTMLSpanElement
);
if (ratingEls.length > 0)
switch (ratingEls[0].innerText) {
case "General":
post.rating = "safe";
break;
case "Mature":
post.rating = "sketchy";
break;
case "Adult":
post.rating = "unsafe";
break;
}
// Set tags
post.tags = Array.from(document.querySelectorAll("section.tags-row > span.tags"))
.map((x) => (x as HTMLSpanElement).innerText)
.map((x) => new ScrapedTag(x));
// Set source
post.source = document.location.href;
result.tryAddPost(post);
return result;
}
}

View File

@ -2,6 +2,7 @@ export { default as AnimePictures } from "./AnimePictures";
export { default as Danbooru } from "./Danbooru";
export { default as e621 } from "./e621";
export { default as Fallback } from "./Fallback";
export { default as FurAffinity } from "./FurAffinity";
export { default as Gelbooru } from "./Gelbooru";
export { default as Inkbunny } from "./Inkbunny";
export { default as Moebooru } from "./Moebooru";