Initial commit
This commit is contained in:
90
src/backends/163.ts
Normal file
90
src/backends/163.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import neteaseApi from '@neteasecloudmusicapienhanced/api'
|
||||
import { select, input, password } from '@inquirer/prompts'
|
||||
import config from 'config'
|
||||
const { login_cellphone, captcha_sent, captcha_verify } = neteaseApi;
|
||||
|
||||
class CouldMusic {
|
||||
private cookie: string[]
|
||||
private loginMode: string
|
||||
constructor() {
|
||||
this.cookie = [];
|
||||
this.loginMode = ""
|
||||
}
|
||||
public async login() {
|
||||
this.loginMode = await select({
|
||||
message: "选择一个登入方式",
|
||||
choices: [
|
||||
{
|
||||
name: "手机号登入",
|
||||
value: "phone",
|
||||
description: "使用手机号登入"
|
||||
},
|
||||
{
|
||||
name: "扫码登入",
|
||||
value: "qrCode",
|
||||
description: "使用二维码"
|
||||
},
|
||||
{
|
||||
name: "邮箱登入",
|
||||
value: "email",
|
||||
disabled: true
|
||||
},
|
||||
]
|
||||
})
|
||||
switch (this.loginMode) {
|
||||
case "phone":
|
||||
var authMode = await select({
|
||||
message: "验证码or密码",
|
||||
choices: [
|
||||
{
|
||||
name: "验证码",
|
||||
value: "captcha",
|
||||
description: "使用验证码登入"
|
||||
},
|
||||
{
|
||||
name: "密码",
|
||||
value: "passwd",
|
||||
description: "使用验证码登入"
|
||||
},
|
||||
]
|
||||
})
|
||||
if (authMode == "passwd") {
|
||||
var phoneid = await input({
|
||||
message: "请输入手机号"
|
||||
})
|
||||
var passwd = await password({
|
||||
message: "请输入密码"
|
||||
})
|
||||
var result = await login_cellphone({
|
||||
phone: phoneid,
|
||||
password: encodeURIComponent(passwd)
|
||||
})
|
||||
if (result.body.code == 400) {
|
||||
console.error("❌账号或密码错误!")
|
||||
}
|
||||
}else if(authMode=="captcha"){
|
||||
var phoneid = await input({
|
||||
message: "请输入手机号"
|
||||
})
|
||||
captcha_sent({
|
||||
phone:phoneid
|
||||
})
|
||||
var verifyCode = await input({
|
||||
message: "请输入验证码"
|
||||
})
|
||||
try{
|
||||
var result=await login_cellphone({
|
||||
phone:phoneid,
|
||||
captcha:verifyCode
|
||||
})
|
||||
}finally{
|
||||
console.error("❌验证码错误!")
|
||||
}
|
||||
this.cookie=result.cookie
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
export default CouldMusic;
|
||||
9
src/index.ts
Normal file
9
src/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import chalk from 'chalk'
|
||||
import config from 'config'
|
||||
import oobe from './oobe.js'
|
||||
console.info(chalk.bgBlueBright("> ChloudMusic b0.1 "))
|
||||
console.info(chalk.bgBlueBright("> Read Configuration"))
|
||||
var isOobe=config.get("OOBE")
|
||||
if(!isOobe){
|
||||
oobe()
|
||||
}
|
||||
28
src/oobe.ts
Normal file
28
src/oobe.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { select, input } from '@inquirer/prompts'
|
||||
import CloudMusic from './backends/163.js'
|
||||
async function oobe() {
|
||||
const backends = await select({
|
||||
message: "选择一个音乐服务商",
|
||||
choices: [
|
||||
{
|
||||
name: "163CloudMusic",
|
||||
value: "163",
|
||||
description: "网易云音乐"
|
||||
},
|
||||
{
|
||||
name: "spotify",
|
||||
value: "spotify",
|
||||
description: "Spotify"
|
||||
}
|
||||
|
||||
]
|
||||
})
|
||||
switch (backends) {
|
||||
case "163":
|
||||
var backend=new CloudMusic()
|
||||
backend.login()
|
||||
break;
|
||||
case "spotify": break;
|
||||
}
|
||||
}
|
||||
export default oobe
|
||||
Reference in New Issue
Block a user