ampache/ampacheapi-php

Ampache API PHP 库。

1.0.3 2023-06-29 07:02 UTC

This package is auto-updated.

Last update: 2024-09-16 06:33:05 UTC


README

Ampache API PHP 库。

新闻

此库的版本 2 正在开发中。

有重大更改以支持多个目的以及 XML 和 JSON 响应。

该库现在将返回 SimpleXMLElement 或 json_encode 字符串,而不是 Frankenstein。

此库版本从 Ampache 6.2.0+ 开始支持。

许可证

Ampache API PHP 库是免费软件;您可以在自由软件基金会发布的 GNU Affero 通用公共许可证 v3 (AGPLv3) 的条款下重新分发和/或修改它。

开始使用

初始化

$ampache = new AmpacheApi(array(
   'username' => 'user1', // Username
   'password' => 'test', // Password
   'server' => 'localhost', // Server address, without http/https prefix
   'debug_callback' => 'debug_event', // server callback function
   'api_secure' => 'false' // Set to true to use https
   'api_version' => 6 // Set API response version. 3, 4, 5, 6 (default: 6)
   'api_format' => 'xml' // Set API response format. xml, json (default: json)
));

if ($ampache->state() != 'CONNECTED') {
  echo "Ampache API client failed to connected.\n";
  exit;
}

获取服务器统计信息

$stats = $ampache->info();
echo "Songs: " . $stats->songs . "<br />\n";
echo "Albums: " . $stats->albums . "<br />\n";
echo "Artists: " . $stats->artists . "<br />\n";
echo "Playlists: " . $stats->playlists . "<br />\n";
echo "Videos: " . $stats->videos . "<br />\n";

获取所有艺术家

$total = $stats->artists;
$step = 500; // Request per 500
$start = 0;

echo "Artists: <br />\n";
while ($total > $start) {
  $artists = $ampache->send_command('artists', array('offset' => $start, 'limit' => $step));
  foreach ($artists as $artist) {
    echo "\t" . $artist->name . "\n"
  }
}