Skip to content

Commit

Permalink
Merge branch 'xizeyoupan:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy authored Jan 12, 2024
2 parents 6e5e005 + fe4095c commit dab4daa
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 127 deletions.
100 changes: 14 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ Meting后端的api结构较为复杂,基础是一个[接口](https://github.co

## 进度

| | server参数名称 | 单曲/song | 歌单/playlist |
| ------------- | -------------- | --------- | ------------- |
| 网易云 | netease |||
| qq音乐 | tencent |||
| youtube music | ytmusic |||
| more.. | | | |
| | server参数名称 | 图片 | 歌词 | url | 单曲/song | 歌单/playlist | 歌手/artist |
| ------------- | -------------- | ---- | ---- | --- | --------- | ------------- | ----------- |
| 网易云 | netease |||||||
| qq音乐 | tencent |||||| × |
| youtube music | ytmusic || √⁰ |||| × |
| spotify | spotify || √⁰ | √⁰ | √⁰ | √⁰ | × |
| more.. | | | | | | | |

## 地区限制

Expand All @@ -44,6 +45,7 @@ Meting后端的api结构较为复杂,基础是一个[接口](https://github.co
| 网易云 |||
| qq音乐 | √¹ | × |
| youtube music | √² ||
| spotify music | √² ||

### 部署在国内

Expand All @@ -52,6 +54,9 @@ Meting后端的api结构较为复杂,基础是一个[接口](https://github.co
| 网易云 |||
| qq音乐 || × |
| youtube music | √² ||
| spotify music | √² ||

⁰youtube和spotify的歌词由于不易访问,由 https://github.com/xizeyoupan/syncedlyrics_aio 检索而来,歌词匹配准确度不会特别高。spotify的音乐源由 https://github.com/spotDL/spotify-downloader 检索而来,歌曲匹配准确度不会很高,并且获取url的时间较长,使spotify歌曲加载缓慢。

¹使用jsonp,**需要替换前端插件**https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js => https://cdn.jsdelivr.net/npm/@xizeyoupan/meting@latest/dist/Meting.min.js , or
https://unpkg.com/meting@2.0.1/dist/Meting.min.js => https://unpkg.com/@xizeyoupan/meting@latest/dist/Meting.min.js
Expand All @@ -64,7 +69,7 @@ More info https://github.com/xizeyoupan/MetingJS
以下参数均由环境变量配置

- YT_API
默认的youtube music api地址。youtube music的可用性取决于YT_API的连通性。已经内置了一个。如果你需要自己部署youtube music api,[此仓库](https://github.com/xizeyoupan/ytmusic-api-server)提供示例。注:youtube music api必须部署在国外!
默认的youtube music和spotify的api地址。国内可用性取决于YT_API的连通性。**你需要自己部署youtube music和spotify的api**[此仓库](https://github.com/xizeyoupan/ytmusic-api-server)提供示例。
- OVERSEAS
用于判断是否部署于国外。设为1会启用qq音乐的jsonp返回,同时需要替换[前端插件](https://github.com/xizeyoupan/MetingJS),能实现国内访问国外api服务解析qq音乐。部署在国内不用设置这个选项。当部署到vercel上时,此选项自动设为1。
- PORT
Expand All @@ -79,10 +84,6 @@ More info https://github.com/xizeyoupan/MetingJS

https://meting-dd.2333332.xyz/api => Deno Deploy

https://meting-ve.2333332.xyz/api => vercel

https://m.boochinoob.shop/api => cloudflare (deprecated, see below)

可自行测试,如 https://meting-dd.2333332.xyz/test

## 部署
Expand Down Expand Up @@ -134,94 +135,21 @@ docker run -d --name meting -p 3000:3000 intemd/meting-api:latest

一直下一步即可。

### Cloudflare Workers

<details><summary>deprecated</summary>

由于cf会[自动去除x-real-ip以及在headers中加shit](https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/#cf-connecting-ip-in-worker-subrequests),网易云可能会失效。使用网易云的同学请尝试其他部署方式。

在全球拥有数据中心,提供的域名被阻断,使用自有域名后速度很快。冷启动速度很快。

fork本项目,依次点击actions/publish/run workflow。保持默认即可。待CI构建结束后下载cloudflare-workers.js并解压。在[Workers](https://dash.cloudflare.com)创建一个Service,点右上角Quick edit。把cloudflare-workers.js的内容复制进去deploy即可。

</details>

### Deno Deploy

类似Cloudflare Workers,但提供的域名未被阻断,使用Deno为runtime。

fork本项目后新建一个[project](https://dash.deno.com/projects),首先在设置中加一个Environment Variable,名称是OVERSEAS,值为1。接着link到你自己的项目,部署方式选action,project的name需要与你自己的yml吻合
fork本项目后新建一个[project](https://dash.deno.com/projects),首先在设置中加一个Environment Variable,名称是OVERSEAS,值为1。接着link到你自己的项目,部署方式选action,Deno Deploy 的 project 的 name 需要与你自己的yml中设置的吻合

```yml
uses: denoland/deployctl@v1
with:
project: meting #这里要改成你的project的name
project: meting #这里要改成你的Deno Deploy的project的name
entrypoint: deno.js
```
接着在actions/publish/run workflow中勾选Deno即可。
<details><summary>部署到国内平台</summary>
目前国内云服务商呈现两超多强的态势。本人到官方文档翻来翻去,发现各厂商免费的云函数服务是越来越少了,腾讯云免费额度就[三个月](https://cloud.tencent.com/document/product/583/12282),阿里云似乎有[一年](https://help.aliyun.com/document_detail/54301.html)。
#### 华为云
> 不是华为我不用。因为他是有良心的,中国制造🫡
目前华为云每个月提供一定的[免费额度](https://support.huaweicloud.com/productdesc-functiongraph/functiongraph_01_0190.html),包括[日志](https://www.huaweicloud.com/pricing.html?tab=detail#/aom)。
> 爆!爆!爆!这下真的爆了!
👆指的是华为云虽然函数工作流有免费额度,但配套的API网关却不免费,这不刚调试完没多久就发现欠费1分钱,无奈被迫充值了**1元**。理论上1元应该能用挺久的。当然你如果没有1元,也可以选择充1毛试试水。
1. 注册并认证
- 中国站需要手机验证码+实名认证。
- 外国站需要手机验证码+可用的Visa/MasterCard/*信用卡。
2. 下载镜像
- 在github上Fork本项目。
- 依次点击actions/workflow/run workflow。 ![](assets/1.png)
- 等待CI完成后点进第一个workflow下载artifact。 ![](assets/2.png)
- 从下载的文件中解压出meting.tar.gz。
3. 上传镜像
- 登录[镜像服务](https://console.huaweicloud.com/swr),选择页面上传,创建一个名字随意的组织,上传镜像。
- 点击meting-api,找到下载指令,复制 docker pull 后面的镜像地址。
4. 创建函数
- 在[函数服务](https://console.huaweicloud.com/functiongraph)点击创建函数。注意类型选**HTTP**。 ![](assets/3.png)
- 区域选国内的,并且后续服务也建议开在相同区域。
- 镜像填刚刚复制的地址。
5. 创建委托
- 名称随便。
- 类型选云服务。
- 云服务选择"函数工作流 FunctionGraph"。
- 下一步策略勾选"SWR Admin"即可。
- 一路完成,返回创建函数页面选择刚创建的委托,创建函数。
6. 设置函数
- 建议需要调整的设置如下: ![](assets/4.png) ![](assets/5.png)
- 创建触发器,其中分组按提示创建即可。 ![](assets/6.png)
7. 设置网关
- 点击刚创建的APIG触发器,右上角编辑,这里除了改请求path,其他都下一步。 ![](assets/7.png)
- 接着发布API。在API详情界面可以看到你的API URL。在其后加上/api访问,能看到数据就说明成功了。
8. 完成
总结一下:华为云的这个服务确实又臭又长,对于大公司可能叫生态丰富,体系健全,但对想快速上手的同学确实不太友好。各服务之间的文档分布松散,难以跳转。在我写这段话的时候还突然抽风了几小时,我还以为昨晚能跑的代码怎么睡一觉就不好使了。当然把Meting用js重写可能会是一个更好的选择。
</details>
## 杂项
### 反向代理
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meting-backend-js",
"version": "1.0.3",
"version": "1.0.6",
"description": "",
"main": "node.js",
"scripts": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"esbuild": "0.17.5",
"hono": "^2.7.5",
"hono": "^3.7.2",
"nanoid": "^4.0.0"
}
}
7 changes: 5 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { get_runtime } from "./util.js"

let OVERSEAS = globalThis?.Deno?.env?.get("OVERSEAS") || globalThis?.process?.env?.OVERSEAS
const YT_API = globalThis?.Deno?.env?.get("YT_API") || globalThis?.process?.env?.YT_API || 'https://yt-ra.2333332.xyz/api'
const YT_API = globalThis?.Deno?.env?.get("YT_API") || globalThis?.process?.env?.YT_API
const runtime = get_runtime()

if (['cloudflare', 'vercel'].includes(runtime)) OVERSEAS = true
Expand All @@ -10,8 +10,11 @@ const PORT = globalThis?.Deno?.env?.get("PORT") || globalThis?.process?.env?.POR

OVERSEAS = Boolean(OVERSEAS)

const net_ease_anonymous_token = "de91e1f8119d32e01cc73efcb82c0a30c9137e8d4f88dbf5e3d7bf3f28998f21add2bc8204eeee5e56c0bbb8743574b46ca2c10c35dc172199bef9bf4d60ecdeab066bb4dc737d1c3324751bcc9aaf44c3061cd18d77b7a0"

export default {
YT_API,
OVERSEAS,
PORT
PORT,
net_ease_anonymous_token,
}
5 changes: 5 additions & 0 deletions src/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ export default {
"netease": {
"playlist": { "show": true, "value": "6907557348" },
"song": { "show": true, "value": "473403185" },
"artist": { "show": true, "value": "12441107" },
"lrc": { "show": false, "value": "2015217630" },
"url": { "show": false, "value": "473403185" },
},
"ytmusic": {
"playlist": { "show": true, "value": "RDCLAK5uy_l12ynH8dyLsBmE11ToAHLm9P04NS2i9ME" },
"song": { "show": true, "value": "G3s98l2-GXg" }
},
"spotify": {
"playlist": { "show": true, "value": "4D7JFKXy4daI9tUVJfGVFF" },
"song": { "show": true, "value": "5HU2Ddr33JPv7ZVI77M7D5" }
}
}
2 changes: 2 additions & 0 deletions src/providers/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tencent from "./tencent/index.js"
import netease from './netease/index.js'
import ytmusic from './ytmusic/index.js'
import spotify from "./spotify/index.js"

class Providers {

Expand All @@ -10,6 +11,7 @@ class Providers {
tencent.register(this)
netease.register(this)
ytmusic.register(this)
spotify.register(this)

}

Expand Down
20 changes: 20 additions & 0 deletions src/providers/netease/artist_songs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { request } from "./util.js"
import { map_song_list } from "./util.js"

export const get_artist_songs = async (id, cookie) => {
id = parseInt(id)
const data = {
id,
}

const res = await request('POST', `https://music.163.com/api/artist/top/song`, data, {
crypto: 'weapi',
cookie: {},
})

return map_song_list(res)

}

// const res = await get_artist_songs("12441107");
// console.log(res)
10 changes: 7 additions & 3 deletions src/providers/netease/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { get_playlist } from "./playlist.js";
import { get_song_url, get_song_info } from "./song.js";
import { get_playlist } from "./playlist.js"
import { get_song_url, get_song_info } from "./song.js"
import { get_lyric } from "./lyric.js"
import { get_artist_songs } from "./artist_songs.js"

const support_type = ['url', 'lrc', 'song', 'playlist']
const support_type = ['url', 'lrc', 'song', 'playlist', 'artist']

const handle = async (type, id, cookie = '') => {
let result;
Expand All @@ -19,6 +20,9 @@ const handle = async (type, id, cookie = '') => {
case 'playlist':
result = await get_playlist(id)
break
case 'artist':
result = await get_artist_songs(id)
break
default:
return -1;
}
Expand Down
9 changes: 2 additions & 7 deletions src/providers/netease/playlist.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { request } from './util.js'
import { map_song_list } from "./util.js"

export const get_playlist = async (id, cookie = '') => {
const data = {
Expand Down Expand Up @@ -31,13 +32,7 @@ export const get_playlist = async (id, cookie = '') => {
{ crypto: 'weapi' }
)

res = res.songs.map(song => ({
title: song.name,
author: song.ar.reduce((i, v) => ((i ? i + " / " : i) + v.name), ''),
pic: song.al.picUrl,
url: song.id,
lrc: song.id
}))
res = map_song_list(res)

return res

Expand Down
11 changes: 3 additions & 8 deletions src/providers/netease/song.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { request } from "./util.js"
import { map_song_list } from "./util.js"

export const get_song_url = async (id, cookie = '') => {

Expand Down Expand Up @@ -40,14 +41,8 @@ export const get_song_info = async (id, cookie = '') => {
throw res
}

res = {
title: res.songs[0].name,
author: res.songs[0].ar.reduce((i, v) => ((i ? i + " / " : i) + v.name), ''),
pic: res.songs[0].al.picUrl,
url: res.songs[0].id,
lrc: res.songs[0].id
}
return [res]
res = map_song_list(res)
return res
}


Expand Down
Loading

0 comments on commit dab4daa

Please sign in to comment.