Skip to content

Commit

Permalink
🎉 支持 APlayer 1.7
Browse files Browse the repository at this point in the history
 - 升级 MetingJS 1.1.1
 - 增强接口安全性
 - 修复虾米音乐 HTTPS
  • Loading branch information
metowolf committed Mar 12, 2018
1 parent 0776242 commit 00f8c05
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 51 deletions.
20 changes: 12 additions & 8 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ private function api()
}

// auth 验证
$EID = $server.'/'.$type.'/'.$id;
$EID = $server.$type.$id;
$salt = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->salt;

if (!empty($salt) && in_array($type, array('lrc','pic','url'))) {
$auth1 = md5($salt.$type.$id.$salt);
if (!empty($salt)) {
$auth1 = md5($salt.$EID.$salt);
$auth2 = $this->request->get('auth');
if (strcmp($auth1, $auth2)) {
http_response_code(403);
Expand Down Expand Up @@ -129,6 +129,10 @@ private function api()
$url = str_replace('http://m10.', 'https://m10.', $url);
}

if ($server == 'xiami') {
$url = str_replace('http://', 'https://', $url);
}

if ($server == 'baidu') {
$url = str_replace('http://zhangmenshiting.qianqian.com', 'https://gss3.baidu.com/y0s1hSulBw92lNKgpU_Z2jR7b2w6buu', $url);
}
Expand All @@ -155,11 +159,11 @@ private function api()
$music = array();
foreach ($data as $vo) {
$music[] = array(
'title' => $vo['name'],
'author' => implode(' / ', $vo['artist']),
'url' => $url.'?server='.$vo['source'].'&type=url&id='.$vo['url_id'].'&auth='.md5($salt.'url'.$vo['url_id'].$salt),
'pic' => $url.'?server='.$vo['source'].'&type=pic&id='.$vo['pic_id'].'&auth='.md5($salt.'pic'.$vo['pic_id'].$salt),
'lrc' => $url.'?server='.$vo['source'].'&type=lrc&id='.$vo['lyric_id'].'&auth='.md5($salt.'lrc'.$vo['lyric_id'].$salt),
'name' => $vo['name'],
'artist' => implode(' / ', $vo['artist']),
'url' => $url.'?server='.$vo['source'].'&type=url&id='.$vo['url_id'].'&auth='.md5($salt.$vo['source'].'url'.$vo['url_id'].$salt),
'cover' => $url.'?server='.$vo['source'].'&type=pic&id='.$vo['pic_id'].'&auth='.md5($salt.$vo['source'].'pic'.$vo['pic_id'].$salt),
'lrc' => $url.'?server='.$vo['source'].'&type=lrc&id='.$vo['lyric_id'].'&auth='.md5($salt.$vo['source'].'lrc'.$vo['lyric_id'].$salt),
);
}
header("Content-Type: application/javascript");
Expand Down
26 changes: 15 additions & 11 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
*
* @package APlayer for Typecho | Meting
* @author METO
* @version 2.1.1
* @version 2.1.2
* @dependence 14.10.10-*
* @link https://github.com/MoePlayer/APlayer-Typecho
*
*/

define('METING_VERSION', '2.1.1');
define('METING_VERSION', '2.1.2');

class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
{
Expand Down Expand Up @@ -84,9 +84,9 @@ public static function config(Typecho_Widget_Helper_Form $form)
);
$form->addInput($t);
$t = new Typecho_Widget_Helper_Form_Element_Radio(
'mode',
array('circulation' => _t('循环'),'single' => _t('单曲'),'order' => _t('列表'),'random' => _t('随机')),
'circulation',
'order',
array('list' => _t('列表'), 'random' => _t('随机')),
'list',
_t('全局播放模式'),
_t('')
);
Expand Down Expand Up @@ -143,7 +143,7 @@ public static function config(Typecho_Widget_Helper_Form $form)
$t = new Typecho_Widget_Helper_Form_Element_Text(
'api',
null,
Typecho_Common::url('action/metingapi', Helper::options()->index)."?server=:server&type=:type&id=:id&r=:r",
Typecho_Common::url('action/metingapi', Helper::options()->index)."?server=:server&type=:type&id=:id&auth=:auth&r=:r",
_t('* 云解析地址'),
_t('示例:https://api.i-meto.com/meting/api?server=:server&type=:type&id=:id&r=:r')
);
Expand Down Expand Up @@ -177,7 +177,7 @@ public static function configHandle($config, $is_init)
{
if (!$is_init) {
if (empty($config['api'])) {
$config['api'] = Typecho_Common::url('action/metingapi', Helper::options()->index)."?server=:server&type=:type&id=:id&r=:r";
$config['api'] = Typecho_Common::url('action/metingapi', Helper::options()->index)."?server=:server&type=:type&id=:id&auth=:auth&r=:r";
}
if ($config['cachetype'] != 'none') {
require_once 'driver/cache.interface.php';
Expand Down Expand Up @@ -215,6 +215,7 @@ public static function header()
$api = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->api;
$dir = Helper::options()->pluginUrl.'/Meting/assets';
$ver = METING_VERSION;
echo "<link rel=\"stylesheet\" href=\"{$dir}/APlayer.min.css?v={$ver}\">\n";
echo "<script type=\"text/javascript\" src=\"{$dir}/APlayer.min.js?v={$ver}\"></script>\n";
echo "<script>var meting_api=\"{$api}\";</script>";
}
Expand Down Expand Up @@ -258,8 +259,8 @@ public static function parseMusic($matches, $setting)
'theme' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->theme?:'red',
'preload' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->preload?:'auto',
'autoplay' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->autoplay?:'false',
'listmaxheight' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->height?:'340px',
'mode' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->mode?:'circulation',
'listMaxHeight' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->height?:'340px',
'order' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->order?:'list',
);
if (isset($t['server'])) {
if (!in_array($t['server'], array('netease','tencent','xiami','baidu','kugou'))) {
Expand All @@ -270,7 +271,10 @@ public static function parseMusic($matches, $setting)
}
$data = $t;

$str .= "<div class=\"aplayer\" data-id=\"{$data['id']}\" data-server=\"{$data['server']}\" data-type=\"{$data['type']}\"";
$salt = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->salt;
$auth = md5($salt.$data['server'].$data['type'].$data['id'].$salt);

$str .= "<div class=\"aplayer\" data-id=\"{$data['id']}\" data-server=\"{$data['server']}\" data-type=\"{$data['type']}\" data-auth=\"{$auth}\"";
if (is_array($setting)) {
foreach ($setting as $key => $vo) {
$player[$key] = $vo;
Expand All @@ -283,7 +287,7 @@ public static function parseMusic($matches, $setting)
} else {
$data = $t;

$str .= "<div class=\"aplayer\" data-title=\"{$data['title']}\" data-author=\"{$data['author']}\" data-url=\"{$data['url']}\" data-pic=\"{$data['pic']}\" data-lrc=\"{$data['lrc']}\"";
$str .= "<div class=\"aplayer\" data-name=\"{$data['title']}\" data-artist=\"{$data['author']}\" data-url=\"{$data['url']}\" data-cover=\"{$data['pic']}\" data-lrc=\"{$data['lrc']}\"";
if (is_array($setting)) {
foreach ($setting as $key => $vo) {
$player[$key] = $vo;
Expand Down
69 changes: 44 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
2. 简单快捷,复制音乐详情页面网址,后台自动生成播放代码
3. 前端 APlayer,后端 Meting 及时更新,保证兼容性及 API 高可用性
4. 支持 MySql、SQLite 数据库
5. **支持 Redis 缓存**
5. **支持 Redis, Memcached 缓存**
6. 支持自定义歌曲播放
7. **自定义 API 支持**

Expand All @@ -36,32 +36,37 @@
- 榜单 http://music.163.com/#/discover/toplist?id=60198

QQ 音乐 https://y.qq.com
- 单曲 https://y.qq.com/n/yqq/song/000jDQWP4JiB3y.html
- 专辑 https://y.qq.com/n/yqq/album/003rytri2FHG3V.html
- 歌手 https://y.qq.com/n/yqq/singer/003Nz2So3XXYek.html
- 歌单 https://y.qq.com/n/yqq/playlist/1144188779.html
- 单曲 https://y.qq.com/n/yqq/song/000jDQWP4JiB3y.html
- 专辑 https://y.qq.com/n/yqq/album/003rytri2FHG3V.html
- 歌手 https://y.qq.com/n/yqq/singer/003Nz2So3XXYek.html
- 歌单 https://y.qq.com/n/yqq/playlist/1144188779.html

虾米音乐 http://www.xiami.com or http://h.xiami.com
- 单曲 http://www.xiami.com/song/bf08DNT3035f
- 专辑 http://www.xiami.com/album/ddOZW6a10eb
- 歌手 http://www.xiami.com/artist/be6yda0f8
- 歌单 http://www.xiami.com/collect/254478782
- 单曲 http://www.xiami.com/song/bf08DNT3035f
- 专辑 http://www.xiami.com/album/ddOZW6a10eb
- 歌手 http://www.xiami.com/artist/be6yda0f8
- 歌单 http://www.xiami.com/collect/254478782

酷狗音乐 http://www.kugou.com
- 单曲 http://www.kugou.com/song/#hash=09E8DE70A24C97B92A29F6A19F3528A2
- 专辑 http://www.kugou.com/yy/album/single/1645030.html
- 歌手 http://www.kugou.com/yy/singer/home/3520.html
- 歌单 http://www.kugou.com/yy/special/single/119859.html
- 单曲 http://www.kugou.com/song/#hash=09E8DE70A24C97B92A29F6A19F3528A2
- 专辑 http://www.kugou.com/yy/album/single/1645030.html
- 歌手 http://www.kugou.com/yy/singer/home/3520.html
- 歌单 http://www.kugou.com/yy/special/single/119859.html

百度音乐 http://music.baidu.com/
- 单曲 http://music.baidu.com/song/268275324
- 专辑 http://music.baidu.com/album/268275533
- 歌手 http://music.baidu.com/artist/1219
- 歌单 http://music.baidu.com/songlist/364201689
- 单曲 http://music.baidu.com/song/268275324
- 专辑 http://music.baidu.com/album/268275533
- 歌手 http://music.baidu.com/artist/1219
- 歌单 http://music.baidu.com/songlist/364201689

## FAQ
Q: pjax 页面切换无法停止播放?
A: 需要另外在主题的回调函数中添加

<details><summary>PJAX 页面切换问题?</summary><br>

需要视情况在主题设置中添加回调函数

### 停止播放

```
if (typeof aplayers !== 'undefined'){
for (var i = 0; i < aplayers.length; i++) {
Expand All @@ -70,14 +75,28 @@ if (typeof aplayers !== 'undefined'){
}
```

Q: 不支持混合歌单?
A: 由于 2.0 版本重写了实现方式,旧的混合歌单将不再支持,建议通过各音乐平台创建歌单的方式添加。
### 重载播放器

```
loadMeting();
```

</details>


<details><summary>不支持混合歌单?</summary><br>

由于 2.x 版本重写了实现方式,旧的混合歌单将不再支持,建议通过各音乐平台创建歌单的方式添加。

</details>


<details><summary>升级问题?</summary><br>

目前插件支持在设置页面差量升级,但由于某些版本做了较大调整,可能造成插件无法使用,可以禁用插件再启用修复。

Q: 部分歌曲失效?
A: 可能 API 失效导致的,可以尝试点击插件升级按钮升级到最新,或填写 cookie 信息。
</details>

Q: PJAX 中播放器不加载?
A: 需要在主题回调函数中添加 `loadMeting();`

更多问题可以通过 issue 页面提交,或者通过 Telegram、邮件向我反馈

Expand Down
Loading

0 comments on commit 00f8c05

Please # to comment.