新增将歌词嵌入音频文件中

pull/277/head
lyswhut 2020-07-02 12:03:18 +08:00
parent d94d880569
commit 3b25e0a112
10 changed files with 60 additions and 33 deletions

View File

@ -3,7 +3,7 @@ const os = require('os')
const { isMac } = require('./utils') const { isMac } = require('./utils')
const defaultSetting = { const defaultSetting = {
version: '1.0.33', version: '1.0.34',
player: { player: {
togglePlayMethod: 'listLoop', togglePlayMethod: 'listLoop',
highQuality: false, highQuality: false,
@ -41,6 +41,7 @@ const defaultSetting = {
maxDownloadNum: 3, maxDownloadNum: 3,
isDownloadLrc: false, isDownloadLrc: false,
isEmbedPic: true, isEmbedPic: true,
isEmbedLyric: true,
}, },
leaderboard: { leaderboard: {
source: 'kw', source: 'kw',

View File

@ -112,7 +112,7 @@ function createWindow() {
global.modules.mainWindow.loadURL(winURL) global.modules.mainWindow.loadURL(winURL)
winEvent(global.modules.mainWindow) winEvent(global.modules.mainWindow)
// mainWindow.webContents.openDevTools() // global.modules.mainWindow.webContents.openDevTools()
if (!isDev) autoUpdate() if (!isDev) autoUpdate()
} }

View File

@ -10,6 +10,7 @@ const extReg = /^(\.(?:jpe?g|png)).*$/
const vendor = 'reference libFLAC 1.2.1 20070917' const vendor = 'reference libFLAC 1.2.1 20070917'
const writeMeta = async(filePath, meta, picPath) => { const writeMeta = async(filePath, meta, picPath) => {
if (meta.lyric) delete meta.lyric
const comments = Object.keys(meta).map(key => `${key.toUpperCase()}=${meta[key] || ''}`) const comments = Object.keys(meta).map(key => `${key.toUpperCase()}=${meta[key] || ''}`)
const data = { const data = {
vorbis: { vorbis: {

View File

@ -4,11 +4,22 @@ const fs = require('fs')
const request = require('request') const request = require('request')
const extReg = /^(\.(?:jpe?g|png)).*$/ 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) => { module.exports = (filePath, meta) => {
if (!meta.APIC) return NodeID3.write(meta, filePath) if (!meta.APIC) return handleWriteMeta(meta, filePath)
if (!/^http/.test(meta.APIC)) { if (!/^http/.test(meta.APIC)) {
delete meta.APIC delete meta.APIC
return NodeID3.write(meta, filePath) return handleWriteMeta(meta, filePath)
} }
let ext = path.extname(meta.APIC) let ext = path.extname(meta.APIC)
let picPath = filePath.replace(/\.mp3$/, '') + (ext ? ext.replace(extReg, '$1') : '.jpg') let picPath = filePath.replace(/\.mp3$/, '') + (ext ? ext.replace(extReg, '$1') : '.jpg')
@ -16,7 +27,7 @@ module.exports = (filePath, meta) => {
.on('response', respones => { .on('response', respones => {
if (respones.statusCode !== 200 && respones.statusCode != 206) { if (respones.statusCode !== 200 && respones.statusCode != 206) {
delete meta.APIC delete meta.APIC
NodeID3.write(meta, filePath) handleWriteMeta(meta, filePath)
return return
} }
respones respones
@ -24,10 +35,10 @@ module.exports = (filePath, meta) => {
.on('finish', () => { .on('finish', () => {
if (respones.complete) { if (respones.complete) {
meta.APIC = picPath meta.APIC = picPath
NodeID3.write(meta, filePath) handleWriteMeta(meta, filePath)
} else { } else {
delete meta.APIC delete meta.APIC
NodeID3.write(meta, filePath) handleWriteMeta(meta, filePath)
} }
fs.unlink(picPath, err => { fs.unlink(picPath, err => {
if (err) console.log(err.message) if (err) console.log(err.message)
@ -35,12 +46,12 @@ module.exports = (filePath, meta) => {
}).on('error', err => { }).on('error', err => {
if (err) console.log(err.message) if (err) console.log(err.message)
delete meta.APIC delete meta.APIC
NodeID3.write(meta, filePath) handleWriteMeta(meta, filePath)
}) })
}) })
.on('error', err => { .on('error', err => {
if (err) console.log(err.message) if (err) console.log(err.message)
delete meta.APIC delete meta.APIC
NodeID3.write(meta, filePath) handleWriteMeta(meta, filePath)
}) })
} }

View File

@ -72,8 +72,9 @@
"download_path_change_btn": "Change", "download_path_change_btn": "Change",
"download_name_title": "Select the music naming method for downloading", "download_name_title": "Select the music naming method for downloading",
"download_name": "Music file naming", "download_name": "Music file naming",
"download_embed_pic_title": "Select whether to embed the cover into the music file", "download_data_embed": "Whether to embed the following content in the audio file",
"download_embed_pic": "Embedding cover (supports MP3 format only)", "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_title": "Select whether to download the lyrics file",
"download_lyric": "Lyrics download", "download_lyric": "Lyrics download",
"download_name1": "Title - Artist", "download_name1": "Title - Artist",

View File

@ -72,8 +72,9 @@
"download_path_change_btn": "更改", "download_path_change_btn": "更改",
"download_name_title": "下载歌曲时的命名方式", "download_name_title": "下载歌曲时的命名方式",
"download_name": "文件命名方式", "download_name": "文件命名方式",
"download_embed_pic_title": "是否将封面嵌入音频文件中", "download_data_embed": "是否将以下内容嵌入到音频文件中",
"download_embed_pic": "封面嵌入", "download_embed_pic": "封面嵌入",
"download_embed_lyric": "歌词嵌入(只支持 mp3 格式)",
"download_lyric_title": "是否同时下载歌词文件", "download_lyric_title": "是否同时下载歌词文件",
"download_lyric": "歌词下载", "download_lyric": "歌词下载",
"download_name1": "歌名 - 歌手", "download_name1": "歌名 - 歌手",

View File

@ -67,8 +67,9 @@
"download_path_change_btn": "更改", "download_path_change_btn": "更改",
"download_name_title": "下載歌曲時的命名方式", "download_name_title": "下載歌曲時的命名方式",
"download_name": "文件命名方式", "download_name": "文件命名方式",
"download_embed_pic_title": "是否將封面嵌入音頻文件中", "download_data_embed": "是否將以下內容嵌入到音頻文件中",
"download_embed_pic": "封面嵌入", "download_embed_pic": "封面嵌入",
"download_embed_lyric": "歌詞嵌入(只支持 mp3 格式)",
"download_lyric_title": "是否同時下載歌詞文件", "download_lyric_title": "是否同時下載歌詞文件",
"download_lyric": "歌詞下載", "download_lyric": "歌詞下載",
"download_name1": "歌名 - 歌手", "download_name1": "歌名 - 歌手",

View File

@ -164,25 +164,33 @@ const getUrl = (downloadInfo, isRefresh) => {
* @param {*} filePath * @param {*} filePath
* @param {*} isEmbedPic // 是否嵌入图片 * @param {*} isEmbedPic // 是否嵌入图片
*/ */
const saveMeta = (downloadInfo, filePath, isEmbedPic) => { const saveMeta = (downloadInfo, filePath, isEmbedPic, isEmbedLyric) => {
if (downloadInfo.type === 'ape') return if (downloadInfo.type === 'ape') return
const promise = isEmbedPic const tasks = [
? downloadInfo.musicInfo.img isEmbedPic
? Promise.resolve(downloadInfo.musicInfo.img) ? downloadInfo.musicInfo.img
: music[downloadInfo.musicInfo.source].getPic(downloadInfo.musicInfo).promise ? Promise.resolve(downloadInfo.musicInfo.img)
: Promise.resolve() : music[downloadInfo.musicInfo.source].getPic(downloadInfo.musicInfo).promise.catch(err => {
promise.then(url => { console.log(err)
setMeta(filePath, { return null
title: downloadInfo.musicInfo.name, })
artist: downloadInfo.musicInfo.singer, : Promise.resolve(),
album: downloadInfo.musicInfo.albumName, isEmbedLyric
APIC: url, ? downloadInfo.musicInfo.lrc
}) ? Promise.resolve(downloadInfo.musicInfo.lrc)
}).catch(() => { : 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, { setMeta(filePath, {
title: downloadInfo.musicInfo.name, title: downloadInfo.musicInfo.name,
artist: downloadInfo.musicInfo.singer, artist: downloadInfo.musicInfo.singer,
album: downloadInfo.musicInfo.albumName, album: downloadInfo.musicInfo.albumName,
APIC: imgUrl,
lyric,
}) })
}) })
} }
@ -311,7 +319,7 @@ const actions = {
commit('onCompleted', downloadInfo) commit('onCompleted', downloadInfo)
dispatch('startTask') 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) if (rootState.setting.download.isDownloadLrc) downloadLyric(downloadInfo, downloadInfo.filePath)
console.log('on complate') console.log('on complate')
}, },

View File

@ -113,7 +113,7 @@ export default {
albumId: decodeName(info.ALBUMID || ''), albumId: decodeName(info.ALBUMID || ''),
interval: Number.isNaN(interval) ? 0 : formatPlayTime(interval), interval: Number.isNaN(interval) ? 0 : formatPlayTime(interval),
albumName: info.ALBUM ? decodeName(info.ALBUM) : '', albumName: info.ALBUM ? decodeName(info.ALBUM) : '',
lyric: null, lrc: null,
img: null, img: null,
types, types,
_types, _types,

View File

@ -125,10 +125,12 @@ div.scroll(:class="$style.setting")
div div
material-checkbox(:id="`setting_download_musicName_${item.value}`" :class="$style.gapLeft" name="setting_download_musicName" :value="item.value" :key="item.value" need 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") v-model="current_setting.download.fileName" v-for="item in musicNames" :label="item.name")
dd(:title="$t('view.setting.download_embed_pic_title')") dd
h3 {{$t('view.setting.download_embed_pic')}} h3 {{$t('view.setting.download_data_embed')}}
div div(:class="$style.gapTop")
material-checkbox(id="setting_download_isEmbedPic" v-model="current_setting.download.isEmbedPic" :label="$t('view.setting.is_enable')") 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')") dd(:title="$t('view.setting.download_lyric_title')")
h3 {{$t('view.setting.download_lyric')}} h3 {{$t('view.setting.download_lyric')}}
div div
@ -421,6 +423,7 @@ export default {
fileName: '歌名 - 歌手', fileName: '歌名 - 歌手',
isDownloadLrc: false, isDownloadLrc: false,
isEmbedPic: true, isEmbedPic: true,
isEmbedLyric: true,
}, },
network: { network: {
proxy: { proxy: {