mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-22 04:03:42 +08:00
feat: Extract and display video quality from titles on video cards and update package version.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user