File release/contrib/lualibs/mympd.lua
Functions
mympd.api (method, params) | Calls the myMPD jsonrpc api |
mympd.covercache_write (src, uri) | Write a file for the cover cache |
mympd.hash_sha1 (string) | Returns the SHA1 hash of string. |
mympd.hash_sha256 (string) | Returns the SHA256 hash of string. |
mympd.http_client (method, uri, headers, payload) | Simple HTTP client |
mympd.http_download (uri, 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.lyricscache_write (str, uri) | Write a string to a file in the lyrics cache |
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.thumbscache_write (src, tagvalue) | Write a file for the thumbs cache |
mympd.tmp_file () | Generates a random tmp filename for the misc cache |
mympd.urldecode (string, form) | URL decoding |
mympd.urlencode (string) | URL encoding |
Functions
- mympd.api (method, params)
-
Calls the myMPD jsonrpc api
Parameters
- method:
- params:
Return values:
- 0 for success, else 1
- jsonrpc result
- mympd.covercache_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 value:
written name - mympd.hash_sha1 (string)
-
Returns the SHA1 hash of string.
Parameters
- string: String to hash
Return value:
SHA1 hash of string - mympd.hash_sha256 (string)
-
Returns the SHA256 hash of string.
Parameters
- string: String to hash
Return value:
SHA256 hash of string - mympd.http_client (method, uri, headers, payload)
-
Simple HTTP client
Parameters
- method: HTTP method, only GET or POST is supported
- uri: The uri to access
- headers: Additional headers terminated by "\r\n"
- payload: Payload to send (POST only)
Return values:
- rc 0 for success, else 1
- HTTP status code
- HTTP Headers
- HTTP Body
- mympd.http_download (uri, out)
-
Download a file over http
Parameters
- uri: The uri to access
- out: Filename to write the response body
Return value:
0 for success, else 1 - 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
- mympd.log (loglevel, message)
-
Logs to the myMPD log.
Parameters
- loglevel: Syslog loglevel 0 = Emergency 1 = Alert 2 = Critical 3 = Error 4 = Warning 5 = Notice 6 = Info 7 = Debug
- message:
- mympd.lyricscache_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 value:
written name - mympd.notify_client (severity, message)
-
Sends a notification to the client that started this script.
Parameters
- severity: Severity 0 = Info 1 = Warning 2 = 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 = Info 1 = Warning 2 = 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.thumbscache_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 value:
written name - mympd.tmp_file ()
-
Generates a random tmp filename for the misc cache
Return value:
temp filename - mympd.urldecode (string, form)
-
URL decoding
Parameters
- string: String to URL decode
- form: true = decode a url form encoded string
Return value:
Decoded string - mympd.urlencode (string)
-
URL encoding
Parameters
- string: String to URL encode
Return value:
Encoded string