-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
5,136 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require": { | ||
"metowolf/meting": "^1.5" | ||
} | ||
} |
Oops, something went wrong.