Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit badbad7e3574a22e8eec5fdcdcc9f1d74c2b55a3
parent c145be798dc16d2077778e36afc9a3e9c65226b6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  2 Nov 2026 04:23:21 -0500

wayback pages: a Newgrounds extractor -- a user page's pods read whole, art and movie pages as items

The generic extractor kept one block of a 2014 Newgrounds user page (its content sits in many small
pods and a sidebar). extractors/newgrounds.ts claims <user>.newgrounds.com/, /art/view/<user>/<slug>
and /portal/view/<id>: a user page is one record per capture (every pod as "Heading" then its lines,
<dl> stats as "Term: value"), an art or movie page an item (ng-art-<user>-<slug>, ng-movie-<id>) with
its comments, image or file, tags, credits and date. Kinds ng-user, ng-art, ng-movie, with labels.
Synthetic fixtures in both layouts (pod-head/pod-body, podtop/podcontent); a stored capture the
generic extractor read is stale and reextract-pages makes it the Newgrounds record.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Acommon/controller/reextractPages.newgrounds.test.ts | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/waybackPages/extractors/__fixtures__/ng-art-2014.html | 33+++++++++++++++++++++++++++++++++
Acommon/lib/waybackPages/extractors/__fixtures__/ng-movie-2014.html | 28++++++++++++++++++++++++++++
Acommon/lib/waybackPages/extractors/__fixtures__/ng-user-2010.html | 19+++++++++++++++++++
Acommon/lib/waybackPages/extractors/__fixtures__/ng-user-2014.html | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/waybackPages/extractors/generic.ts | 2+-
Mcommon/lib/waybackPages/extractors/index.test.ts | 8++++++--
Mcommon/lib/waybackPages/extractors/index.ts | 8+++++---
Acommon/lib/waybackPages/extractors/newgrounds.test.ts | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/waybackPages/extractors/newgrounds.ts | 315+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/waybackPages/types.ts | 6+++++-
Mcommon/lib/waybackPages/view.ts | 3+++
12 files changed, 698 insertions(+), 7 deletions(-)

diff --git a/common/controller/reextractPages.newgrounds.test.ts b/common/controller/reextractPages.newgrounds.test.ts @@ -0,0 +1,90 @@ +// Release 38 lane C: the raw captures a Wayback pages channel keeps are what +// make a new extractor worth having. A Newgrounds user page imported while +// only the generic extractor read it is STALE now, and `reextract-pages` +// turns its record into the Newgrounds extractor's, asking nobody anything. +// +// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/reextractPages.newgrounds.test.ts + +import test, { after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { mkdir, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { createHash } from "node:crypto"; +import type { Paths } from "../lib/paths"; +import { reextractPages } from "./reextractPages"; +import { readAllPosts, upsertPosts } from "../lib/posts-server"; +import { genericExtractor } from "../lib/waybackPages/extractors/generic"; +import { pageRecordId } from "../lib/waybackPages/types"; +import { draftToPost } from "../lib/waybackPages/toPost"; +import { listStoredCaptures, writeStoredCapture } from "../lib/waybackPages/store-server"; + +const ROOT = mkdtempSync(path.join(tmpdir(), "reextract-ng-")); +after(() => rmSync(ROOT, { recursive: true, force: true })); +const paths = { channelsDir: path.join(ROOT, "channels"), transcriptsDir: ROOT, jobsDir: path.join(ROOT, "jobs") } as unknown as Paths; + +const USER = "http://pocketfox.newgrounds.com/"; +const TS = "20140304120000"; +const HTML = readFileSync(new URL("../lib/waybackPages/extractors/__fixtures__/ng-user-2014.html", import.meta.url), "utf8"); + +test("a Newgrounds capture the generic extractor read is stale, and a re-extract reads it as a user page", async () => { + const root = path.join(paths.channelsDir, "ng-pages"); + await mkdir(root, { recursive: true }); + await writeFile( + path.join(root, "config.json"), + JSON.stringify({ + handling: "transcribe", + name: "Newgrounds pages", + sourceKind: "social", + platform: "webpage", + socialHandle: "pocketfox.newgrounds.com", + url: "https://web.archive.org/web/*/pocketfox.newgrounds.com*", + wayback: { targets: [{ url: "pocketfox.newgrounds.com/", match: "prefix" }] }, + }), + ); + // As an import before this extractor existed stored it: the body, and the generic extractor's record. + const body = Buffer.from(HTML, "utf8"); + const capture = { originalUrl: USER, captureTs: TS }; + const old = genericExtractor.extract({ html: HTML, capture: { ...capture, waybackUrl: "", rawUrl: "" } }); + const oldPost = draftToPost(old[0], { channelSlug: "ng-pages", capture, extractor: { name: "generic", version: 1 } }); + await writeStoredCapture( + root, + { + ...capture, + mimetype: "text/html", + bytes: body.length, + sha256: createHash("sha256").update(body).digest("hex"), + fetchedAt: "2026-10-20T00:00:00.000Z", + extractor: "generic", + extractorVersion: 1, + records: [oldPost.id], + }, + body, + ); + await upsertPosts(root, [oldPost]); + + const dry = await reextractPages({ paths, slug: "ng-pages", dryRun: true }); + assert.equal(dry.ok, true, dry.error); + assert.equal(dry.stale, 1, "made by the generic extractor, now claimed by newgrounds"); + assert.equal(dry.written, false); + + const done = await reextractPages({ paths, slug: "ng-pages" }); + assert.equal(done.ok, true, done.error); + assert.equal(done.written, true); + const posts = await readAllPosts(root); + assert.equal(posts.length, 1); + const p = posts[0]; + assert.equal(p.id, pageRecordId(TS, USER), "a user page's record is the capture's, as before"); + assert.equal(p.page?.kind, "ng-user"); + assert.equal(p.page?.extractor, "newgrounds"); + assert.equal(p.author, "pocketfox"); + assert.match(p.text, /Location: Lake Erie/); + assert.match(p.text, /The lighthouse loop finally went up/); + const [entry] = await listStoredCaptures(root); + assert.equal(entry.capture.extractor, "newgrounds"); + + const again = await reextractPages({ paths, slug: "ng-pages" }); + assert.equal(again.stale, 0); + assert.equal(again.written, false); +}); diff --git a/common/lib/waybackPages/extractors/__fixtures__/ng-art-2014.html b/common/lib/waybackPages/extractors/__fixtures__/ng-art-2014.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<!-- SYNTHETIC: a Newgrounds art page (/art/view/<user>/<slug>), 2014 layout. Invented, every word. --> +<html lang="en"> +<head> +<title>Lighthouse at Dusk by pocketfox on Newgrounds</title> +<meta property="og:title" content="Lighthouse at Dusk"> +<meta property="og:description" content="Painted over three nights."> +<meta itemprop="datePublished" content="2014-03-03T15:22:00-05:00"> +</head> +<body> +<div id="header"><a href="http://www.newgrounds.com/">Newgrounds</a></div> +<div class="column wide"> + <div class="pod"> + <div class="pod-head"><h2 itemprop="name">Lighthouse at Dusk</h2></div> + <div class="pod-body"><div class="image"><img src="https://web.archive.org/web/20140310000000im_/http://art.ngfiles.com/images/123/pocketfox_lighthouse-at-dusk.png" alt="Lighthouse at Dusk"></div></div> + </div> + <div class="pod"> + <div class="pod-head"><h2>Author Comments</h2></div> + <div class="pod-body"><div id="author_comments"><p>Painted over three nights. The keeper's window is the only warm thing in it.</p><p>Prints: <a href="http://pocketfox.tumblr.com/prints">pocketfox.tumblr.com/prints</a></p></div></div> + </div> +</div> +<div class="column thin"> + <div class="pod"> + <div class="pod-body"> + <div class="item-user"><div class="item-details-main"><h4><a href="http://pocketfox.newgrounds.com/">pocketfox</a></h4></div></div> + <dl class="sidestats"><dt>Score</dt><dd>4.21 / 5.00</dd><dt>Uploaded</dt><dd>Mar 3, 2014</dd><dd>| 3:22 PM EST</dd><dt>Views</dt><dd>1,024</dd></dl> + <dl class="sidestats"><dt>Tags</dt><dd><ul class="tags"><li><a href="/search/conduct/art?match=tags&amp;tags=lighthouse">lighthouse</a></li><li><a href="/search/conduct/art?match=tags&amp;tags=harbor">harbor</a></li></ul></dd></dl> + </div> + </div> +</div> +<div id="footer">© Newgrounds</div> +</body> +</html> diff --git a/common/lib/waybackPages/extractors/__fixtures__/ng-movie-2014.html b/common/lib/waybackPages/extractors/__fixtures__/ng-movie-2014.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<!-- SYNTHETIC: a Newgrounds movie page (/portal/view/<id>), 2014 layout. Invented, every word. --> +<html lang="en"> +<head> +<title>Lighthouse Loop</title> +<meta property="og:title" content="Lighthouse Loop"> +<meta name="description" content="A short loop of a lighthouse."> +</head> +<body> +<div id="header"><a href="http://www.newgrounds.com/">Newgrounds</a></div> +<div class="column wide"> + <div class="pod"> + <div class="pod-head"><h2 itemprop="name">Lighthouse Loop</h2></div> + <div class="pod-body"><div id="embed_wrapper"><object data="http://uploads.ungrounded.net/634000/634512_lighthouse.swf"><embed src="http://uploads.ungrounded.net/634000/634512_lighthouse.swf"></object></div></div> + </div> + <div class="pod"> + <div class="pod-head"><h2>Author Comments</h2></div> + <div class="pod-body"><div id="author_comments">Forty seconds of a lighthouse. Sound by <a href="http://tidewater.newgrounds.com/">tidewater</a>.</div></div> + </div> +</div> +<div class="column thin"> + <div class="pod"><div class="pod-body"> + <div class="authorlinks"><div class="item-user"><h4><a href="http://pocketfox.newgrounds.com/">pocketfox</a></h4></div><div class="item-user"><h4><a href="http://tidewater.newgrounds.com/">tidewater</a></h4></div></div> + <dl class="sidestats"><dt>Uploaded</dt><dd>Feb 27, 2014</dd><dd>| 9:05 PM EST</dd><dt>Views</dt><dd>8,812</dd></dl> + </div></div> +</div> +</body> +</html> diff --git a/common/lib/waybackPages/extractors/__fixtures__/ng-user-2010.html b/common/lib/waybackPages/extractors/__fixtures__/ng-user-2010.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<!-- SYNTHETIC: a Newgrounds user page in the older layout (a podtop heading and a podcontent body side by side). Invented user, every word. --> +<html> +<head><title>Newgrounds.com — pocketfox's Profile</title></head> +<body> +<div id="topnav"><a href="http://www.newgrounds.com/">Home</a></div> +<div class="two3"> + <div class="podtop"><h2 class="profile">pocketfox's Profile</h2></div> + <div class="podcontent"> + <p>Harbors, boats, and the odd lighthouse.</p> + <dl><dt>Location:</dt><dd>Lake Erie</dd><dt>Joined:</dt><dd>3/4/09</dd></dl> + </div> + <div class="podtop"><h2>Recent Submissions</h2></div> + <div class="podcontent"> + <ul><li><a href="http://www.newgrounds.com/portal/view/634512">Lighthouse Loop</a></li></ul> + </div> +</div> +</body> +</html> diff --git a/common/lib/waybackPages/extractors/__fixtures__/ng-user-2014.html b/common/lib/waybackPages/extractors/__fixtures__/ng-user-2014.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<!-- SYNTHETIC: a Newgrounds user page in the 2012–2017 layout (pods with a pod-head and a pod-body). Invented user, every word. --> +<html lang="en"> +<head> +<title>pocketfox on Newgrounds</title> +<meta property="og:title" content="pocketfox"> +<meta property="og:description" content="pocketfox's profile on Newgrounds."> +<link rel="stylesheet" href="//css.ngfiles.com/ng_publish.css"> +</head> +<body> +<!-- BEGIN WAYBACK TOOLBAR INSERT --><div id="wm-ipp-base">toolbar</div><!-- END WAYBACK TOOLBAR INSERT --> +<div id="header"><div class="navigation"><a href="https://web.archive.org/web/20140304120000/http://www.newgrounds.com/">Newgrounds</a> <a href="/portal">Movies</a> <a href="/games">Games</a> <a href="/art">Art</a></div></div> +<div id="main"> + <div class="user-header"> + <div class="user-header-icon"><img src="https://web.archive.org/web/20140304120000im_/http://aicon.ngfiles.com/123/1234567.png" alt="pocketfox"></div> + <div class="user-header-name"><h1><a href="http://pocketfox.newgrounds.com/">pocketfox</a></h1></div> + <div class="user-header-links"><a href="http://pocketfox.newgrounds.com/news/">News</a> <a href="http://pocketfox.newgrounds.com/movies/">Movies</a> <a href="http://pocketfox.newgrounds.com/art/">Art</a> <a href="http://pocketfox.newgrounds.com/fans/">Fans</a></div> + </div> + <div class="column thin"> + <div class="pod"> + <div class="pod-head"><h2 class="user">Profile</h2></div> + <div class="pod-body"> + <div class="ql-body">I draw harbors and the boats in them. Short loops, mostly.</div> + <dl class="stats-general"> + <dt>Age, Gender</dt><dd>24, Male</dd> + <dt>Location</dt><dd>Lake Erie</dd> + <dt>Joined on</dt><dd>3/4/09</dd> + <dt>Job</dt><dd>Sign painter</dd> + </dl> + </div> + </div> + <div class="pod"> + <div class="pod-head"><h2>Contact Info / Websites</h2></div> + <div class="pod-body"> + <ul class="links"> + <li><a href="https://web.archive.org/web/20140304120000/http://twitter.com/pocketfoxdraws">twitter.com/pocketfoxdraws</a></li> + <li><a href="http://pocketfox.tumblr.com/">pocketfox.tumblr.com</a></li> + </ul> + </div> + </div> + <div class="pod"> + <div class="pod-head"><h2>Stats</h2></div> + <div class="pod-body"> + <dl class="stats-general"><dt>Level</dt><dd>21</dd><dt>Exp Points</dt><dd>1,234 / 1,600</dd><dt>Fans</dt><dd>312</dd></dl> + </div> + </div> + </div> + <div class="column wide"> + <div class="pod"> + <div class="pod-head"><h2>Latest News</h2></div> + <div class="pod-body"> + <div class="blog-post"> + <h3><a href="http://pocketfox.newgrounds.com/news/post/880011">Harbor loop is up</a></h3> + <span class="date">Mar 1, 2014</span> + <div class="blog-body">The lighthouse loop finally went up. Thanks for the votes.</div> + </div> + </div> + </div> + <div class="pod"> + <div class="pod-head"><h2>Art</h2></div> + <div class="pod-body"> + <a href="http://www.newgrounds.com/art/view/pocketfox/lighthouse-at-dusk" title="Lighthouse at Dusk"><img src="https://web.archive.org/web/20140304120000im_/http://art.ngfiles.com/thumbnails/123/pocketfox_lighthouse.png" alt="Lighthouse at Dusk"></a> + </div> + </div> + </div> +</div> +<div id="footer"><p>© Copyright 1995-2014 Newgrounds, Inc.</p></div> +</body> +</html> diff --git a/common/lib/waybackPages/extractors/generic.ts b/common/lib/waybackPages/extractors/generic.ts @@ -1,6 +1,6 @@ // THE GENERIC EXTRACTOR (release 37 S1): any captured page as ONE record — its // readable text, title, author, date, links and images — for every capture no -// site extractor claims (articles, personal sites, Newgrounds pages, a group's +// site extractor claims (articles, personal sites, a group's // old site). Pure: no network, no disk, no clock (a PageExtractor). // // What it does, in order: diff --git a/common/lib/waybackPages/extractors/index.test.ts b/common/lib/waybackPages/extractors/index.test.ts @@ -34,6 +34,10 @@ const CASES: [html: string, url: string, expected: string | null][] = [ [fixture("yt-about-2019-polymer.html"), "https://www.youtube.com/channel/UCteapot0000000000000001/about", "yt-about"], [fixture("yt-channel-2021.html"), "https://www.youtube.com/c/TeapotChannel", "yt-about"], [fixture("yt-about-2024-handle.html"), "https://www.youtube.com/@TeapotChannel/about", "yt-about"], + [fixture("ng-user-2014.html"), "http://pocketfox.newgrounds.com/", "newgrounds"], + [fixture("ng-user-2010.html"), "http://pocketfox.newgrounds.com/", "newgrounds"], + [fixture("ng-art-2014.html"), "http://www.newgrounds.com/art/view/pocketfox/lighthouse-at-dusk", "newgrounds"], + [fixture("ng-movie-2014.html"), "http://www.newgrounds.com/portal/view/634512", "newgrounds"], // Pages no site extractor claims: an article, a personal site, a video page. [`<!DOCTYPE html><html><head><title>A story</title></head><body><article><h1>A story</h1><p>Words.</p></article></body></html>`, "https://news.example/2014/05/a-story", null], [`<html><body><h1>My homepage</h1><a href="/post/12">a post</a></body></html>`, "http://home.example/", null], @@ -46,8 +50,8 @@ test("the registry sends each capture to its extractor, and an unknown page to n for (const [html, url, expected] of CASES) assert.equal(pick(html, url), expected, url); }); -test("the registry: five extractors, unique names, version 1, most specific first", () => { - assert.deepEqual(SITE_EXTRACTORS.map((e) => e.name), ["gdoc", "yt-about", "x", "xenforo", "tumblr"]); +test("the registry: six extractors, unique names, version 1, most specific first", () => { + assert.deepEqual(SITE_EXTRACTORS.map((e) => e.name), ["gdoc", "yt-about", "x", "newgrounds", "xenforo", "tumblr"]); for (const e of SITE_EXTRACTORS) assert.equal(e.version, 1); }); diff --git a/common/lib/waybackPages/extractors/index.ts b/common/lib/waybackPages/extractors/index.ts @@ -4,18 +4,20 @@ import type { PageExtractor } from "../types"; import { gdocExtractor } from "./gdoc"; +import { newgroundsExtractor } from "./newgrounds"; import { tumblrExtractor } from "./tumblr"; import { xExtractor } from "./x"; import { xenforoExtractor } from "./xenforo"; import { ytAboutExtractor } from "./ytAbout"; -// Most specific first: the three that match by host (Google Docs, YouTube, -// X), then XenForo by its markup on any host, then Tumblr (its own host, or -// a custom domain whose markup is a Tumblr theme). +// Most specific first: the four that match by host (Google Docs, YouTube, +// X, Newgrounds), then XenForo by its markup on any host, then Tumblr (its +// own host, or a custom domain whose markup is a Tumblr theme). export const SITE_EXTRACTORS: readonly PageExtractor[] = [ gdocExtractor, ytAboutExtractor, xExtractor, + newgroundsExtractor, xenforoExtractor, tumblrExtractor, ]; diff --git a/common/lib/waybackPages/extractors/newgrounds.test.ts b/common/lib/waybackPages/extractors/newgrounds.test.ts @@ -0,0 +1,124 @@ +// 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: "<html><body><div id='header'>Newgrounds</div></body></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"); +}); diff --git a/common/lib/waybackPages/extractors/newgrounds.ts b/common/lib/waybackPages/extractors/newgrounds.ts @@ -0,0 +1,315 @@ +// Newgrounds captures (release 38 lane C, "Found during the case"): a user +// page (`<user>.newgrounds.com/`), an art page +// (`www.newgrounds.com/art/view/<user>/<slug>`) and a movie page +// (`www.newgrounds.com/portal/view/<id>`). The generic extractor reads almost +// nothing of a 2014 user page: its content sits in many small "pods" (a +// heading box and a body box, stats as <dl> pairs, a sidebar column) and the +// densest-block pick keeps one of them. Here every pod is read, in page order, +// as "Heading" then its lines. +// +// kind itemId url author +// ng-user none (each capture a version) — the subdomain +// ng-art ng-art-<user>-<slug> https://www.newgrounds.com/art/view/… the URL's user +// ng-movie ng-movie-<id> https://www.newgrounds.com/portal/view/<id> the first author link +// +// Two layouts are read: the 2012–2017 pods (`.pod` holding `.pod-head` and +// `.pod-body`) and the older side-by-side boxes (`.podtop` then +// `.podcontent`). A page with nothing readable is ONE whole-page draft, +// `noContent`, with no item id (a later shell must not overwrite a good +// capture's record). Shapes are synthetic as of 2026-11-02 (no live page was +// read): the raw capture is kept, so a better reading is a `reextract-pages`. + +import type { PageExtractInput, PageExtractor, PageRecordDraft } from "../types"; +import type { PostMedia } from "../../posts"; +import { + absoluteUrl, + findAll, + findFirst, + hasClass, + isEl, + isoFromIso, + metaContent, + pageTitle, + parseEnglishDate, + parseHtml, + pushUnique, + renderBlock, + squash, + textOf, + unwrapWaybackHtml, + type HtmlElement, +} from "./util"; + +export const NEWGROUNDS_EXTRACTOR_NAME = "newgrounds"; +export const NEWGROUNDS_EXTRACTOR_VERSION = 1; + +// Subdomains that are Newgrounds' own services, not a user's page. +const NOT_USERS = new Set(["www", "art", "uploads", "css", "img", "js", "aicon", "uimg", "picon", "chat", "store", "wiki", "m", "api", "audio", "games", "portal"]); + +export type NewgroundsPage = + | { kind: "ng-user"; user: string } + | { kind: "ng-art"; user: string; slug: string } + | { kind: "ng-movie"; id: string }; + +const isNgHost = (host: string) => host === "newgrounds.com" || host.endsWith(".newgrounds.com"); + +// What a Newgrounds URL is a page of, or null (a page this extractor leaves to the generic one). +export function newgroundsPageOf(url: URL): NewgroundsPage | null { + const host = url.hostname.toLowerCase(); + if (!isNgHost(host)) return null; + const path = url.pathname.replace(/\/+$/, "") || "/"; + if (host === "www.newgrounds.com" || host === "newgrounds.com") { + const art = /^\/art\/view\/([A-Za-z0-9_-]+)\/([A-Za-z0-9_-]+)$/.exec(path); + if (art) return { kind: "ng-art", user: art[1].toLowerCase(), slug: art[2].toLowerCase() }; + const movie = /^\/portal\/view\/(\d+)$/.exec(path); + if (movie) return { kind: "ng-movie", id: movie[1] }; + return null; + } + const sub = host.slice(0, -".newgrounds.com".length); + if (!sub || sub.includes(".") || NOT_USERS.has(sub)) return null; + // The user page itself (its root, or the old /profile path). + if (path === "/" || path === "/profile") return { kind: "ng-user", user: sub }; + return null; +} + +// --- the pods ------------------------------------------------------------------------------------ + +type Pod = { heading: string; body: HtmlElement }; + +const isHeading = (e: HtmlElement) => /^h[1-6]$/.test(e.tag); + +// Every pod of the page, in order: a `.pod` with its head and body, or a +// `.podtop` heading followed (as a sibling) by its `.podcontent`. +function podsOf(root: HtmlElement): Pod[] { + const out: Pod[] = []; + const seen = new Set<HtmlElement>(); + const walk = (el: HtmlElement) => { + const kids = el.children.filter(isEl); + for (let i = 0; i < kids.length; i++) { + const c = kids[i]; + if (hasClass(c, "pod")) { + const head = findFirst(c, (e) => hasClass(e, "pod-head") || hasClass(e, "podtop")); + const body = findFirst(c, (e) => hasClass(e, "pod-body") || hasClass(e, "podcontent")); + if (body && !seen.has(body)) { + seen.add(body); + out.push({ heading: head ? textOf(findFirst(head, isHeading) ?? head) : "", body }); + continue; + } + } + if (hasClass(c, "podtop")) { + const next = kids[i + 1]; + if (next && hasClass(next, "podcontent") && !seen.has(next)) { + seen.add(next); + out.push({ heading: textOf(findFirst(c, isHeading) ?? c), body: next }); + i++; + continue; + } + } + if (hasClass(c, "pod-body") || hasClass(c, "podcontent")) { + if (!seen.has(c)) { + seen.add(c); + out.push({ heading: "", body: c }); + } + continue; + } + walk(c); + } + }; + walk(root); + return out; +} + +// A <dl>'s pairs as "Term: value" lines (a term with several values joins them). +function dlLines(dl: HtmlElement): string[] { + const lines: string[] = []; + let term = ""; + let values: string[] = []; + const flush = () => { + if (term || values.length) lines.push(term ? `${term.replace(/:$/, "")}: ${values.join(" ")}`.trim() : values.join(" ")); + term = ""; + values = []; + }; + for (const c of dl.children) { + if (!isEl(c)) continue; + if (c.tag === "dt") { + flush(); + term = textOf(c); + } else if (c.tag === "dd") { + const lis = findAll(c, (e) => e.tag === "li"); + const v = lis.length ? lis.map((li) => textOf(li)).filter(Boolean).join(", ") : textOf(c).replace(/^\|\s*/, ""); + if (v) values.push(v); + } + } + flush(); + return lines; +} + +type Read = { text: string; links: string[]; media: PostMedia[] }; + +// A pod body's lines: its <dl>s as pairs, the rest as the shared renderer writes it. +function readBody(body: HtmlElement, base: string): Read { + const dls = findAll(body, (e) => e.tag === "dl"); + const rest = renderBlock(body, base, (e) => e.tag === "dl"); + const lines = rest.text ? [rest.text] : []; + for (const dl of dls) lines.push(...dlLines(dl)); + return { text: lines.join("\n").trim(), links: rest.links, media: rest.media }; +} + +function addRead(into: Read, r: Read) { + for (const l of r.links) pushUnique(into.links, l); + for (const m of r.media) if (!into.media.some((x) => x.url === m.url && x.kind === m.kind)) into.media.push(m); +} + +// The value of a sidestats term ("Uploaded" → "Mar 3, 2014 3:22 PM EST"). +function sideStat(root: HtmlElement, term: RegExp): string | undefined { + for (const dl of findAll(root, (e) => e.tag === "dl")) { + const kids = dl.children.filter(isEl); + for (let i = 0; i < kids.length; i++) { + if (kids[i].tag !== "dt" || !term.test(textOf(kids[i]))) continue; + const vals: string[] = []; + for (let j = i + 1; j < kids.length && kids[j].tag === "dd"; j++) vals.push(textOf(kids[j]).replace(/^\|\s*/, "")); + const v = squash(vals.join(" ")); + if (v) return v; + } + } + return undefined; +} + +// The users an item credits: links to <user>.newgrounds.com in its author boxes. +function creditedUsers(root: HtmlElement, base: string): string[] { + const boxes = findAll(root, (e) => hasClass(e, "item-user") || hasClass(e, "authorlinks") || hasClass(e, "item-details-main")); + const out: string[] = []; + for (const box of boxes) { + for (const a of findAll(box, (e) => e.tag === "a")) { + const href = absoluteUrl(a.attrs.href, base); + if (!href) continue; + try { + const p = newgroundsPageOf(new URL(href)); + if (p?.kind === "ng-user") pushUnique(out, p.user); + } catch { + // not a URL + } + } + } + return out; +} + +const stripSiteTitle = (t: string | undefined) => + t + ?.replace(/\s*(?:[|—–-]\s*)?Newgrounds\.com\s*(?:[|—–-]\s*)?/i, " ") + .replace(/\s+on Newgrounds$/i, "") + .trim() || undefined; + +// --- the drafts ------------------------------------------------------------------------------------ + +function noContent(page: NewgroundsPage | null, author: string | undefined): PageRecordDraft[] { + return [{ + kind: page?.kind ?? "ng-user", + ...(author ? { author } : {}), + text: "This capture holds no readable Newgrounds content.", + links: [], + noContent: true, + }]; +} + +function extractUser(root: HtmlElement, base: string, user: string): PageRecordDraft[] { + const pods = podsOf(root); + const name = textOf(findFirst(root, (e) => hasClass(e, "user-header-name"))) || undefined; + const all: Read = { text: "", links: [], media: [] }; + const blocks: string[] = []; + for (const p of pods) { + const r = readBody(p.body, base); + addRead(all, r); + if (!r.text) continue; + blocks.push(p.heading ? `${p.heading}\n${r.text}` : r.text); + } + // The header's own links (News, Movies, Art, Fans) are furniture: only the pods are read. + if (blocks.length === 0) return noContent({ kind: "ng-user", user }, user); + const draft: PageRecordDraft = { + kind: "ng-user", + author: user, + title: stripSiteTitle(pageTitle(root)) ?? metaContent(root, "og:title") ?? user, + text: [name && name.toLowerCase() !== user ? name : "", ...blocks].filter(Boolean).join("\n\n"), + links: all.links, + }; + if (name) draft.authorName = name; + if (all.media.length) draft.media = all.media; + return [draft]; +} + +function extractItem(root: HtmlElement, base: string, page: Extract<NewgroundsPage, { kind: "ng-art" | "ng-movie" }>): PageRecordDraft[] { + const title = + textOf(findFirst(root, (e) => e.attrs.itemprop === "name" && isHeading(e))) || + metaContent(root, "og:title") || + stripSiteTitle(pageTitle(root)) || + undefined; + const comments = findFirst(root, (e) => e.attrs.id === "author_comments"); + const credited = creditedUsers(root, base); + const author = page.kind === "ng-art" ? page.user : credited[0]; + const read: Read = { text: "", links: [], media: [] }; + const lines: string[] = []; + if (title) lines.push(title); + if (comments) { + const r = readBody(comments, base); + addRead(read, r); + if (r.text) lines.push(r.text); + } else { + const d = metaContent(root, "og:description") ?? metaContent(root, "description"); + if (d) lines.push(d); + } + if (credited.length > 1) lines.push(`Credits: ${credited.join(", ")}`); + // The work itself: an art page's image, a movie's embedded file. + for (const img of findAll(root, (e) => e.tag === "img" && !!e.attrs.src)) { + const inImage = findFirst(root, (e) => (hasClass(e, "image") || e.attrs.itemprop === "image") && findFirst(e, (x) => x === img) !== null); + if (!inImage) continue; + const src = absoluteUrl(img.attrs.src, base); + if (src && !read.media.some((m) => m.url === src)) read.media.push({ kind: "image", url: src, ...(img.attrs.alt ? { name: img.attrs.alt } : {}) }); + } + for (const e of findAll(root, (x) => (x.tag === "embed" || x.tag === "object") && !!(x.attrs.src ?? x.attrs.data))) { + const src = absoluteUrl(e.attrs.src ?? e.attrs.data, base); + if (src) pushUnique(read.links, src); + } + const tagsDl = findAll(root, (e) => e.tag === "ul" && hasClass(e, "tags")); + const tags: string[] = []; + for (const ul of tagsDl) for (const li of findAll(ul, (e) => e.tag === "li")) pushUnique(tags, textOf(li).toLowerCase()); + const uploaded = sideStat(root, /^(uploaded|date added)/i); + const publishedAt = + isoFromIso(metaContent(root, "datePublished")) ?? (uploaded ? parseEnglishDate(uploaded) : undefined); + if (!title && !comments) return noContent(page, author); + const draft: PageRecordDraft = { + kind: page.kind, + itemId: page.kind === "ng-art" ? `ng-art-${page.user}-${page.slug}` : `ng-movie-${page.id}`, + url: page.kind === "ng-art" ? `https://www.newgrounds.com/art/view/${page.user}/${page.slug}` : `https://www.newgrounds.com/portal/view/${page.id}`, + text: lines.join("\n"), + links: read.links, + }; + if (title) draft.title = title; + if (author) draft.author = author; + if (publishedAt) draft.publishedAt = publishedAt; + if (read.media.length) draft.media = read.media; + if (tags.length) draft.tags = tags; + return [draft]; +} + +export function extractNewgrounds(input: PageExtractInput): PageRecordDraft[] { + const html = unwrapWaybackHtml(input.html); + const base = input.capture.originalUrl; + let page: NewgroundsPage | null = null; + try { + page = newgroundsPageOf(new URL(base)); + } catch { + page = null; + } + const root = parseHtml(html); + if (!page) return noContent(null, undefined); + return page.kind === "ng-user" ? extractUser(root, base, page.user) : extractItem(root, base, page); +} + +export const newgroundsExtractor: PageExtractor = { + name: NEWGROUNDS_EXTRACTOR_NAME, + version: NEWGROUNDS_EXTRACTOR_VERSION, + matches(originalUrl) { + return newgroundsPageOf(originalUrl) !== null; + }, + extract: extractNewgrounds, +}; diff --git a/common/lib/waybackPages/types.ts b/common/lib/waybackPages/types.ts @@ -9,7 +9,7 @@ import type { WaybackProvenance } from "../wayback"; import type { ForumPostInfo, PostMedia, PostRef } from "../posts"; // What an extractor recognised the capture as. "generic" is the fallback for -// every page no site extractor claims (articles, personal sites, Newgrounds). +// every page no site extractor claims (articles, personal sites). export const PAGE_KINDS = [ "generic", "tumblr-post", @@ -19,6 +19,10 @@ export const PAGE_KINDS = [ "forum-post", "gdoc", "yt-about", + // Release 38 lane C: Newgrounds (extractors/newgrounds.ts). + "ng-user", + "ng-art", + "ng-movie", ] as const; export type PageKind = (typeof PAGE_KINDS)[number]; diff --git a/common/lib/waybackPages/view.ts b/common/lib/waybackPages/view.ts @@ -29,6 +29,9 @@ export const PAGE_KIND_LABELS: Record<string, string> = { "forum-post": "Forum post", gdoc: "Google Doc", "yt-about": "YouTube channel page", + "ng-user": "Newgrounds user page", + "ng-art": "Newgrounds art", + "ng-movie": "Newgrounds movie", }; export function pageKindLabel(kind: string): string {