Module to communicate with roaraudio playlist daemon
use Audio::RPLD; # Open new connection my $rpld = Audio::RPLD->new([$addr[, $type[, $port]]]); # Work with the connection $rpld->play(); $rpld->stop(); #... # close the connection $rpld->disconnect(); # reconnect: $rpld->connect($addr[, $type[, $port]]);
This module is used to communicate with a RoarAudio PlayList Daemon (rpld). It includes support for nearly all of the protocol.
Here is a list of all the arguments used in this documentation so I do not need to explain later for each method again. The Address of the server. This can be a filename or host or nodename. If the type is known to you, you should set the $type argument. Do not limit the user to hostname or filenames or something. The user should be abled to enter any server location in a freeform text input. This is the type of the address of the server. Currently defined types are:
Use a \s-1UNIX\s0 socket to connect to the server.
Use a DECnet socket to connect to the server (currently not supported because there is no IO::Socket::DECnet yet).
Use a \s-1INET\s0 (IPv4) socket to connect to the server.
Use a already connected socket as connection to the server. This can for example be a object opened with a \s-1SSL/TLS\s0 or proxy module or any other bidirectional \s-1IO\s0 object. Object is passed as $addr parameter.
Use Autodetection.
If using a \s-1INET\s0 socket this is the port number to connect to. Use undef (not include in arguments list) to use defaults. A Playlist to use. This can be a integer to use the playlist \s-1ID\s0 (which is preferred), a string to use the playlist name or $any (return value of $rpld->any()) to search thru all playlists and use the first hint. $any is not supported by all commands as it does not make sense for all commands. A volume. If this is an integer the volume is in range 0 to 65535 (recommended). If it's a string and suffixed by a '%' it is in range 0 to 100. A value of zero always means total silence. A history size. This is an integer or undef. If undef the server's default is used. The address of a RoarAudio server as used as backend for a queue. If undef the default server will be used. The mixer \s-1ID\s0 of the mixer core which should be used by a queue. If undef the server's default mixer core will be used. This should normally be undef. The stream role as used by a queue. This is the name or undef to use rpld's or RoarAudio server's default. This is the name of the role not the \s-1ID\s0. Common values include \*(L"music\*(R" and \*(L"background_music\*(R". A floating point describing how much the user likes a song. A string of a name of some object. A Playlist entry (item) identifier. This is a string of one of the several types. Here is a quick overview:
The long \s-1GTN\s0 is a hex string (with leading 0x) prefixed by 'long:' with a length of 64 bit (16 raw digits). It is used to identify a playlist entry within the runtime of the server process. This one is the one you normally use for all operations like queuing a track for playback.
The short \s-1GTN\s0 is a shorter (only 32 bit) version of the \s-1GTN\s0 prefixed with 'short:'. It's use is exactly the same as for the long \s-1GTN\s0. It exists to get the \s-1GTN\s0 passed thru things which do not support more than 32 bit. As this is normally not the case for Perl (you pass them around as strings anyway) you should not need to use it at all. It's not recommended to use this one.
The \s-1UUID\s0 is a string prefixed with 'uuid:' followed by the normal hex-dash notation (example: uuid:54ab0c5f-b058-4c9b-ab3b-dea11b608482). It is used to identify a song. In contrast to the \s-1GTN\s0 this is not changed by commands such like copy or move operations. The normal use for this is if you want to store something over multiple runtimes of the server process like favorites or something. If a song does not include a \s-1UUID\s0 in it's meta data the server will generate a random one so each song has one. Those UUIDs can also be used together with the Tantalos protocol.
A pointer is a string (the pointer name) prefixed by 'pointer:' (example: pointer:default). Those are used to have symbolic pointers a playlist entry. The following pointers are currently known by rpld:
If the Main Queue runs out of songs and the current pointer reached the end of the current playlist the current pointer is set to this value and song lookup is done again. For details about the current pointer see below.
If the Main Queue run out of queued songs the song this pointer points to is automatically queued and this pointer is set to the next entry the the playlist. This is used for 'start here and just play the playlist' behavior. If this pointer reaches the end of the playlist it becomes undefined and if the default pointer is set redefined with it's value. See above for more information about the default pointer.
If the startup pointer is set the song it points to is added once at startup of the daemon. This can for example be used to implement boot sounds.
The temp pointer is a pointer for user defined jobs. It is the only pointer which is not global (shared with all clients) but a client local pointer. The application can use it for whatever it wants to use it for.
As of rpld 0.1rc7 multi queue support was added. To support this pointers can have a queue and client \s-1ID\s0 suffix. The suffix has the syntax: pointer[queue:client]. Both queue and client can be omitted. If the client \s-1ID\s0 is omitted the colon (':') can be omitted, too. If both are omitted the brackets ('[]') can also be omitted. Queue defaults to the current client's default queue and client defaults to the current client.
This is a numerical index of the entry. It's format is num:N where N is the index starting with zero. For example num:0 is the first entry in playlist, num:15 is the 16th entry.
This is like the normal numerical index just uses the likeness values of the entries. This is hardly of use to the user and mainly for internal use. Syntax is likeness:F with F the floating point index.
A Random entry can be selected by using random:[\s-1PLI\s0]. \s-1PLI\s0 is a optional parameter. It must be the \s-1ID\s0 of the playlist to select entry from. If no playlist is given the current one is used.
This is like normal random entry but prioritized by the value set with \s-1LIKE\s0 and \s-1DISLIKE\s0 commands. Syntax is: randomlike:[\s-1PLI\s0].
A Pointer. This is a string of the pointer name. It is not prefixed with 'pointer:' as when used as \s-1PLE\s0.
The following return types are used by methods in this module: The instance of this module as returned by new(). A general return value. This is undef in case of failure or a defined value in case of no error. The value may be a string, hash- or arrayref depending on the method. See description of the method for details. The return value of any(). This can be used as wildcard for playlist names in some cases.
$rpld = Audio::RPLD->new([$addr[, $type[, $port]]])
This method creates a new Audio::RPLD object. If arguments are passed they are directly passed to a call to the connect method (see below) in order to connect to the server. If this fails undef is returned. If no arguments are given you need to connect the object to the server via the connect method later on your own.
$res = $rpld->connect($addr[, $type[, $port]])
Connect to a server. You must not call this on a already connected object.
$res = $rpld->connect_default()
Connect to a server by trying default locations. You must not call this on a already connected object.
$res = $rpld->disconnect()
Disconnect from the server. You may use $rpld->connect() again to connect to a (new/different) server.
$res = $rpld->is_connected()
Returns true value if the object is currently connected to a server or undef if not.
$res = $rpld->identify([%options])
This identifies the process at the server. An optional list of options is taken. Each key-value pair is send to the server as it is.
Currently supported keys are: name, pid, nodename and hostid.
This command is send automatically at connect. You only need to call this manually if want to set one of those options. It is recommended to do this at least for the application name.
$any = $rpld->any()
This function returns a value that can be used as playlist wildcard.
$res = $rpld->noop()
Send a \s-1NOOP\s0 command to the server.
This can be used to ping the server or for keep-alive.
$res = $rpld->serverinfo()
Send a \s-1SERVERINFO\s0 command to the server.
This tells basic information about the server like it's version and location.
The return value is a hashref which contains the following keys (all keys may or may not be set depending on what info the server provides):
This is the product name, version and vendor information for the server.
This is the location of the server in a lion readable way e.g. \*(L"kitchen\*(R".
This is a description for the server e.g. \*(L"Central Media Server\*(R"
Those are information on the server administrator. Normally contains nick or real name as well as an e-mail address.
This is a string with the serial number of the device.
This contains address data of the device.
This is an \s-1URL\s0 to a user interface used to control the server. This can be a web interface such as Romie or some other kind of interface. All protocols are allowed. This includes telnet:// and ssh://.
This is the \s-1UNIX\s0 HostID of the server.
This is the license of the server software or device.
This is a build stamp. It contains information on the build. This is mostly useful when reporting problems to upstream or the distributor.
This contains a sub-hash with information about the server's \s-1OS\s0. Those information are normally read via the uname() system call by the server software. This means all limits of uname() also apply to those data. The following keys are know as of this writing:
The operating system's name e.g. \*(L"NetBSD\*(R".
The operating system's release.
The node name of as known by the operating system.
The host architecture as known by the operating system.
This is a sub-hash with vendor specific information. The name is based on the \*(L"X-\*(R"-prefix those keys have. The content and format is fully up to the server software. However the following keys have been seen in the wild:
$res = $rpld->store()
Ask the server to store (dump) all data on permanent storage (disk). This is normally used at exit to save all the playlists on disk so they can be restored at next startup.
$res = $rpld->restore()
Restore from disk. This is normally done at startup time (by rpld itself). You should not call this again if the server already restored it's state because this may result in undefined behavior. Current behavior of rpld is that it forgets the complete current state and loads the new state. This was changed in version 0.1rc7. Before version 0.1rc7 it added everything to the current state resulting in duplicates. This may change in future.
$res = $rpld->play()
Start playback.
$res = $rpld->stop()
Stop playback.
$res = $rpld->next()
Skip to next song.
$res = $rpld->prev()
Skip to previous song.
$res = $rpld->isplaying()
Return a true value if we are currently playing.
$res = $rpld->showidentifier()
Return a identifier for the currently running stream at the server. The format of this identifier is undefined. This should not be used. Using this value can result in race conditions.
$res = $rpld->flushq()
Flush the Main Queue. Playback is stopped (because no songs are left in the queue).
$res = $rpld->showcur()
Return the Playlist entry for the current song (if playback is running this is the currently played song). This contains information about this song from the playlist. If you want to read the current meta data or other live data use $rpld->showplaying().
The return value is in the same format as that of $rpld->showple(). See $rpld->showple() for more information on it.
$res = $rpld->showplaying()
Returns live information on what is currently played.
The return value is a hashref which contains the following keys (all keys may or may not be set depending on what info the server provides):
A string of the current playback state in uppercase. Possible values include: \s-1STOPPED\s0, \s-1PAUSE\s0, \s-1RUNNING\s0.
The long \s-1GTN\s0 of the current ple.
The short \s-1GTN\s0 of the current ple.
The \s-1UUID\s0 of the current ple.
A hash containing keys for the current playback time in different units. The unit name is the key name. Units may include: samples, s.
A hash containing keys for each meta data type provided by the server. Types may include: title, album, artist, performer, version.
The meta data update counter (\s-1MDUC\s0) for current playback.
The sample rate of the current playback.
The number of channels of the current playback.
The number of bits of the current playback.
$res = $rpld->listq([$playlist])
List playlist entries of the Main Queue or the given playlist. This is the same as $rpld->listple() expect that the default playlist is the Main Queue not the currently selected playlist.
$res = $rpld->showqueue([$playlist])
Returns a hashref with information about the given list or the current queue if no list is given. The structure of the hashref is the same as for listplaylist(). This function is the same as showlist() but returns the current queue as default of no list is given.
$res = $rpld->setvolume($vol)
Set volume to $vol.
$res = $rpld->showvolume()
Return a hashref to a hash containing volume information.
The hash contains the following keys:
The current playback volume in units of scale.
The unit of value.
The volume in percent.
The current volume (as float) is value/scale.
$res = $rpld->pause()
Set the playback in pause mode.
You should not use this function but $rpld->togglepause() if possible.
$res = $rpld->unpause()
Unpause the playback.
You should not use this function but $rpld->togglepause() if possible.
$res = $rpld->togglepause()
Toggle the pause state. This is the recommended function to change the pause state of playback.
This is because it interacts best with other applications changing the current pause state.
$res = $rpld->setplaylist($playlist)
Select the given playlist. After selecting a playlist it becomes the default playlist for most operations which take a optional playlist argument. (Operations for which this does not set the default are marked in the corresponding description).
$res = $rpld->addplaylist($name)
Add a playlist.
$res = $rpld->delplaylist($playlist)
Delete a playlist. All entries are deleted, too.
$res = $rpld->flushplaylist($playlist)
Flush a playlist. If this is used on the Main Queue the playback is stopped as no songs are left to play.
$res = $rpld->listplaylist()
Get a list of playlists known by the server. This returns a arrayref to a array containing a hashref for each list. This hash contains the following keys:
The \s-1ID\s0 of the playlist.
The \s-1ID\s0 of the parent playlist.
The name of the playlist.
A arrayref with the IDs of the children playlists.
The size of the history if this is a history. This is the number of PLEs this playlist will store before old entries becomes deleted automatically.
The \s-1PLI\s0 of the playlist used as history if this is a queue.
The playback volume if this is a queue.
The backend used by this queue (if this is a queue). The backend is the name (server address) of the RoarAudio server.
The \s-1ID\s0 of the Mixer used on the RoarAudio server. -1 for default. Only set if this is a queue.
The Stream role used by this queue. Often \*(L"music\*(R" or \*(L"background_music\*(R". Only if this is a queue.
Parent/child information should be used to display a tree to the user.
$res = $rpld->showlist($playlist)
Returns a hashref with information about the given playlist. The structure of the hashref is the same as for listplaylist().
$res = $rpld->setparentlist($playlist)
Set the parent playlist of the current playlist. Setting parent playlist of a list the current one is currently not supported.
$res = $rpld->setqueue($playlist)
Select the given playlist as queue. After selecting a queue it becomes the default queue for the current connection.
$res = $rpld->delqueue($playlist)
Delete a queue from a playlist. The playlist will not be removed just the queue.
$res = $rpld->addqueue($playlist, $history[, $backend[, $mixer[, $role]]])
Add a queue to playlist $pl with the playlist $history as history. Optionally the server to connect to can be given as $backend and the mixer to connect to as $mixer. In addition the stream role can be set using $role.
$res = $rpld->addhistory($playlist, [$size])
Add a history to the playlist. The history size can be set using the optional argument $size. If not given the server's default will be used.
$res = $rpld->delhistory($playlist)
Delete a history from a playlist. The playlist will not be removed just the history.
$res = $rpld->delple($ple[, $playlist])
Delete the given playlist entry.
$res = $rpld->queueple($ple[, $playlist[, $pos]])
Queue the given playlist entry. This means it is copied over to the Main Queue. This function is recommended over $rpld->copyple() to queue songs.
The optional position is used to give the place in the playlist where to queue the song. It is counted as 'n entries after the first one'. This means if you pass a value of zero the song is placed as next song. If you pass a value of one it is placed as the song after the next song and so on. A value of -1 means that it is added before the first one. If you place a song before the first one in the Main Queue playback is stopped and restarted so this song becomes the currently played song.
If you omit the position or pass undef the default behavior is to add at the end of the playlist which should be the default in your applications, too.
$res = $rpld->copyple($ple, $playlist_from, $playlist_to[, $pos])
The given playlist entry is copied from the playlist $playlist_from to the playlist $playlist_to. If $playlist_from is undef the currently selected playlist is used as source.
For the meaning of the position parameter ($pos) see $rpld->queueple() above.
$res = $rpld->moveple($ple, $playlist_from, $playlist_to[, $pos])
The given playlist entry is moved from the playlist $playlist_from to the playlist $playlist_to. If $playlist_from is undef the currently selected playlist is used as source.
For the meaning of the position parameter ($pos) see $rpld->queueple() above.
$res = $rpld->listple($playlist)
List all playlist entries from the given playlist. The return value is an arrayref with elements as if they are returned by $rpld->showple(). See $rpld->showple() for more info about the return format.
Note: You should avoid calling this too often as it returns a large amount of data. You also should not store data for currently not used playlists (for example only store data for the playlist currently shown to the user).
$res = $rpld->searchple($needle, $op, $src, [$pli, [$opts]])
List playlist entries matching a given rule. The return value is the same as for $rpld->listple().
This function accepts the following arguments: The needle is the search term the server will search for. It may be a scalar value or a arrayref. If an arrayref the array must have one or two elements. If the array has two elements the first one is the type of needle and the second is the value to search for. The supported types depend on the server. As of version 0.1.5 RoarAudio PlayList Daemon supports: String types, \s-1DISCID\s0, \s-1UUID\s0, \s-1GENRE\s0, TRACKNUM[\s-1BER\s0]. String types are defined with a type of undef. If it has only one element the type defaults to undef (string type). If a scalar value is given the type is automatically selected based on the prefix. If a prefix is found matching one of the known types that type is selected. If no such prefix is found the string is used as string type. This is handy for user interfaces with only a single \*(L"intelligent\*(R" search box. For non-user input the array form is strongly recommended. This is the operator used to compare needle to the source. Currently the following options are defined. For negative versions see $opts.
The needle must to match the source.
The needle must not match the source.
The needle is found anywhere within the source.
The needle is found at the begin of the source.
The needle is found at the end of the source.
This is the source to compare the needle with. This can be undef, a scalar value, $any or a arrayref. $any matches any information within the \s-1PLE\s0. If an arrayref is used the array must consist of one or two elements. The first element is the source. The second is the sub-source. Valid values depend on the server software. As of version 0.1.5 RoarAudio PlayList Daemon supports: \s-1ALBUM\s0, \s-1TITLE\s0, \s-1ARTIST\s0, \s-1PERFORMER\s0, \s-1VERSION\s0, \s-1FILENAME\s0, \s-1DISCID\s0, \s-1UUID\s0, \s-1GENRE\s0, TRACKNUM[\s-1BER\s0] and \s-1TAG:\s0\*(L"Tagname\*(R". Not all of them can be used with all kinds of needles. If $src is a scalar value it is interpreted as ['\s-1TAG\s0', $src] or [$src] depending on the needle. If this is undef the source is selected by the type of needle with string needles defaulting to $any. This is the playlist to search in or $any. This is an hashref with options. All options are optional. The following keys are currently defined:
If set to a true value the search is inverted.
If set to a true value the search is done case sensetive.
If set to true value searching in queues is allowed. If set to a false but not undef value such searches are disallowed. If set to undef the default is used.
Does the same as \*(L"queues\*(R" just for histories.
$res = $rpld->showple($ple[, $playlist])
Return data of the given playlist entry. If no playlist is given the currently selected one is used.
The return value is a hashref with the following keys:
The name of the used codec.
The playback length in seconds.
The filename. This may be anything supported by RoarAudio's \s-1DSTR\s0. Including local files, web radio streams and other types.
The value for the meta key is a hashref of it's own to a list of provided meta data. The following keys may be included. All are optional. Other keys may also be included.
Name of the album.
Title of the song.
Name of the Artist.
Name of the performer for this record.
Version of this record.
\s-1CDDB\s0 DiscID for this song.
Tracknumber of this song in the album.
Total number of tracks in this album.
Genre of this song.
Genre \s-1ID\s0 of this song.
The long \s-1GTN\s0 for the entry.
The short \s-1GTN\s0 for the entry.
The \s-1UUID\s0 for the entry.
The likeness value stored by the server. This is a float in rage from zero to infinity. The bigger the value is the more the song is liked.
$res = $rpld->like($ple[, $likeness])
Tells the server that the user likes this entry. Optionally tells the server how much. A value of +1.0 is the default if no value is given. This is added to the likeness value stored by the server. A value of zero has no effect. A negative value indicates dislikeness. See dislike() for more information about dislikeness.
$res = $rpld->dislike($ple[, $likeness])
This is the same as like() just marks a the given entry as disliked. Optionally tells the server how much. A value of +1.0 is the default if no value is given. The value is subtracted from server's value. A value of zero has no effect. A negative value indicates likeness. See like() for more information about likeness.
$res = $rpld->setpointer($pointer, $ple[, $playlist])
Set the given pointer to the given playlist entry. If no playlist is given the currently selected one is used.
$res = $rpld->unsetpointer($pointer)
Unset the given pointer.
$res = $rpld->showpointer([$pointer])
Returns information about the given or all pointers.
The return value is a hashref with keys of the pointer names. The values for those keys are a hashref containing information on the corresponding pointer. If the hashref for the pointer points to a empty hash (no keys defined) then the pointer is not defined.
If the pointer is defined the following keys are contained:
The playlist entry the pointer points to in a raw format.
If the pointer contains an information about the playlist entries long \s-1GTN\s0 this \s-1GTN\s0.
If the pointer contains an information about the playlist entries short \s-1GTN\s0 this \s-1GTN\s0.
If the pointer contains an information about the playlist entries \s-1UUID\s0 this \s-1UUID\s0.
If the pointer points to a random song within a playlist this contains the corresponding search string.
If the pointer points to a random song (respecting likeness) within a playlist this contains the corresponding search string.
If the pointer contains a playlist hint this contains the playlist \s-1ID\s0.
$res = $rpld->listclients()
Get a list of clients connected to the server. This returns a arrayref to a array containing a hashref for each client. This hash contains the following keys:
The \s-1ID\s0 of the client.
The name of the client.
The name of the protocol the client is using.
The process \s-1ID\s0 of the client.
The name of the node the client is being conneected from.
The unix hostid of the node the client is being connected from.
Philipp "ph3-der-loewe" Schafft <[email protected]>
Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2012
This file is part of Audio::RPLD, a library to access the RoarAudio PlayList Daemon from Perl. See README for details.
This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
Audio::RPLD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this software; see the file COPYING.gplv3. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.