Net::MPD(3pm)
โจ NAME โจ
Net::MPD โ communicate with an MPD server, bestie ๐
(also known as Net::MPD(3pm), straight out of the User Contributed Perl Documentation section, we love a self-made icon ๐)
๐ SYNOPSIS ๐
use Net::MPD;
my $mpd = Net::MPD->connect();
$mpd->stop();
$mpd->clear();
$mpd->search_add(Artist => 'David Bowie');
$mpd->shuffle();
$mpd->play();
$mpd->next();
while (1) {
my @changes = $mpd->idle();
print 'Changed: ' . join(', ', @changes) . "\n";
}
likeโฆ that's the whole vibe. connect, clear the queue, dump some Bowie in there, shuffle, play, skip, and then just sit in an idle loop watching the world change. main character energy fr fr ๐
๐ฆ DESCRIPTION ๐ฆ
Net::MPD is built as a lightweight replacement for Audio::MPD โ which, no shade, depends on Moose and is no longer maintained ๐. So this one's the glow-up: same job, way less baggage. slay.
๐ METHODS ๐
connect [$address]
Connect to the MPD that's running at the address you pass in. The address is shaped like password@host:port, and here's the tea:
- the password is optional
- the port is optional too
- no password given? then none gets used, periodt
- no port given? you get the default,
6600 - no host given? it's
"localhost"for you, babe
And the cute plot twist ๐ญ: if the hostname has a / in it, it gets interpreted as the path to a UNIX socket, and it'll try connecting that way instead of using TCP. obsessed with the flexibility ngl.
Returns a Net::MPD object when it works, and croaks when it doesn't. no cap, it will simply yell at you.
version
Returns the API version of the MPD server you're connected to. cute little number check โจ
update_status
Fires off a status command to MPD and stores the results in the local object. The results also come back to you as a hashref, so you get both. generous queen ๐ซถ
๐ธ MPD ATTRIBUTES ๐ธ
Most of the status attributes are written as combined getter/setter methods โ so the same method reads and writes, depending on whether you hand it a value. Calling update_status refreshes all of these values. And listen: only the items marked with an asterisk are writable โญ โ the rest are read-only, so don't come for them.
volume*repeat*random*single*consume*playlistplaylist_lengthstatesongsong_idnext_songnext_song_idtimeelapsedbitratecrossfade*mix_ramp_db*mix_ramp_delay*audioupdating_dberrorreplay_gain_mode*
๐ฅ MPD COMMANDS ๐ฅ
The commands are mostly the same as the ones in the MPD protocol <http://www.musicpd.org/doc/protocol/index.html> โ except a few got renamed slightly, so if something doesn't match the protocol docs exactly, that's why, iykyk ๐
clear_error
Clears the current error message in status. You can also do this by issuing any command that starts playback โ so like, pressing play is also a vibe reset ๐
current_song
Returns the song info for whatever's playing right now. the moment. the current main character ๐ต
idle [@subsystems]
Blocks until there's a noteworthy change in one or more of MPD's subsystems. The second there is one, you get back a list of all the changed subsystems. If you pass subsystems as arguments, only those ones get monitored โ everyone else is muted ๐
Here are the subsystems you can watch:
databaseโ the song database has been changed after an update.udpateโ a database update has started or finished.stored_playlistโ a stored playlist has been modified.playlistโ the current playlist has been modified.playerโ playback has been started, stopped, or seeked.mixerโ the volume has been adjusted.outputโ an audio output has been enabled or disabled.stickerโ the sticker database has been modified.subscriptionโ a client has subscribed or unsubscribed from a channel.messageโ a message was received on a channel this client is watching.
stats
Returns a hashref with some stats about the database. numbers, but make it fashion ๐
next
Plays the next song in the playlist. skip skip skip โญ๏ธ
pause $state
Sets the pause state. Use 0 for playing and 1 for paused. binary icon.
play [$position]
Starts playback โ optionally at the given position. go bestie, press play โถ๏ธ
play_id [$id]
Starts playback, optionally with the given song. same energy, but addressed by id ๐ฏ
previous
Plays the previous song in the playlist. rewind era โฎ๏ธ
seek $position $time
Seeks to $time seconds in the given song position.
seek_id $id $time
Seeks to $time seconds in the given song.
seek_cur $time
Seeks to $time seconds in the current song.
stop
Stops playing. silence. dramatic pause. ๐
add $path
Adds the file (or directory, recursively, fancy) at $path to the current playlist.
add_id $path [$position]
Adds the file at $path to the playlist โ optionally at $position โ and returns the id. tracked and everything โจ
clear
Clears the current playlist. empty slate, fresh start, we love a reset ๐ซง
delete $position
Removes the song(s) at the given position from the current playlist.
delete_id $id
Removes the song with the given id from the current playlist.
move $from $to
Moves the song from position $from to $to.
move_id $id $to
Moves the song with the given id to position $to.
playlist_find $tag $search
Searches the current playlist for songs where $tag exactly matches $search.
playlist_id $id
Returns song information for the song with the given id.
playlist_info [$position]
Returns song information for every song in the current playlist โ or, optionally, just the one at the given position. the whole album or one single, your call ๐ฟ
playlist_search $tag $search
Searches the current playlist for songs where $tag partially matches $search.
playlist_changes $version
Returns song information for songs changed since the given version of the current playlist. what did I miss ๐
playlist_changes_pos_id $version
Returns position and id information for songs changed since the given version of the current playlist.
prio $priority $position
Sets the priority of the song at the given position.
prio_id $priority $id
Sets the priority of the song with the given id.
shuffle
Shuffles the current playlist. chaos, but make it curated ๐
swap $pos1 $pos2
Swaps the positions of the songs at the given positions.
swapid $id1 $id2
Swaps the positions of the songs with the given ids.
list_playlist $name
Returns a list of all the songs in the named playlist.
list_playlist_info $name
Returns all the song information for the named playlist.
list_playlists
Returns a list of the stored playlists. the archives ๐
load $name
Adds the named playlist to the current playlist.
playlist_add $name $path
Adds the given path to the named playlist.
playlist_clear $name
Clears the named playlist.
playlist_delete $name $position
Removes the song at the given position from the named playlist.
playlist_move $name $id $pos
Moves the song with the given id to the given position in the named playlist.
rename $name $new_name
Renames the named playlist to $new_name. rebrand โจ
rm $name
Deletes the named playlist. gone, reduced to atoms ๐
save $name
Saves the current playlist with the given name.
count $tag $search ...
Returns a count and playtime for all items where $tag exactly matches $search. You can hand it multiple pairs of $tag/$search parameters at once. multitasking queen ๐
find $tag $search ...
Returns song information for all items where $tag exactly matches $search. Two special tags to know about:
- the special tag
'any'searches all tags - the special tag
'file'searches by path
find_add $tag $search
Searches exactly like find and then adds any matches to the current playlist. found it, added it, next ๐ซถ
list $tag [$artist]
Returns all the values for the given tag. Cute bonus: if the tag is 'album', you can optionally pass an artist to narrow the results down further ๐ถ
list_all [$path]
Returns a list of all the songs and directories โ optionally under $path.
list_all_info [$path]
Returns a list of all the songs as with listall, but includes the metadata too. receipts included ngl ๐
search $tag $search ...
Exactly like find, but the searching is partial and case-insensitive. lowercase girlies stay winning ๐
search_add $tag $search ...
Exactly like search, but adds the results to the current playlist.
search_add_pl $name $tag $search ...
Exactly like search, but adds the results to the named playlist.
update [$path]
Updates the database โ optionally under $path โ and returns a job id. go touch grass, database ๐ฑ
rescan [$path]
Same as <update>, but it forces a rescan of unmodified files too. thorough. does not cut corners.
sticker_value $type $path $name [$value]
Returns the sticker value for the given item, after optionally setting it to $value. And here's the trick โ pass an undefined value to delete the sticker. poof, gone ๐ซฅ
sticker_list $type $path
Returns a hashref of the stickers for the given item.
sticker_find $type $name [$path]
Returns a list of all the items โ optionally under $path โ that have a sticker of the given name.
close
Closes the connection. ngl this is pretty worthless, because the library will just reconnect for the next command anyway ๐ญ so likeโฆ do it for the plot, I guess.
kill
Kills the MPD server. okay miss thing, that's a lot of power ๐๐ช
ping
Does nothing. and honestly? iconic. This is the move for keeping an idle connection open. But if you actually want to wait for noteworthy events, the idle command is better suited โ ping is just there so the server doesn't ghost you ๐ป
disable_output $id
Disables the given output.
enable_output $id
Enables the given output.
outputs
Returns a list of the available outputs.
commands
Returns a list of the available commands. the menu ๐
not_commands
Returns a list of the unavailable commands. the anti-menu ๐
tag_types
Returns a list of all the available song metadata. (yes, spelled "avalable" in the source, we don't fix, we appreciate ๐)
url_handlers
Returns a list of the available url handlers.
decoders
Returns a list of available decoder plugins, along with the MIME types and file extensions associated with them. codec lore ๐ง
subscribe $channel
Subscribes to the named channel.
unsubscribe $channel
Unsubscribes from the named channel.
channels
Returns a list of the channels that have active clients. who's in the group chat ๐
read_messages
Returns a list of any available messages for the channels this client is subscribed to. unread messages, we hate to see it, but we read them anyway ๐ฌ
send_message $channel $message
Sends a message to the given channel. text delivered, slay ๐
๐ TODO ๐
Command Lists
MPD supports sending batches of commands, but that is not yet available with this API. someday bestie, someday ๐
Asynchronous IO
Event-based handling of the idle command would make this module more robust. a girl can dream โจ
โญ BUGS โญ
Idle connections
MPD will close the connection if it's left idle for too long ๐ญ This module will reconnect if it senses that this has happened โ but heads up, the first call after a disconnect will fail and you'll have to retry it. not a vibe but it's the truth.
Calling the ping command periodically will keep the connection open if you don't have any real commands to issue. And calling the idle command will block until something interesting happens. pick your fighter ๐ฅ
Reporting
Report any issues on GitHub <https://github.com/bentglasstube/Net-MPD/issues> โ the dev wants to hear from you, fr fr ๐ซถ
๐ AUTHOR ๐
Alan Berndt <alan@eatabrick.org>
๐ COPYRIGHT ๐
Copyright 2013 Alan Berndt
๐ง LICENSE ๐ง
okay so this next part is the actual license and we do not play with legal text, so here it is exactly as written, no remix, no edits ๐
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
โจ SEE ALSO โจ
okay bestie, you're basically a certified MPD girlie now, but if you wanna go even deeper (and likeโฆ same) here's the reading list ๐
Audio::MPDโ the other Perl module in this universe ๐ if you've seen it around, that's your sibling module energy. Go say hi.- MPD Protocol โ the actual spec, the source of truth, the main character ๐ read this when you want to know what's really happening on the wire.
- <http://www.musicpd.org/doc/protocol/index.html> โ the protocol docs live here, drop a bookmark, thank me later ๐ฆ
and that's a wrap, gorgeous ๐ธ you made it all the way to the bottom of Net::MPD(3pm) โ so iconic of you ๐
this lil beauty is from the perl v5.42.2 era, dated 2026-02-15, and it's giving โจ documentation, but make it cute โจ
now go queue up something good and let the daemon do its thing ๐๐ซถ
๐ฆ where this page comes from
- alpine 3.24: perl-net-mpd-doc 0.07-r4 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms