mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-15 00:33:44 +08:00
32 lines
880 B
TypeScript
32 lines
880 B
TypeScript
/**
|
|
* API Response Parsers
|
|
*/
|
|
|
|
import type { Episode } from '@/lib/types';
|
|
|
|
/**
|
|
* Parse episode URL string into structured array
|
|
*/
|
|
export function parseEpisodes(playUrl: string): Episode[] {
|
|
if (!playUrl) return [];
|
|
|
|
try {
|
|
// Format: "Episode1$url1#Episode2$url2#..."
|
|
const episodes = playUrl.split('#').filter(Boolean);
|
|
|
|
return episodes.map((episode, index) => {
|
|
const [name, url] = episode.split('$');
|
|
// Clean up URL: remove double slashes but keep protocol (http:// or https://)
|
|
const cleanUrl = (url || '').replace(/([^:])\/\//g, '$1/');
|
|
return {
|
|
name: name || `Episode ${index + 1}`,
|
|
url: cleanUrl,
|
|
index,
|
|
};
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to parse episodes:', error);
|
|
return [];
|
|
}
|
|
}
|