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

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 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',

View File

@ -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()
}

View File

@ -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: {

View File

@ -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)
})
}

View File

@ -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",

View File

@ -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": "歌名 - 歌手",

View File

@ -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": "歌名 - 歌手",

View File

@ -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
const tasks = [
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,
: music[downloadInfo.musicInfo.source].getPic(downloadInfo.musicInfo).promise.catch(err => {
console.log(err)
return null
})
}).catch(() => {
: 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')
},

View File

@ -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,

View File

@ -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: {