Meting API构建

前提:你正好有一台服务器

Meting API 是一个专为 APlayer 设计的接口服务,它基于Meting构建,允许开发者方便地获取网易云音乐或QQ音乐的数据。

安装

  1. 安装nginx、php
1
2
3
4
5
6
7
8
9
10
# 安装php
yum -y install nginx php-fpm

# 启动
systemctl start nginx
systemctl start php-fpm

# 开机自启
systemctl enable nginx
systemctl enable php-fpm
  1. 安装compose
1
2
3
4
5
6
7
8
9
10
11
# 安装依赖
yum install php php-cli php-zip wget

# 下载并安装 Composer
curl -sS https://getcomposer.org/installer | php

# 将 Composer 移动到全局可执行路径
mv composer.phar /usr/local/bin/composer

# 验证安装:
composer --version
  1. 安装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

配置

  1. 添加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;
}
}
  1. 修改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');

// 设置API路径
define('API_URI', api_uri());
// 设置中文歌词
define('TLYRIC', true);
// 设置歌单文件缓存及时间
define('CACHE', true);
define('CACHE_TIME', 86400);
// 设置短期缓存-需要安装apcu
define('APCU_CACHE', false);
// 设置AUTH密钥-更改'meting-secret'
define('AUTH', false);
define('AUTH_SECRET', 'meting-secret');

验证

访问你的 https://IP:端口,当你出现这个则代表部署成功

验证

进阶

自建API以后会发现提供的cover图非常小只有120*120,导致在音乐馆页面的封面图很模糊,可以通过修改src/Meting.php824行左右代码,将所有调用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

配置文件