From fe35081e03182423317f62aad4dbd111a418065b Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 26 Aug 2021 16:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E2=80=9C=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=9A=84=E6=AD=8C=E8=AF=8D=E6=96=87=E4=BB=B6=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E2=80=9D=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/common/defaultSetting.js | 3 ++- src/renderer/lang/en-us/view/setting.json | 3 +++ src/renderer/lang/zh-cn/view/setting.json | 3 +++ src/renderer/lang/zh-tw/view/setting.json | 3 +++ src/renderer/store/modules/download.js | 6 +++--- src/renderer/utils/index.js | 20 ++++++++++++++++---- src/renderer/views/Setting.vue | 18 ++++++++++++++++++ 8 files changed, 49 insertions(+), 8 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 3ca4fcb9..ffa82477 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -4,6 +4,7 @@ ### 新增 - 歌曲搜索框新增清理按钮,点击此按钮可以清理搜索框并返回初始搜索界面 +- 新增“下载的歌词文件编码格式”设置,默认下载的歌词编码仍是`UTF-8`,对于某些在设备(如车机)上出现歌词中文乱码的用户可以尝试选择以`GBK`编码格式保存歌词文件 ### 优化 diff --git a/src/common/defaultSetting.js b/src/common/defaultSetting.js index fe0764cb..43936936 100644 --- a/src/common/defaultSetting.js +++ b/src/common/defaultSetting.js @@ -2,7 +2,7 @@ const path = require('path') const os = require('os') const defaultSetting = { - version: '1.0.43', + version: '1.0.44', player: { togglePlayMethod: 'listLoop', highQuality: false, @@ -44,6 +44,7 @@ const defaultSetting = { fileName: '歌名 - 歌手', maxDownloadNum: 3, isDownloadLrc: false, + lrcFormat: 'utf8', isEmbedPic: true, isEmbedLyric: false, isUseOtherSource: false, diff --git a/src/renderer/lang/en-us/view/setting.json b/src/renderer/lang/en-us/view/setting.json index 1db3e36c..f5bf4830 100644 --- a/src/renderer/lang/en-us/view/setting.json +++ b/src/renderer/lang/en-us/view/setting.json @@ -59,6 +59,9 @@ "download_embed_pic": "Embedding cover", "download_enable": "Whether to enable download function", "download_lyric": "Lyrics download", + "download_lyric_format": "Downloaded lyrics file encoding format", + "download_lyric_format_gbk": "GBK (Try to select this format when Chinese garbled characters appear on some devices)", + "download_lyric_format_utf8": "UTF-8", "download_lyric_title": "Select whether to download the lyrics file", "download_name": "Music file naming", "download_name1": "Title - Artist", diff --git a/src/renderer/lang/zh-cn/view/setting.json b/src/renderer/lang/zh-cn/view/setting.json index 6c9a8fa5..c162d35a 100644 --- a/src/renderer/lang/zh-cn/view/setting.json +++ b/src/renderer/lang/zh-cn/view/setting.json @@ -59,6 +59,9 @@ "download_embed_pic": "封面嵌入", "download_enable": "是否启用下载功能", "download_lyric": "歌词下载", + "download_lyric_format": "下载的歌词文件编码格式", + "download_lyric_format_gbk": "GBK(在某些设备上出现中文乱码时可尝试选择此格式)", + "download_lyric_format_utf8": "UTF-8", "download_lyric_title": "是否同时下载歌词文件", "download_name": "文件命名方式", "download_name1": "歌名 - 歌手", diff --git a/src/renderer/lang/zh-tw/view/setting.json b/src/renderer/lang/zh-tw/view/setting.json index 4b9308de..9e99c03c 100644 --- a/src/renderer/lang/zh-tw/view/setting.json +++ b/src/renderer/lang/zh-tw/view/setting.json @@ -59,6 +59,9 @@ "download_embed_pic": "封面嵌入", "download_enable": "是否啟用下載功能", "download_lyric": "歌詞下載", + "download_lyric_format": "下載的歌詞文件編碼格式", + "download_lyric_format_gbk": "GBK(在某些設備上出現中文亂碼時可嘗試選擇此格式)", + "download_lyric_format_utf8": "UTF-8", "download_lyric_title": "是否同時下載歌詞文件", "download_name": "文件命名方式", "download_name1": "歌名 - 歌手", diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index 54aa2dac..a72d36a3 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -307,7 +307,7 @@ const saveMeta = function(downloadInfo, filePath, isUseOtherSource, isEmbedPic, * @param {*} downloadInfo * @param {*} filePath */ -const downloadLyric = (downloadInfo, filePath) => { +const downloadLyric = (downloadInfo, filePath, lrcFormat) => { const promise = getLyric(downloadInfo.musicInfo).then(lrcInfo => { return lrcInfo.lyric ? Promise.resolve({ lyric: lrcInfo.lyric, tlyric: lrcInfo.tlyric || '' }) @@ -319,7 +319,7 @@ const downloadLyric = (downloadInfo, filePath) => { promise.then(lrcs => { if (lrcs.lyric) { lrcs.lyric = fixKgLyric(lrcs.lyric) - saveLrc(filePath.replace(/(mp3|flac|ape|wav)$/, 'lrc'), lrcs.lyric) + saveLrc(filePath.replace(/(mp3|flac|ape|wav)$/, 'lrc'), lrcs.lyric, lrcFormat) } }) } @@ -436,7 +436,7 @@ const actions = { dispatch('startTask') saveMeta.call(_this, downloadInfo, downloadInfo.filePath, rootState.setting.download.isUseOtherSource, rootState.setting.download.isEmbedPic, rootState.setting.download.isEmbedLyric) - if (rootState.setting.download.isDownloadLrc) downloadLyric(downloadInfo, downloadInfo.filePath) + if (rootState.setting.download.isDownloadLrc) downloadLyric(downloadInfo, downloadInfo.filePath, rootState.setting.download.lrcFormat) console.log('on complate') }, onError(err) { diff --git a/src/renderer/utils/index.js b/src/renderer/utils/index.js index 879ce4d1..fd507f7a 100644 --- a/src/renderer/utils/index.js +++ b/src/renderer/utils/index.js @@ -3,6 +3,7 @@ import path from 'path' import { shell, clipboard } from 'electron' import crypto from 'crypto' import { rendererSend, rendererInvoke, NAMES } from '../../common/ipc' +import iconv from 'iconv-lite' /** * 获取两个数之间的随机整数,大于等于min,小于max @@ -276,11 +277,22 @@ export const setMeta = (filePath, meta) => { * 保存歌词文件 * @param {*} filePath * @param {*} lrc + * @param {*} format */ -export const saveLrc = (filePath, lrc) => { - fs.writeFile(filePath, lrc, 'utf8', err => { - if (err) console.log(err) - }) +export const saveLrc = (filePath, lrc, format) => { + switch (format) { + case 'gbk': + fs.writeFile(filePath, iconv.encode(lrc, 'gbk', { addBOM: true }), err => { + if (err) console.log(err) + }) + break + case 'utf8': + default: + fs.writeFile(filePath, lrc, 'utf8', err => { + if (err) console.log(err) + }) + break + } } /** diff --git a/src/renderer/views/Setting.vue b/src/renderer/views/Setting.vue index d25658b4..711237f8 100644 --- a/src/renderer/views/Setting.vue +++ b/src/renderer/views/Setting.vue @@ -149,6 +149,11 @@ div(:class="$style.main") h3#download_lyric {{$t('view.setting.download_lyric')}} div material-checkbox(id="setting_download_isDownloadLrc" v-model="current_setting.download.isDownloadLrc" :label="$t('view.setting.is_enable')") + dd + h3#download_lyric {{$t('view.setting.download_lyric_format')}} + div + material-checkbox(v-for="item in lrcFormatList" :key="item.id" :class="$style.gapLeft" :id="`setting_download_lrcFormat_${item.id}`" + name="setting_basic_control_btn_position" need v-model="current_setting.download.lrcFormat" :value="item.id" :label="item.name") dt#sync {{$t('view.setting.sync')}} dd @@ -424,6 +429,18 @@ export default { }, ] }, + lrcFormatList() { + return [ + { + name: this.$t('view.setting.download_lyric_format_utf8'), + id: 'utf8', + }, + { + name: this.$t('view.setting.download_lyric_format_gbk'), + id: 'gbk', + }, + ] + }, trayThemeList() { return [ { @@ -494,6 +511,7 @@ export default { savePath: '', fileName: '歌名 - 歌手', isDownloadLrc: false, + lrcFormat: 'utf8', isEmbedPic: true, isEmbedLyric: true, },