The showtime object¶
Properties¶
currentVersionInt¶
Current version of Movian encoded as an integer. This can be used to check if running a given version X or greater, etc.
The version number is encoded as:
v = major * 10000000 + minor * 100000 + commit;
So to check if the running Movian is 3.4.2 or greater, just do
if(showtime.currentVersionInt >= 30400002) {
// yep
}
currentVersionString¶
Display name of current version. This will also include GIT commit hash and dirty flag.
deviceId¶
Returns deviceId which should be unique for every device (it's a hash based on various things)
Remember that your plugin must check for version 4.5.369 before depending on this property (either by a hard dependency in the plugin.json file or you could check that in runtime, like this:
if (showtime.currentVersionInt >= 40500369) {
showtime.print(showtime.deviceId);
}
Functions¶
trace(String Message, [String Tag])¶
Send/print message to Movian's debug log. The Tag value identifies the message in a context, if that value is not specified, Movian will use by default "JS".
This will appear both in log and on the console if Movian is started with the -d option.
print(String Message)¶
Print Message to the console. To get it working it's a must to run Movian with -d switch (works only in debug mode).
httpGet(String URL, [Object QueryArgs], [Object Headers], [Object Control])¶
This method is deprecated in favour of showtime.httpReq()
- URL - URL to request. HTTP:// and HTTPS:// is supported.
- QueryArgs - Object with properties that will be appended to the URL
as query arguments. This can also be a list of objects and if so the
properties from each object will be merged. - Headers - Object with properties that will be interpreted as extra
HTTP headers to send. If these includes a header that is default
sent by Movian, the default will be overridden with the value from
this object. Available from 3.1.177 - Control - Object with properties that control the HTTP client.
The following properties are understood: Available from 3.5.125
- debug - If set to true, it will print debug info about the transfer
- noFollow - If set to true, no redirects will be followed
- headRequest - If set to true, the request will return only headers
Returns a HTTP response object
httpPost(String URL, Object PostData, [Object QueryArgs], [Object Headers], [Object Control])¶
This method is deprecated in favour of showtime.httpReq()
- URL - URL to request. HTTP:// and HTTPS:// is supported.
- PostData - Object where each property will be encoded and POSTed as
application/x-www-form-urlencoded content. - QueryArgs - Object with properties that will be appended to the URL
as query arguments. This can also be a list of objects and if so the
properties from each object will be merged. - Headers - Object with properties that will be interpreted as extra
HTTP headers to send. If these includes a header that is default
sent by Movian, the default will be overridden with the value from
this object. Available from 3.1.177 - Control - See httpGet method
Returns a HTTP response object
httpReq(String URL, [Object Parameters])¶
Perform an HTTP request to URL according to a bunch of optional parameters.
Available from 4.3.210
Parameter | Type | Description |
---|---|---|
args | Object | Each property and its corresponding value will be send as a URL query args (appended to the URL after proper URI escaping) |
headers | Object | Objects with additional headers. Any header specified here will override Movian's default headers |
postdata | If postdata is a string it will be send as-is (and content type will be set to text/ascii). If postdata is an object it will be URI encoded and sent as application/x-www-form-urlencoded (Standard form post) |
|
method | String | Can be used to override method. By default Movian will try to infer the method. GET is default unless postdata is set in which case it is POST |
debug | Boolean | If set to true debug information about the request is sent to Movian's standard logging output |
noFollow | Boolean | Ask HTTP client to not follow HTTP redirects (this is default off which means that Movian follows them) |
headRequest | Boolean | Do an HTTP HEAD request instead of GET |
caching | Boolean | Turn on local HTTP caching of objects. The local HTTP cache complies with HTTP cache-control header meaning that an object will only be cached as long as the server tells us to. If the object have expired Movian will still retain it in its cache for a while but the request will be a conditional GET (meaning that it uses If-Modified-Since and/or If-None-Match HTTP headers) to check if the object have changed server-side. This is default off. |
compression | Boolean | Ask server (via Accept-Encoding) to transfer contents compressed with gzip. This is default off. |
cacheTime | Number | Force Movian to keep result in cache for at least this many seconds (if server allows Movian to cache it longer it will do so). This implicitly turns on 'caching' This is default 0. |
noFail | Boolean | Returns response object even if the request fails with an error (available from 4.99.211) |
Returns a HTTP response object
Example¶
var v = showtime.httpReq("http://showtime.lonelycoder.com/plugins/plugins-v1.json", {
debug: true,
compression: true,
headers: {
'X-foo-bar': 'baz'
},
args: {
version: 33
}
});
readFile(String URL)¶
Open the file specified by URL and return the contents as a String
This method should only be used for development and is not available in release builds of Movian
querySplitString(String s)¶
Returns object with properties set to values according to contents from the query string.
pathEscape(String s)¶
Escapes a URL Path component.
paramEscape(String s)¶
Escapes a HTTP query parameter component.
canHandle(String URL)¶
Return true if Movian can handle the URL. This does not open or probe the URL in any way. It's a strict syntax check.
message(String Message, Boolean ShowOk, Boolean ShowCancel)¶
Display a message to the user.
- Message - text to display to the user
- ShowOk - Set to true if a OK button should be displayed
- ShowCancel - Set to true if a Cancel button should be displayed
Return true if OK was pressed, false otherwise.
sleep(Integer seconds)¶
Sleep for the specified time (in seconds).
JSONEncode(Object o)¶
JSON encodes the Object and return the encoded JSON string.
JSONDecode(String s)¶
JSON decodes the String and return a JSON Object.
entityDecode(String s)¶
Decode HTML entities in string s and return the new string
Available from 3.5.174
notify(String s, Int i, [String icon])¶
Create a Popup that shows the string s during i seconds. Optionally with the icon being displaced next to the notification
Available from 3.99.48
time()¶
Return current time in seconds since 1970
durationToString(Integer duration)¶
Convert duration into a string that is suitable for display to the user for presentation of duration (of movies, etc)
43 -> 0:43 3601 -> 1:00:01
probe(String URL)¶
Available from 3.1.156
Probe the given URL to check if it is accessible.
Returns an object with two properties
- result - Result code, 0 means OK, the following codes are currently defined
- 1 - Authentication problem - Resource can not be probed due to missing authentication credentials
- 2 - No URI handler - No support for the URI scheme
- 3 - Fail - Other failure
- errmsg - Error message intended to be displyed to the user
md5digest(String s)¶
Available from 4.1.389
Return a 16 byte hexstring representing the MD5 digest of input string s
sha1digest(String s)¶
Available from 4.1.389
Return a 20 byte hexstring representing the SHA-1 digest of input string s
textDialog(String Message, Boolean ShowOk, Boolean ShowCancel)¶
Shows a box with a message where user can write something intended.
Returns an object with one of following fields:- input - If not cancelled, it contains the text inserted by user
- rejected - If cancelled, defines the state of the text dialog
- Message - text to display to the user
- ShowOk - Set to true if a OK button should be displayed
- ShowCancel - Set to true if a Cancel button should be displayed
systemIpAddress()¶
Available from 4.1.192
Return a string with the system IP address. At the moment this is IPv4 only.
xmlrpc(String URL, String Method, ...)¶
Available from 4.1.402
Invoke an XMLRPC request to the specified URL. Method is sent as the XMLRPC Method and the rest of the arguments are sent as XMLRPC arguments.
Returns an array with return values.
For example usage see the Opensubtitles Plugin
getSubtitleLanguages()¶
Return an array object with the user's preferred subtitle languages. The language strings are in ISO 639-2 encoding
basename(String path)¶
Return basename of the path. If path = '/blah/foo/bar' then it retuns 'bar'
RichText(String html)¶
Return richtext object created from html string
Link(String alias, String URI)¶
Returns link object for use in metadata when there is a link that can be followed to an Artist or Album, etc