Skip to content

Commit e683034

Browse files
committed
新增 Any Listen 歌词标签数据嵌入、下载、读取播放(#2485
1 parent ffa979d commit e683034

11 files changed

Lines changed: 141 additions & 41 deletions

File tree

publish/changeLog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
### 新增
22

3-
- 新增「设置 → 其他设置 → 主窗口使用软件内置的圆角及阴影」选项(#2360
3+
- 新增「设置 → 其他设置 → 主窗口使用软件内置的圆角及阴影」选项(#2360
44
*默认启用,关闭后将使用系统原生的窗口样式,该选项重启软件后生效*
55
- 开放 API 新增播放器声音大小、静音、播放进度控制,详情看接入文档(#2386
66
- 新增「设置 → 播放设置 → 调换歌词翻译与歌词罗马音位置」选项,默认关闭(#2451
77
- 新增启动参数 `-hidden`,在启动时将软件最小化到系统托盘(#2459
8+
- 新增 Any Listen 歌词标签数据读取与播放(#2485
9+
- 新增 Any Listen 歌词(包含逐字歌词、翻译、罗马音歌词,如果有)嵌入与下载,默认启用
810

911
### 修复
1012

1113
- 尝试修复进度为0时仍然显示下载完成的问题(#2471
1214

1315
### 变更
1416

15-
- 调换「歌词翻译」与「歌词罗马音」的位置,现在歌词罗马音在歌词翻译的上方展示
17+
- 调换「歌词翻译」与「歌词罗马音」的位置,现在歌词罗马音在歌词翻译的上方展示
1618
*若你想要恢复以前的行为,可以开启「调换歌词翻译与歌词罗马音位置」选项*
1719
- 更新代理配置规则,现在不启用代理时,图片、音频加载将不再走系统代理(#2382 @Folltoshe
1820

src/common/defaultSetting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ const defaultSetting: LX.AppSetting = {
116116
'download.maxDownloadNum': 3,
117117
'download.skipExistFile': true,
118118
'download.isDownloadLrc': false,
119+
'download.isDownloadLxLrc': true,
119120
'download.isDownloadTLrc': false,
120121
'download.isDownloadRLrc': false,
121122
'download.lrcFormat': 'utf8',
122123
'download.isEmbedPic': true,
123124
'download.isEmbedLyric': false,
125+
'download.isEmbedLyricLx': true,
124126
'download.isEmbedLyricT': false,
125127
'download.isEmbedLyricR': false,
126128
'download.isUseOtherSource': false,

src/common/types/app_setting.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ declare global {
530530
*/
531531
'download.isDownloadLrc': boolean
532532

533+
/**
534+
* 是否在下载 lx 歌词
535+
*/
536+
'download.isDownloadLxLrc': boolean
537+
533538
/**
534539
* 是否下载翻译歌词文件
535540
*/
@@ -550,6 +555,11 @@ declare global {
550555
*/
551556
'download.isEmbedPic': boolean
552557

558+
/**
559+
* 是否在音频文件中嵌入 lx 歌词
560+
*/
561+
'download.isEmbedLyricLx': boolean
562+
553563
/**
554564
* 是否在音频文件中嵌入歌词
555565
*/

src/lang/en-us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,13 @@
407407
"setting__dislike_list_title": "Disliked Song Rule List",
408408
"setting__download": "Download",
409409
"setting__download_data_embed": "Embed the Following into Audio File",
410+
"setting__download_embed_lxlyric": "Embed LX Music lyrics at the same time (if any, verbatim lyrics can be supported when playing with LX Music)",
410411
"setting__download_embed_lyric": "Embed lyrics",
411412
"setting__download_embed_pic": "Embed cover",
412413
"setting__download_embed_rlyric": "Also embed romanized lyrics if available",
413414
"setting__download_embed_tlyric": "Also embed translated lyrics if available",
414415
"setting__download_enable": "Enable Download",
416+
"setting__download_lxlyric": "Also write LX Music lyrics into the lyrics file (if any, verbatim lyrics can be supported when playing with LX Music)",
415417
"setting__download_lyric": "Lyric Download",
416418
"setting__download_lyric_format": "Encoding Format of Downloaded Lyric Files",
417419
"setting__download_lyric_format_gbk": "GBK",

src/lang/zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,13 @@
407407
"setting__dislike_list_title": "「不喜欢的歌曲」规则列表",
408408
"setting__download": "下载设置",
409409
"setting__download_data_embed": "嵌入到音频文件中的内容",
410+
"setting__download_embed_lxlyric": "同时嵌入 LX Music 歌词(如果有,使用 LX Music 播放时可支持逐字歌词)",
410411
"setting__download_embed_lyric": "嵌入歌词",
411412
"setting__download_embed_pic": "嵌入封面",
412413
"setting__download_embed_rlyric": "同时嵌入罗马音歌词(如果有)",
413414
"setting__download_embed_tlyric": "同时嵌入翻译歌词(如果有)",
414415
"setting__download_enable": "启用下载功能",
416+
"setting__download_lxlyric": "同时将 LX Music 歌词写入歌词文件中(如果有,使用 LX Music 播放时可支持逐字歌词)",
415417
"setting__download_lyric": "歌词下载",
416418
"setting__download_lyric_format": "下载的歌词文件编码格式",
417419
"setting__download_lyric_format_gbk": "GBK",

src/lang/zh-tw.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,13 @@
407407
"setting__dislike_list_title": "「不喜歡的歌曲」規則清單",
408408
"setting__download": "下載設定",
409409
"setting__download_data_embed": "嵌入到音訊檔案中的內容",
410+
"setting__download_embed_lxlyric": "同時嵌入 LX Music 歌詞(如果有,使用 LX Music 播放時可支持逐字歌詞)",
410411
"setting__download_embed_lyric": "嵌入歌詞",
411412
"setting__download_embed_pic": "嵌入封面",
412413
"setting__download_embed_rlyric": "同時嵌入羅馬音歌詞(如果有)",
413414
"setting__download_embed_tlyric": "同時嵌入翻譯歌詞(如果有)",
414415
"setting__download_enable": "啟用下載功能",
416+
"setting__download_lxlyric": "同時將 LX Music 歌詞寫入歌詞文件中(如果有,使用 LX Music 播放時可支持逐字歌詞)",
415417
"setting__download_lyric": "歌詞下載",
416418
"setting__download_lyric_format": "下載的歌詞檔案編碼格式",
417419
"setting__download_lyric_format_gbk": "GBK",

src/renderer/store/download/action.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,17 @@ const saveMeta = (downloadInfo: LX.Download.ListItem) => {
166166
: Promise.resolve(null),
167167
]
168168
void Promise.all(tasks).then(([imgUrl, lyrics]) => {
169-
const lrcData = {
170-
lrc: '',
171-
tlrc: null as string | null,
172-
rlrc: null as string | null,
173-
}
174-
if (lyrics) {
175-
lrcData.lrc = lyrics.lyric
176-
if (appSetting['download.isEmbedLyricT'] && lyrics.tlyric) lrcData.tlrc = lyrics.tlyric
177-
if (appSetting['download.isEmbedLyricR'] && lyrics.rlyric) lrcData.rlrc = lyrics.rlyric
178-
}
179-
void window.lx.worker.download.writeMeta(downloadInfo.metadata.filePath, {
169+
const info = {
170+
filePath: downloadInfo.metadata.filePath,
171+
isEmbedLyricLx: appSetting['download.isEmbedLyricLx'],
172+
isEmbedLyricT: appSetting['download.isEmbedLyricT'],
173+
isEmbedLyricR: appSetting['download.isEmbedLyricR'],
180174
title: downloadInfo.metadata.musicInfo.name,
181175
artist: downloadInfo.metadata.musicInfo.singer?.replaceAll('、', ';'),
182176
album: downloadInfo.metadata.musicInfo.meta.albumName,
183177
APIC: imgUrl,
184-
}, lrcData, getProxy())
178+
}
179+
void window.lx.worker.download.writeMeta(info, lyrics ?? { lyric: '' }, getProxy())
185180
})
186181
}
187182

@@ -198,14 +193,14 @@ const downloadLyric = (downloadInfo: LX.Download.ListItem) => {
198193
}).then(lrcs => {
199194
if (lrcs.lyric) {
200195
lrcs.lyric = fixKgLyric(lrcs.lyric)
201-
const lrcData = {
202-
lrc: lrcs.lyric,
203-
tlrc: appSetting['download.isDownloadTLrc'] && lrcs.tlyric ? lrcs.tlyric : null,
204-
rlrc: appSetting['download.isDownloadRLrc'] && lrcs.rlyric ? lrcs.rlyric : null,
196+
const info = {
197+
filePath: downloadInfo.metadata.filePath.substring(0, downloadInfo.metadata.filePath.lastIndexOf('.')) + '.lrc',
198+
format: appSetting['download.lrcFormat'],
199+
downloadLxlrc: appSetting['download.isDownloadLxLrc'],
200+
downloadTlrc: appSetting['download.isDownloadTLrc'],
201+
downloadRlrc: appSetting['download.isDownloadRLrc'],
205202
}
206-
void window.lx.worker.download.saveLrc(lrcData,
207-
downloadInfo.metadata.filePath.substring(0, downloadInfo.metadata.filePath.lastIndexOf('.')) + '.lrc',
208-
appSetting['download.lrcFormat'])
203+
void window.lx.worker.download.saveLrc(lrcs, info)
209204
}
210205
})
211206
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { setMeta } from '@common/utils/musicMeta'
2-
import { mergeLyrics } from './lrcTool'
2+
import { buildLyrics } from './lrcTool'
33

4-
export const writeMeta = (filePath: string, meta: Omit<LX.Music.MusicFileMeta, 'lyrics'>, lyricData: { lrc: string, tlrc: string | null, rlrc: string | null }, proxy?: { host: string, port: number }) => {
5-
setMeta(filePath, { ...meta, lyrics: mergeLyrics(lyricData.lrc, lyricData.tlrc, lyricData.rlrc) || null }, proxy)
4+
export const writeMeta = ({ filePath, isEmbedLyricLx, isEmbedLyricT, isEmbedLyricR, ...meta }: {
5+
filePath: string
6+
isEmbedLyricLx: boolean
7+
isEmbedLyricT: boolean
8+
isEmbedLyricR: boolean
9+
title: string
10+
artist: string
11+
album: string
12+
APIC: string | null
13+
}, lyric: LX.Music.LyricInfo, proxy?: { host: string, port: number }) => {
14+
setMeta(filePath, { ...meta, lyrics: buildLyrics(lyric, isEmbedLyricLx, isEmbedLyricT, isEmbedLyricR) }, proxy)
615
}
716

817
export { saveLrc } from './utils'

src/renderer/worker/download/lrcTool.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,38 @@ const parseLrcTimeLabel = (lrc: string) => {
6161
return linesSet
6262
}
6363

64+
const buildAwlyric = (lrcData: LX.Music.LyricInfo) => {
65+
let lrc: string[] = []
66+
if (lrcData.lyric) {
67+
lrc.push(`lrc:${Buffer.from(lrcData.lyric.trim(), 'utf-8').toString('base64')}`)
68+
}
69+
if (lrcData.tlyric) {
70+
lrc.push(`tlrc:${Buffer.from(lrcData.tlyric.trim(), 'utf-8').toString('base64')}`)
71+
}
72+
if (lrcData.rlyric) {
73+
lrc.push(`rlrc:${Buffer.from(lrcData.rlyric.trim(), 'utf-8').toString('base64')}`)
74+
}
75+
if (lrcData.lxlyric) {
76+
lrc.push(`awlrc:${Buffer.from(lrcData.lxlyric.trim(), 'utf-8').toString('base64')}`)
77+
}
78+
return lrc.length ? `[awlrc:${lrc.join(',')}]` : ''
79+
}
6480

65-
export const mergeLyrics = (lrc: string, tlrc: string | null, rlrc: string | null) => {
66-
if (!tlrc && !rlrc) return lrc
81+
export const buildLyrics = (lrcData: LX.Music.LyricInfo, downloadAwlrc: boolean, downloadTlrc: boolean, downloadRlrc: boolean) => {
82+
if (!lrcData.tlyric && !lrcData.rlyric && !lrcData.lxlyric) return lrcData.lyric
6783

68-
const lrcTimeLabels = parseLrcTimeLabel(lrc)
69-
// console.log(lrcTimeLabels)
70-
if (tlrc) lrc += `\n\n${filterExtendedLyricLabel(lrcTimeLabels, tlrc)}\n`
71-
if (rlrc) lrc += `\n\n${filterExtendedLyricLabel(lrcTimeLabels, rlrc)}\n`
72-
// console.log(lrc)
84+
const lrcTimeLabels = parseLrcTimeLabel(lrcData.lyric)
85+
86+
let lrc = lrcData.lyric
87+
if (downloadTlrc && lrcData.tlyric) {
88+
lrc = lrc.trim() + `\n\n${filterExtendedLyricLabel(lrcTimeLabels, lrcData.tlyric)}\n`
89+
}
90+
if (downloadRlrc && lrcData.rlyric) {
91+
lrc = lrc.trim() + `\n\n${filterExtendedLyricLabel(lrcTimeLabels, lrcData.rlyric)}\n`
92+
}
93+
if (downloadAwlrc) {
94+
const awlrc = buildAwlyric(lrcData)
95+
if (awlrc) lrc = lrc.trim() + `\n\n${awlrc}\n`
96+
}
7397
return lrc
7498
}

src/renderer/worker/download/utils.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
import { DOWNLOAD_STATUS, QUALITYS } from '@common/constants'
22
import { filterFileName } from '@common/utils/common'
3-
import { mergeLyrics } from './lrcTool'
3+
import { buildLyrics } from './lrcTool'
44
import fs from 'fs'
55
import { clipFileNameLength, clipNameLength } from '@common/utils/tools'
66

77
/**
88
* 保存歌词文件
9-
* @param {*} filePath
10-
* @param {*} lrc
11-
* @param {*} format
129
*/
13-
export const saveLrc = async(lrcData: { lrc: string, tlrc: string | null, rlrc: string | null }, filePath: string, format: LX.LyricFormat) => {
10+
export const saveLrc = async(lrcData: LX.Music.LyricInfo, info: {
11+
filePath: string
12+
format: LX.LyricFormat
13+
downloadLxlrc: boolean
14+
downloadTlrc: boolean
15+
downloadRlrc: boolean
16+
}) => {
1417
const iconv = await import('iconv-lite')
15-
const lrc = mergeLyrics(lrcData.lrc, lrcData.tlrc, lrcData.rlrc)
16-
switch (format) {
18+
const lrc = buildLyrics(lrcData, info.downloadLxlrc, info.downloadTlrc, info.downloadRlrc)
19+
switch (info.format) {
1720
case 'gbk':
18-
fs.writeFile(filePath, iconv.encode(lrc, 'gbk', { addBOM: true }), err => {
21+
fs.writeFile(info.filePath, iconv.encode(lrc, 'gbk', { addBOM: true }), err => {
1922
if (err) console.log(err)
2023
})
2124
break
2225
case 'utf8':
2326
default:
24-
fs.writeFile(filePath, iconv.encode(lrc, 'utf8', { addBOM: true }), err => {
27+
fs.writeFile(info.filePath, iconv.encode(lrc, 'utf8', { addBOM: true }), err => {
2528
if (err) console.log(err)
2629
})
2730
break

0 commit comments

Comments
 (0)