From 45c5ccf9e9dc7fa9c71ab887b309d75e7f141a4b Mon Sep 17 00:00:00 2001
From: metowolf
Date: Sat, 3 Mar 2018 23:19:26 +0800
Subject: [PATCH] =?UTF-8?q?:cake:=202.1.0,=20=E8=88=B9=E6=96=B0=E7=9A=84?=
=?UTF-8?q?=E7=89=88=E6=9C=AC,=20=E6=94=AF=E6=8C=81Redis=E7=BC=93=E5=AD=98?=
=?UTF-8?q?=E3=80=81=E6=8F=92=E4=BB=B6=E5=8D=87=E7=BA=A7=E3=80=81=E6=96=B0?=
=?UTF-8?q?=E7=9A=84=E9=9F=B3=E4=B9=90=20API?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Action.php | 409 +++++++-----
LICENSE | 2 +-
Plugin.php | 356 ++++++----
README.md | 19 +-
assets/Meting.min.js | 3 +-
assets/editer.js | 2 +-
driver/cache.interface.php | 8 +
driver/mysql.class.php | 57 ++
driver/redis.class.php | 25 +
driver/sqlite.class.php | 56 ++
include/Meting.php | 1281 ++++++++++++++++++++----------------
shasum.txt | 12 +
12 files changed, 1352 insertions(+), 878 deletions(-)
create mode 100644 driver/cache.interface.php
create mode 100644 driver/mysql.class.php
create mode 100644 driver/redis.class.php
create mode 100644 driver/sqlite.class.php
create mode 100644 shasum.txt
diff --git a/Action.php b/Action.php
index 3e3cc6a..b1b42d3 100644
--- a/Action.php
+++ b/Action.php
@@ -1,206 +1,317 @@
on($this->request->is('do=update'))->update();
$this->on($this->request->is('do=parse'))->shortcode();
$this->on($this->request->isGet())->api();
}
- private function check($a,$b){
- if(!in_array($a,array('netease','tencent','baidu','xiami','kugou')))return false;
- if(!in_array($b,array('song','album','search','artist','playlist','lrc','url','pic')))return false;
+ private function check($a, $b)
+ {
+ if (!in_array($a, array('netease','tencent','baidu','xiami','kugou'))) {
+ return false;
+ }
+ if (!in_array($b, array('song','album','search','artist','playlist','lrc','url','pic'))) {
+ return false;
+ }
return true;
}
- private function api(){
+ private function api()
+ {
$this->filterReferer();
- $server=$this->request->get('server');
- $type=$this->request->get('type');
- $id=$this->request->get('id');
+ $server = $this->request->get('server');
+ $type = $this->request->get('type');
+ $id = $this->request->get('id');
- if(!$this->check($server,$type)||empty($id))die('[]');
+ if (!$this->check($server, $type) || empty($id)) {
+ die('[]');
+ }
- if(!extension_loaded('Meting'))include_once 'include/Meting.php';
- $api=new \Metowolf\Meting($server);
+ if (!extension_loaded('Meting')) {
+ include_once 'include/Meting.php';
+ }
+ $api = new \Metowolf\Meting($server);
$api->format(true);
- $EID=md5($server.'/'.$type.'/'.$id);
- $salt=Typecho_Widget::widget('Widget_Options')->plugin('Meting')->salt;
+ if (!extension_loaded('Meting')) {
+ $cachetype = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->cachetype;
+ if ($cachetype != 'none') {
+ $cachehost = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->cachehost;
+ $cacheport = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->cacheport;
+ include_once 'driver/cache.interface.php';
+ include_once 'driver/'.$cachetype.'.class.php';
+ $this->cache = new MetingCache(array(
+ 'host' => $cachehost,
+ 'port' => $cacheport
+ ));
+ }
+ }
+ $api = new \Metowolf\Meting($server);
+ $api->format(true);
+ $cookie = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->cookie;
+ if ($server == 'netease' && !empty($cookie)) {
+ $api->cookie($cookie);
+ }
- if(in_array($type,array('lrc','pic','url'))){
- $auth1=md5($salt.$id.$salt);
- $auth2=$this->request->get('auth');
- if(strcmp($auth1,$auth2)){
+ $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);
+ $auth2 = $this->request->get('auth');
+ if (strcmp($auth1, $auth2)) {
http_response_code(403);
die();
}
}
- if($type=='lrc'){
- $data=$this->cacheRead($EID,60*60*24);
- if(empty($data)){
- $data=$api->lyric($id);
- $this->cacheWrite($EID,$data);
+ if ($type == 'lrc') {
+ $data = $this->cacheRead($EID);
+ if (empty($data)) {
+ $data = $api->lyric($id);
+ $this->cacheWrite($EID, $data, 86400);
}
- $data=json_decode($data,true);
+ $data = json_decode($data, true);
header("Content-Type: application/javascript");
echo $data['lyric'];
- }
- elseif($type=='pic'){
- $data=$this->cacheRead($EID,60*60*24);
- if(empty($data)){
- $data=$api->pic($id,90);
- $this->cacheWrite($EID,$data);
+ } elseif ($type == 'pic') {
+ $data = $this->cacheRead($EID);
+ if (empty($data)) {
+ $data = $api->pic($id, 90);
+ $this->cacheWrite($EID, $data, 86400);
}
- $data=json_decode($data,true);
+ $data = json_decode($data, true);
$this->response->redirect($data['url']);
- }
- elseif($type=='url'){
- $data=$this->cacheRead($EID,60*15);
- if(empty($data)){
- $rate=Typecho_Widget::widget('Widget_Options')->plugin('Meting')->bitrate;
- $cookie=Typecho_Widget::widget('Widget_Options')->plugin('Meting')->cookie;
- if($server=='netease'&&!empty($cookie))$api->cookie($cookie);
- $data=$api->url($id,$rate);
- $this->cacheWrite($EID,$data);
+ } elseif ($type == 'url') {
+ $data = $this->cacheRead($EID);
+ if (empty($data)) {
+ $rate = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->bitrate;
+ $data = $api->url($id, $rate);
+ $this->cacheWrite($EID, $data, 1200);
}
- $data=json_decode($data,true);
- $url=$data['url'];
+ $data = json_decode($data, true);
+ $url = $data['url'];
- if($server=='netease'){
- $url=str_replace('://m7c.','://m7.',$url);
- $url=str_replace('://m8c.','://m8.',$url);
- $url=str_replace('http://m8.','https://m9.',$url);
- $url=str_replace('http://m7.','https://m9.',$url);
- $url=str_replace('http://m10.','https://m10.',$url);
+ if ($server == 'netease') {
+ $url = str_replace('://m7c.', '://m7.', $url);
+ $url = str_replace('://m8c.', '://m8.', $url);
+ $url = str_replace('http://m8.', 'https://m9.', $url);
+ $url = str_replace('http://m7.', 'https://m9.', $url);
+ $url = str_replace('http://m10.', 'https://m10.', $url);
}
- if(empty($url))$url='https://meting.coding.i-meto.com/empty.mp3';
+ if ($server == 'baidu') {
+ $url = str_replace('http://zhangmenshiting.qianqian.com', 'https://gss3.baidu.com/y0s1hSulBw92lNKgpU_Z2jR7b2w6buu', $url);
+ }
+
+ if (empty($url)) {
+ $url = 'https://coding.meting.api.i-meto.com/empty.mp3';
+ }
$this->response->redirect($url);
- }
- else{
- $data=$this->cacheRead($EID,60*60*2);
- if(empty($data)){
- $data=$api->$type($id);
- $this->cacheWrite($EID,$data);
+ } else {
+ $data = $this->cacheRead($EID);
+ if (empty($data)) {
+ $data = $api->$type($id);
+ $this->cacheWrite($EID, $data, 7200);
}
- $data=json_decode($data,1);
- $url=Typecho_Common::url('action/metingapi',Helper::options()->index);
+ $data = json_decode($data, 1);
+ $url = Typecho_Common::url('action/metingapi', Helper::options()->index);
- $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.$vo['url_id'].$salt),
- 'pic' => $url.'?server='.$vo['source'].'&type=pic&id='.$vo['pic_id'].'&auth='.md5($salt.$vo['pic_id'].$salt),
- 'lrc' => $url.'?server='.$vo['source'].'&type=lrc&id='.$vo['lyric_id'].'&auth='.md5($salt.$vo['lyric_id'].$salt),
+ $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),
);
}
header("Content-Type: application/javascript");
echo json_encode($music);
}
-
}
- private function shortcode(){
- $url=$this->request->get('data');
- $url=trim($url);
- if(empty($url))return;
- $server='netease';$id='';$type='';
- if(strpos($url,'163.com')!==false){
- $server='netease';
- if(preg_match('/playlist\?id=(\d+)/i',$url,$id))list($id,$type)=array($id[1],'playlist');
- elseif(preg_match('/toplist\?id=(\d+)/i',$url,$id))list($id,$type)=array($id[1],'playlist');
- elseif(preg_match('/album\?id=(\d+)/i',$url,$id))list($id,$type)=array($id[1],'album');
- elseif(preg_match('/song\?id=(\d+)/i',$url,$id))list($id,$type)=array($id[1],'song');
- elseif(preg_match('/artist\?id=(\d+)/i',$url,$id))list($id,$type)=array($id[1],'artist');
- }
- elseif(strpos($url,'qq.com')!==false){
- $server='tencent';
- if(preg_match('/playlist\/([^\.]*)/i',$url,$id))list($id,$type)=array($id[1],'playlist');
- elseif(preg_match('/album\/([^\.]*)/i',$url,$id))list($id,$type)=array($id[1],'album');
- elseif(preg_match('/song\/([^\.]*)/i',$url,$id))list($id,$type)=array($id[1],'song');
- elseif(preg_match('/singer\/([^\.]*)/i',$url,$id))list($id,$type)=array($id[1],'artist');
- }
- elseif(strpos($url,'xiami.com')!==false){
- $server='xiami';
- if(preg_match('/collect\/(\w+)/i',$url,$id))list($id,$type)=array($id[1],'playlist');
- elseif(preg_match('/album\/(\w+)/i',$url,$id))list($id,$type)=array($id[1],'album');
- elseif(preg_match('/[\/.]\w+\/[songdem]+\/(\w+)/i',$url,$id))list($id,$type)=array($id[1],'song');
- elseif(preg_match('/artist\/(\w+)/i',$url,$id))list($id,$type)=array($id[1],'artist');
- if(!preg_match('/^\d*$/i',$id,$t)){
- $data=self::curl($url);
- preg_match('/'.$type.'\/(\d+)/i',$data,$id);
- $id=$id[1];
- }
- }
- elseif(strpos($url,'kugou.com')!==false){
- $server='kugou';
- if(preg_match('/special\/single\/(\d+)/i',$url,$id))list($id,$type)=array($id[1],'playlist');
- elseif(preg_match('/#hash\=(\w+)/i',$url,$id))list($id,$type)=array($id[1],'song');
- elseif(preg_match('/album\/[single\/]*(\d+)/i',$url,$id))list($id,$type)=array($id[1],'album');
- elseif(preg_match('/singer\/[home\/]*(\d+)/i',$url,$id))list($id,$type)=array($id[1],'artist');
- }
- elseif(strpos($url,'baidu.com')!==false){
- $server='baidu';
- if(preg_match('/songlist\/(\d+)/i',$url,$id))list($id,$type)=array($id[1],'playlist');
- elseif(preg_match('/album\/(\d+)/i',$url,$id))list($id,$type)=array($id[1],'album');
- elseif(preg_match('/song\/(\d+)/i',$url,$id))list($id,$type)=array($id[1],'song');
- elseif(preg_match('/artist\/(\d+)/i',$url,$id))list($id,$type)=array($id[1],'artist');
- }
- else{
- echo "[Meting]\n[Music title=\"歌曲名\" author=\"歌手\" url=\"{$url}\" pic=\"图片文件URL\" lrc=\"歌词文件URL\"/]\n[/Meting]\n";
+ private function shortcode()
+ {
+ $url = $this->request->get('data');
+ $url = trim($url);
+ if (empty($url)) {
return;
}
- echo "[Meting]\n[Music server=\"{$server}\" id=\"{$id}\" type=\"{$type}\"/]\n[/Meting]\n";
+ $server = 'netease';
+ $id = '';
+ $type = '';
+ if (strpos($url, '163.com') !== false) {
+ $server = 'netease';
+ if (preg_match('/playlist\?id=(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'playlist');
+ } elseif (preg_match('/toplist\?id=(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'playlist');
+ } elseif (preg_match('/album\?id=(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'album');
+ } elseif (preg_match('/song\?id=(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'song');
+ } elseif (preg_match('/artist\?id=(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'artist');
+ }
+ } elseif (strpos($url, 'qq.com') !== false) {
+ $server = 'tencent';
+ if (preg_match('/playsquare\/([^\.]*)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'playlist');
+ } elseif (preg_match('/album\/([^\.]*)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'album');
+ } elseif (preg_match('/song\/([^\.]*)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'song');
+ } elseif (preg_match('/singer\/([^\.]*)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'artist');
+ }
+ } elseif (strpos($url, 'xiami.com') !== false) {
+ $server = 'xiami';
+ if (preg_match('/collect\/(\w+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'playlist');
+ } elseif (preg_match('/album\/(\w+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'album');
+ } elseif (preg_match('/[\/.]\w+\/[songdem]+\/(\w+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'song');
+ } elseif (preg_match('/artist\/(\w+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'artist');
+ }
+ if (!preg_match('/^\d*$/i', $id, $t)) {
+ $data = self::curl($url);
+ preg_match('/'.$type.'\/(\d+)/i', $data, $id);
+ $id = $id[1];
+ }
+ } elseif (strpos($url, 'kugou.com') !== false) {
+ $server = 'kugou';
+ if (preg_match('/special\/single\/(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'playlist');
+ } elseif (preg_match('/#hash\=(\w+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'song');
+ } elseif (preg_match('/album\/[single\/]*(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'album');
+ } elseif (preg_match('/singer\/[home\/]*(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'artist');
+ }
+ } elseif (strpos($url, 'baidu.com') !== false) {
+ $server = 'baidu';
+ if (preg_match('/songlist\/(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'playlist');
+ } elseif (preg_match('/album\/(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'album');
+ } elseif (preg_match('/song\/(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'song');
+ } elseif (preg_match('/artist\/(\d+)/i', $url, $id)) {
+ list($id, $type) = array($id[1],'artist');
+ }
+ } else {
+ die("[Meting]\n[Music title=\"歌曲名\" author=\"歌手\" url=\"{$url}\" pic=\"图片文件URL\" lrc=\"歌词文件URL\"/]\n[/Meting]\n");
+ return;
+ }
+ die("[Meting]\n[Music server=\"{$server}\" id=\"{$id}\" type=\"{$type}\"/]\n[/Meting]\n");
+
}
- private function curl($url){
- $curl=curl_init();
- curl_setopt($curl,CURLOPT_URL,$url);
- curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,10);
- curl_setopt($curl,CURLOPT_TIMEOUT,10);
- curl_setopt($curl,CURLOPT_REFERER,$url);
- $result=curl_exec($curl);
+ private function update()
+ {
+ $isAdmin = call_user_func(function () {
+ $hasLogin = $this->widget('Widget_User')->hasLogin();
+ $isAdmin = false;
+ if (!$hasLogin) {
+ return false;
+ }
+ $isAdmin = $this->widget('Widget_User')->pass('administrator', true);
+ return $isAdmin;
+ }, $this);
+ if (!$isAdmin) {
+ die('非管理员,禁止操作!');
+ }
+
+ header("Content-Type: application/javascript");
+
+ $shasum = $this->curl('https://raw.githubusercontent.com/MoePlayer/APlayer-Typecho/master/shasum.txt');
+
+ echo "获取最新特征库...\n";
+ echo $shasum."\n\n";
+
+ $shasum = explode("\n", $shasum);
+ array_pop($shasum);
+
+ echo "开始检查本地文件...\n";
+
+ foreach ($shasum as $remote) {
+ list($remote_sha256, $filename) = explode(' ', $remote);
+ if (!file_exists(__DIR__.'/'.$filename)) {
+ continue;
+ }
+ $local_sha256 = hash('sha256', file_get_contents(__DIR__.'/'.$filename));
+ if (!hash_equals($local_sha256, $remote_sha256)) {
+ echo "下载 ".$filename;
+ $url = 'https://raw.githubusercontent.com/MoePlayer/APlayer-Typecho/master'.substr($filename, 1);
+
+ if (file_put_contents(__DIR__.'/'.$filename, $this->curl($url))) {
+ echo " (OK)\n";
+ } else {
+ die("\n下载失败,错误信息: $url\n");
+ }
+ } else {
+ echo "无需更新 ".$filename."\n";
+ }
+ }
+
+ echo "\n\n如果插件出现错误,建议禁用再启用一次插件完成升级。";
+ die();
+ }
+
+ private function curl($url)
+ {
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
+ curl_setopt($curl, CURLOPT_TIMEOUT, 10);
+ curl_setopt($curl, CURLOPT_REFERER, $url);
+ $result = curl_exec($curl);
curl_close($curl);
return $result;
}
- private function cacheWrite($k,$v){
- if(empty($v)||is_null($v))return;
- $db=Typecho_Db::get();
- $insert=$db->insert('table.metingv1')->rows(array('id'=>md5($k),'value'=>$v,'last'=>time()));
- return $db->query($insert);
+ private function cacheWrite($k, $v, $t)
+ {
+ if (!isset($this->cache)) {
+ return;
+ }
+ return $this->cache->set($k, $v, $t);
}
- private function cacheRead($k,$t=3600){
- $db=Typecho_Db::get();
- $query=$db->select('value','last')->from('table.metingv1')->where('id=?',md5($k));
- $result=$db->fetchRow($query);
-
- if(isset($result['value'])){
- if(time()-$result['last']>$t){
- $delete=$db->delete('table.metingv1')->where('last',time()-$t);
- $db->query($delete);
- return false;
- }
- header("Meting-Cache: HIT");
- return $result['value'];
- }
- else{
- header("Meting-Cache: MISS");
+ private function cacheRead($k)
+ {
+ if (!isset($this->cache)) {
return false;
}
+ return $this->cache->get($k);
}
- private function filterReferer(){
- if(isset($_SERVER['HTTP_REFERER'])&&strpos($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])===false){
+ private function filterReferer()
+ {
+ $salt = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->salt;
+ if (empty($salt)) {
+ header("Access-Control-Allow-Origin: *");
+ header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie");
+ return;
+ }
+ if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false) {
http_response_code(403);
die('[]');
}
diff --git a/LICENSE b/LICENSE
index 1a5c137..81809b5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2017 METO
+Copyright (c) 2018 METO
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Plugin.php b/Plugin.php
index 7a7b252..46c0465 100644
--- a/Plugin.php
+++ b/Plugin.php
@@ -1,18 +1,20 @@
contentEx=array('Meting_Plugin','playerReplace');
- Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx=array('Meting_Plugin','playerReplace');
- Typecho_Plugin::factory('Widget_Archive')->header=array('Meting_Plugin','header');
- Typecho_Plugin::factory('Widget_Archive')->footer=array('Meting_Plugin','footer');
+ Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('Meting_Plugin','playerReplace');
+ Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('Meting_Plugin','playerReplace');
+ Typecho_Plugin::factory('Widget_Archive')->header = array('Meting_Plugin','header');
+ Typecho_Plugin::factory('Widget_Archive')->footer = array('Meting_Plugin','footer');
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('Meting_Plugin', 'addButton');
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('Meting_Plugin', 'addButton');
}
@@ -42,8 +45,8 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
* @return void
* @throws Typecho_Plugin_Exception
*/
- public static function deactivate(){
- Meting_Plugin::uninstall();
+ public static function deactivate()
+ {
Helper::removeAction("metingapi");
}
@@ -54,56 +57,114 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
- public static function config(Typecho_Widget_Helper_Form $form){
+ public static function config(Typecho_Widget_Helper_Form $form)
+ {
$t = new Typecho_Widget_Helper_Form_Element_Text(
- 'theme', null, '#ad7a86',
+ 'theme',
+ null,
+ '#ad7a86',
_t('播放器颜色'),
- _t('播放器默认的主题颜色,支持如 #372e21、#75c、red,该设定会被[Meting]标签中的theme属性覆盖,默认为 #ad7a86'));
+ _t('播放器默认的主题颜色,支持如 #372e21、#75c、red,该设定会被[Meting]标签中的theme属性覆盖,默认为 #ad7a86')
+ );
$form->addInput($t);
$t = new Typecho_Widget_Helper_Form_Element_Text(
- 'height', null, '340px',
+ 'height',
+ null,
+ '340px',
_t('播放器列表最大高度'),
- _t(''));
+ _t('')
+ );
$form->addInput($t);
$t = new Typecho_Widget_Helper_Form_Element_Radio(
- 'autoplay', array('true'=>_t('是'),'false'=>_t('否')),'false',
+ 'autoplay',
+ array('true' => _t('是'),'false' => _t('否')),
+ 'false',
_t('全局自动播放'),
- _t(''));
+ _t('')
+ );
$form->addInput($t);
$t = new Typecho_Widget_Helper_Form_Element_Radio(
- 'mode', array('circulation'=>_t('循环'),'single'=>_t('单曲'),'order'=>_t('列表'),'random'=>_t('随机')),'circulation',
+ 'mode',
+ array('circulation' => _t('循环'),'single' => _t('单曲'),'order' => _t('列表'),'random' => _t('随机')),
+ 'circulation',
_t('全局播放模式'),
- _t(''));
+ _t('')
+ );
$form->addInput($t);
- $t= new Typecho_Widget_Helper_Form_Element_Radio(
- 'preload', array('auto'=>_t('自动'),'none'=>_t('不加载'),'metadata'=>_t('加载元数据')), 'auto',
+ $t = new Typecho_Widget_Helper_Form_Element_Radio(
+ 'preload',
+ array('auto' => _t('自动'),'none' => _t('不加载'),'metadata' => _t('加载元数据')),
+ 'auto',
_t('预加载属性'),
- _t(''));
+ _t('')
+ );
$form->addInput($t);
- $t= new Typecho_Widget_Helper_Form_Element_Radio(
- 'bitrate', array('128'=>_t('流畅品质'),'192'=>_t('清晰品质'),'320'=>_t('高品质')), '192',
+
+ $list = array(
+ 'none' => _t('关闭'),
+ 'redis' => _t('Redis'),
+ 'mysql' => _t('Mysql'),
+ 'sqlite' => _t('SQLite')
+ );
+ $t = new Typecho_Widget_Helper_Form_Element_Radio(
+ 'cachetype',
+ $list,
+ 'none',
+ _t('缓存驱动'),
+ _t('缓存歌曲解析信息,降低服务器压力')
+ );
+ $form->addInput($t);
+ $t = new Typecho_Widget_Helper_Form_Element_Text(
+ 'cachehost',
+ null,
+ '127.0.0.1',
+ _t('缓存服务地址'),
+ _t('通常为 localhost, 127.0.0.1')
+ );
+ $form->addInput($t);
+ $t = new Typecho_Widget_Helper_Form_Element_Text(
+ 'cacheport',
+ null,
+ '6379',
+ _t('缓存服务端口'),
+ _t('默认端口 memcache: 11211, Redis: 6379, Mysql: 3306')
+ );
+ $form->addInput($t);
+
+ $t = new Typecho_Widget_Helper_Form_Element_Radio(
+ 'bitrate',
+ array('128' => _t('流畅品质 128K'),'192' => _t('清晰品质 192K'),'320' => _t('高品质 320K')),
+ '192',
_t('默认音质'),
- _t(''));
+ _t('')
+ );
$form->addInput($t);
$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",
- _t('云解析地址'),
- _t('示例:https://api.i-meto.com/meting/api?server=:server&type=:type&id=:id&r=:r'));
+ 'api',
+ null,
+ Typecho_Common::url('action/metingapi', Helper::options()->index)."?server=:server&type=:type&id=:id&r=:r",
+ _t('* 云解析地址'),
+ _t('示例:https://api.i-meto.com/meting/api?server=:server&type=:type&id=:id&r=:r')
+ );
$form->addInput($t);
$t = new Typecho_Widget_Helper_Form_Element_Text(
- 'salt', null, md5(time()."Meting"),
- _t('接口保护'),
- _t('加盐保护 API 接口不被滥用,自动生成无需设置。'));
+ 'salt',
+ null,
+ Typecho_Common::randString(32),
+ _t('* 接口保护'),
+ _t('加盐保护 API 接口不被滥用,自动生成无需设置。')
+ );
$form->addInput($t);
$t = new Typecho_Widget_Helper_Form_Element_Textarea(
- 'cookie', null, '',
- _t('网易云音乐 Cookie (高级)'),
- _t('如果您是网易云音乐的会员,可以将您的 cookie 填入此处来获取云盘等付费资源,听歌将不会计入下载次数。
如果不知道这是什么意思,忽略即可。'));
- $form->addInput($t);
- $t = new Typecho_Widget_Helper_Form_Element_Radio(
- 'clean', array(_t('关闭'), _t('清除所有缓存')), 0,
- _t('保存时清除所有缓存'));
+ 'cookie',
+ null,
+ '',
+ _t('* 网易云音乐 Cookie'),
+ _t('如果您是网易云音乐的会员,可以将您的 cookie 填入此处来获取云盘等付费资源,听歌将不会计入下载次数。
如果不知道这是什么意思,忽略即可。')
+ );
$form->addInput($t);
+
+ echo '';
}
/**
@@ -113,20 +174,32 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
*/
public static function configHandle($config, $is_init)
{
- if($is_init!=true){
- if($config['api']==""){
- $config['api']=Typecho_Common::url('action/metingapi',Helper::options()->index)."?server=:server&type=:type&id=:id&r=:r";
+ 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";
}
- if($config['clean']==1){
- self::clean();
- $config['clean']=0;
+ if ($config['cachetype'] != 'none') {
+ require_once 'driver/cache.interface.php';
+ require_once 'driver/'.$config['cachetype'].'.class.php';
+ try {
+ $cache = new MetingCache(array(
+ 'host' => $config['cachehost'],
+ 'port' => $config['cacheport']
+ ));
+ $cache->install();
+ $cache->flush();
+ } catch (Exception $e) {
+ throw new Typecho_Plugin_Exception(_t($e->getMessage()));
+ }
}
}
Helper::configPlugin('Meting', $config);
}
- public static function personalConfig(Typecho_Widget_Helper_Form $form){}
+ public static function personalConfig(Typecho_Widget_Helper_Form $form)
+ {
+ }
/**
* 获取插件配置面板
@@ -135,100 +208,125 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
- public static function header(){
- $api=Typecho_Widget::widget('Widget_Options')->plugin('Meting')->api;
- $dir=Helper::options()->pluginUrl.'/Meting/assets';
- $ver=METING_VERSION;
+ public static function header()
+ {
+ $api = Typecho_Widget::widget('Widget_Options')->plugin('Meting')->api;
+ $dir = Helper::options()->pluginUrl.'/Meting/assets';
+ $ver = METING_VERSION;
echo "\n";
echo "";
}
- public static function footer(){
- $dir=Helper::options()->pluginUrl.'/Meting/assets';
- $ver=METING_VERSION;
+ public static function footer()
+ {
+ $dir = Helper::options()->pluginUrl.'/Meting/assets';
+ $ver = METING_VERSION;
echo "\n";
}
- public static function playerReplace($data,$widget,$last){
- $text=empty($last)?$data:$last;
- if($widget instanceof Widget_Archive){
- $data=$text;
- $pattern=self::get_shortcode_regex(array('Meting'));
- $text=preg_replace_callback("/$pattern/",array('Meting_Plugin','parseCallback'),$data);
+ public static function playerReplace($data, $widget, $last)
+ {
+ $text = empty($last)?$data:$last;
+ if ($widget instanceof Widget_Archive) {
+ $data = $text;
+ $pattern = self::get_shortcode_regex(array('Meting'));
+ $text = preg_replace_callback("/$pattern/", array('Meting_Plugin','parseCallback'), $data);
}
return $text;
}
- public static function parseCallback($matches){
- $setting=self::shortcode_parse_atts(htmlspecialchars_decode($matches[3]));
- $matches[5]=htmlspecialchars_decode($matches[5]);
- $pattern=self::get_shortcode_regex(array('Music'));
- preg_match_all("/$pattern/",$matches[5],$all);
- if(sizeof($all[3]))return Meting_Plugin::parseMusic($all[3],$setting);
+ public static function parseCallback($matches)
+ {
+ $setting = self::shortcode_parse_atts(htmlspecialchars_decode($matches[3]));
+ $matches[5] = htmlspecialchars_decode($matches[5]);
+ $pattern = self::get_shortcode_regex(array('Music'));
+ preg_match_all("/$pattern/", $matches[5], $all);
+ if (sizeof($all[3])) {
+ return Meting_Plugin::parseMusic($all[3], $setting);
+ }
}
- public static function parseMusic($matches,$setting){
- $data=array();
- $str="";
- foreach($matches as $vo){
- $t=self::shortcode_parse_atts(htmlspecialchars_decode($vo));
- $player=array(
- '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',
+ public static function parseMusic($matches, $setting)
+ {
+ $data = array();
+ $str = "";
+ foreach ($matches as $vo) {
+ $t = self::shortcode_parse_atts(htmlspecialchars_decode($vo));
+ $player = array(
+ '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',
+ 'mode' => Typecho_Widget::widget('Widget_Options')->plugin('Meting')->mode?:'circulation',
);
- if(isset($t['server'])){
- if(!in_array($t['server'],array('netease','tencent','xiami','baidu','kugou')))continue;
- if(!in_array($t['type'],array('search','album','playlist','artist','song')))continue;
- $data=$t;
+ if (isset($t['server'])) {
+ if (!in_array($t['server'], array('netease','tencent','xiami','baidu','kugou'))) {
+ continue;
+ }
+ if (!in_array($t['type'], array('search','album','playlist','artist','song'))) {
+ continue;
+ }
+ $data = $t;
- $str.="
插入音乐
'+ - '请在下方的输入框内输入要插入的音乐地址,如多个地址请用回车隔开'+ + '
请在下方的输入框内输入要插入的音乐地址'+ '
'+ '