update: 文档和示例更新

This commit is contained in:
binaryify 2024-03-12 14:29:31 +08:00
parent 571c35da55
commit dfcdc04fbb
12 changed files with 506 additions and 584 deletions

View File

@ -1,4 +1,7 @@
# 更新日志
### 4.15.6 | 2024.03.12
- 文档和示例更新
### 4.15.5 | 2024.02.28
- 文档更新

View File

@ -10,7 +10,6 @@
<a href="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi"><img src="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi/badges/gpa.svg" /></a>
</p>
## 灵感来自
[disoul/electron-cloud-music](https://github.com/disoul/electron-cloud-music)
@ -21,7 +20,6 @@
[greats3an/pyncm](https://github.com/greats3an/pyncm)
## 环境要求
需要 NodeJS 14+ 环境
@ -43,6 +41,7 @@ $ npm install
```
## 运行
调用前务必阅读文档的`调用前须知`
```shell
@ -62,12 +61,14 @@ $ set PORT=4000 && node app.js
```
## npx 方式运行
可在终端直接执行
```bash
npx NeteaseCloudMusicApi@latest
```
使用此命令,可直接启动服务,无需下载或者 clone 项目
使用此命令,可直接启动服务,无需下载或者 clone 项目
## Vercel 部署
@ -80,27 +81,32 @@ v4.0.8 加入了 Vercel 配置文件,可以直接在 Vercel 下部署了,不需
3. 点击 `Import Git Repository` 并选择你 fork 的此项目并点击`import`
4. 点击 `PERSONAL ACCOUNT` 的 `select`
5. 直接点`Continue`
6. `PROJECT NAME`自己填,`FRAMEWORK PRESET` 选 `Other` 然后直接点 `Deploy` 接着等部署完成即可
6. `PROJECT NAME`自己填,`FRAMEWORK PRESET` 选 `Other` 然后直接点 `Deploy` 接着等部署完成即可
## 腾讯云 serverless 部署
因 `Vercel` 在国内访问太慢,在此提供腾讯云 serverless 部署方法(注意:腾讯云 serverless 并不是免费的,前三个月有免费额度,之后收费)
### 操作方法
1. fork 此项目
2. 在腾讯云serverless应用管理页面( https://console.cloud.tencent.com/sls ),点击`新建应用`
2. 在腾讯云 serverless 应用管理页面( https://console.cloud.tencent.com/sls ),点击`新建应用`
3. 顶部`创建方式`选择 `Web 应用`
4. 选择 `Express框架`,点击底部`下一步按钮`
5. 输入`应用名`,上传方式选择`代码仓库`,进行GitHub授权(如已授权可跳过这一步),代码仓库选择刚刚fork的项目
5. 输入`应用名`,上传方式选择`代码仓库`,进行 GitHub 授权(如已授权可跳过这一步),代码仓库选择刚刚 fork 的项目
6. 启动文件填入:
```
#!/bin/bash
export PORT=9000
/var/lang/node16/bin/node app.js
```
```
7. 点击`完成`,等待部署完成,点击`资源列表`的 `API网关` 里的 `URL`,正常情况会打开文档地址,点击文档`例子`可查看接口调用效果
## 可以在Node.js调用
## 可以在 Node.js 调用
v3.31.0后支持Node.js调用,导入的方法为`module`内的文件名,返回内容包含`status`和`body`,`status`为状态码,`body`为请求返回内容,参考`module_example` 文件夹下的 `test.js`
v3.31.0 后支持 Node.js 调用,导入的方法为`module`内的文件名,返回内容包含`status`和`body`,`status`为状态码,`body`为请求返回内容,参考`module_example` 文件夹下的 `test.js`
```js
const { login_cellphone, user_cloud } = require('NeteaseCloudMusicApi')
@ -108,14 +114,13 @@ async function main() {
try {
const result = await login_cellphone({
phone: '手机号',
password: '密码'
password: '密码',
})
console.log(result)
const result2 = await user_cloud({
cookie: result.body.cookie // 凭证
cookie: result.body.cookie, // 凭证
})
console.log(result2.body)
} catch (error) {
console.log(error)
}
@ -128,19 +133,14 @@ main()
```ts
// test.ts
import { banner } from 'NeteaseCloudMusicApi'
banner({ type:0 }).then(res=>{
banner({ type: 0 }).then((res) => {
console.log(res)
})
```
## 使用文档
[文档地址](https://docs-neteasecloudmusicapi.vercel.app)
![文档](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/public/static/docs.png)
[文档地址](https://docs-neteasecloudmusicapi.vercel.app)
## 功能特性
@ -259,10 +259,10 @@ banner({ type:0 }).then(res=>{
113. 云盘数据详情
114. 私信内容
115. 我的数字专辑
116. batch批量请求接口
116. batch 批量请求接口
117. 获取视频标签列表
118. 全部mv
119. 网易出品mv
118. 全部 mv
119. 网易出品 mv
120. 收藏/取消收藏专辑
121. 专辑动态信息
122. 热搜列表(详细)
@ -274,7 +274,7 @@ banner({ type:0 }).then(res=>{
128. 更新歌单标签
129. 默认搜索关键词
130. 删除歌单
131. 电台banner
131. 电台 banner
132. 用户电台
133. 热门电台
134. 电台 - 节目详情
@ -282,12 +282,12 @@ banner({ type:0 }).then(res=>{
136. 电台 - 新晋电台榜/热门电台榜
137. 类别热门电台
138. 云村热评
139. 电台24小时节目榜
140. 电台24小时主播榜
139. 电台 24 小时节目榜
140. 电台 24 小时主播榜
141. 电台最热主播榜
142. 电台主播新人榜
143. 电台付费精品榜
144. 歌手热门50首歌曲
144. 歌手热门 50 首歌曲
145. 购买数字专辑
146. 获取 mv 点赞转发评论数数据
147. 获取视频点赞转发评论数数据
@ -295,7 +295,7 @@ banner({ type:0 }).then(res=>{
149. 调整歌曲顺序
150. 独家放送列表
151. 获取推荐视频
152. 获取视频分类列表
152. 获取视频分类列表
153. 获取全部视频列表接口
154. 获取历史日推可用日期列表
155. 获取历史日推详细数据
@ -326,7 +326,7 @@ banner({ type:0 }).then(res=>{
180. 云贝签到信息
181. 云贝签到
182. 云贝所有任务
183. 云贝todo任务
183. 云贝 todo 任务
184. 云贝今日签到信息
185. 云贝完成任务
186. 云贝收入
@ -339,7 +339,7 @@ banner({ type:0 }).then(res=>{
193. 评论抱一抱列表
194. 收藏的专栏
195. 关注歌手新歌
196. 关注歌手新MV
196. 关注歌手新 MV
197. 歌手详情
198. 云盘上传
199. 二维码登录
@ -353,12 +353,12 @@ banner({ type:0 }).then(res=>{
207. 云贝推歌
208. 云贝推歌历史记录
209. 已购单曲
210. 获取mlog播放地址
211. 将mlog id转为视频id
212. vip成长值
213. vip成长值获取记录
214. vip任务
215. 领取vip成长值
210. 获取 mlog 播放地址
211. 将 mlog id 转为视频 id
212. vip 成长值
213. vip 成长值获取记录
214. vip 任务
215. 领取 vip 成长值
216. 歌手粉丝
217. 数字专辑详情
218. 数字专辑销量
@ -403,12 +403,12 @@ banner({ type:0 }).then(res=>{
257. 验证接口-二维码生成
258. 验证接口-二维码检测
259. 听歌识曲
260. 根据nickname获取userid接口
260. 根据 nickname 获取 userid 接口
261. 播客声音列表
262. 专辑简要百科信息
263. 歌曲简要百科信息
264. 歌手简要百科信息
265. mv简要百科信息
265. mv 简要百科信息
266. 搜索歌手
267. 用户贡献内容
268. 用户贡献条目、积分、云贝数量
@ -421,28 +421,24 @@ banner({ type:0 }).then(res=>{
275. 歌曲红心数量
276. 私人 FM 模式选择
## 单元测试
```shell
$ npm test
```
## SDK
| 语言 | 作者 | 地址 | 类型 |
| :--: | :-----------------------------------------: | :----------------------------------------------------------: | :----: |
| Java | [JackuXL](https://github.com/JackuXL) | [https://github.com/JackuXL/NeteaseCloudMusicApi-SDK](https://github.com/JackuXL/NeteaseCloudMusicApi-SDK) | 第三方 |
| Java | [1015770492](https://github.com/1015770492) | https://github.com/1015770492/yumbo-music-utils | 第三方 |
| Python | [盧瞳](https://github.com/2061360308) | [NeteaseCloudMusic_PythonSDK](https://github.com/2061360308/NeteaseCloudMusic_PythonSDK) | 第三方 |
| 语言 | 作者 | 地址 | 类型 |
| :----: | :-----------------------------------------: | :--------------------------------------------------------------------------------------------------------: | :----: |
| Java | [JackuXL](https://github.com/JackuXL) | [https://github.com/JackuXL/NeteaseCloudMusicApi-SDK](https://github.com/JackuXL/NeteaseCloudMusicApi-SDK) | 第三方 |
| Java | [1015770492](https://github.com/1015770492) | https://github.com/1015770492/yumbo-music-utils | 第三方 |
| Python | [盧瞳](https://github.com/2061360308) | [NeteaseCloudMusic_PythonSDK](https://github.com/2061360308/NeteaseCloudMusic_PythonSDK) | 第三方 |
## 贡献者
![](https://opencollective.com/NeteaseCloudMusicApi/contributors.svg?width=890)
## License
[The MIT License (MIT)](https://gitlab.com/Binaryify/NeteaseCloudMusicApi/blob/main/LICENSE)

View File

@ -1,6 +1,6 @@
{
"name": "NeteaseCloudMusicApi",
"version": "4.15.5",
"version": "4.15.6",
"description": "网易云音乐 NodeJS 版 API",
"scripts": {
"start": "node app.js",

View File

@ -1,82 +1,73 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>更新头像</title>
</head>
<body>
<input id="file" type="file" />
<img id="avatar" style="height: 200px; width: 200px; border-radius: 50%" />
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>更新头像</title>
</head>
<body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<input id="file" type="file" />
<img id="avatar" style="height: 200px; width: 200px; border-radius: 50%" />
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
"></script>
<script>
const phone = ''
const password = ''
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
<script>
main()
main()
login()
async function main() {
document.querySelector('input[type="file"]').addEventListener(
'change',
function (e) {
var file = this.files[0]
upload(file)
},
false,
)
const res = await axios({
url: `/user/detail?uid=32953014&timestamp=${Date.now()}`,
withCredentials: true, //跨域的话必须设置
})
document.querySelector('#avatar').src = res.data.profile.avatarUrl
}
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
async function upload(file) {
var formData = new FormData()
formData.append('imgFile', file)
const imgSize = await getImgSize(file)
const res = await axios({
method: 'post',
url: `/avatar/upload?cookie=${cookieToken}&imgSize=${
imgSize.width
async function main() {
document.querySelector('input[type="file"]').addEventListener(
'change',
function (e) {
var file = this.files[0]
upload(file)
},
false,
)
const res = await axios({
url: `/user/detail?uid=32953014&timestamp=${Date.now()}`,
withCredentials: true, //跨域的话必须设置
})
document.querySelector('#avatar').src = res.data.profile.avatarUrl
}
async function upload(file) {
var formData = new FormData()
formData.append('imgFile', file)
const imgSize = await getImgSize(file)
const res = await axios({
method: 'post',
url: `/avatar/upload?cookie=${localStorage.getItem('cookie')}&imgSize=${imgSize.width
}&imgX=0&imgY=0&timestamp=${Date.now()}`,
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
})
document.querySelector('#avatar').src = res.data.data.url
}
function getImgSize(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = function (theFile) {
let image = new Image()
image.src = theFile.target.result
image.onload = function () {
resolve({
width: this.width,
height: this.height,
})
}
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
})
document.querySelector('#avatar').src = res.data.data.url
}
function getImgSize(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = function (theFile) {
let image = new Image()
image.src = theFile.target.result
image.onload = function () {
resolve({
width: this.width,
height: this.height,
})
}
})
}
</script>
</body>
}
})
}
</script>
</body>
</html>

View File

@ -8,29 +8,48 @@
</head>
<body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<input id="file" type="file" multiple />
<div id="app">
<ul>
<li v-for="(item,index) in songs" :key="index">
{{item.songName}}
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
const phone = '' // 这里填手机号
const password = '' // 这里填密码
const app = Vue.createApp({
data() {
return {
songs: []
}
},
created() {
this.getData()
},
methods: {
getData() {
console.log('getdata');
const _this = this
axios({
url: `/user/cloud?time=${Date.now()}&cookie=${localStorage.getItem('cookie')}`,
}).then(res => {
console.log(res.data)
_this.songs = res.data.data
})
}
}
}).mount('#app')
const fileUpdateTime = {}
let fileLength = 0
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
login()
main()
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${encodeURIComponent(password)}`,
withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
function main() {
document
.querySelector('input[type="file"]')
@ -44,13 +63,14 @@
}
})
}
main()
function upload(file, currentIndx) {
var formData = new FormData()
formData.append('songFile', file)
axios({
method: 'post',
url: `/cloud?time=${Date.now()}&cookie=${cookieToken}`,
url: `/cloud?time=${Date.now()}&cookie=${localStorage.getItem('cookie')}`,
headers: {
'Content-Type': 'multipart/form-data',
},
@ -58,6 +78,7 @@
}).then(res => {
console.log(`${file.name} 上传成功`)
if (currentIndx >= fileLength) { console.log('上传完毕') }
app.getData()
}).catch(async err => {
console.log(err)
console.log(fileUpdateTime)

View File

@ -8,32 +8,18 @@
</head>
<body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script>
const phone = '' // 这里填手机号
const password = '' // 这里填密码
const fileUpdateTime = {}
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${encodeURIComponent(
password,
)}`,
})
cookieToken = res.data.cookie
}
async function main() {
await login()
const res = await axios({
url: `/homepage/block/page`,
data: {
cookie: cookieToken,
cookie: localStorage.getItem('cookie'),
},
method: 'post',
})
@ -44,7 +30,7 @@
const res2 = await axios({
url: `/homepage/block/page?time=${Date.now()}`,
data: {
cookie: cookieToken,
cookie: localStorage.getItem('cookie'),
cursor: cursor,
},
method: 'post',

View File

@ -3,240 +3,257 @@
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>一起听 - 主机模式</title>
<script src="https://unpkg.com/petite-vue"></script>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/mdui@1.0.2/dist/css/mdui.min.css" />
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>一起听 - 主机模式</title>
<script src="https://unpkg.com/petite-vue"></script>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/mdui@1.0.2/dist/css/mdui.min.css" />
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
</head>
<body class="mdui-container">
<h1>一起听 - 主机模式</h1>
<div>消息: {{message}}</div>
<audio
id="player"
autoplay
controls>
</audio>
<br />
<br />
<button v-if="!account.login" @click="login">获取登录状态</button>
<div>您的当前登录账号为: {{account.nickname}}</div>
<br />
<div v-if="account.login">
<button v-if="!roomInfo.roomId" @click="createRoom">创建房间</button>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<h1>一起听 - 主机模式</h1>
<div>消息: {{message}}</div>
<audio id="player" autoplay controls>
</audio>
<br />
<br />
<button v-if="!account.login" @click="login">获取登录状态</button>
<div>您的当前登录账号为: {{account.nickname}}</div>
<br />
<div v-if="account.login">
<button v-if="!roomInfo.roomId" @click="createRoom">创建房间</button>
<div v-if="roomInfo.roomId">
<div>分享链接为:
https://st.music.163.com/listen-together/share/?songId=1372188635&roomId={{roomInfo.roomId}}&inviterId={{account.userId}}
</div>
<br />
<button @click="refreshRoom">刷新房间状态</button>
<div>在线用户: </div>
<ul class="mdui-list">
<li v-for="user in roomInfo.roomUsers" class="mdui-list-item mdui-ripple">
<div class="mdui-list-item-avatar">
<img :src="user.avatarUrl" />
</div>
<div class="mdui-list-item-content">{{user.nickname}}</div>
</li>
</ul>
<button v-if="roomInfo.roomId" @click="closeRoom">关闭房间</button>
</div>
<div v-if="roomInfo.roomId">
<div>分享链接为:
https://st.music.163.com/listen-together/share/?songId=1372188635&roomId={{roomInfo.roomId}}&inviterId={{account.userId}}
</div>
<br />
<button @click="refreshRoom">刷新房间状态</button>
<div>在线用户: </div>
<ul class="mdui-list">
<li v-for="user in roomInfo.roomUsers" class="mdui-list-item mdui-ripple">
<div class="mdui-list-item-avatar">
<img :src="user.avatarUrl" />
</div>
<div class="mdui-list-item-content">{{user.nickname}}</div>
</li>
</ul>
<button v-if="roomInfo.roomId" @click="closeRoom">关闭房间</button>
</div>
<button @click="playTrack">播放</button>
<button @click="pauseTrack">暂停</button>
<button @click="seekTrack">同步进度</button>
<details>
<summary>播放列表</summary>
<br />
<div><span>歌单ID: </span><input v-model="playlistInfo.playlistId" /></div>
<button @click="loadPlaylist">加载歌单到播放列表</button>
<span>{{playlistInfo.playlistName}}</span>
<br />
<br />
<div>歌单内容: </div>
<ul class="mdui-list">
<li @click="gotoTrack(track.id)" v-for="track in playlistInfo.playlistTracks"
class="mdui-list-item mdui-ripple">
<div class="mdui-list-item-avatar">
<img :src="track.al.picUrl" />
</div>
<div class="mdui-list-item-content">{{track.name}}</div>
</li>
</ul>
</details>
</div>
<button @click="playTrack">播放</button>
<button @click="pauseTrack">暂停</button>
<button @click="seekTrack">同步进度</button>
<details>
<summary>播放列表</summary>
<br />
<div><span>歌单ID: </span><input v-model="playlistInfo.playlistId" /></div>
<button @click="loadPlaylist">加载歌单到播放列表</button>
<span>{{playlistInfo.playlistName}}</span>
<br />
<br />
<div>歌单内容: </div>
<ul class="mdui-list">
<li @click="gotoTrack(track.id)" v-for="track in playlistInfo.playlistTracks" class="mdui-list-item mdui-ripple">
<div class="mdui-list-item-avatar">
<img :src="track.al.picUrl" />
</div>
<div class="mdui-list-item-content">{{track.name}}</div>
</li>
</ul>
</details>
</body>
<script>
PetiteVue.createApp({
message: '请点击获取登录状态',
account: {
login: false,
userId: 0,
nickname: '未登录',
},
roomInfo: {
roomId: null,
roomUsers: [],
},
playlistInfo: {
playlistId: 0,
playlistName: '未获取',
playlistTrackIds: [],
playlistTracks: [],
},
playingInfo: {
trackId: 0,
status: 'PLAY',
progress: 1,
},
clientSeq: 1,
login: async function () {
const res = await axios({
url: `/login/status`,
method: 'get',
})
if (res.data.data.code != 200) {
alert('请先使用登录 API 登录到网易云音乐')
} else {
this.account.userId = res.data.data.profile.userId
this.account.nickname = res.data.data.profile.nickname
this.account.login = true
this.message = '成功登录, 请创建房间'
}
},
createRoom: async function () {
const res = await axios({
url: 'listentogether/room/create',
method: 'get',
})
console.log(res)
if (res.data.code != 200) {
this.message = '创建房间出现问题: ' + res.data.message
} else {
this.message = '创建房间成功: ' + res.data.data.roomInfo.roomId
this.roomInfo.roomId = res.data.data.roomInfo.roomId
res = await axios({
url: 'listentogether/room/check',
method: 'post',
data: {
roomId: this.roomInfo.roomId,
},
})
console.log(res)
}
},
refreshRoom: async function () {
const res = await axios({
url: '/listentogether/status',
})
console.log(res)
if (res.data.code != 200 || !res.data.data.inRoom) {
this.message = '房间状态获取失败, 可能退出了房间'
} else {
this.roomInfo.roomUsers = res.data.data.roomInfo.roomUsers
}
},
closeRoom: async function () {
const res = await axios({
url: '/listentogether/end',
PetiteVue.createApp({
message: '请点击获取登录状态',
account: {
login: false,
userId: 0,
nickname: '未登录',
},
roomInfo: {
roomId: null,
roomUsers: [],
},
playlistInfo: {
playlistId: 0,
playlistName: '未获取',
playlistTrackIds: [],
playlistTracks: [],
},
playingInfo: {
trackId: 0,
status: 'PLAY',
progress: 1,
},
clientSeq: 1,
login: async function () {
const res = await axios({
url: `/login/status`,
method: 'get',
data: {
cookie: localStorage.getItem('cookie'),
},
})
if (res.data.data.code != 200) {
alert('请先使用登录 API 登录到网易云音乐')
} else {
this.account.userId = res.data.data.profile.userId
this.account.nickname = res.data.data.profile.nickname
this.account.login = true
this.message = '成功登录, 请创建房间'
}
},
createRoom: async function () {
const res = await axios({
url: 'listentogether/room/create',
method: 'get',
data: {
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
if (res.data.code != 200) {
this.message = '创建房间出现问题: ' + res.data.message
} else {
this.message = '创建房间成功: ' + res.data.data.roomInfo.roomId
this.roomInfo.roomId = res.data.data.roomInfo.roomId
const res2 = await axios({
url: 'listentogether/room/check',
method: 'post',
data: {
roomId: this.roomInfo.roomId,
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
if (res.data.code != 200 || !res.data.data.success) {
this.message = '房间关闭失败'
} else {
this.message = '房间关闭成功'
this.roomInfo.roomId = null
}
},
loadPlaylist: async function () {
const res = await axios({
url: '/playlist/detail',
method: 'post',
data: {
id: this.playlistInfo.playlistId,
},
})
console.log(res)
this.playlistInfo.playlistName = res.data.playlist.name
this.playlistInfo.playlistTrackIds = res.data.playlist.trackIds
.map((track) => track.id)
.join(',')
const resa = await axios({
url: '/song/detail',
method: 'post',
data: {
ids: this.playlistInfo.playlistTrackIds,
},
})
console.log(resa)
this.playlistInfo.playlistTracks = resa.data.songs
if (this.roomInfo.roomId) {
const resb = await axios({
url: 'listentogether/sync/list/command',
method: 'post',
data: {
roomId: this.roomInfo.roomId,
commandType: 'REPLACE',
userId: this.account.userId,
version: this.clientSeq++,
playMode: 'ORDER_LOOP',
displayList: this.playlistInfo.playlistTrackIds,
randomList: this.playlistInfo.playlistTrackIds,
},
})
console.log(resb)
}
},
gotoTrack: async function (trackId) {
this.playingInfo.trackId = trackId
if (this.roomInfo.roomId) {
await this.playCommand('GOTO')
}
document.getElementById('player').src =
'https://music.163.com/song/media/outer/url?id=' + trackId + '.mp3'
},
playTrack: async function () {
this.playingInfo.status = 'PLAY'
await this.playCommand('PLAY')
document.getElementById('player').play()
},
pauseTrack: async function () {
this.playingInfo.status = 'PAUSE'
await this.playCommand('PAUSE')
document.getElementById('player').pause()
},
seekTrack: async function () {
this.playingInfo.status = 'PLAY'
await this.playCommand('seek')
document.getElementById('player').play()
},
playCommand: async function (action) {
const res = await axios({
url: 'listentogether/play/command',
console.log(res2)
}
},
refreshRoom: async function () {
const res = await axios({
url: '/listentogether/status',
data: {
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
if (res.data.code != 200 || !res.data.data.inRoom) {
this.message = '房间状态获取失败, 可能退出了房间'
} else {
this.roomInfo.roomUsers = res.data.data.roomInfo.roomUsers
}
},
closeRoom: async function () {
const res = await axios({
url: '/listentogether/end',
method: 'post',
data: {
roomId: this.roomInfo.roomId,
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
if (res.data.code != 200 || !res.data.data.success) {
this.message = '房间关闭失败'
} else {
this.message = '房间关闭成功'
this.roomInfo.roomId = null
}
},
loadPlaylist: async function () {
const res = await axios({
url: '/playlist/detail',
method: 'post',
data: {
id: this.playlistInfo.playlistId,
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
this.playlistInfo.playlistName = res.data.playlist.name
this.playlistInfo.playlistTrackIds = res.data.playlist.trackIds
.map((track) => track.id)
.join(',')
const resa = await axios({
url: '/song/detail',
method: 'post',
data: {
ids: this.playlistInfo.playlistTrackIds,
cookie: localStorage.getItem('cookie'),
},
})
console.log(resa)
this.playlistInfo.playlistTracks = resa.data.songs
if (this.roomInfo.roomId) {
const resb = await axios({
url: 'listentogether/sync/list/command',
method: 'post',
data: {
roomId: this.roomInfo.roomId,
progress: Math.floor(
document.getElementById('player').currentTime * 1000,
),
commandType: action,
formerSongId: '-1',
targetSongId: this.playingInfo.trackId,
clientSeq: this.clientSeq++,
playStatus: this.playingInfo.status,
commandType: 'REPLACE',
userId: this.account.userId,
version: this.clientSeq++,
playMode: 'ORDER_LOOP',
displayList: this.playlistInfo.playlistTrackIds,
randomList: this.playlistInfo.playlistTrackIds,
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
},
}).mount()
console.log(resb)
}
},
gotoTrack: async function (trackId) {
this.playingInfo.trackId = trackId
if (this.roomInfo.roomId) {
await this.playCommand('GOTO')
}
document.getElementById('player').src =
'https://music.163.com/song/media/outer/url?id=' + trackId + '.mp3'
},
playTrack: async function () {
this.playingInfo.status = 'PLAY'
await this.playCommand('PLAY')
document.getElementById('player').play()
},
pauseTrack: async function () {
this.playingInfo.status = 'PAUSE'
await this.playCommand('PAUSE')
document.getElementById('player').pause()
},
seekTrack: async function () {
this.playingInfo.status = 'PLAY'
await this.playCommand('seek')
document.getElementById('player').play()
},
playCommand: async function (action) {
const res = await axios({
url: 'listentogether/play/command',
method: 'post',
data: {
roomId: this.roomInfo.roomId,
progress: Math.floor(
document.getElementById('player').currentTime * 1000,
),
commandType: action,
formerSongId: '-1',
targetSongId: this.playingInfo.trackId,
clientSeq: this.clientSeq++,
playStatus: this.playingInfo.status,
cookie: localStorage.getItem('cookie'),
},
})
console.log(res)
},
}).mount()
</script>
</html>

View File

@ -1,89 +1,77 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>歌单封面上传</title>
</head>
<body>
<input id="file" type="file" name="filename" />
<img
id="playlist_cover"
style="height: 200px; width: 200px; border-radius: 50%"
/>
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script>
const phone = ''
const password = ''
const playlist_id = ''
let cookieToken = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
if (!playlist_id) {
const msg = '请设置你的歌单id'
alert(msg)
throw new Error(msg)
}
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>歌单封面上传</title>
</head>
main()
login()
async function main() {
document.querySelector('input[type="file"]').addEventListener(
'change',
function (e) {
var file = this.files[0]
upload(file)
},
false,
)
const res = await axios({
url: `/playlist/detail?id=${playlist_id}&timestamp=${Date.now()}`,
})
document.querySelector('#playlist_cover').src = res.data.playlist.coverImgUrl
}
async function login() {
const res = await axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
withCredentials: true, //跨域的话必须设置
})
cookieToken = res.data.cookie
}
async function upload(file) {
var formData = new FormData()
formData.append('imgFile', file)
const imgSize = await getImgSize(file)
const res = await axios({
method: 'post',
url: `/playlist/cover/update?id=${playlist_id}&cookie=${cookieToken}&imgSize=${
imgSize.width
<body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<input id="file" type="file" name="filename" />
<img id="playlist_cover" style="height: 200px; width: 200px; border-radius: 50%" />
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
<script>
const playlist_id = ''
if (!playlist_id) {
const msg = '请设置你的歌单id'
alert(msg)
throw new Error(msg)
}
main()
async function main() {
document.querySelector('input[type="file"]').addEventListener(
'change',
function (e) {
var file = this.files[0]
upload(file)
},
false,
)
const res = await axios({
url: `/playlist/detail?id=${playlist_id}&timestamp=${Date.now()}`,
})
document.querySelector('#playlist_cover').src = res.data.playlist.coverImgUrl
}
async function upload(file) {
var formData = new FormData()
formData.append('imgFile', file)
const imgSize = await getImgSize(file)
const res = await axios({
method: 'post',
url: `/playlist/cover/update?id=${playlist_id}&cookie=${localStorage.getItem('cookie')}&imgSize=${imgSize.width
}&imgX=0&imgY=0&timestamp=${Date.now()}`,
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
})
document.querySelector('#playlist_cover').src = res.data.data.url
}
function getImgSize(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = function (theFile) {
let image = new Image()
image.src = theFile.target.result
image.onload = function () {
resolve({
width: this.width,
height: this.height,
})
}
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
})
document.querySelector('#playlist_cover').src = res.data.data.url
}
function getImgSize(file) {
return new Promise((resolve, reject) => {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = function (theFile) {
let image = new Image()
image.src = theFile.target.result
image.onload = function () {
resolve({
width: this.width,
height: this.height,
})
}
})
}
</script>
</body>
}
})
}
</script>
</body>
</html>

View File

@ -13,22 +13,7 @@
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
"></script>
<script>
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}&noCookie=true`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
async function login() {
let timer
let timestamp = Date.now()
@ -59,6 +44,23 @@
}, 3000)
}
login()
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}&noCookie=true`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
</script>
<style>
.info {

View File

@ -13,22 +13,6 @@
<script src="https://cdn.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js
"></script>
<script>
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
async function login() {
let timer
let timestamp = Date.now()
@ -59,6 +43,23 @@
}, 3000)
}
login()
async function checkStatus(key) {
const res = await axios({
url: `/login/qr/check?key=${key}&timestamp=${Date.now()}`,
})
return res.data
}
async function getLoginStatus(cookie = '') {
const res = await axios({
url: `/login/status?timestamp=${Date.now()}`,
method: 'post',
data: {
cookie,
},
})
document.querySelector('#info').innerText = JSON.stringify(res.data, null, 2)
}
</script>
<style>
.info {

View File

@ -1,63 +0,0 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>test</title>
</head>
<body>
<p>请在控制台看结果</p>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script>
const phone = ''
const password = ''
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
$.ajax({
url: `/login/cellphone?phone=${phone}&password=${password}`,
xhrFields: {
withCredentials: true, //跨域的话必须设置
},
success: function (data) {
console.log(data)
$.ajax({
url: `/recommend/resource `,
xhrFields: {
withCredentials: true, //跨域的话必须设置
},
success: function (data) {
console.log(data)
},
error: function (err) {
console.log(err)
},
})
},
error: function (err) {
console.log(err)
},
})
axios({
url: `/login/cellphone?phone=${phone}&password=${password}`,
withCredentials: true, //跨域的话必须设置
}).then(function (res) {
console.log(res.data)
axios({
url: `/recommend/resource`,
withCredentials: true, //跨域的话必须设置
}).then(function (res) {
console.log(res.data)
})
})
</script>
</body>
</html>

View File

@ -8,6 +8,11 @@
</head>
<body>
<div>
<a href="/qrlogin-nocookie.html">
如果没登录,请先登录
</a>
</div>
<div id="app">
<ul>
<li v-for="(item,index) in voicelist" @click="currentVoiceIndex=index"
@ -61,31 +66,10 @@
const file = document.querySelector('input[type=file]').files[0]
this.upload(file)
},
async login() {
const phone = '' // 这里填手机号
const password = '' // 这里填密码
const fileUpdateTime = {}
let fileLength = 0
if (!phone || !password) {
const msg = '请设置你的手机号码和密码'
alert(msg)
throw new Error(msg)
}
const res = await axios({
url: `/login/cellphone`,
method: 'post',
data: {
phone,
password,
},
})
this.cookieToken = res.data.cookie
},
async getData() {
await this.login()
const res = await axios({
url: `/voicelist/search?cookie=${this.cookieToken}`,
url: `/voicelist/search?cookie=${localStorage.getItem('cookie')}`,
})
console.log(res.data.data)
@ -103,15 +87,11 @@
formData.append('songFile', file)
axios({
method: 'post',
url: `/voice/upload?time=${Date.now()}&cookie=${
this.cookieToken
}&songName=${this.songName}&voiceListId=${
this.currentVoice.voiceListId
}&categoryId=${this.currentVoice.categoryId}&coverImgId=${
this.currentVoice.coverImgId
}&secondCategoryId=${this.currentVoice.secondCategoryId}&description=${
this.description
}&privacy=1`,
url: `/voice/upload?time=${Date.now()}&cookie=${localStorage.getItem('cookie')
}&songName=${this.songName}&voiceListId=${this.currentVoice.voiceListId
}&categoryId=${this.currentVoice.categoryId}&coverImgId=${this.currentVoice.coverImgId
}&secondCategoryId=${this.currentVoice.secondCategoryId}&description=${this.description
}&privacy=1`,
headers: {
'Content-Type': 'multipart/form-data',
},