Add e-shuushuu.net, update TypeScript, and some small fixes
parent
f897d21664
commit
36ae6d1e5e
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "neo-scraper",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
@ -4738,9 +4738,9 @@
|
|||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz",
|
||||
"integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==",
|
||||
"version": "3.7.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz",
|
||||
"integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==",
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "neo-scraper",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "Scrape a booru-like post object from the DOM.",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.js",
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
"jest": "^24.9.0",
|
||||
"jsdom": "^15.1.1",
|
||||
"ts-jest": "^24.1.0",
|
||||
"typescript": "^3.6.3"
|
||||
"typescript": "^3.7.4"
|
||||
},
|
||||
"jest": {
|
||||
"transform": {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export default class NeoScraper {
|
|||
new engines.Reddit(),
|
||||
new engines.SankakuComplex(),
|
||||
new engines.Shimmie2(),
|
||||
new engines.Shuushuu(),
|
||||
new engines.Twitter(),
|
||||
new engines.Zerochan(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export class ScrapedTag {
|
|||
category?: TagCategory;
|
||||
|
||||
constructor(name: string, category?: TagCategory) {
|
||||
this.name = name.replace(/\s/g, "_"); // Replace all spaces with underscores
|
||||
this.name = name.replace(/\s/g, "_").toLowerCase(); // Replace all spaces with underscores and make everything lowercase
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export default class Shimmie2 implements ScrapeEngine {
|
|||
// Tags might not match with other booru-likes, but that is for the user to figure out.
|
||||
// For example by deleting 'wrong' tags or setting up some aliases in szurubooru.
|
||||
post.tags = Array.from(document.querySelectorAll("a.tag_name"))
|
||||
.map(x => (x as HTMLAnchorElement).innerText.toLowerCase())
|
||||
.map(x => (x as HTMLAnchorElement).innerText)
|
||||
.map(x => new ScrapedTag(x));
|
||||
|
||||
result.tryAddPost(post);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine";
|
||||
import { TagCategory } from "../BooruTypes";
|
||||
|
||||
export default class Shuushuu implements ScrapeEngine {
|
||||
name = "shuushuu";
|
||||
|
||||
canImport(url: Location): boolean {
|
||||
return url.host == "e-shuushuu.net";
|
||||
}
|
||||
|
||||
scrapeDocument(document: Document): ScrapeResult {
|
||||
let result = new ScrapeResult(this.name);
|
||||
let post = new ScrapedPost();
|
||||
post.source = document.location.href;
|
||||
|
||||
// Set image url
|
||||
const imgElement = document.querySelector(".thumb_image") as HTMLAnchorElement;
|
||||
if (imgElement) {
|
||||
post.imageUrl = imgElement.href;
|
||||
}
|
||||
|
||||
// Set rating
|
||||
post.rating = "safe";
|
||||
|
||||
// Set tags
|
||||
const exp = new RegExp(/(.*)_(\w+)/);
|
||||
const tagElements = document.getElementsByClassName("quicktag");
|
||||
|
||||
for (const tagElement of tagElements) {
|
||||
// id = quicktag1_1009628
|
||||
// match[0] = quicktag1_1009628 (aka input str)
|
||||
// match[1] = quicktag1
|
||||
// match[2] = 1009628
|
||||
const match = exp.exec(tagElement.id);
|
||||
if (!match || match.length != 3) { continue; }
|
||||
|
||||
let tagCategory: TagCategory | undefined;
|
||||
switch (match[1]) {
|
||||
// Source, aka copyright
|
||||
case "quicktag2":
|
||||
tagCategory = "copyright";
|
||||
break;
|
||||
// Artist
|
||||
case "quicktag3":
|
||||
tagCategory = "artist";
|
||||
break;
|
||||
// Characters
|
||||
case "quicktag4":
|
||||
tagCategory = "character";
|
||||
break;
|
||||
}
|
||||
|
||||
for (const el of tagElement.children) {
|
||||
const tagName = (el?.firstElementChild as HTMLAnchorElement)?.innerText;
|
||||
if (tagName) {
|
||||
post.tags.push(new ScrapedTag(tagName, tagCategory));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,5 +5,6 @@ export { default as Moebooru } from "./Moebooru";
|
|||
export { default as Reddit } from "./Reddit";
|
||||
export { default as SankakuComplex } from "./SankakuComplex";
|
||||
export { default as Shimmie2 } from "./Shimmie2";
|
||||
export { default as Shuushuu } from "./Shuushuu";
|
||||
export { default as Twitter } from "./Twitter";
|
||||
export { default as Zerochan } from "./Zerochan";
|
||||
|
|
|
|||
Loading…
Reference in New Issue