export async function extractListId(url: string): Promise { let resolved = url; if (url.includes("goo.gl/") || url.includes("maps.app")) { resolved = await followRedirects(url); } const placelistMatch = /\/maps\/placelists\/list\/([^/?#]+)/.exec(resolved); if (placelistMatch?.[1]) { return placelistMatch[1]; } const decoded = decodeURIComponent(resolved); const dataMatch = /!2s([^!&?#\s]+)/.exec(decoded); if (dataMatch?.[1]) { return dataMatch[1]; } throw new Error(`Could not extract list ID from URL: ${url}`); } async function followRedirects(url: string, maxHops = 10): Promise { let current = url; for (let i = 0; i < maxHops; i++) { const response = await fetch(current, { redirect: "manual" }); await response.body?.cancel(); const location = response.headers.get("location"); if (!location) { return response.url || current; } current = location.startsWith("/") ? new URL(location, current).href : location; } return current; }