azuracast / nowplaying
AzuraCast软件套件的一部分,Icecast和SHOUTcast 1/2的轻量级PHP适配器,用于查看当前正在播放的数据。
2.2
2022-11-07 00:28 UTC
Requires
- php: >=7.4
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
- ext-xml: *
- guzzlehttp/guzzle: >7
- psr/http-client: *
- psr/http-factory: *
- psr/log: >=1
Requires (Dev)
README
NowPlaying是一个轻量级、现代、面向对象的PHP库,它将流行的广播软件中当前正在播放的元数据抽象为统一的返回格式。
安装
NowPlaying是一个Composer包,您可以通过运行以下命令将其包含到项目中:
composer require azuracast/nowplaying
兼容性
使用示例
<?php // Example PSR-17 and PSR-18 implementation from Guzzle 7 // Install those with: // composer require guzzlehttp/guzzle $httpFactory = new GuzzleHttp\Psr7\HttpFactory(); $adapterFactory = new NowPlaying\AdapterFactory( $httpFactory, $httpFactory, new GuzzleHttp\Client ); $adapter = $adapterFactory->getAdapter( NowPlaying\Enums\AdapterType::Shoutcast2, 'http://my-station-url.example.com:8000' ); // You can also call: // $adapterFactory->getShoutcast2Adapter('http://url'); // Optionally set administrator password $adapter->setAdminUsername('admin'); // "admin" is the default $adapter->setAdminPassword('AdminPassword!'); // The first argument to the functions is the mount point or // stream ID (SID), to pull one specific stream's information. $now_playing = $adapter->getNowPlaying('1'); $clients = $adapter->getClients('1');
示例“正在播放”响应(PHP对象以JSON表示)
{
"currentSong": {
"text": "Joe Bagale - Until We Meet Again",
"title": "Until We Meet Again",
"artist": "Joe Bagale"
},
"listeners": {
"total": 0,
"unique": 0
},
"meta": {
"online": true,
"bitrate": 128,
"format": "audio/mpeg"
},
"clients": []
}
示例“客户端”响应
[
{
"uid": 1,
"ip": "127.0.0.1",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
"connectedSeconds": 123
}
]