KTV / lib /utils /video.ts
l-g-t's picture
Upload 212 files
3c76719 verified
/**
* Parses a video title to extract quality tags (e.g., [HD], [TS])
* and return a cleaned title.
*/
export function parseVideoTitle(title: string): { cleanTitle: string, quality?: string } {
// Regex to match tags in brackets at the start of the title
// Example: "[HD] εˆ©εˆƒε‡Ίιž˜3" -> quality: "HD", cleanTitle: "εˆ©εˆƒε‡Ίιž˜3"
// Example: "εˆ©εˆƒε‡Ίιž˜3 [HD]" -> quality: "HD", cleanTitle: "εˆ©εˆƒε‡Ίιž˜3"
const bracketRegex = /\[([^\]]+)\]/g;
let quality: string | undefined;
let cleanTitle = title;
const matches = [...title.matchAll(bracketRegex)];
if (matches.length > 0) {
// Take the first bracket content as quality (usually what we want)
quality = matches[0][1];
// Remove all brackets and their content from the title
cleanTitle = title.replace(bracketRegex, '').trim();
}
return {
cleanTitle: cleanTitle || title,
quality
};
}