提交 7c7080ce 编写于 作者: L Lunan Li

Added Batch Music Upload Feature

上级 1c05f8f5
const { cloud, login_cellphone } = require('../main') const { cloud, login_cellphone } = require('../main')
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const yargs = require('yargs')
const MUSIC_FILE_EXTENSIONS = new Set(['.mp3', '.flac'])
function getAllMusicFiles(dir, arrayOfFiles) {
arrayOfFiles = arrayOfFiles || []
fs.readdirSync(dir).forEach((file) => {
let fullPath = path.join(dir, file)
if (fs.lstatSync(fullPath).isDirectory()) {
getAllMusicFiles(fullPath, arrayOfFiles)
} else {
if (MUSIC_FILE_EXTENSIONS.has(path.extname(fullPath))) {
arrayOfFiles.push(fullPath)
}
}
})
return arrayOfFiles
}
function getParsedArgs() {
return yargs(process.argv.slice(2))
.option('country_code', {
default: '86',
describe: 'The country code of your phone number',
type: 'string',
})
.option('phone_number', {
demandOption: true,
describe: 'Your phone number',
type: 'string',
})
.option('password', {
demandOption: true,
describe: 'Your password',
type: 'string',
})
.option('file', {
describe: 'The absolute path to the single music file to be uploaded',
type: 'string',
})
.option('dir', {
describe: 'The absolute to the directory of music files to be uploaded',
type: 'string',
})
.conflicts('file', 'dir')
.help()
.alias('help', 'h').argv
}
async function main() { async function main() {
const args = getParsedArgs()
const result = await login_cellphone({ const result = await login_cellphone({
phone: '手机号', countrycode: args.country_code,
password: '密码', phone: args.phone_number,
password: args.password,
}) })
const filePath = './test.mp3' const files = args.file
try { ? getAllMusicFiles(args.file)
await cloud({ : getAllMusicFiles(args.dir)
songFile: { let processed = 0
name: path.basename(filePath), let failed = 0
data: fs.readFileSync(filePath), for (let k in files) {
}, const file = files[k]
cookie: result.body.cookie, try {
}) await cloud({
} catch (error) { songFile: {
console.log(error, 'error') name: path.basename(file),
data: fs.readFileSync(file),
},
cookie: result.body.cookie,
})
} catch (error) {
console.log(error)
failed += 1
}
processed += 1
console.log(`Processed ${processed}/${files.length} songs...`)
if (failed) {
console.log(`Failed to upload ${failed} songs...`)
}
} }
console.log('Finished!')
} }
main() main()
此差异已折叠。
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
"pac-proxy-agent": "^5.0.0", "pac-proxy-agent": "^5.0.0",
"qrcode": "^1.4.4", "qrcode": "^1.4.4",
"safe-decode-uri-component": "^1.2.1", "safe-decode-uri-component": "^1.2.1",
"tunnel": "^0.0.6" "tunnel": "^0.0.6",
"yargs": "^17.1.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "14.17.15", "@types/node": "14.17.15",
......
...@@ -3,11 +3,14 @@ const axios = require('axios') ...@@ -3,11 +3,14 @@ const axios = require('axios')
const host = global.host || 'http://localhost:3000' const host = global.host || 'http://localhost:3000'
console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!') console.log('注意: 测试登录需在 test/login.test.js 中填写账号密码!!!')
const phone = '' const country_code = '1'
const password = '' const phone = '3156678705'
const password = '1q2w3e4R'
describe('测试登录是否正常', () => { describe('测试登录是否正常', () => {
it('手机登录 code 应该等于200', (done) => { it('手机登录 code 应该等于200', (done) => {
const qs = { const qs = {
countrycode:
process.env.NCM_API_TEST_LOGIN_COUNTRY_CODE || country_code || '',
phone: process.env.NCM_API_TEST_LOGIN_PHONE || phone || '', phone: process.env.NCM_API_TEST_LOGIN_PHONE || phone || '',
password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '', password: process.env.NCM_API_TEST_LOGIN_PASSWORD || password || '',
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册