Skip to content

Commit

Permalink
add:ytmusic
Browse files Browse the repository at this point in the history
  • Loading branch information
xizeyoupan committed Mar 8, 2023
1 parent 5d49410 commit 2b19e55
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ FROM denoland/deno:alpine-1.30.0 as prod

ARG UID
ARG GID
ARG PORT

ENV UID=${UID:-1010}
ENV GID=${GID:-1010}
ENV PORT=${PORT:-3000}

RUN addgroup -g ${GID} --system meting \
&& adduser -G meting --system -D -s /bin/sh -u ${UID} meting
Expand All @@ -22,6 +24,6 @@ RUN deno cache /app/dist/deno.js
RUN chown -R meting:meting /app
USER meting

EXPOSE 3000
EXPOSE ${PORT}

CMD deno run --allow-net --allow-env /app/dist/deno.js
61 changes: 48 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,65 @@ Meting后端的api结构较为复杂,基础是一个[接口](https://github.co
- 采用jsonp解决Tencent系地区限制
- 插件系统,编写新接口及音源简单

## api网址
https://meting-dd.2333332.xyz/api => Deno Deploy
## 进度

https://meting-ve.2333332.xyz/api => vercel
| | server参数名称 | 单曲/song | 歌单/playlist |
| ------------- | -------------- | --------- | ------------- |
| 网易云 | netease |||
| qq音乐 | tencent |||
| youtube music | ytmusic |||
| more.. | | | |

https://m.boochinoob.shop/api => cloudflare (deprecated, see below)
## 地区限制

可自行测试,如 https://meting-dd.2333332.xyz/test
### 部署在国外

## 进度
| 客户端/浏览器访问地区 | 国内 | 国外 |
| --------------------- | ---- | ---- |
| 网易云 |||
| qq音乐 | √¹ | × |
| youtube music | √² ||

**从国内访问**
### 部署在国内

| | 单曲/song | 歌单/playlist | 地区限制 |
| ------ | --------- | ------------- | -------- |
| 网易云 | | | |
| qq音乐 | | |* |
| more | | | |
| 客户端/浏览器访问地区 | 国内 | 国外 |
| --------------------- | ---- | ---- |
| 网易云 | | |
| qq音乐 | | × |
| youtube music | √² | |

\*使用jsonp,**需要替换前端插件**https://cdn.jsdelivr.net/npm/[email protected]/dist/Meting.min.js => https://cdn.jsdelivr.net/npm/@xizeyoupan/meting@latest/dist/Meting.min.js , or
¹使用jsonp,**需要替换前端插件**https://cdn.jsdelivr.net/npm/[email protected]/dist/Meting.min.js => https://cdn.jsdelivr.net/npm/@xizeyoupan/meting@latest/dist/Meting.min.js , or
https://unpkg.com/[email protected]/dist/Meting.min.js => https://unpkg.com/@xizeyoupan/meting@latest/dist/Meting.min.js

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必须部署在国外!
- OVERSEAS
用于判断是否部署于国外。设为1会启用qq音乐的jsonp返回,同时需要替换[前端插件](https://github.com/xizeyoupan/MetingJS),能实现国内访问国外api服务解析qq音乐。部署在国内不用设置这个选项。当部署到vercel上时,此选项自动设为1。
- PORT
api监听端口,也是docker需要映射的端口。默认3000
- UID
用于docker,默认1010
- GID
用于docker,默认1010

## api网址
仅为示例,不保证稳定性

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

## 部署

部署 Meting-API 需要基本的计算机编程常识,如果您在部署过程中遇到无法解决的问题请到 issues 向我们提问,我们会尽快给您答复。
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +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 runtime = get_runtime()

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

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

class Providers {

Expand All @@ -8,6 +9,7 @@ class Providers {

tencent.register(this)
netease.register(this)
ytmusic.register(this)

}

Expand Down
21 changes: 21 additions & 0 deletions src/providers/ytmusic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import config from "../../config.js"
const support_type = ['song', 'playlist']
const YT_API = config.YT_API
const handle = async (type, id, cookie = '') => {
let result
const query = `?type=${type}&id=${id}`
if (support_type.includes(type)) {
result = await fetch(YT_API + query)
result = await result.json()
} else {
result = -1
}

return result
}

export default {
register: (ctx) => {
ctx.register('ytmusic', { handle, support_type })
}
}
2 changes: 2 additions & 0 deletions src/service/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ export default async (ctx) => {
let req_url = perfix ? perfix + getPathFromURL(ctx.req.url.split('?')[0]) : ctx.req.url.split('?')[0]
if (runtime === 'vercel') req_url = req_url.replace('http://', 'https://')

// json 类型数据填充api
return ctx.json(data.map(x => {
for (let i of ['url', 'pic', 'lrc']) {
const _ = String(x[i])
// 正常对象_均为id,以下例外不用填充:1.@开头/size为0=>qq音乐jsonp 2.已存在完整链接
if (!_.startsWith('@') && !_.startsWith('http') && _.length > 0) {
x[i] = `${req_url}?server=${server}&type=${i}&id=${_}`
}
Expand Down

1 comment on commit 2b19e55

@vercel
Copy link

@vercel vercel bot commented on 2b19e55 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.