diff --git a/src/modules/sub/utils.js b/src/modules/sub/utils.js index e965bd9a..0db85649 100644 --- a/src/modules/sub/utils.js +++ b/src/modules/sub/utils.js @@ -1,30 +1,43 @@ const forbiddenCharsString = ['}', '{', '%', '>', '<', '^', ';', '`', '$', '"', "@", '=']; 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"] + const keys = Object.keys(obj); + const tags = [ + "album", + "copyright", + "title", + "artist", + "track", + "date" + ] let commands = [] - for (let i in keys) { if (tags.includes(keys[i])) commands.push('-metadata', `${keys[i]}=${obj[keys[i]]}`) } + for (const i in keys) { + if (tags.includes(keys[i])) + commands.push('-metadata', `${keys[i]}=${obj[keys[i]]}`) + } return commands; } export function cleanString(string) { - for (let i in forbiddenCharsString) { - string = string.replaceAll("/", "_").replaceAll(forbiddenCharsString[i], '') + for (const i in forbiddenCharsString) { + string = string.replaceAll("/", "_") + .replaceAll(forbiddenCharsString[i], '') } return string; } export function verifyLanguageCode(code) { - return RegExp(/[a-z]{2}/).test(String(code.slice(0, 2).toLowerCase())) ? String(code.slice(0, 2).toLowerCase()) : "en" + const languageCode = String(code.slice(0, 2).toLowerCase()); + if (RegExp(/[a-z]{2}/).test(languageCode)) { + return languageCode + } + return "en" } export function languageCode(req) { - return req.header('Accept-Language') ? verifyLanguageCode(req.header('Accept-Language')) : "en" -} -export function unicodeDecode(str) { - return str.replace(/\\u[\dA-F]{4}/gi, (unicode) => { - return String.fromCharCode(parseInt(unicode.replace(/\\u/g, ""), 16)); - }); + if (req.header('Accept-Language')) { + return verifyLanguageCode(req.header('Accept-Language')) + } + return "en" } export function cleanHTML(html) { let clean = html.replace(/ {4}/g, '');