From 0c0299d63a34f7b3253c2e89863946127b87f31c Mon Sep 17 00:00:00 2001 From: MengYX Date: Thu, 6 Feb 2020 16:18:40 +0800 Subject: [PATCH] Remove Useless Information --- src/App.vue | 2 +- src/component/util.js | 4 +--- src/decrypt/mflac.js | 9 +++------ src/decrypt/ncm.js | 5 +---- src/decrypt/qmc.js | 13 +++++-------- src/decrypt/raw.js | 17 +++++------------ src/decrypt/util.js | 7 +++---- 7 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/App.vue b/src/App.vue index 743a4f5..017d0aa 100644 --- a/src/App.vue +++ b/src/App.vue @@ -98,7 +98,7 @@ let _rp_data = [data.title, data.artist, data.album]; window._paq.push(["trackEvent", "Unlock", data.rawExt + "," + data.mime, JSON.stringify(_rp_data)]); } else { - this.showFail(data.message, data.rawFilename) + this.showFail(data.message, data.rawFilename + "." + data.rawExt) } }, showFail(errInfo, filename) { diff --git a/src/component/util.js b/src/component/util.js index dcc671b..c0202f3 100644 --- a/src/component/util.js +++ b/src/component/util.js @@ -5,15 +5,13 @@ export function DownloadBlobMusic(data, format) { case "1": a.download = data.title + "." + data.ext; break; + default: case "2": a.download = data.artist + " - " + data.title + "." + data.ext; break; case "3": a.download = data.title + " - " + data.artist + "." + data.ext; break; - default: - a.download = data.filename; - break; } document.body.append(a); a.click(); diff --git a/src/decrypt/mflac.js b/src/decrypt/mflac.js index ec27afa..585b97e 100644 --- a/src/decrypt/mflac.js +++ b/src/decrypt/mflac.js @@ -25,22 +25,19 @@ async function Decrypt(file, raw_filename, raw_ext) { } // 导出 const musicData = new Blob([audioData], {type: "audio/flac"}); - const musicUrl = URL.createObjectURL(musicData); // 读取Meta let tag = await musicMetadata.parseBlob(musicData); - const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename, "flac"); - let picUrl = util.GetCoverURL(tag); + const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename); // 返回 return { status: true, - filename: info.filename, title: info.title, artist: info.artist, ext: 'flac', album: tag.common.album, - picture: picUrl, - file: musicUrl, + picture: util.GetCoverURL(tag), + file: URL.createObjectURL(musicData), mime: "audio/flac" } } diff --git a/src/decrypt/ncm.js b/src/decrypt/ncm.js index 5778629..49fa0cb 100644 --- a/src/decrypt/ncm.js +++ b/src/decrypt/ncm.js @@ -49,17 +49,14 @@ async function Decrypt(file) { } const musicData = new Blob([audioData], {type: mime}); - const musicUrl = URL.createObjectURL(musicData); - const filename = artists.join(" & ") + " - " + musicMeta.musicName + "." + musicMeta.format; return { status: true, - filename: filename, title: musicMeta.musicName, artist: artists.join(" & "), ext: musicMeta.format, album: musicMeta.album, picture: musicMeta.albumPic, - file: musicUrl, + file: URL.createObjectURL(musicData), mime: mime }; } diff --git a/src/decrypt/qmc.js b/src/decrypt/qmc.js index 748d069..0a19b86 100644 --- a/src/decrypt/qmc.js +++ b/src/decrypt/qmc.js @@ -26,7 +26,7 @@ async function Decrypt(file, raw_filename, raw_ext) { if (!(raw_ext in OriginalExtMap)) { return {status: false, message: "File type is incorrect!"} } - let new_ext = OriginalExtMap[raw_ext]; + const new_ext = OriginalExtMap[raw_ext]; const mime = util.AudioMimeType[new_ext]; // 读取文件 const fileBuffer = await util.GetArrayBuffer(file); @@ -38,22 +38,19 @@ async function Decrypt(file, raw_filename, raw_ext) { } // 导出 const musicData = new Blob([audioData], {type: mime}); - const musicUrl = URL.createObjectURL(musicData); // 读取Meta - let tag = await musicMetadata.parseBlob(musicData); - const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename, new_ext); - let picUrl = util.GetCoverURL(tag); + const tag = await musicMetadata.parseBlob(musicData); + const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename); // 返回 return { status: true, - filename: info.filename, title: info.title, artist: info.artist, ext: new_ext, album: tag.common.album, - picture: picUrl, - file: musicUrl, + picture: util.GetCoverURL(tag), + file: URL.createObjectURL(musicData), mime: mime } } diff --git a/src/decrypt/raw.js b/src/decrypt/raw.js index c957f60..a04cd5e 100644 --- a/src/decrypt/raw.js +++ b/src/decrypt/raw.js @@ -4,23 +4,16 @@ export {Decrypt} async function Decrypt(file, raw_filename, raw_ext) { - let tag = await musicMetadata.parseBlob(file); - - let fileUrl = URL.createObjectURL(file); - - const picUrl = util.GetCoverURL(tag); - const mime = util.AudioMimeType[raw_ext]; - const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename, raw_ext); - + const tag = await musicMetadata.parseBlob(file); + const info = util.GetFileInfo(tag.common.artist, tag.common.title, raw_filename); return { status: true, - filename: info.filename, title: info.title, artist: info.artist, ext: raw_ext, album: tag.common.album, - picture: picUrl, - file: fileUrl, - mime: mime + picture: util.GetCoverURL(tag), + file: URL.createObjectURL(file), + mime: util.AudioMimeType[raw_ext] } } diff --git a/src/decrypt/util.js b/src/decrypt/util.js index a00f42a..9f00b58 100644 --- a/src/decrypt/util.js +++ b/src/decrypt/util.js @@ -18,7 +18,7 @@ const AudioMimeType = { ogg: "audio/ogg" }; -function GetFileInfo(artist, title, filenameNoExt, ext) { +function GetFileInfo(artist, title, filenameNoExt) { let newArtist = "", newTitle = ""; let filenameArray = filenameNoExt.split("-"); if (filenameArray.length > 1) { @@ -34,8 +34,7 @@ function GetFileInfo(artist, title, filenameNoExt, ext) { if (typeof title == "string" && title !== "") { newTitle = title; } - let newFilename = newArtist + " - " + newTitle + "." + ext; - return {artist: newArtist, title: newTitle, filename: newFilename}; + return {artist: newArtist, title: newTitle}; } /** @@ -48,4 +47,4 @@ function GetCoverURL(metadata) { pic_url = URL.createObjectURL(pic); } return pic_url; -} \ No newline at end of file +}