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,59 @@
export function extractZillowStructuredPhotoCandidatesFromNextDataScript(scriptText) {
if (typeof scriptText !== "string" || !scriptText.trim()) {
return [];
}
let nextData;
try {
nextData = JSON.parse(scriptText);
} catch {
return [];
}
const cacheText = nextData?.props?.pageProps?.componentProps?.gdpClientCache;
if (typeof cacheText !== "string" || !cacheText.trim()) {
return [];
}
let cache;
try {
cache = JSON.parse(cacheText);
} catch {
return [];
}
const out = [];
for (const entry of Object.values(cache)) {
const photos = entry?.property?.responsivePhotos;
if (!Array.isArray(photos)) continue;
for (const photo of photos) {
if (typeof photo?.url === "string" && photo.url) {
out.push({ url: photo.url });
continue;
}
const mixedSources = photo?.mixedSources;
if (!mixedSources || typeof mixedSources !== "object") continue;
let best = null;
for (const variants of Object.values(mixedSources)) {
if (!Array.isArray(variants)) continue;
for (const variant of variants) {
if (typeof variant?.url !== "string" || !variant.url) continue;
const width = Number(variant.width || 0);
if (!best || width > best.width) {
best = { url: variant.url, width };
}
}
}
if (best) {
out.push(best);
}
}
}
return out;
}