feat(api): support Prime Video scraping and provider-aware metadata

This commit is contained in:
2026-03-01 01:08:25 +03:00
parent 74348f224d
commit c0e62e778c
11 changed files with 515 additions and 166 deletions

49
src/utils/contentUrl.ts Normal file
View File

@@ -0,0 +1,49 @@
export type SupportedProvider = 'netflix' | 'primevideo';
const NETFLIX_HOSTS = new Set([
'www.netflix.com',
'netflix.com',
'www.netflix.com.tr',
'netflix.com.tr',
]);
const PRIME_HOSTS = new Set([
'www.primevideo.com',
'primevideo.com',
]);
export interface ParsedContentUrl {
provider: SupportedProvider;
id: string;
}
export function parseSupportedContentUrl(rawUrl: string): ParsedContentUrl | null {
try {
const parsedUrl = new URL(rawUrl);
const hostname = parsedUrl.hostname.toLowerCase();
if (NETFLIX_HOSTS.has(hostname)) {
const titleIdMatch = parsedUrl.pathname.match(/\/title\/(\d+)/);
if (!titleIdMatch) return null;
const id = titleIdMatch[1];
if (!id) return null;
return { provider: 'netflix', id };
}
if (PRIME_HOSTS.has(hostname)) {
const detailIdMatch = parsedUrl.pathname.match(/\/detail\/([A-Za-z0-9]+)/);
if (!detailIdMatch) return null;
const id = detailIdMatch[1];
if (!id) return null;
return { provider: 'primevideo', id };
}
return null;
} catch {
return null;
}
}
export function isSupportedContentUrl(rawUrl: string): boolean {
return Boolean(parseSupportedContentUrl(rawUrl));
}