Movian Development
overview
Movian 插件使用 ECMAScript
编写,从 v4.9.401
起使用解析器 Duktape
Movian plugins do not interact directly to the user via the user interface (similar to a web browser) but rather respond to browse and search requests and populate the internal data model with information that is then presented to the user via Movian’s user interface(s).
Structure of a plugin
每个插件都在它自己的目录中。该目录必须包含一个 plugin.json
文件,其中包含有关该插件的信息。除了 plugin.json
文件之外,对插件目录中文件的命名没有进一步的限制,或者文件放在子目录中等等
plugin.json
Headweb
插件为例:
{
"type": "ecmascript",
"apiversion": 1,
"id": "headweb",
"file": "headweb.js",
"showtimeVersion": "4.1.22",
"version": "1.5.3",
"author": "Andreas Öman",
"title": "Headweb",
"icon": "headweb_square.png",
"synopsis": "Headweb online video",
"category": "video",
"description": "<p>Headweb is a Swedish online video store.<p>For more information, visit <a href=\"http://www.headweb.com\">http://www.headweb.com</a>",
"homepage":"https://github.com/andoma/showtime-plugin-headweb"
}
type (REQUIRED)
Type of plugin, as described by the following list.
- ecmascript - loads the plugin using Duktape.
- views - used for user interface (screen keyboard plugin)
apiversion (OPTIONAL)
Only applicable if type is ecmascript, ie. when running using the Duktape engine. This controls the API exposed by Movian to the plugin.
- 1 - The version 1 API is the default and is compatible with the API which was exposed through the old SpiderMonkey engine.
- 2 - The version 2 API is a new API which more resembles modern ECMAScript using modules and CommonJS interfaces. Please try to use this.
The version 1 API is emulated using the version 2 API using a wrapper. The emulation code can be found here api-v1
id (REQUIRED)
Unique identifier for a plugin. The IDs are assigned by the Movian project. Any ID starting with the string “test” is reserved for development and can be used by plugin developers until a final ID has been assigned. The assigned IDs will be ASCII lowercase. To get an ID please mail andreas@lonelycoder.com
file (REQUIRED)
Name of the plugin executable/script. Usually it’s a good idea to give the file a name resembling the plugin ID.
title (RECOMMENDED)
Short title of the Plugin. If omitted the ‘id’ field will be used instead which might look a bit bad due to lowercasing, etc
showtimeVersion (RECOMMENDED)
Minimum version required of Movian for this plugin to work. If the current version of Movian is less than this version the user won’t be able to install the plugin but will be notified about what version of Movian is required. The same goes if a plugin is updated and the new version requires a newer version of Movian. Then the user will be refused to upgrade the plugin. If this field is omitted Movian will assume the plugin works on all versions of Movian.
version (RECOMMENDED)
Version of the plugin. If this does not match the current installed version of a user’s plugin the user will be presented with the possibility to upgrade the plugin. If the field is omitted Movian will set the version to “Unknown”
category (RECOMMENDED)
Category of the plugin. If the field is omitted Movian will set the category to “Unknown”. Following categories are known:
- “tv” - online TV
- “video” - streaming video
- “music” - streaming music
- “glwview” - UI extentions
- “subtitles” - subtitles
- “glwosk” - on screen keyboard
synopsis (RECOMMENDED)
A short one line summary of the plugin or the service it accesses
author (OPTIONAL)
Plugin developer. Any UTF-8 characters are valid.
homepage (RECOMMENDED)
An URI with the location of the plugin homepage
icon (OPTIONAL)
Path to plugin icon. The path is relative to the plugin root directory. If no icon is available Movian will use a placeholder image instead.
description (OPTIONAL)
Long RichText formatted (some HTML features are supported) description of the plugin.
Getting Started
debug
You can reload the development plugin at any time by pressing Shift+F5
in Movian
./build.linux/showtime -d -p testplugin
Go ahead and create the directory:
mkdir testplugin
Edit the JSON file with your favorite text editor:
vim testplugin/plugin.json
And put the required fields in there:
{
"type": "ecmascript",
"file": "testplugin.js",
"id": "testplugin"
}
Now go ahead and edit the ECMAScript file
vim testplugin/testplugin.js
(function(plugin) {
showtime.print("Hello! I'm a plugin running inside Movian " + showtime.currentVersionString);
})(this);
URI
Almost everything in Movian has an URI. This is used for crossplugin communications and interaction with user via unified search edit box at the top of the home screen. Each plugin registers URI starting with plugin’s ID.
(function(plugin) {
plugin.addURI("testplugin:hello", function(page) {
showtime.print("I was called");
})
})(this);
testplugin:helllo
是 URI
,将触发函数
somafa
中的 start URI
plugin.addURI(plugin.getDescriptor().id + ":start", function(page) {
...
}
somafm:start
触发函数 start
ECMAScript API reference
This API is effective for plugins with apiversion: 1
Service object
res/ecmascript/modules/movian/service.js
Showtime object
res/ecmascript/legacy/api-v1.js
Plugin object
res/ecmascript/legacy/api-v1.js
Page object
res/ecmascript/modules/movian/page.js
Item object
res/ecmascript/modules/movian/page.js
Settings object
res/ecmascript/modules/movian/settings.js
HTTP response object
res/ecmascript/modules/movian/http.js
Playing a video file
Playing (or more correctly referring to) a video can be done in two ways.
- Direct URL
- Via a video page
XML parsing in ECMAScript
When using ECMAScript and Duktape the plugins need to rely on Movian’s XML parser. To access do:
var XML = require('showtime/xml');
Parsing HTML with Movian
Starting with version 4.9.389 Movian features a HTML parsing library called gumbo.
This allows parsing of a HTML DOM using APIs not very different from a normal browser.
To use it first do:
var html = require('showtime/html');