Add Zillow and HAR photo extractors

This commit is contained in:
2026-03-27 17:35:46 -05:00
parent e7c56fe760
commit eeea0c8ef1
11 changed files with 873 additions and 8 deletions

View File

@@ -0,0 +1,69 @@
import test from "node:test";
import assert from "node:assert/strict";
import { extractZillowStructuredPhotoCandidatesFromNextDataScript } from "./zillow-photo-data.js";
test("extractZillowStructuredPhotoCandidatesFromNextDataScript reads responsivePhotos", () => {
const scriptText = JSON.stringify({
props: {
pageProps: {
componentProps: {
gdpClientCache: JSON.stringify({
SomeQuery: {
property: {
responsivePhotos: [
{
url: "https://photos.zillowstatic.com/fp/photo-one-p_d.jpg",
mixedSources: {
jpeg: [{ url: "https://photos.zillowstatic.com/fp/photo-one-cc_ft_384.jpg", width: 384 }],
},
},
{
url: "https://photos.zillowstatic.com/fp/photo-two-p_d.jpg",
},
],
},
},
}),
},
},
},
});
assert.deepEqual(extractZillowStructuredPhotoCandidatesFromNextDataScript(scriptText), [
{ url: "https://photos.zillowstatic.com/fp/photo-one-p_d.jpg" },
{ url: "https://photos.zillowstatic.com/fp/photo-two-p_d.jpg" },
]);
});
test("extractZillowStructuredPhotoCandidatesFromNextDataScript falls back to mixedSources", () => {
const scriptText = JSON.stringify({
props: {
pageProps: {
componentProps: {
gdpClientCache: JSON.stringify({
SomeQuery: {
property: {
responsivePhotos: [
{
mixedSources: {
jpeg: [
{ url: "https://photos.zillowstatic.com/fp/photo-one-cc_ft_384.jpg", width: 384 },
{ url: "https://photos.zillowstatic.com/fp/photo-one-cc_ft_1536.jpg", width: 1536 },
],
webp: [{ url: "https://photos.zillowstatic.com/fp/photo-one-cc_ft_1152.webp", width: 1152 }],
},
},
],
},
},
}),
},
},
},
});
assert.deepEqual(extractZillowStructuredPhotoCandidatesFromNextDataScript(scriptText), [
{ url: "https://photos.zillowstatic.com/fp/photo-one-cc_ft_1536.jpg", width: 1536 },
]);
});