Skip to content

Commit 834feee

Browse files
committed
更换了api
1 parent 2fac54f commit 834feee

38 files changed

+5136
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ HeoMusic支持URL参数 `https://music.zhheo.com/?id=`+ id +`&server=` + server
111111

112112
## 许可
113113

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

116116
图标采用remixicon,使用 Apache 协议
117117

css/APlayer.css

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/APlayer.min.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/Meting.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
class MetingJSElement extends HTMLElement {
2+
3+
connectedCallback() {
4+
if (window.APlayer && window.fetch) {
5+
this._init()
6+
this._parse()
7+
}
8+
}
9+
10+
disconnectedCallback() {
11+
if (!this.lock) {
12+
this.aplayer.destroy()
13+
}
14+
}
15+
16+
_camelize(str) {
17+
return str
18+
.replace(/^[_.\- ]+/, '')
19+
.toLowerCase()
20+
.replace(/[_.\- ]+(\w|$)/g, (m, p1) => p1.toUpperCase())
21+
}
22+
23+
_init() {
24+
let config = {}
25+
for (let i = 0; i < this.attributes.length; i += 1) {
26+
config[this._camelize(this.attributes[i].name)] = this.attributes[i].value
27+
}
28+
let keys = [
29+
'server', 'type', 'id', 'api', 'auth',
30+
'auto', 'lock',
31+
'name', 'title', 'artist', 'author', 'url', 'cover', 'pic', 'lyric', 'lrc',
32+
]
33+
this.meta = {}
34+
for (let key of keys) {
35+
this.meta[key] = config[key]
36+
delete config[key]
37+
}
38+
this.config = config
39+
40+
this.api = this.meta.api || window.meting_api || 'https://music.zhheo.com/meting-api/?server=:server&type=:type&id=:id&r=:r'
41+
if (this.meta.auto) this._parse_link()
42+
}
43+
44+
_parse_link() {
45+
let rules = [
46+
['music.163.com.*song.*id=(\\d+)', 'netease', 'song'],
47+
['music.163.com.*album.*id=(\\d+)', 'netease', 'album'],
48+
['music.163.com.*artist.*id=(\\d+)', 'netease', 'artist'],
49+
['music.163.com.*playlist.*id=(\\d+)', 'netease', 'playlist'],
50+
['music.163.com.*discover/toplist.*id=(\\d+)', 'netease', 'playlist'],
51+
['y.qq.com.*song/(\\w+).html', 'tencent', 'song'],
52+
['y.qq.com.*album/(\\w+).html', 'tencent', 'album'],
53+
['y.qq.com.*singer/(\\w+).html', 'tencent', 'artist'],
54+
['y.qq.com.*playsquare/(\\w+).html', 'tencent', 'playlist'],
55+
['y.qq.com.*playlist/(\\w+).html', 'tencent', 'playlist'],
56+
['xiami.com.*song/(\\w+)', 'xiami', 'song'],
57+
['xiami.com.*album/(\\w+)', 'xiami', 'album'],
58+
['xiami.com.*artist/(\\w+)', 'xiami', 'artist'],
59+
['xiami.com.*collect/(\\w+)', 'xiami', 'playlist'],
60+
]
61+
62+
for (let rule of rules) {
63+
let patt = new RegExp(rule[0])
64+
let res = patt.exec(this.meta.auto)
65+
if (res !== null) {
66+
this.meta.server = rule[1]
67+
this.meta.type = rule[2]
68+
this.meta.id = res[1]
69+
return
70+
}
71+
}
72+
}
73+
74+
_parse() {
75+
if (this.meta.url) {
76+
let result = {
77+
name: this.meta.name || this.meta.title || 'Audio name',
78+
artist: this.meta.artist || this.meta.author || 'Audio artist',
79+
url: this.meta.url,
80+
cover: this.meta.cover || this.meta.pic,
81+
lrc: this.meta.lrc || this.meta.lyric || '',
82+
type: this.meta.type || 'auto',
83+
}
84+
if (!result.lrc) {
85+
this.meta.lrcType = 0
86+
}
87+
if (this.innerText) {
88+
result.lrc = this.innerText
89+
this.meta.lrcType = 2
90+
}
91+
this._loadPlayer([result])
92+
return
93+
}
94+
95+
let url = this.api
96+
.replace(':server', this.meta.server)
97+
.replace(':type', this.meta.type)
98+
.replace(':id', this.meta.id)
99+
.replace(':auth', this.meta.auth)
100+
.replace(':r', Math.random())
101+
102+
fetch(url)
103+
.then(res => res.json())
104+
.then(result => this._loadPlayer(result))
105+
}
106+
107+
_loadPlayer(data) {
108+
109+
let defaultOption = {
110+
audio: data,
111+
mutex: true,
112+
lrcType: this.meta.lrcType || 3,
113+
storageName: 'metingjs'
114+
}
115+
116+
if (!data.length) return
117+
118+
let options = {
119+
...defaultOption,
120+
...this.config,
121+
}
122+
for (let optkey in options) {
123+
if (options[optkey] === 'true' || options[optkey] === 'false') {
124+
options[optkey] = (options[optkey] === 'true')
125+
}
126+
}
127+
128+
let div = document.createElement('div')
129+
options.container = div
130+
this.appendChild(div)
131+
132+
this.aplayer = new APlayer(options)
133+
}
134+
135+
}
136+
137+
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;')
138+
139+
if (window.customElements && !window.customElements.get('meting-js')) {
140+
window.MetingJSElement = MetingJSElement
141+
window.customElements.define('meting-js', MetingJSElement)
142+
}

js/Meting2.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function loadMusicScript() {
3232
if (typeof localMusic === 'undefined' || !Array.isArray(localMusic) || localMusic.length === 0) {
3333
// 如果 localMusic 为空数组或未定义,加载 Meting2.min.js
3434
var script = document.createElement('script');
35-
script.src = './js/Meting2.min.js';
35+
script.src = './js/Meting.js';
3636
document.body.appendChild(script);
3737
} else {
3838
// 否则加载 localEngine.js

main.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ body {
114114
gap: 32px;
115115
width: 40%;
116116
height: 100%;
117+
max-width: 332px;
117118
}
118119

119120
#heoMusic-page.localMusic {
@@ -146,8 +147,8 @@ body #nav-music {
146147
}
147148
#heoMusic-page .aplayer-pic {
148149
float: none;
149-
width: 200px;
150-
height: 200px;
150+
width: 300px;
151+
height: 300px;
151152
border-radius: 12px;
152153
z-index: 999;
153154
position: relative;
@@ -323,7 +324,7 @@ body #nav-music {
323324
margin-left: 15px;
324325
}
325326

326-
#heoMusic-page .aplayer-info .aplayer-time .aplayer-icon::before {
327+
#heoMusic-page .aplayer-info .aplayer-time .aplayer-volume-wrap::before {
327328
content: '';
328329
position: absolute;
329330
padding: 8px;
@@ -344,7 +345,8 @@ body #nav-music {
344345

345346
#heoMusic-page .aplayer-list {
346347
width: 100%;
347-
height: calc(100vh - 445px);
348+
height: 100%;
349+
flex: 1;
348350
min-width: 200px;
349351
}
350352

meting-api/.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = false
8+
indent_style = space
9+
10+
[*.md]
11+
indent_size = 2
12+
insert_final_newline = false
13+
trim_trailing_whitespace = false
14+
15+
[*.php]
16+
indent_size = 4
17+
insert_final_newline = true

meting-api/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 injahow
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

meting-api/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<p align="center">
2+
<img src="https://user-images.githubusercontent.com/2666735/30651452-58ae6c88-9deb-11e7-9e13-6beae3f6c54c.png" alt="Meting">
3+
</p>
4+
5+
# meting-api
6+
7+
## Descriptions
8+
9+
- 这是基于 [Meting](https://github.com/metowolf/Meting) 创建的 APlayer API
10+
- 灵感源于 [https://api.fczbl.vip/163/](https://api.fczbl.vip/163/)
11+
- 部分参考 [Meting-API](https://github.com/metowolf/Meting-API)
12+
13+
## Build Setup
14+
15+
```bash
16+
# 克隆仓库
17+
$ git clone https://github.com/injahow/meting-api.git
18+
19+
$ cd meting-api
20+
21+
# 安装依赖
22+
$ composer install
23+
24+
# 或者使用中国镜像
25+
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
26+
27+
$ composer install
28+
```
29+
30+
或者下载打包文件[https://github.com/injahow/meting-api/releases](https://github.com/injahow/meting-api/releases)
31+
32+
或者直接使用 Meting.php
33+
34+
```php
35+
// include __DIR__ . '/vendor/autoload.php';
36+
include __DIR__ . '/src/Meting.php';
37+
```
38+
39+
修改代码参数
40+
41+
```php
42+
<?php
43+
// 设置API路径(可默认)
44+
define('API_URI', api_uri());
45+
// 设置中文歌词
46+
define('TLYRIC', true);
47+
// 设置歌单文件缓存及时间
48+
define('CACHE', false);
49+
define('CACHE_TIME', 86400);
50+
// 设置短期缓存-需要安装apcu
51+
define('APCU_CACHE', false);
52+
// 设置AUTH密钥-更改'meting-secret'
53+
define('AUTH', false);
54+
define('AUTH_SECRET', 'meting-secret');
55+
56+
......
57+
```
58+
59+
## Demo
60+
61+
API-Demo:
62+
63+
- [https://api.injahow.cn/meting/?type=url&id=416892104](https://api.injahow.cn/meting/?type=url&id=416892104)
64+
- [https://api.injahow.cn/meting/?type=song&id=591321](https://api.injahow.cn/meting/?type=song&id=591321)
65+
- [https://api.injahow.cn/meting/?type=playlist&id=2619366284](https://api.injahow.cn/meting/?type=playlist&id=2619366284)
66+
67+
APlayer-Demo:
68+
69+
- [https://injahow.github.io/meting-api/](https://injahow.github.io/meting-api/)
70+
- [https://injahow.github.io/meting-api/?id=2904749230](https://injahow.github.io/meting-api/?id=2904749230)
71+
72+
## Thanks
73+
74+
- [APlayer](https://github.com/MoePlayer/APlayer)
75+
- [Meting](https://github.com/metowolf/Meting)
76+
- [MetingJS](https://github.com/metowolf/MetingJS)
77+
78+
## Requirement
79+
80+
PHP 5.4+ and BCMath, Curl, OpenSSL extension installed.
81+
82+
## License
83+
84+
[MIT](https://github.com/injahow/meting-api/blob/master/LICENSE) license.
85+
86+
Copyright (c) 2019 injahow

meting-api/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"metowolf/meting": "^1.5"
4+
}
5+
}

0 commit comments

Comments
 (0)