diff --git a/README.md b/README.md index 617ccf2..7b78b98 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ ## ✔注意事项 -⭐如果喜欢的话请帮忙star一下!⭐ +⭐ 如果喜欢的话请帮忙star支持一下! -部分代码在上 +🐛 有Bug可以开Issue或PR + +**[这里看更新日志](changelog.txt)** diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..ad8a722 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,4 @@ +V0.0.1 Alpha + +可以导出PDF琴谱,MIDI文件,MP3文件 +导出的MIDI正常播放,支持变速 \ No newline at end of file diff --git a/functions.js b/functions.js new file mode 100644 index 0000000..ea8ce37 --- /dev/null +++ b/functions.js @@ -0,0 +1,96 @@ + +const libCCMZ = require('./libCCMZ'); +const ccApi = require('./ccApi'); +const util = require('./utils'); +const fs = require('fs'); + +var args = require('minimist')(process.argv.slice(2)); +debug = args['dbg']; + +//初始化保存的文件名 +var fileName, _saveDir = 'test'; + +let writeAndConvert = async (ccmzResolved) => { + if (ccmzResolved['ver'] == 2) { + const ccmzObj = { + score : JSON.parse(ccmzResolved['score']), + midi : JSON.parse(ccmzResolved['midi']) + } + if (util.isDetailedOutput()) console.log('解析琴谱文件完成'); + if (debug) { + fs.writeFileSync(`${_saveDir}/${fileName}.json`, JSON.stringify(ccmzObj,"","\t")); + if (util.isDetailedOutput()) console.log('转换为json并写出'); + } + if (util.isDetailedOutput()) console.log('解析MIDI'); + libCCMZ.writeMIDI(ccmzObj['midi'], `${_saveDir}/${fileName}.mid`); + } else { + fs.writeFileSync(`${_saveDir}/${fileName}.mid`, midi); + } + + if (util.isDetailedOutput()) console.log('成功写出MIDI文件'); + console.log('下载成功!'); + if (util.isDetailedOutput()) console.log('程序已结束'); + +} + +//////主程序////// +let getCCMZ = async (musicID, saveDir, downloadMP3, downloadPDF) => { + _saveDir = saveDir; + + //初始化变量 + var opernID, details, ccmzRaw; + + //开始获取opernID与曲谱链接 + opernID = await ccApi.getOpernID(musicID); + details = await ccApi.getDetails(opernID); + + if (util.isDetailedOutput()) console.log('开始解析信息'); + var detailsJSON = JSON.parse(details)['list']; + + //解析json + const PDFlink = detailsJSON['pdf'];//解析PDF链接 + const ccmzLink = detailsJSON['audition_midi'];//解析CCMZ链接 + const MP3Link = detailsJSON['audition_urtext'];//解析MP3链接 + const musicName = detailsJSON['name'];//获取歌曲名 + const authorcName = detailsJSON['author'];//获取上传者 + const typename = detailsJSON['typename'];//获取原作者 + const paid = detailsJSON['is_pay'];//获取付费 + + fileName = musicName.replace(/[/\\:\|\*\?"<>]/g," ") + '-' + musicID; + + console.log('解析了琴谱信息'); + console.log(`付费歌曲: ${util.booleanString(paid == '1', true)}`) + console.log(`音乐名: ${musicName}`); + console.log(`原作者: ${typename}`); + console.log(`上传人: ${authorcName}`); + + + //下载PDF或MP3 + if (downloadMP3) { + if (util.isDetailedOutput()) console.log('下载MP3'); + if (MP3Link != '') fs.writeFileSync(`${saveDir}/${fileName}.mp3`, await util.httpget(MP3Link, '', true, 'MP3', false)); + else console.log('无mp3可下载'); + } + + if (downloadPDF) { + if (util.isDetailedOutput()) console.log('下载PDF'); + if (PDFlink != '') fs.writeFileSync(`${saveDir}/${fileName}.pdf`, await util.httpget(PDFlink, '', true, 'PDF', false)); + else console.log('无原始pdf可下载'); + } + + if (ccmzLink != '') { + if (util.isDetailedOutput()) console.log('开始下载并解析琴谱'); + ccmzRaw = await libCCMZ.downloadCCMZ(ccmzLink); + + //开始写出,转换CCMZ + if (util.isDetailedOutput()) console.log('开始解析琴谱文件'); + libCCMZ.readCCMZ(ccmzRaw, writeAndConvert); + } else { + console.log('无MIDI可下载'); + if (util.isDetailedOutput()) console.log('程序已结束'); + } + +} +//////主程序////// + +module.exports = { getCCMZ }; \ No newline at end of file diff --git a/index.js b/index.js index 10a9b0c..6322f26 100644 --- a/index.js +++ b/index.js @@ -4,19 +4,22 @@ chongchong-free by ThebestkillerTBK */ //导入库 -const libCCMZ = require('./libCCMZ'); -const ccApi = require('./ccApi'); const util = require('./utils'); const path = require('path'); const fs = require('fs'); +//打印信息 +console.log +(`chongchong-free by ThebestkillerTBK +免费下载虫虫钢琴曲谱并解密 +V${require('./package.json').version}`); + //解析参数 var args = require('minimist')(process.argv.slice(2)); debug = args['dbg']; //显示帮助 if (!args.i && !debug) { - console.log('chongchong-free by ThebestkillerTBK\n 免费下载虫虫钢琴曲谱并解密'); console.log('-i 琴谱ID'); console.log('-o 输出目录(可选),默认为output'); console.log('-p 输出原始PDF(可选),默认不输出'); @@ -67,90 +70,5 @@ if (util.isDetailedOutput()) { console.log(`琴谱ID: ${musicID} 输出目录: ${saveDir}\n生成PDF: ${util.booleanString(downloadPDF, true)} 生成MP3: ${util.booleanString(downloadMP3, true)}`); } -//初始化保存的文件名 -var fileName = ''; - -let writeAndConvert = async (ccmzResolved) => { - if (ccmzResolved['ver'] == 2) { - const ccmzObj = { - score : JSON.parse(ccmzResolved['score']), - midi : JSON.parse(ccmzResolved['midi']) - } - if (util.isDetailedOutput()) console.log('解析琴谱文件完成'); - if (debug) { - fs.writeFileSync(`${saveDir}/${fileName}.json`, JSON.stringify(ccmzObj,"","\t")); - if (util.isDetailedOutput()) console.log('转换为json并写出'); - } - if (util.isDetailedOutput()) console.log('解析MIDI'); - libCCMZ.writeMIDI(ccmzObj['midi'], `${saveDir}/${fileName}.mid`); - } else { - fs.writeFileSync(`${saveDir}/${fileName}.mid`, midi); - } - - if (util.isDetailedOutput()) console.log('成功写出MIDI文件'); - console.log('下载成功!'); - if (util.isDetailedOutput()) console.log('程序已结束'); - -} - -//////主程序////// -let getCCMZ = async () => { - - //初始化变量 - var opernID, details, ccmzRaw; - - //开始获取opernID与曲谱链接 - opernID = await ccApi.getOpernID(musicID); - details = await ccApi.getDetails(opernID); - - if (util.isDetailedOutput()) console.log('开始解析信息'); - var detailsJSON = JSON.parse(details)['list']; - - //解析json - const PDFlink = detailsJSON['pdf'];//解析PDF链接 - const ccmzLink = detailsJSON['audition_midi'];//解析CCMZ链接 - const MP3Link = detailsJSON['audition_urtext'];//解析MP3链接 - const musicName = detailsJSON['name'];//获取歌曲名 - const authorcName = detailsJSON['author'];//获取上传者 - const typename = detailsJSON['typename'];//获取原作者 - const paid = detailsJSON['is_pay'];//获取付费 - - fileName = musicName.replace(/[/\\:\|\*\?"<>]/g," ") + '-' + musicID; - - console.log('解析了琴谱信息'); - console.log(`付费歌曲: ${util.booleanString(paid == '1', true)}`) - console.log(`音乐名: ${musicName}`); - console.log(`原作者: ${typename}`); - console.log(`上传人: ${authorcName}`); - - - //下载PDF或MP3 - if (downloadMP3) { - if (util.isDetailedOutput()) console.log('下载MP3'); - if (MP3Link != '') fs.writeFileSync(`${saveDir}/${fileName}.mp3`, await util.httpget(MP3Link, '', true, 'MP3', false)); - else console.log('无mp3可下载'); - } - - if (downloadPDF) { - if (util.isDetailedOutput()) console.log('下载PDF'); - if (PDFlink != '') fs.writeFileSync(`${saveDir}/${fileName}.pdf`, await util.httpget(PDFlink, '', true, 'PDF', false)); - else console.log('无原始pdf可下载'); - } - - if (ccmzLink != '') { - if (util.isDetailedOutput()) console.log('开始下载并解析琴谱'); - ccmzRaw = await libCCMZ.downloadCCMZ(ccmzLink); - - //开始写出,转换CCMZ - if (util.isDetailedOutput()) console.log('开始解析琴谱文件'); - libCCMZ.readCCMZ(ccmzRaw, writeAndConvert); - } else { - console.log('无MIDI可下载'); - if (util.isDetailedOutput()) console.log('程序已结束'); - } - -} -//////主程序////// - //进入主程序 -getCCMZ() \ No newline at end of file +require('./functions').getCCMZ(musicID, saveDir, downloadMP3, downloadPDF); \ No newline at end of file diff --git a/libCCMZ.js b/libCCMZ.js index 970cdca..d0310bb 100644 --- a/libCCMZ.js +++ b/libCCMZ.js @@ -1,7 +1,6 @@ const JSZip = require('jszip'); const util = require('./utils'); -var MidiWriter = require('./midi-writer-js');//源代码在https://github.com/ThebestkillerTBK/MidiWriterJS -const { forEach } = require('jszip'); +var MidiWriter = require('midi-writer-js'); //歌谱和midi class CCMZ { diff --git a/package.json b/package.json index 672bf81..e9e920c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chongchong-free", - "version": "1.0.0", + "version": "0.0.1", "description": "free www.gangqinpu.com", "main": "index.js", "repository": { @@ -12,14 +12,15 @@ "homepage": "https://github.com/ThebestkillerTBK/chongchong-free", "dependencies": { "jszip": "^3.7.1", + "midi-writer-js": "^2.0.1", "minimist": "^1.2.5", "needle": "^3.0.0", "pkg": "^5.5.2", "tonal-midi": "^0.69.7" }, - "bin":"index.js", + "bin": "index.js", "scripts": { "run": "node index.js --dbg", "build": "pkg . --targets node14-win-x64,node14-macos-x64,node14-linux-x64 -o ./dist/chongchong-free" - } + } }