Linux教程Meting API构建
墨颜丶Meting API 是一个专为 APlayer 设计的接口服务,它基于Meting构建,允许开发者方便地获取网易云音乐或QQ音乐的数据。
安装
- 安装nginx、php
1 2 3 4 5 6 7 8 9 10
| yum -y install nginx php-fpm
systemctl start nginx systemctl start php-fpm
systemctl enable nginx systemctl enable php-fpm
|
- 安装compose
1 2 3 4 5 6 7 8 9 10 11
| yum install php php-cli php-zip wget
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
composer --version
|
- 安装meting-api
1 2 3 4 5 6 7 8 9 10 11 12
| $ 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
配置
- 添加nginx配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| server { listen [端口]; server_name [地址];
root [meting-api安装目录]; index index.php index.html index.htm;
location / { try_files $uri $uri/ =404; }
location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
location ~ /\.ht { deny all; } }
|
- 修改index.php
在根目录会有index.php
,可以在这里调整参数设置API路径缓存及时间等等,详细见原项目README.md,博主全默认配置,注意配置完后可能会存在跨域的情况,可以修改index.php
前面加上允许跨站的两行代码,修复这个情况,虽然本来就有这个,但是不知道为什么写在后面就会跨域,写在前面就不会再有这种情况了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?php
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET');
define('API_URI', api_uri());
define('TLYRIC', true);
define('CACHE', true); define('CACHE_TIME', 86400);
define('APCU_CACHE', false);
define('AUTH', false); define('AUTH_SECRET', 'meting-secret');
|
验证
访问你的 https://IP:端口
,当你出现这个则代表部署成功

进阶
自建API以后会发现提供的cover图非常小只有120*120
,导致在音乐馆页面的封面图很模糊,可以通过修改src/Meting.php
的824行左右
代码,将所有调用pic方法
的$size
都变成300*300
1 2 3 4 5 6 7
| public function pic($id, $size = 300) { switch ($this->server) { case 'netease': $size = 300; $url = 'https://p3.music.126.net/'.$this->netease_encryptId($id).'/'.$id.'.jpg?param='.$size.'y'.$size; break;
|
弊端就是图片会变大一点点,各有取舍。
开放API
在官方的meting api挂掉以后涌现了一大批优秀的公益api
https://api.injahow.cn/meting/
https://meting.qjqq.cn/
在主题中只需在CDN.option.meting_api
填入下面中的任何一个即可
https://api.injahow.cn/meting/?server=:server&type=:type&id=:id&auth=:auth&r=:r
https://meting.qjqq.cn/?server=:server&type=:type&id=:id&auth=:auth&r=:r
自用
在配置文件的最下方修改CDN.option.meting_api
