添加修改MP3的artist和title功能
parent
6feb8326e7
commit
6356c10e09
|
@ -65,6 +65,9 @@ _server.get("/api/store", async (req, res, query) => {
|
|||
let music_url = query.music_url;
|
||||
let lrc_content = query.lrc_content;
|
||||
let pic_url = query.pic_url;
|
||||
let title = query.title;
|
||||
let author = query.author;
|
||||
let extension = query.extension;
|
||||
let store_music = parseInt(query.store_music);
|
||||
let store_lrc = parseInt(query.store_lrc);
|
||||
let store_pic = parseInt(query.store_pic);
|
||||
|
@ -72,7 +75,7 @@ _server.get("/api/store", async (req, res, query) => {
|
|||
let pic_extension = pic_url.split('?')[0].split('.').pop();
|
||||
let result = '';
|
||||
if(store_music) {
|
||||
await storeMusic(music_path, music_url);
|
||||
await storeMusic(music_path, music_url, {title, author, extension});
|
||||
result += '保存歌曲成功! ';
|
||||
}
|
||||
if(store_lrc) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const fs = require('fs');
|
||||
const request = require('request');
|
||||
const _path = require("path");
|
||||
//var ffmetadata = require("ffmetadata");
|
||||
const { exec } = require('child_process');
|
||||
|
||||
//递归创建目录 同步方法
|
||||
function mkdirsSync(dirname) {
|
||||
|
@ -26,8 +28,45 @@ function storeResource(path, url) {
|
|||
});
|
||||
}
|
||||
|
||||
async function storeMusic(path, url) {
|
||||
return await storeResource(path, url);
|
||||
async function storeMusic(path, url, info) {
|
||||
await storeResource(path, url);
|
||||
if(info.extension == 'mp3') {
|
||||
await modifyMP3Info2(path, info);
|
||||
}
|
||||
}
|
||||
|
||||
// async function modifyMP3Info(path, info) {
|
||||
// path = handlePath(path);
|
||||
// // Read song.mp3 metadata
|
||||
// ffmetadata.read(path, function(err, data) {
|
||||
// if (err) console.error("Error reading metadata", err);
|
||||
// else console.log(data);
|
||||
// });
|
||||
|
||||
// // Set the artist for song.mp3
|
||||
// var data = {
|
||||
// title: info.title,
|
||||
// artist: info.author
|
||||
// };
|
||||
// ffmetadata.write(path, data, function(err) {
|
||||
// if (err) console.error("Error writing metadata", err);
|
||||
// else console.log("Data written");
|
||||
// });
|
||||
// }
|
||||
|
||||
async function modifyMP3Info2(path, info) {
|
||||
path = handlePath(path);
|
||||
// 要执行的命令行指令
|
||||
const command = `mp3info -a ${info.author} -t ${info.title} ${path}`;
|
||||
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`修改mp3文件信息时发生错误:${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`修改mp3文件信息:\n${stdout}`);
|
||||
});
|
||||
}
|
||||
|
||||
function storeLrc(path, content) {
|
||||
|
@ -50,7 +89,9 @@ function checkMusicExists(path) {
|
|||
function handlePath(path) {
|
||||
// 必须保存到downloads目录,过滤关键字符防止目录穿越
|
||||
if(path.indexOf('/downloads/') != 0) path = '/downloads/' + path;
|
||||
return path.replace('..', '').replace(/\.+/g, '.').replace(/\/+/g, '/').replace(/\\+/g, '\\');
|
||||
path = path.replace('..', '').replace(/\.+/g, '.').replace(/\/+/g, '/').replace(/\\+/g, '\\');
|
||||
if(process.cwd()[0] != '/') path = process.cwd()[0] + ':' + path; // 兼容windows盘符
|
||||
return path;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -276,7 +276,10 @@
|
|||
pic_url: this.current_item.pic,
|
||||
store_music: this.is_store_music + 0,
|
||||
store_lrc: this.is_store_lrc + 0,
|
||||
store_pic: this.is_store_pic + 0
|
||||
store_pic: this.is_store_pic + 0,
|
||||
title: this.current_item.title,
|
||||
author: this.current_item.author,
|
||||
extension: this.current_item.extension,
|
||||
}).then(response => {
|
||||
this.store_message = response.data.message;
|
||||
this.$Message.success(response.data.message);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"ffmetadata": "^1.7.0",
|
||||
"request": "^2.88.2"
|
||||
}
|
||||
},
|
||||
|
@ -57,6 +58,14 @@
|
|||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz",
|
||||
"integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg=="
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz",
|
||||
"integrity": "sha512-Pj9L87dCdGcKlSqPVUjD+q96pbIx1zQQLb2CUiWURfjiBELv84YX+0nGnKmyT/9KkC7PQk7UN1w+Al8bBozaxQ==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/bcrypt-pbkdf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||
|
@ -65,6 +74,15 @@
|
|||
"tweetnacl": "^0.14.3"
|
||||
}
|
||||
},
|
||||
"node_modules/bops": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/bops/-/bops-0.0.6.tgz",
|
||||
"integrity": "sha512-EWD8/Ei9o/h/wmR3w/YL/8dGKe4rSFHlaO8VNNcuXnjXjeTgxdcmhjPf9hRCYlqTrBPZbKaht+FxZKahcob5UQ==",
|
||||
"dependencies": {
|
||||
"base64-js": "0.0.2",
|
||||
"to-utf8": "0.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/caseless": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
|
||||
|
@ -81,6 +99,17 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-stream": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.0.1.tgz",
|
||||
"integrity": "sha512-nAHFsgeRVVvZ+aB3S1gLeN73fQ+tdOcw075BHbXMbC6MY0h6nqAkEeqPVCw8kRuDJJZDvaUjxI4jZv2FD0Tl8A==",
|
||||
"engines": [
|
||||
"node >= 0.8.0"
|
||||
],
|
||||
"dependencies": {
|
||||
"bops": "0.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/core-util-is": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
|
@ -105,6 +134,11 @@
|
|||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/duplexer": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.0.4.tgz",
|
||||
"integrity": "sha512-nO0WWuIDTde3CWK/8IPpG50dyhUilgpsqzYSIP+w20Yh+4iDgb/2Gs75QItcp0Hmx/JtxtTXBalj+LSTD1VemA=="
|
||||
},
|
||||
"node_modules/ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
|
@ -137,6 +171,18 @@
|
|||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
|
||||
},
|
||||
"node_modules/ffmetadata": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/ffmetadata/-/ffmetadata-1.7.0.tgz",
|
||||
"integrity": "sha512-9qiv40lskKAz63qJKemVxmfH3Xkp3TuXK7teQOxh69kSJDxkBu1Mzr93bSKL9fyqqZ4uo6hnZfCHb/40AEF8+A==",
|
||||
"dependencies": {
|
||||
"concat-stream": "~1.0.0",
|
||||
"split": "~0.2.6",
|
||||
"stream-combiner": "0.0.2",
|
||||
"stream-filter": "1",
|
||||
"through": "~2.3.4"
|
||||
}
|
||||
},
|
||||
"node_modules/forever-agent": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||
|
@ -353,6 +399,17 @@
|
|||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"node_modules/split": {
|
||||
"version": "0.2.10",
|
||||
"resolved": "https://registry.npmjs.org/split/-/split-0.2.10.tgz",
|
||||
"integrity": "sha512-e0pKq+UUH2Xq/sXbYpZBZc3BawsfDZ7dgv+JtRTUPNcvF5CMR4Y9cvJqkMY0MoxWzTHvZuz1beg6pNEKlszPiQ==",
|
||||
"dependencies": {
|
||||
"through": "2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/sshpk": {
|
||||
"version": "1.17.0",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz",
|
||||
|
@ -377,6 +434,32 @@
|
|||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/stream-combiner": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.2.tgz",
|
||||
"integrity": "sha512-Z2D5hPQapscuHNqiyUgjnF1sxG/9CB7gs1a9vcS2/OvMiFwmm6EZw9IjbU34l5mPXS62RidpoBdyB83E0GXHLw==",
|
||||
"dependencies": {
|
||||
"duplexer": "~0.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/stream-filter": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/stream-filter/-/stream-filter-1.0.0.tgz",
|
||||
"integrity": "sha512-FnB+RV/hfX5nU758FY1ImWwmbHRCiqTdZHMlLfnEz/rR8S1HPvt7LzcZh/poqVBvn3cgoiUTmsAipb8oN+EbFA==",
|
||||
"dependencies": {
|
||||
"through": "~2"
|
||||
}
|
||||
},
|
||||
"node_modules/through": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
|
||||
"integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg=="
|
||||
},
|
||||
"node_modules/to-utf8": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/to-utf8/-/to-utf8-0.0.1.tgz",
|
||||
"integrity": "sha512-zks18/TWT1iHO3v0vFp5qLKOG27m67ycq/Y7a7cTiRuUNlc4gf3HGnkRgMv0NyhnfTamtkYBJl+YeD1/j07gBQ=="
|
||||
},
|
||||
"node_modules/tough-cookie": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
|
||||
|
@ -476,6 +559,11 @@
|
|||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz",
|
||||
"integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg=="
|
||||
},
|
||||
"base64-js": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz",
|
||||
"integrity": "sha512-Pj9L87dCdGcKlSqPVUjD+q96pbIx1zQQLb2CUiWURfjiBELv84YX+0nGnKmyT/9KkC7PQk7UN1w+Al8bBozaxQ=="
|
||||
},
|
||||
"bcrypt-pbkdf": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||
|
@ -484,6 +572,15 @@
|
|||
"tweetnacl": "^0.14.3"
|
||||
}
|
||||
},
|
||||
"bops": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/bops/-/bops-0.0.6.tgz",
|
||||
"integrity": "sha512-EWD8/Ei9o/h/wmR3w/YL/8dGKe4rSFHlaO8VNNcuXnjXjeTgxdcmhjPf9hRCYlqTrBPZbKaht+FxZKahcob5UQ==",
|
||||
"requires": {
|
||||
"base64-js": "0.0.2",
|
||||
"to-utf8": "0.0.1"
|
||||
}
|
||||
},
|
||||
"caseless": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
|
||||
|
@ -497,6 +594,14 @@
|
|||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"concat-stream": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.0.1.tgz",
|
||||
"integrity": "sha512-nAHFsgeRVVvZ+aB3S1gLeN73fQ+tdOcw075BHbXMbC6MY0h6nqAkEeqPVCw8kRuDJJZDvaUjxI4jZv2FD0Tl8A==",
|
||||
"requires": {
|
||||
"bops": "0.0.6"
|
||||
}
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||
|
@ -515,6 +620,11 @@
|
|||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
|
||||
},
|
||||
"duplexer": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.0.4.tgz",
|
||||
"integrity": "sha512-nO0WWuIDTde3CWK/8IPpG50dyhUilgpsqzYSIP+w20Yh+4iDgb/2Gs75QItcp0Hmx/JtxtTXBalj+LSTD1VemA=="
|
||||
},
|
||||
"ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
|
@ -544,6 +654,18 @@
|
|||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
|
||||
},
|
||||
"ffmetadata": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/ffmetadata/-/ffmetadata-1.7.0.tgz",
|
||||
"integrity": "sha512-9qiv40lskKAz63qJKemVxmfH3Xkp3TuXK7teQOxh69kSJDxkBu1Mzr93bSKL9fyqqZ4uo6hnZfCHb/40AEF8+A==",
|
||||
"requires": {
|
||||
"concat-stream": "~1.0.0",
|
||||
"split": "~0.2.6",
|
||||
"stream-combiner": "0.0.2",
|
||||
"stream-filter": "1",
|
||||
"through": "~2.3.4"
|
||||
}
|
||||
},
|
||||
"forever-agent": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||
|
@ -707,6 +829,14 @@
|
|||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"split": {
|
||||
"version": "0.2.10",
|
||||
"resolved": "https://registry.npmjs.org/split/-/split-0.2.10.tgz",
|
||||
"integrity": "sha512-e0pKq+UUH2Xq/sXbYpZBZc3BawsfDZ7dgv+JtRTUPNcvF5CMR4Y9cvJqkMY0MoxWzTHvZuz1beg6pNEKlszPiQ==",
|
||||
"requires": {
|
||||
"through": "2"
|
||||
}
|
||||
},
|
||||
"sshpk": {
|
||||
"version": "1.17.0",
|
||||
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz",
|
||||
|
@ -723,6 +853,32 @@
|
|||
"tweetnacl": "~0.14.0"
|
||||
}
|
||||
},
|
||||
"stream-combiner": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.2.tgz",
|
||||
"integrity": "sha512-Z2D5hPQapscuHNqiyUgjnF1sxG/9CB7gs1a9vcS2/OvMiFwmm6EZw9IjbU34l5mPXS62RidpoBdyB83E0GXHLw==",
|
||||
"requires": {
|
||||
"duplexer": "~0.0.3"
|
||||
}
|
||||
},
|
||||
"stream-filter": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/stream-filter/-/stream-filter-1.0.0.tgz",
|
||||
"integrity": "sha512-FnB+RV/hfX5nU758FY1ImWwmbHRCiqTdZHMlLfnEz/rR8S1HPvt7LzcZh/poqVBvn3cgoiUTmsAipb8oN+EbFA==",
|
||||
"requires": {
|
||||
"through": "~2"
|
||||
}
|
||||
},
|
||||
"through": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
|
||||
"integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg=="
|
||||
},
|
||||
"to-utf8": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/to-utf8/-/to-utf8-0.0.1.tgz",
|
||||
"integrity": "sha512-zks18/TWT1iHO3v0vFp5qLKOG27m67ycq/Y7a7cTiRuUNlc4gf3HGnkRgMv0NyhnfTamtkYBJl+YeD1/j07gBQ=="
|
||||
},
|
||||
"tough-cookie": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 安装工具
|
||||
apt update
|
||||
apt install mp3info
|
||||
|
||||
# 下载依赖包
|
||||
cd /music-downloader
|
||||
npm install
|
||||
|
|
Loading…
Reference in New Issue