mirror of
https://github.com/MoePlayer/APlayer-Typecho.git
synced 2024-12-21 20:30:24 +08:00
Merge pull request #5 from metowolf/sqlite
[1.1.0] 支持 SQLite 数据库,更新 Meting、APlayer 版本
This commit is contained in:
commit
dc4ab0af25
29
Action.php
29
Action.php
@ -96,7 +96,7 @@ class Meting_Action extends Typecho_Widget implements Widget_Interface_Do {
|
||||
$EID=md5('js/'.$vo['server'].'/'.$vo['type'].'/'.$vo['id']);
|
||||
$t=self::cacheRead($EID,60*60*24*3);
|
||||
if(!$t){
|
||||
$API=(new Meting($vo['server']))->format(true);
|
||||
$API=(new \Metowolf\Meting($vo['server']))->format(true);
|
||||
$t=call_user_func_array(array($API,$vo['type']),array($vo['id']));
|
||||
$t=json_decode($t,1);
|
||||
self::cacheWrite($EID,$t);
|
||||
@ -149,11 +149,11 @@ class Meting_Action extends Typecho_Widget implements Widget_Interface_Do {
|
||||
$cachekey="url/{$site}/{$id}/{$rate}";
|
||||
$data=self::cacheRead($cachekey,60*15);
|
||||
if(!$data){
|
||||
$data=(new Meting($site))->url($id,$rate);
|
||||
$data=(new \Metowolf\Meting($site))->format()->url($id,$rate);
|
||||
$data=json_decode($data,1);
|
||||
self::cacheWrite($cachekey,$data);
|
||||
}
|
||||
if(empty($data['url']))$data['url']='https://oc1pe0tot.qnssl.com/copyright.m4a';
|
||||
if(empty($data['url']))$data['url']="https://api.i-meto.com/music/copyright?s={$site}id={$id}";
|
||||
$this->response->redirect($data['url']);
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ class Meting_Action extends Typecho_Widget implements Widget_Interface_Do {
|
||||
$cachekey="pic/{$site}/{$id}";
|
||||
$data=self::cacheRead($cachekey,60*60*24*30);
|
||||
if(!$data){
|
||||
$data=(new Meting($site))->pic($id,90);
|
||||
$data=(new \Metowolf\Meting($site))->pic($id,90);
|
||||
$data=json_decode($data,1);
|
||||
self::cacheWrite($cachekey,$data);
|
||||
}
|
||||
@ -180,7 +180,7 @@ class Meting_Action extends Typecho_Widget implements Widget_Interface_Do {
|
||||
$cachekey="lyric/{$site}/{$id}";
|
||||
$data=self::cacheRead($cachekey,60*60*24*10);
|
||||
if(!$data){
|
||||
$data=(new Meting($site))->format(true)->lyric($id);
|
||||
$data=(new \Metowolf\Meting($site))->format(true)->lyric($id);
|
||||
$data=json_decode($data,1);
|
||||
self::cacheWrite($cachekey,$data);
|
||||
}
|
||||
@ -208,25 +208,24 @@ class Meting_Action extends Typecho_Widget implements Widget_Interface_Do {
|
||||
}
|
||||
|
||||
private function cacheWrite($k,$v){
|
||||
if(!is_array($v))return;
|
||||
if(!is_array($v)||is_null($v))return;
|
||||
$db=Typecho_Db::get();
|
||||
$prefix=$db->getPrefix();
|
||||
$insert=$db->insert($prefix.'meting')->rows(array('id'=>sha1($k),'value'=>serialize($v),'date'=>time()));
|
||||
$insert=$db->insert('table.metingv1')->rows(array('id'=>md5($k),'value'=>serialize($v),'last'=>time()));
|
||||
return $db->query($insert);
|
||||
}
|
||||
|
||||
private function cacheRead($k,$t=60*60){
|
||||
$db=Typecho_Db::get();
|
||||
$prefix=$db->getPrefix();
|
||||
$query=$db->select('value','date')->from($prefix.'meting')->where('id=?',sha1($k));
|
||||
$result=$db->fetchAll($query);
|
||||
if(sizeof($result)){
|
||||
if(time()-$result[0]['date']>$t){
|
||||
$delete=$db->delete($prefix.'meting')->where('date<?',time()-$t);
|
||||
$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;
|
||||
}
|
||||
return unserialize($result[0]['value']);
|
||||
return unserialize($result['value']);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
37
Plugin.php
37
Plugin.php
@ -6,13 +6,13 @@ if(!defined('__TYPECHO_ROOT_DIR__'))exit;
|
||||
*
|
||||
* @package Meting
|
||||
* @author METO
|
||||
* @version 1.0.5
|
||||
* @version 1.1.0
|
||||
* @dependence 14.10.10-*
|
||||
* @link https://github.com/metowolf/Meting-Typecho-Plugin
|
||||
*
|
||||
*/
|
||||
|
||||
define('METING_VERSION','1.0.5');
|
||||
define('METING_VERSION','1.1.0');
|
||||
|
||||
class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
|
||||
{
|
||||
@ -192,40 +192,27 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
|
||||
|
||||
public static function install(){
|
||||
$db=Typecho_Db::get();
|
||||
$prefix=$db->getPrefix();
|
||||
$scripts=file_get_contents(__DIR__.'/include/install.sql');
|
||||
$scripts=str_replace('typecho_',$prefix,$scripts);
|
||||
$scripts=explode(';', $scripts);
|
||||
$dbname=$db->getPrefix().'metingv1';
|
||||
try{
|
||||
foreach($scripts as $script){
|
||||
$script=trim($script);
|
||||
if($script){
|
||||
$db->query($script,Typecho_Db::WRITE);
|
||||
}
|
||||
}
|
||||
$db->query("CREATE TABLE IF NOT EXISTS {$dbname} (
|
||||
id CHAR(32) PRIMARY KEY NOT NULL UNIQUE,
|
||||
value TEXT NOT NULL,
|
||||
last int NOT NULL
|
||||
)");
|
||||
}catch(Typecho_Db_Exception $e){
|
||||
$code=$e->getCode();
|
||||
if($code=='42S01'||$code==1050)return;
|
||||
throw new Typecho_Plugin_Exception('数据表建立失败,插件启用失败。错误号: '.$code);
|
||||
throw new Typecho_Plugin_Exception('插件启用失败。错误号:'.$code);
|
||||
}
|
||||
}
|
||||
|
||||
public static function uninstall(){
|
||||
$db=Typecho_Db::get();
|
||||
$prefix=$db->getPrefix();
|
||||
$scripts=file_get_contents(__DIR__.'/include/uninstall.sql');
|
||||
$scripts=str_replace('typecho_',$prefix,$scripts);
|
||||
$scripts=explode(';', $scripts);
|
||||
$dbname=$db->getPrefix().'metingv1';
|
||||
try{
|
||||
foreach($scripts as $script){
|
||||
$script=trim($script);
|
||||
if($script){
|
||||
$db->query($script,Typecho_Db::WRITE);
|
||||
}
|
||||
}
|
||||
$db->query("DROP TABLE IF EXISTS {$dbname};");
|
||||
}catch(Typecho_Db_Exception $e){
|
||||
$code=$e->getCode();
|
||||
throw new Typecho_Plugin_Exception('数据表清空失败,插件禁用失败。错误号: '.$code);
|
||||
throw new Typecho_Plugin_Exception('插件禁用失败。错误号:'.$code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
![](http://ww2.sinaimg.cn/large/a15b4afegw1fbg1l7wn09j20fw05gq34)
|
||||
|
||||
# Meting for Typecho
|
||||
在 Typecho 中使用 APlayer 播放在线音乐吧~
|
||||
[在线演示](http://demo.i-meto.com)
|
||||
[发布页面](https://i-meto.com/meting-typecho/)
|
||||
[在线演示](https://demo.i-meto.com)
|
||||
|
||||
## 介绍
|
||||
1. 支持国内五大音乐平台(网易云、QQ、虾米、百度、酷狗)的单曲/专辑/歌单播放
|
||||
2. 简单快捷,复制音乐详情页面网址,后台自动生成播放代码
|
||||
3. **支持不同音乐平台歌曲混合播放**
|
||||
4. 前端 Aplayer,后端 Meting 及时更新,保证兼容性及 API 高可用性
|
||||
5. 支持 MySql、SQLite 数据库
|
||||
|
||||
## 声明
|
||||
本作品仅供个人学习研究使用,请勿将其用作商业用途。
|
||||
|
9
assets/APlayer.min.js
vendored
9
assets/APlayer.min.js
vendored
File diff suppressed because one or more lines are too long
@ -2,12 +2,12 @@
|
||||
/*!
|
||||
* Meting music framework
|
||||
* https://i-meto.com
|
||||
* Version 1.3.0
|
||||
* Version 1.3.2.1
|
||||
*
|
||||
* Copyright 2017, METO Sheel <i@i-meto.com>
|
||||
* Released under the MIT license
|
||||
*/
|
||||
|
||||
namespace Metowolf;
|
||||
class Meting
|
||||
{
|
||||
protected $_SITE;
|
||||
@ -72,13 +72,15 @@ class Meting
|
||||
}
|
||||
curl_close($curl);
|
||||
if ($error) {
|
||||
return json_encode(array(
|
||||
'error' => $error,
|
||||
'info' => $info,
|
||||
'status' => $status,
|
||||
));
|
||||
return json_encode(
|
||||
array(
|
||||
'error' => $error,
|
||||
'info' => $info,
|
||||
'status' => $status,
|
||||
)
|
||||
);
|
||||
}
|
||||
if (isset($API['decode'])) {
|
||||
if ($this->_FORMAT&&isset($API['decode'])) {
|
||||
$data=call_user_func_array(array($this,$API['decode']), array($data));
|
||||
}
|
||||
if ($this->_FORMAT&&isset($API['format'])) {
|
||||
@ -557,7 +559,7 @@ class Meting
|
||||
case 'xiami':
|
||||
$API=array(
|
||||
'method' => 'GET',
|
||||
'url' => 'http://api.xiami.com/web',
|
||||
'url' => 'http://www.xiami.com/song/gethqsong/sid/'.$id,
|
||||
'body' => array(
|
||||
'v' => '2.0',
|
||||
'app_key' => '1',
|
||||
@ -698,14 +700,16 @@ class Meting
|
||||
$format=$this->_FORMAT;
|
||||
$data=$this->format(false)->song($id);
|
||||
$this->format($format);
|
||||
$url=json_decode($data, 1)['data']['song']['logo'];
|
||||
$url=str_replace(['_1.','http:','img.'], ['.','https:','pic.'], $url).'@'.$size.'h_'.$size.'w_100q_1c.jpg';
|
||||
$data=json_decode($data, 1);
|
||||
$url=$data['data']['song']['logo'];
|
||||
$url=str_replace(array('_1.','http:','img.'), array('.','https:','pic.'), $url).'@'.$size.'h_'.$size.'w_100q_1c.jpg';
|
||||
break;
|
||||
case 'kugou':
|
||||
$format=$this->_FORMAT;
|
||||
$data=$this->format(false)->song($id);
|
||||
$this->format($format);
|
||||
$url=json_decode($data, 1)['imgUrl'];
|
||||
$data=json_decode($data, 1);
|
||||
$url=$data['imgUrl'];
|
||||
$url=str_replace('{size}', '400', $url);
|
||||
break;
|
||||
case 'baidu':
|
||||
@ -723,7 +727,7 @@ class Meting
|
||||
{
|
||||
$BASE=array(
|
||||
'netease'=>array(
|
||||
'referer' => 'http://music.163.com/',
|
||||
'referer' => 'https://music.163.com/',
|
||||
'cookie' => 'os=linux; appver=1.0.0.1026; osver=Ubuntu%2016.10; MUSIC_U=78d411095f4b022667bc8ec49e9a44cca088df057d987f5feaf066d37458e41c4a7d9447977352cf27ea9fee03f6ec4441049cea1c6bb9b6; __remember_me=true',
|
||||
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
|
||||
),
|
||||
@ -760,7 +764,7 @@ class Meting
|
||||
$KEY='7246674226682325323F5E6544673A51';
|
||||
$body=json_encode($API['body']);
|
||||
if (function_exists('openssl_encrypt')) {
|
||||
$body=openssl_encrypt($body, 'aes-128-ecb', hex2bin($KEY));
|
||||
$body=openssl_encrypt($body, 'aes-128-ecb', pack('H*', $KEY));
|
||||
} else {
|
||||
$PAD=16-(strlen($body)%16);
|
||||
$body=base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hex2bin($KEY), $body.str_repeat(chr($PAD), $PAD), MCRYPT_MODE_ECB));
|
||||
@ -801,7 +805,7 @@ class Meting
|
||||
$song_id[$i]=chr(ord($song_id[$i])^ord($magic[$i%count($magic)]));
|
||||
}
|
||||
$result=base64_encode(md5(implode('', $song_id), 1));
|
||||
$result=str_replace(['/','+'], ['_','-'], $result);
|
||||
$result=str_replace(array('/','+'), array('_','-'), $result);
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
@ -811,10 +815,18 @@ class Meting
|
||||
private function netease_url($result)
|
||||
{
|
||||
$data=json_decode($result, 1);
|
||||
$url=array(
|
||||
'url' => str_replace('http:', 'https:', $data['data'][0]['url']),
|
||||
'br' => $data['data'][0]['br']/1000,
|
||||
);
|
||||
if($data['data'][0]['uf'] != null) {
|
||||
$url=array(
|
||||
'url' => str_replace('http:', 'https:', $data['data'][0]['uf']['url']),
|
||||
'br' =>$data['data'][0]['uf']['br']/1000,
|
||||
);
|
||||
}
|
||||
else{
|
||||
$url=array(
|
||||
'url' => str_replace('http:', 'https:', $data['data'][0]['url']),
|
||||
'br' => $data['data'][0]['br']/1000,
|
||||
);
|
||||
}
|
||||
return json_encode($url);
|
||||
}
|
||||
private function tencent_url($result)
|
||||
@ -830,13 +842,14 @@ class Meting
|
||||
),
|
||||
'decode' => 'jsonp2json',
|
||||
);
|
||||
$KEY=json_decode($this->curl($API), 1)['key'];
|
||||
$KEY=json_decode($this->curl($API), 1);
|
||||
$KEY=$KEY['key'];
|
||||
|
||||
$type=array(
|
||||
'size_320mp3'=>array(320,'M800','mp3'),
|
||||
'size_128mp3'=>array(128,'M500','mp3'),
|
||||
'size_96aac'=>array(96,'C400','m4a'),
|
||||
'size_48aac'=>array(48,'C200','m4a'),
|
||||
'size_320mp3' => array(320,'M800','mp3'),
|
||||
'size_128mp3' => array(128,'M500','mp3'),
|
||||
'size_96aac' => array(96 ,'C400','m4a'),
|
||||
'size_48aac' => array(48 ,'C200','m4a'),
|
||||
);
|
||||
foreach ($type as $key=>$vo) {
|
||||
if ($data['data'][0]['file'][$key]&&$vo[0]<=$this->_temp['br']) {
|
||||
@ -852,10 +865,42 @@ class Meting
|
||||
private function xiami_url($result)
|
||||
{
|
||||
$data=json_decode($result, 1);
|
||||
$url=array(
|
||||
'url' => str_replace('http:', 'https:', $data['data']['song']['listen_file']),
|
||||
'br' => 128,
|
||||
);
|
||||
if(isset($data['location'])) {
|
||||
$location = $data['location'];
|
||||
$num = (int)$location[0];
|
||||
$str = substr($location, 1);
|
||||
$len = floor(strlen($str)/$num);
|
||||
$sub = strlen($str) % $num;
|
||||
$qrc = array();
|
||||
$tmp = 0;
|
||||
$urlt = '';
|
||||
for(;$tmp<$sub;$tmp++){
|
||||
$qrc[$tmp] = substr($str, $tmp*($len+1), $len+1);
|
||||
}
|
||||
for(;$tmp<$num;$tmp++){
|
||||
$qrc[$tmp] = substr($str, $len*$tmp+$sub, $len);
|
||||
}
|
||||
for($tmpa=0;$tmpa<$len+1;$tmpa++){
|
||||
for($tmpb=0;$tmpb<$num;$tmpb++){
|
||||
if(isset($qrc[$tmpb][$tmpa])) { $urlt.=$qrc[$tmpb][$tmpa];
|
||||
}
|
||||
}
|
||||
}
|
||||
for($tmp=0;$tmp<$sub;$tmp++){
|
||||
//if(isset($qrc[$tmp][$len])) (string)$urlt.=(string)$qrc[$tmp][$len];
|
||||
}
|
||||
$urlt=str_replace('^', '0', urldecode($urlt));
|
||||
$url=array(
|
||||
'url' => urldecode($urlt),
|
||||
'br' => 320,
|
||||
);
|
||||
}
|
||||
else{
|
||||
$url=array(
|
||||
'url' => "error",//str_replace('http:', 'https:', $data['data']['song']['listen_file']),
|
||||
'br' => 0,
|
||||
);
|
||||
}
|
||||
return json_encode($url);
|
||||
}
|
||||
private function kugou_url($result)
|
||||
@ -904,18 +949,18 @@ class Meting
|
||||
* 歌词处理模块
|
||||
* 用于规范化歌词输出
|
||||
*/
|
||||
private function netease_lyric($result)
|
||||
{
|
||||
if (!$this->_FORMAT) {
|
||||
return $result;
|
||||
}
|
||||
$result=json_decode($result, 1);
|
||||
$data=array(
|
||||
'lyric' => (@$result['lrc']['lyric'])?:'',
|
||||
'tlyric' => (@$result['tlyric']['lyric'])?:'',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
private function netease_lyric($result)
|
||||
{
|
||||
if (!$this->_FORMAT) {
|
||||
return $result;
|
||||
}
|
||||
$result=json_decode($result, 1);
|
||||
$data=array(
|
||||
'lyric' => (@$result['lrc']['lyric'])?:'',
|
||||
'tlyric' => (@$result['tlyric']['lyric'])?:'',
|
||||
);
|
||||
return json_encode($data);
|
||||
}
|
||||
private function tencent_lyric($result)
|
||||
{
|
||||
$result=$this->jsonp2json($result);
|
||||
|
@ -1,6 +0,0 @@
|
||||
CREATE TABLE typecho_meting (
|
||||
id binary(40) NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
date int(11) NOT NULL
|
||||
)ENGINE=MYISAM DEFAULT CHARSET=utf8;
|
||||
ALTER TABLE typecho_meting ADD UNIQUE(id);
|
@ -1 +0,0 @@
|
||||
DROP TABLE typecho_meting;
|
Loading…
Reference in New Issue
Block a user