ngsoft/emby-client-php

Emby.SDK的PHP版本。

1.1.2 2023-12-22 21:59 UTC

This package is auto-updated.

Last update: 2024-08-22 23:32:34 UTC


README

这是一个为Emby.SDK的PHP端口,用于Emby媒体服务器。使用它,您可以连接到您的Emby媒体服务器并管理它。

如何安装

您可以在项目内部使用composer安装此包

composer require ngsoft/emby-client-php

此库需要使用PSR-18 Http客户端,并使用Guzzle进行开发

如果您想使用guzzle

composer require guzzlehttp/guzzle

此库还支持任何PSR-6缓存(以保持您的EmbyConnect连接令牌)。

您可以使用以下方式安装缓存库

composer require symfony/cache

如何使用

您可以像这样初始化库

<?php

use EmbyClient\Connection;
use EmbyClient\EmbyConnect;
use EmbyClient\Cache;
use EmbyClient\HttpClient;

// if you are using a custom cache library you can add that line
// if you installed symfony/cache you don't need that line
Cache::setCachePool($myCacheItemPoolInstance);
// if you are using a custom Http Client you can add that line
// with guzzle it is automatic
HttpClient::setHttpClient($myHttpClientInstance);
// To make a connection using emby connect:
$connection = EmbyConnect::connect('usernameOrEmail', 'password', 'serverName');
// or to make a connection to a local or remote server using its ip or address using an api key
// you can generate an api key for your server in the web interface of your emby server:
// settings -> Advanced -> Api Keys -> New Api Key
$connection = Connection::getConnection('ipAddressOrHostname', 'api_key');
// or with custom port 
$connection = Connection::getConnection('ipAddressOrHostname:port', 'api_key');
// you can also connect to a server using its http(s) address and port
$connection = Connection::getConnection('https://example.com:8096', 'api_key');

// you can also test if a connection is authenticated
if($connection->testConnection())
{
    // you can also make a connection active globally
    // the first to connect is automatically registered
    $connection->makeActive();
}

要执行API调用,您可以使用emby api客户端

use EmbyClient\ApiClient;

$devices = ApiClient::getDevices();

您还可以直接使用服务

use EmbyClient\Model\Services\DeviceService;

$service = new DeviceService($connection)

$devices = $service->getDevices();

信息

所有位于'lib/'和ApiClient中的模型都是使用src/generator.php和位于resources/openapi_v3.json中的emby模式生成的。

PHP-CS-Fixer已用于使其符合PSR-12。还使用了phan来检查错误