UNPKG

justlyrics

Version:

A comprehensive TypeScript library for parsing, converting, and processing various lyric formats including LRC, ALRC, YRC, QRC, and more

118 lines (117 loc) 3.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.attLinesToCoreLyric = attLinesToCoreLyric; exports.attKvToObject = attKvToObject; exports.attMetaToLrcHeader = attMetaToLrcHeader; exports.attMetaToYrcHeader = attMetaToYrcHeader; const lyric_1 = require("./lyric"); function attLinesToCoreLyric(lines) { return lines.map((line) => { const syllables = line.words.map((word) => { const syl = { start: new lyric_1.CoreLyric.Timestamp(word.startTime), end: new lyric_1.CoreLyric.Timestamp(word.endTime), text: word.word, annotations: [], }; return syl; }); const voiceAgentIndex = line.isDuet ? 2 : 1; const voiceAgent = { n: voiceAgentIndex, type: line.isBG ? lyric_1.CoreLyric.VoiceAgentType.BackgroundVocal : lyric_1.CoreLyric.VoiceAgentType.Vocal, }; const anno = []; if (line.translatedLyric) { anno.push({ role: lyric_1.CoreLyric.LineAnnotationRole.Translation, line: new lyric_1.CoreLyric.LineSyncedLine({ text: line.translatedLyric, }), }); } if (line.romanLyric) { anno.push({ role: lyric_1.CoreLyric.LineAnnotationRole.Prononciation, line: new lyric_1.CoreLyric.LineSyncedLine({ text: line.romanLyric, }), }); } const newSylSyncedLine = new lyric_1.CoreLyric.SyllableSyncedLine({ syllables, voiceAgent: voiceAgent, annotations: anno, }); return newSylSyncedLine; }); } function attKvToObject(kv) { const obj = {}; for (const item of kv) { obj[item.key] = item.value; } return obj; } function attMetaToLrcHeader(metaKv) { const meta = attKvToObject(metaKv); let header = ''; if (meta.musicName) { for (const item of meta.musicName) { header += `[ti:${item}]\n`; } } if (meta.isrc) { for (const item of meta.isrc) { header += `[isrc:${item}]\n`; } } if (meta.album) { for (const item of meta.album) { header += `[al:${item}]\n`; } } if (meta.artists) { for (const item of meta.artists) { header += `[ar:${item}]\n`; } } if (meta.ncmMusicId) { for (const item of meta.ncmMusicId) { header += `[ncm-id:${item}]\n`; } } if (meta.qqMusicId) { for (const item of meta.qqMusicId) { header += `[qqmusic-id:${item}]\n`; } } if (meta.spotifyId) { for (const item of meta.spotifyId) { header += `[spotify-id:${item}]\n`; } } if (meta.appleMusicId) { for (const item of meta.appleMusicId) { header += `[applemusic-id:${item}]\n`; } } if (meta.ttmlAuthorGithubLogin && meta.ttmlAuthorGithub) { const login = meta.ttmlAuthorGithubLogin[0]; const id = meta.ttmlAuthorGithub[0]; header += `[by:${login}]\n`; header += `[by-github-login:${login}]\n`; header += `[by-github-id:${id}]\n`; } return header; } function attMetaToYrcHeader(metaKv) { const meta = attKvToObject(metaKv); const params = { lyricists: meta.lyricists || [], musicians: meta.musicians || meta.artists || [], }; return lyric_1.LyricIO.Dumping.YRC.createHeaderLines(params); }