// The Tumblr extractor over SYNTHETIC theme pages (__fixtures__/tumblr-*): // a 2012 classic theme (permalink and index), a 2014 article.post theme on a // custom domain served through Wayback's replay, a minimal theme's tagged // page, and a page with no post. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/waybackPages/extractors/tumblr.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { extractTumblr, isTumblrBlogHost, tumblrBlogName, tumblrExtractor } from "./tumblr"; import { captureOf, fixture } from "./__fixtures__/capture"; const run = (file: string, url: string, ts: string) => extractTumblr({ html: fixture(file), capture: captureOf(url, ts) }); test("a classic theme's permalink page: one post, its own fields, none of the page around it", () => { const drafts = run("tumblr-2012-classic-post.html", "http://teapot-notes.tumblr.com/post/20000000001/on-spouts", "20120601000000"); assert.equal(drafts.length, 1); const [d] = drafts; assert.equal(d.kind, "tumblr-post"); assert.equal(d.itemId, "tumblr-20000000001"); assert.equal(d.url, "http://teapot-notes.tumblr.com/post/20000000001/on-spouts"); assert.equal(d.author, "teapot-notes"); assert.equal(d.title, "On spouts"); assert.equal(d.publishedAt, "2012-05-03T00:00:00.000Z"); assert.deepEqual(d.tags, ["teapots", "kitchen history"]); // Google's redirector unwrapped; the post's own permalinks are not links. assert.deepEqual(d.links, ["http://example.com/spouts"]); assert.deepEqual(d.media, [{ kind: "image", url: "http://24.media.tumblr.com/tumblr_m3abc_500.jpg", name: "a brown teapot" }]); assert.equal( d.text, "On spouts\nA good spout never drips.\nSee the spout survey (http://example.com/spouts) for more.\n[image]", ); assert.equal(d.noContent, undefined); assert.equal(d.isRepost, undefined); }); test("an index page: one draft per post, and a post on it is the SAME draft as on its permalink", () => { const index = run("tumblr-2012-classic-index.html", "http://teapot-notes.tumblr.com/", "20120601000000"); assert.deepEqual(index.map((d) => d.itemId), ["tumblr-20000000002", "tumblr-20000000001"]); assert.equal(index[0].publishedAt, "2012-05-10T00:00:00.000Z"); assert.equal(index[0].text, "On handles\nHandles should be warm to the touch."); const [permalink] = run("tumblr-2012-classic-post.html", "http://teapot-notes.tumblr.com/post/20000000001/on-spouts", "20120601000000"); assert.deepEqual(index[1], permalink); }); test("a 2014 article.post theme on a custom domain, through Wayback's replay: three posts, a reblog, a photo", () => { const drafts = run("tumblr-2014-article-index.html", "http://blog.kettle-studio.example/page/2", "20140405060708"); // The toolbar's own link to another post is gone with the toolbar. assert.deepEqual(drafts.map((d) => d.itemId), ["tumblr-40000000003", "tumblr-40000000002", "tumblr-40000000001"]); const [text, photo, reblog] = drafts; for (const d of drafts) assert.equal(d.author, "kettlestudio"); assert.equal(text.title, "Three glazes"); assert.equal(text.url, "http://blog.kettle-studio.example/post/40000000003/glazes"); assert.equal(text.publishedAt, "2014-03-02T15:15:00.000Z"); assert.deepEqual(text.tags, ["glaze", "kiln day"]); assert.deepEqual(text.links, ["http://glaze-wiki.example/celadon"]); assert.equal( text.text, "Three glazes\nWe tried three glazes this week:\n- celadon\n- tenmoku\n- shino\nNotes on the celadon page (http://glaze-wiki.example/celadon).", ); assert.equal(photo.publishedAt, "2014-02-27T08:00:00.000Z"); assert.equal(photo.url, "http://blog.kettle-studio.example/post/40000000002"); assert.deepEqual(photo.media, [{ kind: "image", url: "http://31.media.tumblr.com/tumblr_n1photo_1280.jpg", name: "kiln shelf" }]); assert.equal(photo.text, "[image]\nFresh out of the kiln."); assert.equal(reblog.isRepost, true); assert.deepEqual(reblog.repostOf, { platform: "webpage", id: "tumblr-39999999999", url: "http://clay-friends.tumblr.com/post/39999999999/wheel-tips", author: "clay-friends", }); assert.equal(reblog.text, "Center the clay before you open it.\nAlways good advice."); assert.equal(reblog.publishedAt, "2014-02-20T00:00:00.000Z"); assert.deepEqual(reblog.tags, ["wheel"]); }); test("a minimal theme with no post markup: posts found by their permalinks, dates from the theme's line", () => { const drafts = run("tumblr-minimal-tagged.html", "http://quiet-kettle.tumblr.com/tagged/steam", "20130310000000"); assert.deepEqual( drafts.map((d) => [d.itemId, d.publishedAt, d.text, d.tags]), [ ["tumblr-30000000002", "2013-03-02T10:00:00.000Z", "Steam is just water being dramatic.", ["steam"]], ["tumblr-30000000001", "2013-02-28T21:30:00.000Z", "The whistle is a feature.\nNot a bug.", ["steam", "whistles"]], ], ); assert.equal(drafts[0].author, "quiet-kettle"); }); test("a page holding no post: one whole-page tumblr-index draft with its text", () => { const drafts = run("tumblr-about.html", "http://quiet-kettle.tumblr.com/about", "20130310000000"); assert.equal(drafts.length, 1); assert.equal(drafts[0].kind, "tumblr-index"); assert.equal(drafts[0].itemId, undefined); assert.equal(drafts[0].text, "About\nA blog about kettles, run by one person."); assert.equal(drafts[0].noContent, undefined); const empty = extractTumblr({ html: "", capture: captureOf("http://quiet-kettle.tumblr.com/ask", "20130310000000") }); assert.equal(empty[0].noContent, true); assert.equal(empty[0].text, "This capture holds no Tumblr posts."); }); test("matches: a blog host, a Tumblr theme on its own domain; not Tumblr's own hosts or other pages", () => { const m = (url: string, html = "") => tumblrExtractor.matches(new URL(url), html); assert.equal(m("http://teapot-notes.tumblr.com/"), true); assert.equal(m("https://www.tumblr.com/dashboard"), false); assert.equal(m("https://64.media.tumblr.com/x.jpg"), false); assert.equal(m("http://blog.kettle-studio.example/page/2", fixture("tumblr-2014-article-index.html")), true); assert.equal(m("https://news.example/story", `x`), false); assert.equal(isTumblrBlogHost("STAFF.tumblr.com"), true); assert.equal(tumblrBlogName("staff.tumblr.com"), "staff"); assert.equal(tumblrExtractor.name, "tumblr"); assert.equal(tumblrExtractor.version, 1); });