Find PNG version of posts on konachan + test fixes
parent
c149992fb2
commit
b2937d3c94
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "neo-scraper",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"description": "Scrape a booru-like post object from the DOM.",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
|
|
|||
|
|
@ -76,3 +76,21 @@ test("get konachan.com post 285782 with notes", async () => {
|
|||
);
|
||||
expect(res.posts[0]).toHaveSource("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=75747354");
|
||||
});
|
||||
|
||||
test("get konachan.com post 358247 jpeg and png", async () => {
|
||||
const pageUrl = "https://konachan.com/post/show/358247/3d-animal_ears-arknights-black_hair-blonde_hair-br";
|
||||
const res = await scrapeUrl(pageUrl);
|
||||
expect(res.posts.length).toBe(2);
|
||||
expect(res.posts[0]).toHaveTag("texas_(arknights)", "character");
|
||||
expect(res.posts[0]).toHaveResolution([6144, 3456]);
|
||||
expect(res.posts[0].pageUrl).toBe(pageUrl);
|
||||
expect(res.posts[0].contentUrl).toBe(
|
||||
"https://konachan.com/image/56983a2166a13f4af963774ccd424f0e/Konachan.com%20-%20358247%203d%20arknights%20computer%20couch%20dress%20drink%20gloves%20gun%20halo%20hoodie%20necklace%20pantyhose%20red_eyes%20red_hair%20shirt%20shorts%20skirt%20tie%20twintails%20weapon%20wolfgirl.png"
|
||||
);
|
||||
expect(res.posts[0]).toHaveSource("https://www.pixiv.net/en/artworks/108925945");
|
||||
|
||||
// JPEG variant
|
||||
expect(res.posts[1].contentUrl).toBe(
|
||||
"https://konachan.com/jpeg/56983a2166a13f4af963774ccd424f0e/Konachan.com%20-%20358247%203d%20arknights%20computer%20couch%20dress%20drink%20gloves%20gun%20halo%20hoodie%20necklace%20pantyhose%20red_eyes%20red_hair%20shirt%20shorts%20skirt%20tie%20twintails%20weapon%20wolfgirl.jpg"
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -110,6 +110,18 @@ export default class Moebooru extends ScrapeEngineBase {
|
|||
post.notes = createNotesFromMoebooruBoxes(document, boxSize);
|
||||
}
|
||||
|
||||
// Sometimes there is both a JPEG and a PNG version of a post.
|
||||
// If this is the case, copy all the information from the JPEG
|
||||
// version and only replace the contentUrl with the link to the PNG version.
|
||||
// We want to add this PNG version before the other version, so that it appears on top.
|
||||
const unchangedImgEl = document.querySelector<HTMLAnchorElement>("a.original-file-unchanged");
|
||||
if (unchangedImgEl && unchangedImgEl.href != post.contentUrl) {
|
||||
const copy = Object.assign(new ScrapedPost(), post);
|
||||
copy.contentUrl = unchangedImgEl.href;
|
||||
result.tryAddPost(copy);
|
||||
}
|
||||
|
||||
// Add normal/non-png post.
|
||||
result.tryAddPost(post);
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ test("get rule34.paheal.net post 2505982", async () => {
|
|||
"http://law-zilla.tumblr.com/post/171249285285/finished-subdraw-37-kaisa-from-league-of-legends"
|
||||
);
|
||||
expect(res.posts[0].contentUrl).toContain(
|
||||
".paheal.net/_images/15427ab5ed2cddbeef947e30f5c9cab6/2505982%20-%20Kai%27Sa%20League_of_Legends%20lawzilla.png"
|
||||
".paheal.net/_images/15427ab5ed2cddbeef947e30f5c9cab6/2505982%20-%20Kai%27Sa%20lawzilla%20League_of_Legends.png"
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { TagCategory } from "../BooruTypes.js";
|
|||
declare global {
|
||||
namespace jest {
|
||||
interface Matchers<R> {
|
||||
// The `= undefined` part is incorrect according to VSCode, but it is actually required.
|
||||
toHaveTag(tagName: string, tagCategory?: TagCategory): CustomMatcherResult;
|
||||
toHaveNote(noteText: string): CustomMatcherResult;
|
||||
toHaveResolution(resolution: [number, number]): CustomMatcherResult;
|
||||
|
|
|
|||
Loading…
Reference in New Issue