2023-08-20 14:14:15 +02:00
|
|
|
const forbiddenCharsString = ['}', '{', '%', '>', '<', '^', ';', '`', '$', '"', "@", '='];
|
2022-12-06 20:21:07 +01:00
|
|
|
|
2022-10-24 15:03:11 +02:00
|
|
|
export function metadataManager(obj) {
|
|
|
|
let keys = Object.keys(obj);
|
|
|
|
let tags = ["album", "composer", "genre", "copyright", "encoded_by", "title", "language", "artist", "album_artist", "performer", "disc", "publisher", "track", "encoder", "compilation", "date", "creation_time", "comment"]
|
|
|
|
let commands = []
|
|
|
|
|
|
|
|
for (let i in keys) { if (tags.includes(keys[i])) commands.push('-metadata', `${keys[i]}=${obj[keys[i]]}`) }
|
|
|
|
return commands;
|
|
|
|
}
|
2023-12-09 12:00:54 +01:00
|
|
|
|
2023-08-20 14:14:15 +02:00
|
|
|
export function cleanString(string) {
|
|
|
|
for (let i in forbiddenCharsString) {
|
2023-10-15 11:11:39 +02:00
|
|
|
string = string.replaceAll("/", "_").replaceAll(forbiddenCharsString[i], '')
|
2023-08-20 14:14:15 +02:00
|
|
|
}
|
|
|
|
return string;
|
|
|
|
}
|
2023-02-26 17:49:25 +01:00
|
|
|
export function verifyLanguageCode(code) {
|
|
|
|
return RegExp(/[a-z]{2}/).test(String(code.slice(0, 2).toLowerCase())) ? String(code.slice(0, 2).toLowerCase()) : "en"
|
|
|
|
}
|
2022-07-24 12:54:05 +02:00
|
|
|
export function languageCode(req) {
|
2023-02-26 17:49:25 +01:00
|
|
|
return req.header('Accept-Language') ? verifyLanguageCode(req.header('Accept-Language')) : "en"
|
2022-07-28 18:03:17 +02:00
|
|
|
}
|
|
|
|
export function unicodeDecode(str) {
|
|
|
|
return str.replace(/\\u[\dA-F]{4}/gi, (unicode) => {
|
|
|
|
return String.fromCharCode(parseInt(unicode.replace(/\\u/g, ""), 16));
|
|
|
|
});
|
2022-08-01 17:48:37 +02:00
|
|
|
}
|
2023-08-04 20:43:12 +02:00
|
|
|
export function cleanHTML(html) {
|
|
|
|
let clean = html.replace(/ {4}/g, '');
|
|
|
|
clean = clean.replace(/\n/g, '');
|
|
|
|
return clean
|
|
|
|
}
|