Add e621 engine + version bump

pull/5/head
neobooru 2020-07-20 00:47:19 +02:00
parent 11b545a934
commit a4a2c60036
4 changed files with 71 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "neo-scraper", "name": "neo-scraper",
"version": "0.2.4", "version": "0.2.5",
"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",

View File

@ -9,6 +9,7 @@ export default class NeoScraper {
if (useDefaultEngines) { if (useDefaultEngines) {
this.engines.push( this.engines.push(
new engines.Danbooru(), new engines.Danbooru(),
new engines.e621(),
new engines.Gelbooru(), new engines.Gelbooru(),
new engines.Moebooru(), new engines.Moebooru(),
new engines.Pixiv(), new engines.Pixiv(),

68
src/engines/e621.ts Normal file
View File

@ -0,0 +1,68 @@
import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine";
import { TagCategory } from "../BooruTypes";
export default class e621 implements ScrapeEngine {
name = "e621";
canImport(url: Location): boolean {
return url.host == "e621.net";
}
scrapeDocument(document: Document): ScrapeResult {
let result = new ScrapeResult(this.name);
let post = new ScrapedPost();
post.source = document.location.href;
// Set image url
const downloadEl = document.querySelector("#image-download-link > a") as HTMLAnchorElement;
post.imageUrl = downloadEl?.href;
// Set rating
const ratingEl = document.getElementById("post-rating-text") as HTMLSpanElement;
switch (ratingEl?.innerText) {
case "Safe":
post.rating = "safe";
break;
case "Questionable":
post.rating = "sketchy";
break;
case "Explicit":
post.rating = "unsafe";
break;
}
// Set tags
const tagEls = Array.from(document.querySelectorAll("#tag-list > ul > li"))
.map(x => x as HTMLLIElement);
for (const el of tagEls) {
const tagName = (el.querySelector(".search-tag") as HTMLAnchorElement)?.innerText;
let category: TagCategory | undefined;
switch (el.className) {
case "category-3":
category = "copyright";
break;
case "category-4":
category = "character";
break;
case "category-1":
category = "artist";
break;
case "category-7":
category = "meta";
break;
}
if (tagName) {
let tag = new ScrapedTag(tagName, category);
post.tags.push(tag);
}
}
result.tryAddPost(post);
return result;
}
}

View File

@ -1,4 +1,5 @@
export { default as Danbooru } from "./Danbooru"; export { default as Danbooru } from "./Danbooru";
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 Moebooru } from "./Moebooru"; export { default as Moebooru } from "./Moebooru";