From 3c5923ba6dbb66bd1dfb37915e47e82ba8862535 Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Fri, 20 Mar 2020 19:56:10 +0100 Subject: [PATCH] Add barebones Pixiv parser --- package.json | 2 +- src/NeoScraper.ts | 1 + src/engines/Pixiv.ts | 28 ++++++++++++++++++++++++++++ src/engines/index.ts | 1 + tsconfig.json | 5 +++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/engines/Pixiv.ts diff --git a/package.json b/package.json index 93657ca..c59fc7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "neo-scraper", - "version": "0.2.3", + "version": "0.2.4", "description": "Scrape a booru-like post object from the DOM.", "main": "dist/index.js", "types": "dist/index.d.js", diff --git a/src/NeoScraper.ts b/src/NeoScraper.ts index 5b9f3f7..45893a4 100644 --- a/src/NeoScraper.ts +++ b/src/NeoScraper.ts @@ -11,6 +11,7 @@ export default class NeoScraper { new engines.Danbooru(), new engines.Gelbooru(), new engines.Moebooru(), + new engines.Pixiv(), new engines.Reddit(), new engines.SankakuComplex(), new engines.Shimmie2(), diff --git a/src/engines/Pixiv.ts b/src/engines/Pixiv.ts new file mode 100644 index 0000000..2e386b7 --- /dev/null +++ b/src/engines/Pixiv.ts @@ -0,0 +1,28 @@ +import { ScrapeEngine, ScrapeResult, ScrapedPost, ScrapedTag } from "../ScrapeEngine"; +import { TagCategory } from "../BooruTypes"; + +export default class Pixiv implements ScrapeEngine { + name = "pixiv"; + + canImport(url: Location): boolean { + return ( + url.host == "pixiv.net" || + url.host == "www.pixiv.net" + ); + } + + scrapeDocument(document: Document): ScrapeResult { + let result = new ScrapeResult(this.name); + + const imgLinks = Array.from(document.querySelectorAll("div[role='presentation'] > a")).map(x => x as HTMLAnchorElement); + + for (const imgLink of imgLinks) { + let post = new ScrapedPost(); + post.source = document.location.href; + post.imageUrl = imgLink.href; + result.tryAddPost(post); + } + + return result; + } +} diff --git a/src/engines/index.ts b/src/engines/index.ts index e44505f..747c786 100644 --- a/src/engines/index.ts +++ b/src/engines/index.ts @@ -2,6 +2,7 @@ export { default as Danbooru } from "./Danbooru"; export { default as Fallback } from "./Fallback"; export { default as Gelbooru } from "./Gelbooru"; export { default as Moebooru } from "./Moebooru"; +export { default as Pixiv } from "./Pixiv"; export { default as Reddit } from "./Reddit"; export { default as SankakuComplex } from "./SankakuComplex"; export { default as Shimmie2 } from "./Shimmie2"; diff --git a/tsconfig.json b/tsconfig.json index f4fe37f..99b1cfc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,10 @@ { "compilerOptions": { + "lib": [ + "es6", + "dom", + "dom.iterable" + ], "outDir": "./dist/", "sourceMap": true, "strict": true,