Skip to content

API Reference

coslyk edited this page Sep 6, 2020 · 10 revisions

This page lists the API that you can use in plug-ins.

Standard Javascript functions

Standard functions like console.log(), JSON.parse() can be used in plugins.

Network

In plugins, it's recommended to use these functions to get/post network data. These functions are easy to use, and they also apply MoonPlayer's network settings like proxy.

moonplayer.get_content(url, callback_func)

Download data from url.

  • url: Url of data to be download.
  • callback_func: Callback function.

Example:

function search(key, page) {
    var url = "http://api.example.com/search?key=" + key + "&page=" + page;
    moonplayer.get_content(url, function(content){
        do_something(content);
    });
}

moonplayer.post_content(url, post_data, callback_func)

Post data to url and get response data.

  • url: Url of data to be download.
  • post_data: data to be posted.
  • callback_func: Callback function.

Dialog

These functions show dialog window on screen.

moonplayer.warning(text):

Show a warning dialog.

  • text: Text to be shown.

Example:

moonplayer.warning('Naive! I am angry!');

moonplayer.question(text)

Show a question dialog. Returns boolean value.

  • text: Text to be shown.

Example:

if (moonplayer.question('Are you OK?')) {
    do_something();
}

moonplayer.get_text(msg)

Show a dialog to input some text.

  • msg: Message to be shown.

Example:

var api_key = moonplayer.get_text("Please enter the API Key:");
if (api_key !== '') {
    save_api_key(api_key);
}

moonplayer.get_item(msg, items)

Choose an item from the list.

  • msg: Message to be shown.
  • items: List of items.

Example:

var lang = moonplayer.get_item("Please choose the language of audio:", ["Chinese", "English"]);
if (lang === "Chinese") {
    parse_zh();
} else if (lang === "English") {
    parse_en();
}

Show results

moonplayer.show_result(result)

Show the search result in MoonPlayer.

  • result: list of objects in {title: "item 1", url: "url 1" } form.

Example:

var result = [
    { title: "item 1", url: "https://www.example.com/video1.mp4" },
    { title: "item 2", url: "https://www.example.com/video2.mp4" }
];
moonplayer.show_result(result);

Configuration

Store / Read plugin configurations.

moonplayer.set_configuration(name, value);

Store configurations.

  • name: Configuration item name.
  • value: Configuration item value.

Example:

moonplayer.set_configuration("api_key", api_key);

moonplayer.get_configuration(name);

Read configurations. Type of return value can be variable.

  • name: Configuration item name.

Example:

var api_key = moonplayer.get_configuration("api_key");