File release/contrib/lualibs/mympd.lua
Functions
mympd.api (method, params) | Calls the myMPD jsonrpc api |
mympd.cache_cover_write (src, uri) | Write a file for the cover cache |
mympd.cache_lyrics_write (str, uri) | Write a string to a file in the lyrics cache |
mympd.cache_thumbs_write (src, tagvalue) | Write a file for the thumbs cache |
mympd.dialog (title, data, callback) | Returns an Jsonrpc response for a script dialog. |
mympd.hash_md5 (str) | Returns the MD5 hash of string. |
mympd.hash_sha1 (str) | Returns the SHA1 hash of string. |
mympd.hash_sha256 (str) | Returns the SHA256 hash of string. |
mympd.htmlencode (str) | Simple HTML encoding |
mympd.http_client (method, uri, extra_headers, payload) | Simple HTTP client |
mympd.http_download (uri, extra_headers, out) | Download a file over http |
mympd.http_jsonrpc_error (method, msg) | Sends a JSONRPC 2.0 error. |
mympd.http_jsonrpc_response (obj, result) | Sends a JSONRPC 2.0 response. |
mympd.http_jsonrpc_warn (method, msg) | Sends a JSONRPC 2.0 warning. |
mympd.http_redirect (location) | Sends a HTTP temporary redirect (302). |
mympd.http_reply (status, header, body) | Sends a HTTP reply. |
mympd.http_serve_file (file) | Serves a file from the filesystem. |
mympd.init () | Populate the global mympd_state lua table |
mympd.log (loglevel, message) | Logs to the myMPD log. |
mympd.notify_client (severity, message) | Sends a notification to the client that started this script. |
mympd.notify_partition (severity, message) | Sends a notification to all clients in the current partition. |
mympd.os_capture (cmd) | Execute a system command and capture its output |
mympd.read_file (path) | Read an ascii file |
mympd.sleep (ms) | Sleep ms |
mympd.splitlines (str) | Split string by newline characters and trims the lines |
mympd.tmp_file () | Generates a random tmp filename for the misc cache |
mympd.trim (str) | Trims a string |
mympd.update_mtime (filename) | Updates the timestamp of a file |
mympd.urldecode (str, form) | URL decoding |
mympd.urlencode (str) | URL encoding |
Functions
- mympd.api (method, params)
-
Calls the myMPD jsonrpc api
Parameters
- method:
- params:
Return values:
- 0 for success, else 1
- jsonrpc result for success, else error
- mympd.cache_cover_write (src, uri)
-
Write a file for the cover cache
Parameters
- src: File to rename
- uri: URI to create the cover cache file for
Return values:
- 0 on success, else 1
- written name or error message on error
- mympd.cache_lyrics_write (str, uri)
-
Write a string to a file in the lyrics cache
Parameters
- str: String to save (it must be a valid lyrics json string)
- uri: URI to create the lyrics cache file for
Return values:
- 0 on success, else 1
- written name or error message on error
- mympd.cache_thumbs_write (src, tagvalue)
-
Write a file for the thumbs cache
Parameters
- src: File to rename
- tagvalue: Tag value to create the thumbs cache file for
Return values:
- 0 on success, else 1
- written name or error message on error
- mympd.dialog (title, data, callback)
-
Returns an Jsonrpc response for a script dialog.
Parameters
- title: Dialog title
- data: Dialog definition
- callback: Script to call for the submit button
Return value:
Jsonrpc response - mympd.hash_md5 (str)
-
Returns the MD5 hash of string.
Parameters
- str: String to hash
Return value:
MD5 hash of string - mympd.hash_sha1 (str)
-
Returns the SHA1 hash of string.
Parameters
- str: String to hash
Return value:
SHA1 hash of string - mympd.hash_sha256 (str)
-
Returns the SHA256 hash of string.
Parameters
- str: String to hash
Return value:
SHA256 hash of string - mympd.htmlencode (str)
-
Simple HTML encoding
Parameters
- str: String to HTML encode
Return value:
Encoded string - mympd.http_client (method, uri, extra_headers, payload)
-
Simple HTTP client
Parameters
- method: HTTP method, e.g. GET, POST
- uri: The uri to access
- extra_headers: Additional headers terminated by "\r\n"
- payload: Payload to send
Return values:
- rc 0 for success, else 1
- HTTP status code
- HTTP Headers as Lua table
- HTTP Body
- mympd.http_download (uri, extra_headers, out)
-
Download a file over http
Parameters
- uri: The uri to access
- extra_headers: Additional headers terminated by "\r\n"
- out: Filename to write the response body
Return values:
- 0 for success, else 1
- HTTP status code
- HTTP Headers as Lua table
- mympd.http_jsonrpc_error (method, msg)
-
Sends a JSONRPC 2.0 error.
Parameters
- method: API method
- msg: Error message
Return value:
HTTP response - mympd.http_jsonrpc_response (obj, result)
-
Sends a JSONRPC 2.0 response.
Parameters
- obj:
- result: jsonrpc result object
Return value:
HTTP response - mympd.http_jsonrpc_warn (method, msg)
-
Sends a JSONRPC 2.0 warning.
Parameters
- method: API method
- msg: Error message
Return value:
HTTP response - mympd.http_redirect (location)
-
Sends a HTTP temporary redirect (302). Can be only used in the "http" event
Parameters
- location: Location to redirect
Return value:
HTTP response - mympd.http_reply (status, header, body)
-
Sends a HTTP reply. Can be only used in the "http" event
Parameters
- status: HTTP status code
- header: Additional headers terminated by "\r\n"
- body: HTTP Body to send
Return value:
HTTP response - mympd.http_serve_file (file)
-
Serves a file from the filesystem. Only files from the diskcache are allowed.
Parameters
- file: file to serve
Return value:
HTTP response - mympd.init ()
-
Populate the global mympd_state lua table
Return values:
- 0 for success, else 1
- jsonrpc result for success, else error
- mympd.log (loglevel, message)
-
Logs to the myMPD log.
Parameters
- loglevel: Syslog loglevel 0 = LOG_EMERG = Emergency 1 = LOG_ALERT = Alert 2 = LOG_CRIT = Critical 3 = LOG_ERR = Error 4 = LOG_WARNING = Warning 5 = LOG_NOTICE = Notice 6 = LOG_INFO = Info 7 = LOG_DEBUG = Debug
- message:
- mympd.notify_client (severity, message)
-
Sends a notification to the client that started this script.
Parameters
- severity: Severity 0 = SEVERITY_INFO = Info 1 = SEVERITY_WARNING = Warning 2 = SEVERITY_ERR = Error
- message: Jsonrpc message to send
- mympd.notify_partition (severity, message)
-
Sends a notification to all clients in the current partition.
Parameters
- severity: Severity 0 = SEVERITY_INFO = Info 1 = SEVERITY_WARNING = Warning 2 = SEVERITY_ERR = Error
- message: Jsonrpc message to send
- mympd.os_capture (cmd)
-
Execute a system command and capture its output
Parameters
- cmd: Command to execute
Return value:
Captured output of cmd - mympd.read_file (path)
-
Read an ascii file
Parameters
- path: Filename
Return value:
File content or nil on error - mympd.sleep (ms)
-
Sleep ms
Parameters
- ms: Milliseconds to sleep
- mympd.splitlines (str)
-
Split string by newline characters and trims the lines
Parameters
- str: String to split
Return value:
tables of lines - mympd.tmp_file ()
-
Generates a random tmp filename for the misc cache
Return value:
temp filename - mympd.trim (str)
-
Trims a string
Parameters
- str: String to trim
Return value:
Trimed string - mympd.update_mtime (filename)
-
Updates the timestamp of a file
Parameters
- filename: File to update the timestamp
Return value:
0 on success, else 1 - mympd.urldecode (str, form)
-
URL decoding
Parameters
- str: String to URL decode
- form: true = decode a url form encoded string
Return value:
Decoded string - mympd.urlencode (str)
-
URL encoding
Parameters
- str: String to URL encode
Return value:
Encoded string