From 3b25e0a1127421bbac67c55cedcfbdfe4d29776c Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 2 Jul 2020 12:03:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B0=86=E6=AD=8C=E8=AF=8D?= =?UTF-8?q?=E5=B5=8C=E5=85=A5=E9=9F=B3=E9=A2=91=E6=96=87=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/defaultSetting.js | 3 +- src/main/index.js | 2 +- src/main/utils/flacMeta.js | 1 + src/main/utils/mp3Meta.js | 25 ++++++++++---- src/renderer/lang/en-us/view/setting.json | 5 +-- src/renderer/lang/zh-cn/view/setting.json | 3 +- src/renderer/lang/zh-tw/view/setting.json | 3 +- src/renderer/store/modules/download.js | 38 +++++++++++++--------- src/renderer/utils/music/kw/musicSearch.js | 2 +- src/renderer/views/Setting.vue | 11 ++++--- 10 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/common/defaultSetting.js b/src/common/defaultSetting.js index 237ca595..7cebd120 100644 --- a/src/common/defaultSetting.js +++ b/src/common/defaultSetting.js @@ -3,7 +3,7 @@ const os = require('os') const { isMac } = require('./utils') const defaultSetting = { - version: '1.0.33', + version: '1.0.34', player: { togglePlayMethod: 'listLoop', highQuality: false, @@ -41,6 +41,7 @@ const defaultSetting = { maxDownloadNum: 3, isDownloadLrc: false, isEmbedPic: true, + isEmbedLyric: true, }, leaderboard: { source: 'kw', diff --git a/src/main/index.js b/src/main/index.js index 20eb0d0c..40c30ae2 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -112,7 +112,7 @@ function createWindow() { global.modules.mainWindow.loadURL(winURL) winEvent(global.modules.mainWindow) - // mainWindow.webContents.openDevTools() + // global.modules.mainWindow.webContents.openDevTools() if (!isDev) autoUpdate() } diff --git a/src/main/utils/flacMeta.js b/src/main/utils/flacMeta.js index ab9a18ba..c82e5360 100644 --- a/src/main/utils/flacMeta.js +++ b/src/main/utils/flacMeta.js @@ -10,6 +10,7 @@ const extReg = /^(\.(?:jpe?g|png)).*$/ const vendor = 'reference libFLAC 1.2.1 20070917' const writeMeta = async(filePath, meta, picPath) => { + if (meta.lyric) delete meta.lyric const comments = Object.keys(meta).map(key => `${key.toUpperCase()}=${meta[key] || ''}`) const data = { vorbis: { diff --git a/src/main/utils/mp3Meta.js b/src/main/utils/mp3Meta.js index 2405a49d..20824110 100644 --- a/src/main/utils/mp3Meta.js +++ b/src/main/utils/mp3Meta.js @@ -4,11 +4,22 @@ const fs = require('fs') const request = require('request') const extReg = /^(\.(?:jpe?g|png)).*$/ +const handleWriteMeta = (meta, filePath) => { + if (meta.lyric) { + meta.unsynchronisedLyrics = { + language: 'zho', + text: meta.lyric, + } + delete meta.lyric + } + NodeID3.write(meta, filePath) +} + module.exports = (filePath, meta) => { - if (!meta.APIC) return NodeID3.write(meta, filePath) + if (!meta.APIC) return handleWriteMeta(meta, filePath) if (!/^http/.test(meta.APIC)) { delete meta.APIC - return NodeID3.write(meta, filePath) + return handleWriteMeta(meta, filePath) } let ext = path.extname(meta.APIC) let picPath = filePath.replace(/\.mp3$/, '') + (ext ? ext.replace(extReg, '$1') : '.jpg') @@ -16,7 +27,7 @@ module.exports = (filePath, meta) => { .on('response', respones => { if (respones.statusCode !== 200 && respones.statusCode != 206) { delete meta.APIC - NodeID3.write(meta, filePath) + handleWriteMeta(meta, filePath) return } respones @@ -24,10 +35,10 @@ module.exports = (filePath, meta) => { .on('finish', () => { if (respones.complete) { meta.APIC = picPath - NodeID3.write(meta, filePath) + handleWriteMeta(meta, filePath) } else { delete meta.APIC - NodeID3.write(meta, filePath) + handleWriteMeta(meta, filePath) } fs.unlink(picPath, err => { if (err) console.log(err.message) @@ -35,12 +46,12 @@ module.exports = (filePath, meta) => { }).on('error', err => { if (err) console.log(err.message) delete meta.APIC - NodeID3.write(meta, filePath) + handleWriteMeta(meta, filePath) }) }) .on('error', err => { if (err) console.log(err.message) delete meta.APIC - NodeID3.write(meta, filePath) + handleWriteMeta(meta, filePath) }) } diff --git a/src/renderer/lang/en-us/view/setting.json b/src/renderer/lang/en-us/view/setting.json index c4d20294..b1472bd8 100644 --- a/src/renderer/lang/en-us/view/setting.json +++ b/src/renderer/lang/en-us/view/setting.json @@ -72,8 +72,9 @@ "download_path_change_btn": "Change", "download_name_title": "Select the music naming method for downloading", "download_name": "Music file naming", - "download_embed_pic_title": "Select whether to embed the cover into the music file", - "download_embed_pic": "Embedding cover (supports MP3 format only)", + "download_data_embed": "Whether to embed the following content in the audio file", + "download_embed_pic": "Embedding cover", + "download_embed_lyric": "Embedding lyric (supports MP3 format only)", "download_lyric_title": "Select whether to download the lyrics file", "download_lyric": "Lyrics download", "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 2cffa0ac..a45cba65 100644 --- a/src/renderer/lang/zh-cn/view/setting.json +++ b/src/renderer/lang/zh-cn/view/setting.json @@ -72,8 +72,9 @@ "download_path_change_btn": "更改", "download_name_title": "下载歌曲时的命名方式", "download_name": "文件命名方式", - "download_embed_pic_title": "是否将封面嵌入音频文件中", + "download_data_embed": "是否将以下内容嵌入到音频文件中", "download_embed_pic": "封面嵌入", + "download_embed_lyric": "歌词嵌入(只支持 mp3 格式)", "download_lyric_title": "是否同时下载歌词文件", "download_lyric": "歌词下载", "download_name1": "歌名 - 歌手", diff --git a/src/renderer/lang/zh-tw/view/setting.json b/src/renderer/lang/zh-tw/view/setting.json index a8fccff4..79e3cb28 100644 --- a/src/renderer/lang/zh-tw/view/setting.json +++ b/src/renderer/lang/zh-tw/view/setting.json @@ -67,8 +67,9 @@ "download_path_change_btn": "更改", "download_name_title": "下載歌曲時的命名方式", "download_name": "文件命名方式", - "download_embed_pic_title": "是否將封面嵌入音頻文件中", + "download_data_embed": "是否將以下內容嵌入到音頻文件中", "download_embed_pic": "封面嵌入", + "download_embed_lyric": "歌詞嵌入(只支持 mp3 格式)", "download_lyric_title": "是否同時下載歌詞文件", "download_lyric": "歌詞下載", "download_name1": "歌名 - 歌手", diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index de8695eb..b555e65b 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -164,25 +164,33 @@ const getUrl = (downloadInfo, isRefresh) => { * @param {*} filePath * @param {*} isEmbedPic // 是否嵌入图片 */ -const saveMeta = (downloadInfo, filePath, isEmbedPic) => { +const saveMeta = (downloadInfo, filePath, isEmbedPic, isEmbedLyric) => { if (downloadInfo.type === 'ape') return - const promise = isEmbedPic - ? downloadInfo.musicInfo.img - ? Promise.resolve(downloadInfo.musicInfo.img) - : music[downloadInfo.musicInfo.source].getPic(downloadInfo.musicInfo).promise - : Promise.resolve() - promise.then(url => { - setMeta(filePath, { - title: downloadInfo.musicInfo.name, - artist: downloadInfo.musicInfo.singer, - album: downloadInfo.musicInfo.albumName, - APIC: url, - }) - }).catch(() => { + const tasks = [ + isEmbedPic + ? downloadInfo.musicInfo.img + ? Promise.resolve(downloadInfo.musicInfo.img) + : music[downloadInfo.musicInfo.source].getPic(downloadInfo.musicInfo).promise.catch(err => { + console.log(err) + return null + }) + : Promise.resolve(), + isEmbedLyric + ? downloadInfo.musicInfo.lrc + ? Promise.resolve(downloadInfo.musicInfo.lrc) + : music[downloadInfo.musicInfo.source].getLyric(downloadInfo.musicInfo).promise.catch(err => { + console.log(err) + return null + }) + : Promise.resolve(), + ] + Promise.all(tasks).then(([imgUrl, lyric]) => { setMeta(filePath, { title: downloadInfo.musicInfo.name, artist: downloadInfo.musicInfo.singer, album: downloadInfo.musicInfo.albumName, + APIC: imgUrl, + lyric, }) }) } @@ -311,7 +319,7 @@ const actions = { commit('onCompleted', downloadInfo) dispatch('startTask') - saveMeta(downloadInfo, downloadInfo.filePath, rootState.setting.download.isEmbedPic) + saveMeta(downloadInfo, downloadInfo.filePath, rootState.setting.download.isEmbedPic, rootState.setting.download.isEmbedLyric) if (rootState.setting.download.isDownloadLrc) downloadLyric(downloadInfo, downloadInfo.filePath) console.log('on complate') }, diff --git a/src/renderer/utils/music/kw/musicSearch.js b/src/renderer/utils/music/kw/musicSearch.js index 1e9ab75b..cc689cc6 100644 --- a/src/renderer/utils/music/kw/musicSearch.js +++ b/src/renderer/utils/music/kw/musicSearch.js @@ -113,7 +113,7 @@ export default { albumId: decodeName(info.ALBUMID || ''), interval: Number.isNaN(interval) ? 0 : formatPlayTime(interval), albumName: info.ALBUM ? decodeName(info.ALBUM) : '', - lyric: null, + lrc: null, img: null, types, _types, diff --git a/src/renderer/views/Setting.vue b/src/renderer/views/Setting.vue index 630952b5..8b561f20 100644 --- a/src/renderer/views/Setting.vue +++ b/src/renderer/views/Setting.vue @@ -125,10 +125,12 @@ div.scroll(:class="$style.setting") div material-checkbox(:id="`setting_download_musicName_${item.value}`" :class="$style.gapLeft" name="setting_download_musicName" :value="item.value" :key="item.value" need v-model="current_setting.download.fileName" v-for="item in musicNames" :label="item.name") - dd(:title="$t('view.setting.download_embed_pic_title')") - h3 {{$t('view.setting.download_embed_pic')}} - div - material-checkbox(id="setting_download_isEmbedPic" v-model="current_setting.download.isEmbedPic" :label="$t('view.setting.is_enable')") + dd + h3 {{$t('view.setting.download_data_embed')}} + div(:class="$style.gapTop") + material-checkbox(id="setting_download_isEmbedPic" v-model="current_setting.download.isEmbedPic" :label="$t('view.setting.download_embed_pic')") + div(:class="$style.gapTop") + material-checkbox(id="setting_download_isEmbedLyric" v-model="current_setting.download.isEmbedLyric" :label="$t('view.setting.download_embed_lyric')") dd(:title="$t('view.setting.download_lyric_title')") h3 {{$t('view.setting.download_lyric')}} div @@ -421,6 +423,7 @@ export default { fileName: '歌名 - 歌手', isDownloadLrc: false, isEmbedPic: true, + isEmbedLyric: true, }, network: { proxy: {