bytelus/nowplaying

Icecast和SHOUTcast 1/2当前播放数据的轻量级PHP适配器。Radiolize软件套件的一部分。

1.0 2021-02-15 09:57 UTC

This package is not auto-updated.

Last update: 2024-10-03 03:21:18 UTC


README

NowPlaying是一个轻量级、现代、面向对象的PHP库,它将流行广播软件中的当前播放元数据抽象成一个单一的通用返回格式。

安装

NowPlaying是一个Composer包,您可以通过运行以下命令将其包含到您的项目中:

composer require bytelus/nowplaying

兼容性

使用示例

<?php
// Example PSR-17 and PSR-18 implementation from Guzzle 7
// Install those with:
//   composer require guzzlehttp/guzzle:^7 http-interop/http-factory-guzzle

$adapterFactory = new \NowPlaying\Adapter\AdapterFactory(
    new \Http\Factory\Guzzle\UriFactory,
    new \Http\Factory\Guzzle\RequestFactory,
    new \GuzzleHttp\Client
);

$adapter = $adapterFactory->getAdapter(
    \NowPlaying\Adapter\AdapterFactory::ADAPTER_SHOUTCAST2,
    'http://my-station-url.example.com:8000',
    'AdminPassword!' // Optional
);

// 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');

示例 "now playing" 响应(以JSON表示的PHP对象)

{
    "currentSong": {
        "text": "Joe Bagale - Until We Meet Again",
        "title": "Until We Meet Again",
        "artist": "Joe Bagale"
    },
    "listeners": {
        "current": 0,
        "unique": 0,
        "total": 0
    },
    "meta": {
        "online": true,
        "bitrate": 128,
        "format": "audio/mpeg"
    },
    "clients": []
}

示例 "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
    }
]