Skip to content

Commit

Permalink
更换了api
Browse files Browse the repository at this point in the history
  • Loading branch information
zhheo committed Nov 25, 2024
1 parent 2fac54f commit 834feee
Show file tree
Hide file tree
Showing 38 changed files with 5,136 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ HeoMusic支持URL参数 `https://music.zhheo.com/?id=`+ id +`&server=` + server

## 许可

项目中包含的Aplayer及MetingJS的修改版本,他们均使用 MIT 协议
项目中包含的[Aplayer](https://github.com/DIYgod/APlayer)[MetingJS](https://github.com/metowolf/Meting)[MetingAPI](https://github.com/injahow/meting-api)的修改版本,他们均使用 MIT 协议

图标采用remixicon,使用 Apache 协议

Expand Down
8 changes: 5 additions & 3 deletions css/APlayer.css

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

5 changes: 4 additions & 1 deletion js/APlayer.min.js

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

142 changes: 142 additions & 0 deletions js/Meting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
class MetingJSElement extends HTMLElement {

connectedCallback() {
if (window.APlayer && window.fetch) {
this._init()
this._parse()
}
}

disconnectedCallback() {
if (!this.lock) {
this.aplayer.destroy()
}
}

_camelize(str) {
return str
.replace(/^[_.\- ]+/, '')
.toLowerCase()
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase())
}

_init() {
let config = {}
for (let i = 0; i < this.attributes.length; i += 1) {
config[this._camelize(this.attributes[i].name)] = this.attributes[i].value
}
let keys = [
'server', 'type', 'id', 'api', 'auth',
'auto', 'lock',
'name', 'title', 'artist', 'author', 'url', 'cover', 'pic', 'lyric', 'lrc',
]
this.meta = {}
for (let key of keys) {
this.meta[key] = config[key]
delete config[key]
}
this.config = config

this.api = this.meta.api || window.meting_api || 'https://music.zhheo.com/meting-api/?server=:server&type=:type&id=:id&r=:r'
if (this.meta.auto) this._parse_link()
}

_parse_link() {
let rules = [
['music.163.com.*song.*id=(\\d+)', 'netease', 'song'],
['music.163.com.*album.*id=(\\d+)', 'netease', 'album'],
['music.163.com.*artist.*id=(\\d+)', 'netease', 'artist'],
['music.163.com.*playlist.*id=(\\d+)', 'netease', 'playlist'],
['music.163.com.*discover/toplist.*id=(\\d+)', 'netease', 'playlist'],
['y.qq.com.*song/(\\w+).html', 'tencent', 'song'],
['y.qq.com.*album/(\\w+).html', 'tencent', 'album'],
['y.qq.com.*singer/(\\w+).html', 'tencent', 'artist'],
['y.qq.com.*playsquare/(\\w+).html', 'tencent', 'playlist'],
['y.qq.com.*playlist/(\\w+).html', 'tencent', 'playlist'],
['xiami.com.*song/(\\w+)', 'xiami', 'song'],
['xiami.com.*album/(\\w+)', 'xiami', 'album'],
['xiami.com.*artist/(\\w+)', 'xiami', 'artist'],
['xiami.com.*collect/(\\w+)', 'xiami', 'playlist'],
]

for (let rule of rules) {
let patt = new RegExp(rule[0])
let res = patt.exec(this.meta.auto)
if (res !== null) {
this.meta.server = rule[1]
this.meta.type = rule[2]
this.meta.id = res[1]
return
}
}
}

_parse() {
if (this.meta.url) {
let result = {
name: this.meta.name || this.meta.title || 'Audio name',
artist: this.meta.artist || this.meta.author || 'Audio artist',
url: this.meta.url,
cover: this.meta.cover || this.meta.pic,
lrc: this.meta.lrc || this.meta.lyric || '',
type: this.meta.type || 'auto',
}
if (!result.lrc) {
this.meta.lrcType = 0
}
if (this.innerText) {
result.lrc = this.innerText
this.meta.lrcType = 2
}
this._loadPlayer([result])
return
}

let url = this.api
.replace(':server', this.meta.server)
.replace(':type', this.meta.type)
.replace(':id', this.meta.id)
.replace(':auth', this.meta.auth)
.replace(':r', Math.random())

fetch(url)
.then(res => res.json())
.then(result => this._loadPlayer(result))
}

_loadPlayer(data) {

let defaultOption = {
audio: data,
mutex: true,
lrcType: this.meta.lrcType || 3,
storageName: 'metingjs'
}

if (!data.length) return

let options = {
...defaultOption,
...this.config,
}
for (let optkey in options) {
if (options[optkey] === 'true' || options[optkey] === 'false') {
options[optkey] = (options[optkey] === 'true')
}
}

let div = document.createElement('div')
options.container = div
this.appendChild(div)

this.aplayer = new APlayer(options)
}

}

console.log('\n %c MetingJS v2.0.1 %c https://github.com/metowolf/MetingJS \n', 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;')

if (window.customElements && !window.customElements.get('meting-js')) {
window.MetingJSElement = MetingJSElement
window.customElements.define('meting-js', MetingJSElement)
}
1 change: 0 additions & 1 deletion js/Meting2.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function loadMusicScript() {
if (typeof localMusic === 'undefined' || !Array.isArray(localMusic) || localMusic.length === 0) {
// 如果 localMusic 为空数组或未定义,加载 Meting2.min.js
var script = document.createElement('script');
script.src = './js/Meting2.min.js';
script.src = './js/Meting.js';
document.body.appendChild(script);
} else {
// 否则加载 localEngine.js
Expand Down
10 changes: 6 additions & 4 deletions main.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ body {
gap: 32px;
width: 40%;
height: 100%;
max-width: 332px;
}

#heoMusic-page.localMusic {
Expand Down Expand Up @@ -146,8 +147,8 @@ body #nav-music {
}
#heoMusic-page .aplayer-pic {
float: none;
width: 200px;
height: 200px;
width: 300px;
height: 300px;
border-radius: 12px;
z-index: 999;
position: relative;
Expand Down Expand Up @@ -323,7 +324,7 @@ body #nav-music {
margin-left: 15px;
}

#heoMusic-page .aplayer-info .aplayer-time .aplayer-icon::before {
#heoMusic-page .aplayer-info .aplayer-time .aplayer-volume-wrap::before {
content: '';
position: absolute;
padding: 8px;
Expand All @@ -344,7 +345,8 @@ body #nav-music {

#heoMusic-page .aplayer-list {
width: 100%;
height: calc(100vh - 445px);
height: 100%;
flex: 1;
min-width: 200px;
}

Expand Down
17 changes: 17 additions & 0 deletions meting-api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = false
indent_style = space

[*.md]
indent_size = 2
insert_final_newline = false
trim_trailing_whitespace = false

[*.php]
indent_size = 4
insert_final_newline = true
21 changes: 21 additions & 0 deletions meting-api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 injahow

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
86 changes: 86 additions & 0 deletions meting-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<p align="center">
<img src="https://user-images.githubusercontent.com/2666735/30651452-58ae6c88-9deb-11e7-9e13-6beae3f6c54c.png" alt="Meting">
</p>

# meting-api

## Descriptions

- 这是基于 [Meting](https://github.com/metowolf/Meting) 创建的 APlayer API
- 灵感源于 [https://api.fczbl.vip/163/](https://api.fczbl.vip/163/)
- 部分参考 [Meting-API](https://github.com/metowolf/Meting-API)

## Build Setup

```bash
# 克隆仓库
$ git clone https://github.com/injahow/meting-api.git

$ cd meting-api

# 安装依赖
$ composer install

# 或者使用中国镜像
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com

$ composer install
```

或者下载打包文件[https://github.com/injahow/meting-api/releases](https://github.com/injahow/meting-api/releases)

或者直接使用 Meting.php

```php
// include __DIR__ . '/vendor/autoload.php';
include __DIR__ . '/src/Meting.php';
```

修改代码参数

```php
<?php
// 设置API路径(可默认)
define('API_URI', api_uri());
// 设置中文歌词
define('TLYRIC', true);
// 设置歌单文件缓存及时间
define('CACHE', false);
define('CACHE_TIME', 86400);
// 设置短期缓存-需要安装apcu
define('APCU_CACHE', false);
// 设置AUTH密钥-更改'meting-secret'
define('AUTH', false);
define('AUTH_SECRET', 'meting-secret');

......
```

## Demo

API-Demo:

- [https://api.injahow.cn/meting/?type=url&id=416892104](https://api.injahow.cn/meting/?type=url&id=416892104)
- [https://api.injahow.cn/meting/?type=song&id=591321](https://api.injahow.cn/meting/?type=song&id=591321)
- [https://api.injahow.cn/meting/?type=playlist&id=2619366284](https://api.injahow.cn/meting/?type=playlist&id=2619366284)

APlayer-Demo:

- [https://injahow.github.io/meting-api/](https://injahow.github.io/meting-api/)
- [https://injahow.github.io/meting-api/?id=2904749230](https://injahow.github.io/meting-api/?id=2904749230)

## Thanks

- [APlayer](https://github.com/MoePlayer/APlayer)
- [Meting](https://github.com/metowolf/Meting)
- [MetingJS](https://github.com/metowolf/MetingJS)

## Requirement

PHP 5.4+ and BCMath, Curl, OpenSSL extension installed.

## License

[MIT](https://github.com/injahow/meting-api/blob/master/LICENSE) license.

Copyright (c) 2019 injahow
5 changes: 5 additions & 0 deletions meting-api/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"metowolf/meting": "^1.5"
}
}
Loading

0 comments on commit 834feee

Please sign in to comment.