Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild v2.0.0 #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_modules
.idea/
# package-lock.json

.vscode
# .vscode
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
Expand Down
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3200",
"webRoot": "${workspaceFolder}"
}
]
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"prettier.requireConfig": true,
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
"editor.detectIndentation": false,
"editor.tabSize": 2
}
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,41 @@

</div>

> QQ音乐API koa2 版本, 通过Web网页版请求QQ音乐接口数据, 有问题请提 [issue](https://github.com/Rain120/qq-music-api/issues)
> QQ 音乐 API koa2 版本, 通过 Web 网页版请求 QQ 音乐接口数据, 有问题请提 [issue](https://github.com/Rain120/qq-music-api/issues)

> 当前代码仅共学习,不可做商业用途

### API结构图
### API 结构图

> 目前暂时没有时间做登录模块的接口,欢迎各位大佬给我`PR`, 阿里嘎多

![qq-music](./screenshot/qq-music.png)

### 环境要求

> 因为本项目采用的是`koa2`, 所以请确保你的`node`版本是7.6.0+
> 因为本项目采用的是`koa2`, 所以请确保你的`node`版本是 7.6.0+

```
node -v
```

### 📦 安装

```
[email protected]:Rain120/qq-music-api.git
npm install
```

### 🔨项目启动
### 🔨 项目启动

```
// npm i -g nodemon
npm run start

// or don't install nodemon
node app.js
```

项目监听端口是`3200`

### 🐳 Docker
Expand All @@ -65,7 +68,11 @@ npm run run:images
docker pull qq-music-api
```

### 功能特性
### 功能特性 & 日志更新

- [ ] 大改版, 迭代 `v2.0.0`

- [ ] `API` 设计优化

- [x] 获取歌曲播放链接 **2021-01-24**

Expand All @@ -75,19 +82,19 @@ docker pull qq-music-api

- [x] 获取歌手热门歌曲 **2020-07-04**

- [x] 获取QQ音乐产品的下载地址
- [x] 获取 QQ 音乐产品的下载地址

- [x] 获取歌单分类

- [x] 获取歌单列表

- [x] 获取歌单详情

- [x] 获取MV标签
- [x] 获取 MV 标签

- [x] 获取MV播放信息
- [x] 获取 MV 播放信息

- [x] 获取歌手MV
- [x] 获取歌手 MV

- [x] 获取相似歌手

Expand All @@ -103,13 +110,13 @@ docker pull qq-music-api

- [x] 获取歌曲歌词

- [x] 获取MV
- [x] 获取 MV

- [x] 获取新碟信息

- [x] 获取歌手专辑

- [x] ~~获取歌曲VKey~~ **2021-01-24**
- [x] ~~获取歌曲 VKey~~ **2021-01-24**

- [x] 获取搜索热词

Expand All @@ -123,7 +130,7 @@ docker pull qq-music-api

- [x] 获取排行榜单详情

- [x] 获取评论信息(cmd代表的意思没太弄明白)
- [x] 获取评论信息(cmd 代表的意思没太弄明白)

- [x] 获取票务信息

Expand All @@ -141,7 +148,7 @@ docker pull qq-music-api

[Binaryify/NeteaseCloudMusicApi](https://github.com/Binaryify/NeteaseCloudMusicApi)

[Vue2.0开发企业级移动端音乐Web App](https://coding.imooc.com/class/107.html)
[Vue2.0 开发企业级移动端音乐 Web App](https://coding.imooc.com/class/107.html)

**参考内容**

Expand All @@ -159,7 +166,7 @@ docker pull qq-music-api

#### 🤝 贡献 ![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor)

We welcome all contributions. You can submit any ideas as [pull requests](https://github.com/Rain120/qq-music-api/pulls) or as a GitHub [issue](https://github.com/Rain120/qq-music-api/issues).
We welcome all contributions. You can submit any ideas as [pull requests](https://github.com/Rain120/qq-music-api/pulls) or as a GitHub [issue](https://github.com/Rain120/qq-music-api/issues).

#### 👨‍🏭 作者

Expand Down
92 changes: 68 additions & 24 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("@babel/register");
require('@babel/register');
const Koa = require('koa');
const app = new Koa();
const bodyParser = require('koa-bodyparser');
Expand All @@ -9,35 +9,75 @@ const chalk = require('chalk');

const cors = require('./middlewares/koa-cors');
const router = require('./routers/router');
const newRouter = require('./routers/new-router');
const cookie = require('./util/cookie');
require('./util/colors');
const userInfo = require('./config/user-info')
global = Object.assign({}, userInfo);
const debug = require('./config/debugger');
const userInfo = require('./config/user-info');
global = Object.assign({}, debug, userInfo);

console.log(chalk.green('\n🥳🎉 We had supported config the user cookies. \n'));
console.log(
chalk.yellow(
'\n💪🙏 CN: 我们在新版本为了语义化修改了路由,当然了,我们也是保留了旧版本的路由,如果你是新项目,推荐使用新路由。 \n',
),
);
console.log(chalk.yellow('\n💪🙏 CN: 新路由位置在new-router。\n'));
console.log(
chalk.yellow(
'\n🥳🎉 EN: We have modified the routing in the new version for semantic purposes. Of course, we also keep the old version of the routing. If you are a new project, it is recommended to use the new routing.\n',
),
);
console.log(chalk.yellow('\n💪🙏 EN: The new version at new-router. \n'));
console.log(chalk.green('\n💪🙏 CN: 我们支持 Cookies 配置了 \n'));
console.log(chalk.green('\n🥳🎉 EN: We had supported config the user cookies. \n'));

if (!(global.loginUin || global.uin)) {
console.log(chalk.yellow(`😔 The configuration ${chalk.red('loginUin')} or your ${chalk.red('cookie')} in file ${chalk.green('config/user-info')} has not configured. \n`));
console.log(
chalk.yellow(
`😔 CN: ${chalk.green('config/user-info')} 文件中 ${chalk.red('loginUin')} 或者 ${chalk.red(
'cookie',
)}尚未配置。\n`,
),
);
console.log(
chalk.yellow(
`😔 EN: The configuration ${chalk.red('loginUin')} or your ${chalk.red(
'cookie',
)} in file ${chalk.green('config/user-info')} has not configured. \n`,
),
);
}

if (!global.cookie) {
console.log(chalk.yellow(`😔 The configuration ${chalk.red('cookie')} in file ${chalk.green('config/user-info')} has not configured. \n`));
console.log(
chalk.yellow(
`😔 CN: ${chalk.green('config/user-info')} 文件中 ${chalk.red('cookie')} 尚未配置。\n`,
),
);
console.log(
chalk.yellow(
`😔 EN: The configuration ${chalk.red('cookie')} in file ${chalk.green(
'config/user-info',
)} has not configured. \n`,
),
);
}

exec('npm info QQ-Music-API version', (err, stdout, stderr) => {
if(!err){
let version = stdout.trim()
if(package.version < version){
console.log(`Current Version: ${version}, Current Version: ${package.version}, Please update it.`.prompt);
if (!err) {
let version = stdout.trim();
if (package.version < version) {
console.log(
`Current Version: ${version}, Current Version: ${package.version}, Please update it.`
.prompt,
);
}
}
});

app.use(bodyParser());
app.use(cookie());
app.use(static(
path.join(__dirname, 'public')
));
app.use(static(path.join(__dirname, 'public')));

// logger
app.use(async (ctx, next) => {
Expand All @@ -47,14 +87,16 @@ app.use(async (ctx, next) => {
});

// cors
app.use(cors({
origin: (ctx) => ctx.request.header.origin,
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
maxAge: 5,
credentials: true,
allowMethods: ['GET', 'POST', 'DELETE'],
allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}));
app.use(
cors({
origin: ctx => ctx.request.header.origin,
exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],
maxAge: 5,
credentials: true,
allowMethods: ['GET', 'POST', 'DELETE'],
allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}),
);

// x-response-time
app.use(async (ctx, next) => {
Expand All @@ -64,11 +106,13 @@ app.use(async (ctx, next) => {
ctx.set('X-Response-Time', `${ms}ms`);
});

app.use(router.routes())
.use(router.allowedMethods());
// TODO: v2.0.0 move it
app.use(router.routes()).use(router.allowedMethods());

app.use(newRouter.routes()).use(newRouter.allowedMethods());

const PORT = process.env.PORT || 3200;

app.listen(PORT, () => {
console.log(`server running @ http://localhost:${PORT}`.prompt)
console.log(`server running @ http://localhost:${PORT}`.prompt);
});
10 changes: 10 additions & 0 deletions config/debugger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* @Author: Rainy [https://github.com/rain120]
* @Date: 2021-01-30 14:55:24
* @LastEditors: Rainy
* @LastEditTime: 2021-01-30 15:03:05
*/

module.exports = {
log: true,
}
Loading