| /** | |
| * 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 | |
| }; | |
| } | |