From 67af823cde54d48d534509337d8982b591a818a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Tue, 15 Nov 2022 14:03:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=97=E5=B9=95=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E4=BB=A3=E7=A0=81=EF=BC=88lyric=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lyric/.gitignore | 4 ++ lyric/index.js | 64 ++++++++++++++++++++++++++++++ netease_music/src/index.js | 3 +- package-lock.json | 81 ++++++++++++++++++++++++++++++++++++++ package.json | 8 ++-- 5 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 lyric/.gitignore create mode 100644 lyric/index.js diff --git a/lyric/.gitignore b/lyric/.gitignore new file mode 100644 index 0000000..751b367 --- /dev/null +++ b/lyric/.gitignore @@ -0,0 +1,4 @@ +*.lrc +*.m4a +*.mp3 +*.flac \ No newline at end of file diff --git a/lyric/index.js b/lyric/index.js new file mode 100644 index 0000000..c2434da --- /dev/null +++ b/lyric/index.js @@ -0,0 +1,64 @@ + + + + + + + +const fs = require('fs'); +const path = require('path'); +const iconv = require('iconv-lite');//安装第三方库转换编码格式 +const readline = require('readline'); +const chalk = require('chalk') + +// var filename = path.join(__dirname, './../lyrics/晴天.lrc'); +var filename = path.join(__dirname, './lyric.lrc'); +var streamReader = fs.createReadStream(filename).pipe(iconv.decodeStream('utf8')) // gbk + +console.clear(); +playMusic(); +setTimeout(main, 2600); // 音频加载时间 +function main() { + // 利用readline读取 + var rl = readline.createInterface({ input: streamReader }); + var begin = new Date().getTime(); + rl.on('line', (line) => { + task(line, begin); + }); +} + +var displayLyric = [], index = 0; +var regex = /\[(\d{2})\:(\d{2})\.(\d{2,3})\][ ]*(.+)[ ]*/; +function task(line, begin) { + var matches = regex.exec(line); + if (matches) { + var m = parseFloat(matches[1]); + var s = parseFloat(matches[2]); + var f = parseFloat(matches[3]); + var lyric = matches[4]; + displayLyric.push(lyric); + var offset = new Date().getTime() - begin; + setTimeout(() => { + console.clear(); + console.log(chalk.dim(displayLyric[index - 2] || "")); + console.log(chalk.hex('#b3b3b3').visible(displayLyric[index - 1] || "")); + console.log(chalk.hex('#FFFFFF').bold(displayLyric[index])); + console.log(chalk.hex('#b3b3b3').visible(displayLyric[index + 1] || "")); + console.log(chalk.dim(displayLyric[index + 2] || "")); + index++; + // console.log(lyric); + }, m * 60 * 1000 + s * 1000 + f - offset); + } else { + // 不是一行歌词 + // console.log("err", line); + } +} + + +function playMusic() { + var player = require('play-sound')(opts = {}) + player.play('./music.m4a', function (err) { + if (err) throw err; + console.log("消愁 - 毛不易"); + }); +} \ No newline at end of file diff --git a/netease_music/src/index.js b/netease_music/src/index.js index 341df0c..805fd05 100644 --- a/netease_music/src/index.js +++ b/netease_music/src/index.js @@ -43,6 +43,7 @@ async function test() { // let res = await songInfoUtils.fetch({ songId: "437608327" }); // let res = await playlistUtilsOld.fetch({ playlistId: "4980157066", debug: true }); // let res = await commentUtils.fetch({ songId: "4980157066" }); + // let res = await lyricInfoUtils.fetch({ songId: "569200213" }); // let res = await testUtils.fetch(); @@ -50,7 +51,7 @@ async function test() { // let res = await artistInfoUtils.getFromDatabase({ artistId: "12023508" }); // let res = await songInfoUtils.getFromDatabase({ songId: "437608327" }); - console.log(res); + // console.log(res); } /** diff --git a/package-lock.json b/package-lock.json index da44bdf..8947aff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "chalk": "4.1.2", "cheerio": "^1.0.0-rc.12", "crypto": "^1.0.1", "dotenv": "^16.0.1", @@ -19,6 +20,7 @@ "NeteaseCloudMusicApi": "^4.8.2", "node-schedule": "^2.1.0", "path": "^0.12.7", + "play-sound": "^1.1.5", "request": "^2.88.2", "solarlunar": "^2.0.7" } @@ -283,6 +285,18 @@ "resolved": "https://registry.npmmirror.com/caseless/-/caseless-0.12.0.tgz", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/charenc": { "version": "0.0.2", "resolved": "https://registry.npmmirror.com/charenc/-/charenc-0.0.2.tgz", @@ -822,6 +836,11 @@ "node": ">= 0.8" } }, + "node_modules/find-exec": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/find-exec/-/find-exec-1.0.2.tgz", + "integrity": "sha512-/cs763F5i7Nm/aG+hjBv2nJB/Bl2w0tnuZd5bbfcV+WYapn8T4ez3B87H6MgvsmdheDkitj/rHi557wvE+XylQ==" + }, "node_modules/find-up": { "version": "4.1.0", "resolved": "https://registry.npmmirror.com/find-up/-/find-up-4.1.0.tgz", @@ -1040,6 +1059,14 @@ "node": ">= 0.4.0" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/has-property-descriptors": { "version": "1.0.0", "resolved": "https://registry.npmmirror.com/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", @@ -1689,6 +1716,14 @@ "resolved": "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "node_modules/play-sound": { + "version": "1.1.5", + "resolved": "https://registry.npmmirror.com/play-sound/-/play-sound-1.1.5.tgz", + "integrity": "sha512-gbdF1iLNyL5r9Ne9YwARGMkrvfR4EL9G1ZLtFPLkI2tQt0kkHw5CHM5E6Gl/lDuuk/Uj/O5Q29Bi08jMK4egbA==", + "dependencies": { + "find-exec": "1.0.2" + } + }, "node_modules/pngjs": { "version": "5.0.0", "resolved": "https://registry.npmmirror.com/pngjs/-/pngjs-5.0.0.tgz", @@ -2204,6 +2239,17 @@ "node": ">=10" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.1.tgz", @@ -2669,6 +2715,15 @@ "resolved": "https://registry.npmmirror.com/caseless/-/caseless-0.12.0.tgz", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmmirror.com/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, "charenc": { "version": "0.0.2", "resolved": "https://registry.npmmirror.com/charenc/-/charenc-0.0.2.tgz", @@ -3095,6 +3150,11 @@ "unpipe": "~1.0.0" } }, + "find-exec": { + "version": "1.0.2", + "resolved": "https://registry.npmmirror.com/find-exec/-/find-exec-1.0.2.tgz", + "integrity": "sha512-/cs763F5i7Nm/aG+hjBv2nJB/Bl2w0tnuZd5bbfcV+WYapn8T4ez3B87H6MgvsmdheDkitj/rHi557wvE+XylQ==" + }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmmirror.com/find-up/-/find-up-4.1.0.tgz", @@ -3264,6 +3324,11 @@ "function-bind": "^1.1.1" } }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, "has-property-descriptors": { "version": "1.0.0", "resolved": "https://registry.npmmirror.com/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", @@ -3774,6 +3839,14 @@ "resolved": "https://registry.npmmirror.com/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "play-sound": { + "version": "1.1.5", + "resolved": "https://registry.npmmirror.com/play-sound/-/play-sound-1.1.5.tgz", + "integrity": "sha512-gbdF1iLNyL5r9Ne9YwARGMkrvfR4EL9G1ZLtFPLkI2tQt0kkHw5CHM5E6Gl/lDuuk/Uj/O5Q29Bi08jMK4egbA==", + "requires": { + "find-exec": "1.0.2" + } + }, "pngjs": { "version": "5.0.0", "resolved": "https://registry.npmmirror.com/pngjs/-/pngjs-5.0.0.tgz", @@ -4191,6 +4264,14 @@ "peek-readable": "^4.1.0" } }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + }, "toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmmirror.com/toidentifier/-/toidentifier-1.0.1.tgz", diff --git a/package.json b/package.json index 7d7ab3b..e724ce3 100644 --- a/package.json +++ b/package.json @@ -9,17 +9,19 @@ "author": "coder-xiaomo", "license": "MIT", "dependencies": { + "chalk": "4.1.2", "cheerio": "^1.0.0-rc.12", "crypto": "^1.0.1", + "dotenv": "^16.0.1", "fs": "^0.0.1-security", + "iconv-lite": "^0.6.3", "minimist": "^1.2.6", "mysql": "^2.18.1", "NeteaseCloudMusicApi": "^4.8.2", "node-schedule": "^2.1.0", "path": "^0.12.7", + "play-sound": "^1.1.5", "request": "^2.88.2", - "solarlunar": "^2.0.7", - "dotenv": "^16.0.1", - "iconv-lite": "^0.6.3" + "solarlunar": "^2.0.7" } }