Richard Clamp > Net-DAAP-Client > Net::DAAP::Client

Download:
Net-DAAP-Client-0.42.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.42   Source  

NAME ^

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

SYNOPSIS ^

  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;
  $daap_db($new_db_id);

  $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);

  $daap->disconnect;

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

DESCRIPTION ^

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.

WARNING

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.

METHODS ^

* new()

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

The allowed options are:

SERVER_NAME

The hostname or IP address of the server.

SERVER_PORT

The port number of the server.

PASSWORD

The password to use when authenticating.

DEBUG

Print some debugging output

SONG_ATTRIBUTES

The attributes to retrieve for a song as an array reference. The default list is:

 [qw( dmap.itemid dmap.itemname dmap.persistentid daap.songalbum
      daap.songartist daap.songformat daap.songsize )]

* 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 specified by SONG_ATTRIBUTES, the default set is:

dmap.itemid

Unique ID for the song.

dmap.itemname

Title of the track.

dmap.persistentid

XXX [add useful explanation here]

daap.songalbum

Album name that the track came from.

daap.songartist

Artist who recorded the track.

daap.songformat

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

daap.songsize

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'
        },

To find out what other attributes you can request consult the DAAP spec at http://tapjam.net/daap/draft.html

* 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',
        'com.apple.itunes.smart-playlist' => 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()

    $obj->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.

LIMITATIONS ^

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

AUTHOR ^

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

Richard Clamp <richardc@unixbeard.net> took on maintainership duties for the 0.4 and subsequent releases.

SEE ALSO ^

Net::DAAP::DMAP

syntax highlighting: