歌曲无封面时下载报错的问题
This commit is contained in:
@@ -6,6 +6,10 @@ const extReg = /^(\.(?:jpe?g|png)).*$/
|
||||
|
||||
module.exports = (filePath, meta) => {
|
||||
if (!meta.APIC) return NodeID3.write(meta, filePath)
|
||||
if (!/^http/.test(meta.APIC)) {
|
||||
delete meta.APIC
|
||||
return NodeID3.write(meta, filePath)
|
||||
}
|
||||
let picPath = filePath.replace(/\.mp3$/, '') + path.extname(meta.APIC).replace(extReg, '$1')
|
||||
request(meta.APIC)
|
||||
.on('response', respones => {
|
||||
@@ -17,8 +21,12 @@ module.exports = (filePath, meta) => {
|
||||
respones
|
||||
.pipe(fs.createWriteStream(picPath))
|
||||
.on('finish', () => {
|
||||
meta.APIC = picPath
|
||||
NodeID3.write(meta, filePath)
|
||||
if (respones.complete) {
|
||||
meta.APIC = picPath
|
||||
NodeID3.write(meta, filePath)
|
||||
} else {
|
||||
delete meta.APIC
|
||||
}
|
||||
fs.unlink(picPath, err => {
|
||||
if (err) console.log(err.message)
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ import { httpFetch } from '../../request'
|
||||
export default {
|
||||
getPic({ songmid }) {
|
||||
const requestObj = httpFetch(`http://artistpicserver.kuwo.cn/pic.web?corp=kuwo&type=rid_pic&pictype=500&size=500&rid=${songmid}`)
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => body)
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => /^http/.test(body) ? body : null)
|
||||
return requestObj
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user