Fix tests + add anime-pictures.net engine

pull/5/head
neobooru 2020-08-23 01:19:16 +02:00
parent a4a2c60036
commit 940562c1c3
6 changed files with 3495 additions and 5003 deletions

4999
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -63,7 +63,7 @@ test("get gelbooru.com post 4925055", async () => {
const res = await scrapeUrl(source);
expect(res.posts.length).toBe(1);
expect(res.posts[0].source).toBe(source);
expect(res.posts[0].imageUrl).toBe("https://img2.gelbooru.com//images/3d/03/3d03f6858637805d6473d390a4b1d8c8.jpg");
expect(res.posts[0].imageUrl).toBe("https://img2.gelbooru.com/images/3d/03/3d03f6858637805d6473d390a4b1d8c8.jpg");
});
test("get rule34.xxx post 2740994", async () => {
@ -71,7 +71,7 @@ test("get rule34.xxx post 2740994", async () => {
const res = await scrapeUrl(source);
expect(res.posts.length).toBe(1);
expect(res.posts[0].source).toBe(source);
expect(res.posts[0].imageUrl).toBe("https://img.rule34.xxx//images/2472/35bf31c98f53a369c047baf9bae496fb.jpeg");
expect(res.posts[0].imageUrl).toContain(".rule34.xxx//images/2472/35bf31c98f53a369c047baf9bae496fb.jpeg");
});
// Moebooru
@ -85,7 +85,7 @@ test("get yande.re post 438510", async () => {
});
test("get konachan.com post 289968", async () => {
var source = "http://konachan.com/post/show/289968/ahri_-league_of_legends-akali-animal_ears-blonde_h";
var source = "https://konachan.com/post/show/289968/ahri_-league_of_legends-akali-animal_ears-blonde_h";
const res = await scrapeUrl(source);
expect(res.posts.length).toBe(1);
expect(res.posts[0].source).toBe(source);
@ -117,7 +117,7 @@ test("get rule34.paheal.net post 2505982", async () => {
const res = await scrapeUrl(source);
expect(res.posts.length).toBe(1);
expect(res.posts[0].source).toBe(source);
expect(res.posts[0].imageUrl).toBe("https://pansy.paheal.net/_images/15427ab5ed2cddbeef947e30f5c9cab6/2505982%20-%20Kai%27Sa%20League_of_Legends%20lawzilla.png");
expect(res.posts[0].imageUrl).toContain(".paheal.net/_images/15427ab5ed2cddbeef947e30f5c9cab6/2505982%20-%20Kai%27Sa%20League_of_Legends%20lawzilla.png");
});
// Twitter

View File

@ -8,6 +8,7 @@ export default class NeoScraper {
constructor(useDefaultEngines: boolean = true) {
if (useDefaultEngines) {
this.engines.push(
new engines.AnimePictures(),
new engines.Danbooru(),
new engines.e621(),
new engines.Gelbooru(),

View File

@ -0,0 +1,56 @@
import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine";
import { TagCategory } from "../BooruTypes";
export default class AnimePictures implements ScrapeEngine {
name = "animepictures";
canImport(url: Location): boolean {
return url.host == "anime-pictures.net";
}
scrapeDocument(document: Document): ScrapeResult {
let result = new ScrapeResult(this.name);
let post = new ScrapedPost();
post.source = document.location.href;
// Set image url
const originalImageElements = Array.from(document.getElementsByClassName("download_icon"));
if (originalImageElements.length > 0) {
post.imageUrl = (originalImageElements[0] as HTMLAnchorElement).href;
}
// Set rating
post.rating = "safe"; // Probably
// Set tags
const tagElements = Array.from(document.querySelectorAll("ul.tags > li > a")).map(x => x as HTMLAnchorElement);
for (const tagElement of tagElements) {
let tagName = tagElement.innerText;
let category: TagCategory | undefined;
for (const className of tagElement.classList) {
switch (className) {
case "copyright":
category = "copyright";
break;
case "character":
category = "character";
break;
case "artist":
category = "artist";
break;
}
}
if (tagName) {
let tag = new ScrapedTag(tagName, category);
post.tags.push(tag);
}
}
result.tryAddPost(post);
return result;
}
}

View File

@ -1,3 +1,4 @@
export { default as AnimePictures } from "./AnimePictures";
export { default as Danbooru } from "./Danbooru";
export { default as e621 } from "./e621";
export { default as Fallback } from "./Fallback";

3433
yarn.lock Normal file

File diff suppressed because it is too large Load Diff