Nathan Torkington > dapple > Net::DAAP::Client



Annotate this POD

View/Report Bugs


  Net::DAAP::Client - client for Apple iTunes DAAP service


  my $daap;  # see WARNING below
  $daap = Net::DAAP::Client->new(SERVER_HOST => $hostname,
                                 SERVER_PORT => $portnum,
                                 PASSWORD    => $password);
  $dsn = $daap->connect;

  $dbs_hash = $daap->databases;
  $current_db = $daap->db;

  $songs_hash = $daap->songs;
  $playlists_hash = $daap->playlists;
  $array_of_songs_in_playlist = $daap->playlist($playlist_id);

  $url = $daap->url($song_or_playlist_id);

  $binary_audio_data = $obj->get($song_id);
  $binary_audio_data = $obj->get(@song_ids);
  $song_id = $obj->save($dir, $song_id);
  @song_ids = $obj->get($dir, @song_ids);


  if ($daap->error) {
      warn $daap->error;  # returns error string


Net::DAAP::Client provides objects representing connections to DAAP servers. You can fetch databases, playlists, and songs. This module was written based on a reverse engineering of Apple's iTunes 4 sharing implementation. As a result, features that iTunes 4 doesn't support (browsing, searching) aren't supported here.

Each connection object has a destructor, so that you can forget to disconnect without leaving the server expecting you to call back.


If you store your object in a global variable, Perl can't seem to disconnect gracefully from the server. Until I figure out why, always store your object in a lexical (my) variable.


* new()

    $obj = Net::DAAP::Client->new(OPTNAME => $value, ...);

The allowed options are:


The hostname or IP address of the server.


The port number of the server.


The password to use when authenticating.

* connect()

    $name = $obj->connect
        or die $obj->error;

Attempts to fetch the server information, log in, and learn the latest revision number. It returns the name of the server we've connected to (as that server reported it). It returns undef if any of the steps fail. If it fails fetching the revision number, it logs out before returning undef.

* databases()

    $dbs = $self->databases();

Returns a hash reference. Sample:

* db()

    $db_id = $obj->db;     # learn current database ID
    $obj->db($db_id);      # set current database

A database ID is a key from the hash returned by $obj->databases.

Setting the database loads the playlists and song list for that database. This can take some time if there are a lot of songs in either list.

This method returns true if an error occurred, false otherwise. If an error occurs, you can't rely on the song list or play list having been loaded.

* songs()

    $songs = $obj->songs();

Returns a hash reference. Keys are song IDs, values are hashes with information on the song. Information fetched is:


Unique ID for the song.


Title of the track.


XXX [add useful explanation here]


Album name that the track came from.


Artist who recorded the track.


A string, "mp3", "aiff", etc.


Size in bytes of the file.

A sample record:

    '127' => {
        'daap.songsize' => 2597221,
        'daap.songalbum' => 'Live (Disc 2)',
        'dmap.persistentid' => '4081440092921832180',
        'dmap.itemname' => 'Down To The River To Pray',
        'daap.songartist' => 'Alison Krauss + Union Station',
        'dmap.itemid' => 127,
        'daap.songformat' => 'mp3'

* playlists()

    $songlist = $obj->playlists();

Returns a hash reference. Keys are playlist IDs, values are hashes with information on the playlist.

XXX: explain keys

A sample record:

    '2583' => {
        'dmap.itemcount' => 335,
        'dmap.persistentid' => '4609413108325671202',
        'dmap.itemname' => 'Recently Played',
        '' => 0,
        'dmap.itemid' => 2583

* playlist

    $playlist = $obj->playlist($playlist_id);

A playlist ID is a key from the hash returned from the playlists method. Returns an array of song records.

* url

    $url = $obj->url($song_id);
    $url = $obj->url($playlist_id);

Returns the persistent URL for the track or playlist.

* get

    @tracks = $obj->get(@song_ids);

Returns the binary data of the song. A song ID is a key from the hash returned by songs, or the dmap.itemid from one of the elements in the array returned by playlist.

* save

    $tracks_saved = $obj->save($dir, @song_ids);

Saves the binary data of the song to the directory. Returns the number of songs saved.

* disconnect()


Logs out of the database. Returns undef if an error occurred, a true value otherwise. If an error does occur, there's probably not much you can do about it.

* error()

    $string = $obj->error;

Returns the most recent error code. Empty string if no error occurred.


No authentication. No updates. No browsing. No searching.


Nathan Torkington, <nathan AT>. For support, join the DAAP developers mailing list by sending mail to <daap-devel-subscribe AT>. See the AUTHORS file in the distribution for other contributors.



syntax highlighting: