Rmpcd provides a set of functions available on the global scope to help with plugin development.
Each of the plugins runs on a fully separate Lua VM and as such they are completely isolated from
each other which means that they do not share state and cannot block each other.
You also should not use any of the Lua built in blocking APIs such as io library as that could
starve rmpcd’s async executor.
These modules are available on the global scope
mpd - Functions to interact with MPD directly. These are relatively low level primitives
mirroring the MPD protocol
fs - A set of functions used to interact with the filesystem
http - A simple HTTP client
log - Logging facilities
process - To spawn external programs
sync - Utilities to for asynchronous execution
util - Set of random utility functions that do not fit anywhere else
These functions correspond to the MPD
protocol , see its documentation for more
details.
They are available on global scope by accessing the mpd table.
Function Description + Expand row get_songGet song by its URI Parameters Returns Song | nil The song object if found string | nil Error message if any
+ Expand row get_song_by_idGet song by its ID in the current queue Parameters Returns Song | nil The song object if found string | nil Error message if any
+ Expand row get_current_songGet the currently playing song Parameters Returns Song | nil The song object if found string | nil Error message if any
+ Expand row set_song_stickerSet a song sticker Parameters uri string Song URI name string Sticker name value string Sticker value
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row get_song_stickerGet a song sticker value Parameters uri string Song URI name string Sticker name
Returns string | nil The sticker value if success, nil otherwise string | nil Error message if any
+ Expand row set_consumeSet the consume state Parameters value "on", "off" or "oneshot" The consume state
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row set_crossfadeSet crossfade duration Parameters seconds number Crossfade duration in seconds
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row set_randomSet the random state Parameters value boolean Whether to enable or disable random
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row set_repeatSet the repeat state Parameters value boolean Whether to enable or disable repeat
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row set_singleSet the single state Parameters value "on", "off" or "oneshot" The single state
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row set_volumeSet MPD's volume Parameters volume number Volume between 0 and 100
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row get_volumeGet MPD's current volume Returns number | nil The volume value if successful string | nil Error message if any
+ Expand row volumeSet MPD's volume, supports relative change Parameters value string +5 to increase volume by 5, -5 to decrease by 5 and 5 to set to 5
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row prevSwitch to the previous song Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row nextSwitch to the next song Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row playStart playback Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row pausePause playback Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row stopStop playback Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row toggle_pauseToggle pause state on/off Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row seek_currentSeek the current song Parameters value string +5 to seek forward by 5 seconds, -5 to seek backwards by 5 seconds and 5 to seek to the 5th second directly
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row get_statusReturns MPD's current status info Returns MpdStatus MPD's current status string | nil Error message if any
+ Expand row album_artGet song's album art by searching for cover.jpg, cover.png or cover.webp in the song's directory Parameters Returns number[] | nil Raw bytes of the image if successful string | nil Error message if any
+ Expand row read_pictureGet song's embedded image Parameters Returns number[] | nil Raw bytes of the image if successful string | nil Error message if any
+ Expand row subscribeSubscribe to a channel Parameters channel string Channel name
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row unsubscribeUnsubscribe from a channel Parameters channel string Channel name
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row channelsList of currently active channels Returns string[] | nil List of active channels if successful string | nil Error message if any
+ Expand row send_messageSend message to a channel Parameters channel string Channel name message string Message to send
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row read_messagesRead messages from all channels that rmpcd is currently subscribed to, this probably should not be used directly unless you know what you are doing Returns table Messages if successful string | nil Error message if any
Filesystem API. These are available on global scope by accessing the fs table.
Function Description + Expand row existsCheck whether a file exists Parameters Returns boolean true if the file exists string | nil Error message if any
+ Expand row create_dir_allCreate all directories in the path if they do not exist already Parameters path string Directory path
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row create_dirCreate a directory Parameters path string Directory path
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row writeWrite raw bytes to a file Parameters path string File path contents number[] Raw bytes
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row write_strWrite a string to a file Parameters path string File path contents string Content to write
Returns boolean Whether the call was successful string | nil Error message if any
+ Expand row readRead raw bytes from a file Parameters Returns number[] | nil Raw bytes if successful string | nil Error message if any
+ Expand row read_strRead file as string Parameters Returns string | nil String content if successful string | nil Error message if any
+ Expand row deleteDelete a file Parameters Returns boolean Whether the file was deleted string | nil Error message if any
+ Expand row remove_dirRemove a directory Parameters path string Directory path
Returns boolean Whether the directory was deleted string | nil Error message if any
+ Expand row remove_dirRemove a directory recursively Parameters path string Directory path
Returns boolean Whether the directory was deleted string | nil Error message if any
A simple HTTP client. Available on the global scope by accessing the http table.
Function Description + Expand row callDo an HTTP call Parameters url string URL to call to opts HttpRequestOpts Options for the HTTP request
Returns HttpResponse The response, see below for more details
+ Expand row getDo a GET request Parameters url string URL to call to opts HttpGetOpts Options for the GET HTTP request
Returns HttpResponse The response, see below for more details
+ Expand row postDo a POST request Parameters url string URL to call to opts HttpGetOpts Options for the POST HTTP request
Returns HttpResponse The response, see below for more details
Each of the http functions takes an opts table.
Property Description methodHTTP method string headerstable of HTTP headers bodyString body paramstable to send as query parameters
The get function only takes headers and params in opts.
The post function only takes headers, params and body in opts.
The response is a table with following properties and functions:
Property or function Description codeHttp Response code errorString error if any bodyRaw string body of the response + Expand row textGets the body text + Expand row jsonGets the body json as a table
Logging facilities. Available on the global scope by accessing the log table.
Function Description + Expand row infoLog at the info level Parameters content string String content to log
+ Expand row warnLog at the warn level Parameters content string String content to log
+ Expand row errorLog at the error level Parameters content string String content to log
+ Expand row debugLog at the debug level Parameters content string String content to log
+ Expand row traceLog at the trace level Parameters content string String content to log
Spawn external processes. Available on the global scope by accessing the process table.
Function Description + Expand row spawnSpawn an external process Parameters cmd string[] First element is the program to spawn, rest are passed in as arguments
Returns number | nil The child process PID string | nil Error message if any
Execute things asynchronously. Available on the global scope by accessing the sync table.
Function Description + Expand row set_timeoutSchedule a function to run at some later time Parameters timeout_ms number Timeout in milliseconds callback function A function to run when the timeout expires
Returns TimeoutHandle A handle to the timeout, call handle.cancel() to cancel the timeout
+ Expand row set_intervalSchedule a function to run repeatedly with an interval Parameters interval_ms number Interval in milliseconds callback function A function to run every interval tick
Returns TimeoutHandle A handle to the interval, call handle.cancel() to cancel the interval
+ Expand row debounceCreate a debounced version of a function Parameters interval_ms number Interval in milliseconds callback function A function to run when the debounce timeout expires
Returns function The debounced function
Set of random utilities that do not fit anywhere else. Available on the global scope by accessing
the util table.
Function Description + Expand row dump_tableDump table to the logger Parameters tbl table Dump the table to the logger
+ Expand row md5Compute an md5 hash of a value Parameters + Expand row whichCheck whether a program exists in path Parameters Returns boolean Whether the program exists
+ Expand row nil_or_nullCheck whether a value is nil or null, useful to for example validate HTTP responses Parameters Returns boolean Whether the value is nil or nul
+ Expand row deserialize_ron Deserialize a ron value Parameters data number[] Input bytes
Returns any | nil Deserialized value if success string | nil Error message if any