// Release 38 lane C: the Newgrounds extractor over synthetic captures in // Newgrounds' two layouts — a user page's pods read whole (where the generic // extractor keeps one block), an art page and a movie page as items with // stable ids, a page with nothing readable as a whole-page shell — and which // Newgrounds URLs it claims. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/waybackPages/extractors/newgrounds.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { extractNewgrounds, newgroundsExtractor, newgroundsPageOf } from "./newgrounds"; import { genericExtractor } from "./generic"; import { chooseExtractor } from "../extract"; import { captureOf, fixture } from "./__fixtures__/capture"; const USER = "http://pocketfox.newgrounds.com/"; const ART = "http://www.newgrounds.com/art/view/pocketfox/lighthouse-at-dusk"; const MOVIE = "http://www.newgrounds.com/portal/view/634512"; test("which URLs are Newgrounds pages: a user's root, an art view, a portal view — nothing else", () => { const of = (u: string) => newgroundsPageOf(new URL(u)); assert.deepEqual(of(USER), { kind: "ng-user", user: "pocketfox" }); assert.deepEqual(of("https://PocketFox.newgrounds.com"), { kind: "ng-user", user: "pocketfox" }); assert.deepEqual(of(ART), { kind: "ng-art", user: "pocketfox", slug: "lighthouse-at-dusk" }); assert.deepEqual(of(`${MOVIE}/`), { kind: "ng-movie", id: "634512" }); for (const u of [ "http://www.newgrounds.com/", "http://www.newgrounds.com/portal", "http://pocketfox.newgrounds.com/news/post/880011", "http://uploads.ungrounded.net/634000/634512_lighthouse.swf", "http://art.newgrounds.com/", "http://newgrounds.com.example/", "https://www.youtube.com/user/pocketfox", ]) { assert.equal(of(u), null, u); } assert.equal(newgroundsExtractor.matches(new URL(USER), ""), true); assert.equal(newgroundsExtractor.matches(new URL("http://www.newgrounds.com/"), ""), false); }); test("a 2014 user page: every pod read, its stats as pairs, its links, and no Wayback chrome", () => { const [d, ...rest] = extractNewgrounds({ html: fixture("ng-user-2014.html"), capture: captureOf(USER, "20140304120000") }); assert.equal(rest.length, 0); assert.equal(d.kind, "ng-user"); assert.equal(d.itemId, undefined, "each capture of a user page is a version of it"); assert.equal(d.author, "pocketfox"); assert.equal(d.authorName, "pocketfox"); assert.equal(d.noContent, undefined); for (const line of [ "Profile", "I draw harbors and the boats in them. Short loops, mostly.", "Age, Gender: 24, Male", "Location: Lake Erie", "Joined on: 3/4/09", "Contact Info / Websites", "Exp Points: 1,234 / 1,600", "Latest News", "The lighthouse loop finally went up. Thanks for the votes.", ]) { assert.ok(d.text.includes(line), `has "${line}"`); } assert.ok(!/toolbar|Copyright|Movies Games/.test(d.text), "no toolbar, footer or navigation"); assert.ok(d.links.includes("http://twitter.com/pocketfoxdraws"), "a Wayback-rewritten link, unwrapped"); assert.ok(d.links.includes("http://pocketfox.tumblr.com/")); assert.ok(d.links.includes("http://pocketfox.newgrounds.com/news/post/880011")); assert.ok(d.links.includes(ART)); // The generic extractor on the same capture reads much less of it. const g = genericExtractor.extract({ html: fixture("ng-user-2014.html"), capture: captureOf(USER, "20140304120000") })[0]; assert.ok(g.text.length < d.text.length / 2, `generic ${g.text.length} chars vs ${d.text.length}`); }); test("the older layout: a podtop heading and its podcontent sibling", () => { const [d] = extractNewgrounds({ html: fixture("ng-user-2010.html"), capture: captureOf(USER, "20100601000000") }); assert.equal(d.kind, "ng-user"); assert.match(d.text, /pocketfox's Profile\nHarbors, boats, and the odd lighthouse\./); assert.match(d.text, /Location: Lake Erie/); assert.match(d.text, /Recent Submissions/); assert.equal(d.title, "pocketfox's Profile"); assert.ok(d.links.includes(MOVIE)); }); test("an art page: one item by user and slug, its comments, image, tags and date", () => { const [d, ...rest] = extractNewgrounds({ html: fixture("ng-art-2014.html"), capture: captureOf(ART, "20140310000000") }); assert.equal(rest.length, 0); assert.equal(d.kind, "ng-art"); assert.equal(d.itemId, "ng-art-pocketfox-lighthouse-at-dusk"); assert.equal(d.url, "https://www.newgrounds.com/art/view/pocketfox/lighthouse-at-dusk"); assert.equal(d.title, "Lighthouse at Dusk"); assert.equal(d.author, "pocketfox"); assert.equal(d.publishedAt, "2014-03-03T20:22:00.000Z", "datePublished, its zone kept"); assert.match(d.text, /^Lighthouse at Dusk\nPainted over three nights\. The keeper's window is the only warm thing in it\./); assert.deepEqual(d.tags, ["lighthouse", "harbor"]); assert.deepEqual(d.media, [{ kind: "image", url: "http://art.ngfiles.com/images/123/pocketfox_lighthouse-at-dusk.png", name: "Lighthouse at Dusk" }]); assert.ok(d.links.includes("http://pocketfox.tumblr.com/prints")); }); test("a movie page: one item by id, credited to the first author box, its file linked, the printed date read", () => { const [d] = extractNewgrounds({ html: fixture("ng-movie-2014.html"), capture: captureOf(MOVIE, "20140301000000") }); assert.equal(d.kind, "ng-movie"); assert.equal(d.itemId, "ng-movie-634512"); assert.equal(d.url, "https://www.newgrounds.com/portal/view/634512"); assert.equal(d.author, "pocketfox"); assert.equal(d.title, "Lighthouse Loop"); assert.match(d.text, /Forty seconds of a lighthouse\. Sound by http:\/\/tidewater\.newgrounds\.com\//); assert.match(d.text, /Credits: pocketfox, tidewater/); assert.equal(d.publishedAt, "2014-02-27T21:05:00.000Z", "a printed date is read as UTC"); assert.ok(d.links.includes("http://uploads.ungrounded.net/634000/634512_lighthouse.swf")); }); test("a page with nothing readable is one whole-page shell, never an item", () => { for (const url of [USER, ART, MOVIE]) { const drafts = extractNewgrounds({ html: "", capture: captureOf(url, "20150101000000") }); assert.equal(drafts.length, 1); assert.equal(drafts[0].noContent, true, url); assert.equal(drafts[0].itemId, undefined, url); } }); test("the dispatcher sends a Newgrounds capture here, and every other page where it went before", () => { const html = fixture("ng-user-2014.html"); assert.equal(chooseExtractor({ html, capture: captureOf(USER, "20140304120000") }).name, "newgrounds"); assert.equal(chooseExtractor({ html, capture: captureOf("http://www.newgrounds.com/", "20140304120000") }).name, "generic"); });