Examples


Setup

First of all, include PEAR’s System.php, PEAR’s MDB2.php, and your copy of PHPAmarokDB.php. Change the include path to the path of your own PEAR installation.

set_include_path(
    get_include_path() .
    PATH_SEPARATOR . "/home/okeeblow/pear/php"
);
require_once("System.php");
require_once("MDB2.php");
require_once("PHPAmarokDB.php");

Instantiate an object of the PHPAmarokDB class. The constructor takes two arguments, the first in the form of an MDB2 DSN and the second as the Amarok major version number (1 or 2).

$amarok = new PHPAmarokDB("mysqli://user:password@localhost/amarok", 1);


Basic Fetching


Artists

print_r($amarok->getArtists());

Returns an array of all artists in the collection. fetchCompilations() controls whether this function returns artists existing only on compilations or just ignores them.

Array
(
    [0] => Array
        (
            [name] => !!!
            [id] => 2827
        )

    [1] => Array
        (
            [name] => +/-
            [id] => 2826
        )

    [2] => Array
        (
            [name] => +44
            [id] => 2825
        )

    [3] => Array
        (
            [name] => ...And You Will Know Us by the Trail of Dead
            [id] => 265
        )

    [4] => Array
        (
            [name] => 1-2-3 Blast On!
            [id] => 3244
        )

    [5] => Array
        (
            [name] => 100 Portraits and Waterdeep
            [id] => 3245
        )

    [6] => Array
        (
            [name] => 1000 Homo DJs
            [id] => 957
        )
{..snip..}
    [1575] => Array
        (
            [name] => 永田権太, 若井淑, 峰岸透 & 近藤浩治
            [id] => 175
        )

    [1576] => Array
        (
            [name] => 近藤浩治
            [id] => 472
        )

    [1577] => Array
        (
            [name] => 長沼英樹
            [id] => 1271
        )

)


Albums

print_r($amarok->getAlbums(957));

Returns an array of all albums by artist 957.

code lang=”plain”]
Array
(
[0] => Array
(
[id] => 4087
[name] => Supernaut
[artist] => 957
)

)[/code]


Tracks

print_r($amarok->getTracks(957, 4087));

Returns an array of all tracks by artist 957 on album 4087.

Array
(
    [0] => Array
        (
            [title] => Supernaut
            [artist] => 1000 Homo DJs
            [album] => Supernaut
            [length] => 402
            [track] => 1
            [genre] => Industrial
            [bitrate] => 217
            [discnumber] => 0
            [year] => 1990
        )

    [1] => Array
        (
            [title] => Hey Asshole
            [artist] => 1000 Homo DJs
            [album] => Supernaut
            [length] => 489
            [track] => 2
            [genre] => Industrial
            [bitrate] => 246
            [discnumber] => 0
            [year] => 1990
        )

    [2] => Array
        (
            [title] => Apathy
            [artist] => 1000 Homo DJs
            [album] => Supernaut
            [length] => 277
            [track] => 3
            [genre] => Industrial
            [bitrate] => 243
            [discnumber] => 0
            [year] => 1990
        )

    [3] => Array
        (
            [title] => Better Ways
            [artist] => 1000 Homo DJs
            [album] => Supernaut
            [length] => 323
            [track] => 4
            [genre] => Industrial
            [bitrate] => 249
            [discnumber] => 0
            [year] => 1990
        )

)


Compilations

echo($amarok->countCompilations();

Returns the number of compilation albums in the entire collection. This is useful to either hide or show a "Compilations" widget.

280


Searching


Artists

$amarok->searchString("AFX");
print_r($amarok->getArtists());

Returns an array of all artists whose name matches "AFX" or who have albums or tracks with names matching "AFX".

Array
(
    [0] => Array
        (
            [name] => AFX
            [id] => 225
        )

    [1] => Array
        (
            [name] => Aphex Twin
            [id] => 253
        )

    [2] => Array
        (
            [name] => Caustic Window
            [id] => 3218
        )

)


Albums

$amarok->searchString("AFX");
print_r($amarok->getAlbums(253);

Returns an array of albums by artist 253. The array contains all albums if the artist name matches "AFX" but only the relevant albums if album or track names match "AFX".

Array
(
    [0] => Array
        (
            [id] => 857
            [name] => Drukqs
            [artist] => 253
        )

    [1] => Array
        (
            [id] => 867
            [name] => Inkeys (Live 1997) SBD
            [artist] => 253
        )

)


Tracks

$amarok->searchString("AFX");
print_r($amarok->getTracks(253, 857);

Returns an array of tracks by artist 253 on album 857. The array contains all of the album's tracks if the artist name or album name match "AFX" or the relevant tracks if only track names match "AFX".

Array
(
    [0] => Array
        (
            [title] => Afx 237 V.7
            [artist] => Aphex Twin
            [album] => Drukqs
            [length] => 263
            [track] => 12
            [genre] => IDM
            [bitrate] => 201
            [discnumber] => 2
            [year] => 2001
        )

)


Compilations

$amarok->searchString("AFX");
echo($amarok->countCompilations();

Returns the number of compilation albums with artist, album, or track names matching "AFX". This is useful to either hide or show a "Compilations" widget.

4


Stats


Counts and filesize

print_r($amarok->getStats();

Returns an array with the total number of artists, albums, and tracks in the collection as well as the total filesize of the collection.

Array
(
    [filesize] => 347.48 GiB
    [tagcount] => 53266
    [albumcount] => 4828
    [artistcount] => 3466
)


Update time

echo($amarok->lastUpdated();

Returns a UNIX timestamp marking the last database update.

1256092108