PHP code example of ampache / ampacheapi-php

1. Go to this page and download the library: Download ampache/ampacheapi-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ampache / ampacheapi-php example snippets


// your own username and password are demo';
$hash     = hash('sha256', $password);
$server   = 'develop.ampache.dev';

$config  = [
    'username' => $username,
    'password' => $password,
    'server' => $server,
    'debug' => true,
    'debug_callback' => null,
    'api_version' => 6,
    'api_format' => 'json',
];

$ampache = new AmpacheApi($config);
if ($ampache->state() != 'CONNECTED') {
    echo "Ampache API client failed to connect.\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', ['offset' => $start, 'limit' => $step]);
    foreach ($artists['artist'] as $artist) {
        echo "\t" . $artist['name'] . "\n";
    }
    $start = $start + $step;
}