feat(api): support Prime Video scraping and provider-aware metadata
This commit is contained in:
49
src/utils/contentUrl.ts
Normal file
49
src/utils/contentUrl.ts
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user