====== List of Functions ======

Below is a list of the Version 1 Lua functions

===== AudioResource =====
nil AudioResource(string title, string url, string description, string thumbnail, int duration); not fully supported
//sends a audio "link" to the media device//
AudioResource("Audio Name", "http://www.url.com/audio.mp3", "Audio Description", "http://www.url.com/audio.mp3", 10000);

===== ConvertTime =====
int ConvertTime(string time);
//converts a simple time stamp into milli-seconds//
ConvertTime("16:39");

===== DownloadAndSaveFile =====
string DownloadAndSaveFile(string url, string filePath);
//downloads the file at url and saves it to filePath//
local b = DownloadAndSaveFile("http://www.url.com/image.jpg", "c:\\image.jpg");
if not b then Log("Could not download file"); end;


===== DynamicVirtualFolder =====
nil DynamicVirtualFolder(string folderName, string folderAlias);
//works the same as VirtualFolder() only attempts to refresh the folder's contents//
DynamicVirtualFolder("Test Folder", "testFolderClicked");
function testFolderClicked()
do something here
end;


===== ExecuteFile =====
nil ExecuteFile(string filePath);
//executes a local file, launching it's default application, can also open web pages.//
ExecuteFile("http://www.google.com");

===== FileExists =====
string FileExists(string path);
//check if a file exists on the local machine//
local b = FileExist("c:\\test.txt");
if not b then Log("File does not exist"); end;


===== FormatRTMP =====
string FormatRTMP(string app, string super, string mediaPath, string swfUrl, string pageUrl, string extra)
//returns a formated XML string that can be sent as a RTMP handshake//

local url = "streaming.video.themis-media.com/ondemand/"
local path = "mp4:mp4/escapist/unforgotten-realms/966-c02ecfcfa2f4008b262620469b1a10e0.mp4"
local purl = "http://theescapist.com/"
local swf = "http://cdn2.themis-media.com/media/global/movies/player/LiveRailPlugin315.swf"

local rtmpString = FormatRTMP(url, 1, path, swf, purl, nil);

VideoResource("Test", rtmpString, "Description", "http://www.url.com/thumbnail.jpg", 100000);


===== GetCurrentPath =====
string GetCurrentPath();
//returns the current path on the local machine when playon is installed//
local path = GetCurrentPath();

===== GetDirListing =====
string GetDirListing(string path); deprecated
//returns parsable list of files in a dir//
local s = GetDirListing("C:\\");

===== GetDirListTable =====
table GetDirListTable(string path);\\
//returns a table of files in a directory//
local tbl = GetDirListTable("C:\\");

===== GetFileInfo =====
table GetFileInfo(string filePath);
//returns a table with information about a file//
local arr = GetFileInfo("C:\\test.txt");
Log(arr["Length"]); --get the size of the file.
Log(arr["CreationTime"]);
Log(arr["CreationTimeUTC"]);
Log(arr["Directory"]);
Log(arr["DirectoryName"]);
Log(arr["Exists"]);
Log(arr["Extension"]);
Log(arr["FullName"]);
Log(arr["LastAccessTime"]);
Log(arr["LastAccessTimeUtc"]);
Log(arr["LastWriteTime"]);
Log(arr["LastWriteTimeUtc"]);
Log(arr["Length"]);
Log(arr["Name"]);


===== GetLastHeader =====
string GetLastHeader();
//returns the last complete header received after calling GetURL or GetURLX//
local s=GetLastHeader();

===== GetScriptOption =====
string GetScriptOption(string optionName);
//returns the of value the option name stored in Scripts Plugin.ini//

local s=GetScriptOption("Name");
ShowMsg("Hi, "..s);


===== GetScriptOptionX =====
string GetScriptOptionX(string section, string optionName);
//returns the of value the option name stored in Scripts Plugin.ini//

local s=GetScriptOptionX("Test", "Name");
ShowMsg("Hi, "..s);


===== GetStringFromAMF =====
string GetStringFromAMF(string url, int totalChars);
//returns a AMF string that can be evaluated//

--url is the amf location and any qs arguments
--totalChars is how many we want to process in the request, we may not need the whole thing


===== GetTime =====
string GetTime(string type);
//returns the types of time//

local time = GetTime("utc"); --unix like time
local timeNow = GetTime("now"); --normal time
local timeHour = GetTime("hour");
local timeMinute = GetTime("minute");
local timeSecond = GetTime("second");
local timeDay = GetTime("day");
local timeMonth = GetTime("month");
local timeYear = GetTime("year");
--new in 0.6.0.0
local customDate = GetTime("month / day / year"); --will return: 11 / 10 / 2009


===== GetURL =====
string GetURL(string url);
//returns the contents of the url//
local s=GetURL("http://www.google.com/search?q=hello+world");

===== GetURLCached =====
string GetURLCached(string url, int lengthInMinutes);
//returns the contents of the url, if not cached. If it is cached it will serve only that cache file until lengthInMinutes is met//
local s=GetURLCached("http://www.google.com/search?q=hello+world");

===== GetURLX =====
string GetURLX(string url, string postData, string method, string referer, string userAgent, string contentType, int contentLength, string accept, string headersParse);
//returns the contents of the URL//
local s=GetURLX("http://www.google.com/","search?q=hello+world","POST","","Mozilla 4.0 etc","32","","Accept-Languageen-US,en;q=0.8");

===== GetURLxR =====
string GetURLxR(string url);
//returns the contents of the URL, without automatically following any redirect commands supplied by the server//
local s=GetURLxR("http://www.google.com/search?q=hello+world");

===== GetURLXxR =====
string GetURLXxR(string url, string postData, string method, string referer, string userAgent, string contentType, int contentLength, string accept, string headersParse);
//returns the contents of the URL, without automatically following any redirect commands supplied by the server//
local s=GetURLXxR("http://www.google.com/","search?q=hello+world","POST","","Mozilla 4.0 etc","32","","Accept-Languageen-US,en;q=0.8");

===== GetVideoPerformanceLevel =====
int GetVideoPerformanceLevel();
//returns the users Video Performance preference from the PlayOn Settings window//
local max_performance = 2147483647;
local high_performance = 1600;
local medium_performance = 1000;
local low_performance = 500;
if GetVideoPerformanceLevel() == max_performance then
ShowMsg("You have Max selected");
else if GetVideoPerformanceLevel() == high_performance then
ShowMsg("You have high selected");
else if GetVideoPerformanceLevel() == medium_performance then
ShowMsg("You have Medium selected");
else if GetVideoPerformanceLevel() == low_performance then
ShowMsg("You have Low selected");
end;


===== ImageResource =====
nil ImageResource(string title, string url, string description, string thumbnail); not fully supported
//sends a image "link" to the media device//
ImageResource("Image Name", "http://www.url.com/image.jpg", "Image Description", "http://www.url.com/thumbnail.jpg");

===== isnumeric =====
bool isnumeric(string possibleNumber);
//returns "true" if the supplied string is a number, returns nil if not//

local s = "22";
if isnumber(s) then
Log(s.." is a number");
end;


===== LoadScript =====
nil LoadScript(string luaFile);
//Executes the Lua script file found in luaFile.//
LoadScript("C:\\test.lua");

===== Log =====
nil Log(string message);
//writes to the text based log of the plugin//
Log("This is a test for the log.");

Log files are saved in this folder %ALLUSERSPROFILE%\MediaMall
===== OpenFile =====

string OpenFile(string path);
//open a file located on the hard drive//


local s = OpenFile("c:\\test.txt");
if s=="" then Log("Could not open file"); end;


===== ResolveXML =====
string ResolveXML(string url)
//returns a formated XML string that can be set to _SPECIAL_resolve_xml which then will be passed to PlayOn//
VideoResource("Test", "code:_SPECIAL_resolve_xml=ResolveXML('http://www.url.com/video.mp4');", "Description", "http://www.url.com/thumbnail.jpg", 100000);

===== RestartServer =====
nil RestartServer();
//immediatly restarts the playon server//
VirtualFolder("Restart Server", "code:RestartServer()");

===== RunScript =====
nil RunScript(string luaCode);
//Executes the Lua formatted code in luaCode.//
RunScript("local a = 1; Log(a+1);");

===== SaveFile =====
string SaveFile(string path, string contents);
//saves a file on the hard drive//
local b = SaveFile("c:\\test.txt", "Hello World");
if b=="<error>" then Log("Could not save file"); end;


===== SetScriptOption =====
nil SetScriptOption(string optionName, string optionValue);
//sets the value of the option name stored in Scripts Plugin.ini//

SetScriptOption("Name", "Mayor McCheese");
local s=GetScriptOption("Name");
ShowMsg("Hi, "..s);


===== SetScriptOptionX =====
nil SetScriptOptionX(string section, string optionName, string optionValue);
//sets the value of the option name stored in Scripts Plugin.ini//

SetScriptOptionX("Test", "Name", "Mayor McCheese");
local s=GetScriptOptionX("Test", "Name");
ShowMsg("Hi, "..s);


===== ShowMsg =====
nil ShowMsg(string message);
//Displays a VirtualFolder titled string, minus the code call.//
ShowMsg("Clicking this will do nothing");

===== SpecialResolveXML =====
nil SpecialResolveXML(string url)
//combines _SPECIAL_resolve_xml and ResolveXML into one function which then will be passed to PlayOn//
VideoResource("Test", "code:SpecialResolveXML('http://www.url.com/video.mp4');", "Description", "http://www.url.com/thumbnail.jpg", 100000);

===== str_escape =====
string str_escape(string subject)
//returns an url escaped string//
local s = str_escape("test/this/"); --returns test%2fthis%2f

===== str_find =====
string str_find(string subject, string find, int start);
//returns the position one string inside another, starting from start//
local a = str_find("hello", "ll", 0);

===== str_findlast =====
string str_findlast(string subject, string find, int start);
//returns the last position one string inside another, searching backwards from start//
local a = str_findlast("hello", "ll", 0);

===== str_get_between =====
string str_get_between(string subject, string findFirst, string findSecond, int start);
//returns the string found between the first and second string, starting from start//
local data = "<item>DATA</item>"
local str = str_get_between(data, "<item>", "</item>", 0);


===== str_get_between_a =====
string str_get_between_a(string subject, string findFirst, string findSecond, int start);
//returns a array containing the string found between the first and second strings, starting from start, and the position of the first and second strings//
local data = "<item>DATA</item>"
local tbl = str_get_between_a(data, "<item>", "</item>", 0);


===== str_html_decode =====
string str_html_decode(string subject)
//returns a string with html entities decoded//
local s =str_html_decode("test&amp;this"); --returns test&this

===== str_html_encode =====
string str_html_encode(string subject)
//returns a string with html entities encoded//
local s =str_html_encode("test&this"); --returns test&this

===== str_replace =====
string str_replace(string subject, string find, string replace);
//replaces one part of a string with another string//
local s = str_replace("Hello world!", "world", "Friend");

===== str_strip_tags =====
string str_strip_tags(string subject, string openTag, string closeTag);
//returns a string without the supplied tags//
local s =str_strip_tags("html is &lt;b&gt;cool", "<", ">"); --returns html is cool

===== str_split =====
string str_split(string subject, string delimeter);
//returns an array of strings divided by delimeter//
local arr = str_split("Hello World", " ");
Log(arr[1]); --prints Hello


===== str_trim =====
string str_trim(string subject);
//trims off leading and trailing spaces//
local s =str_trim(" hello "); --returns "hello"

===== str_unescape =====
string str_unescape(string subject)
//returns an url escaped string//
local s =str_unescape("test%2fthis%2f"); --returns test/this/

===== VideoResource =====
nil VideoResource(string title, string url, string description, string thumbnail, int duration)
//sends a video "link" to the media device//
VideoResource("Video", "http://www.url.com/video.mp4", "Video Description", "http://www.url.com/video.jpg", 10000);
--the URL field can also accept code:
VideoResource("Video", "func:nameOfFunction", "Video Description", "http://www.url.com/video.jpg", 10000);
VideoResource("Video", "code:_SPECIAL_resolve_xml=ResolveXML('http://www.url.com/video.mp4');", "Video Description", "http://www.url.com/video.jpg", 10000);
VideoResource("Video", "exec:Script Name.lua", "Video Description", "http://www.url.com/video.jpg", 10000);
--to include the date of a video, add the special XML to the description
VideoResource("Video", "http://www.url.com/video.mp4", 'Video Description<special date=\"1.0\"><year>2009</year><month>11</month><day>23</day></special>', "http://www.url.com/video.jpg", 10000);


===== VideoResourceX =====
nil VideoResourceX(table date)
//sends a video "link" to the media device//

local vrTable = {
title = "Tile of Video",
path = "URL, Local Path, or code",
description = "Video Description",
thumbnail = "URL to image",
date = "11/22/2009 12:33:00 PM",
duration = ConvertTime("1:00:00"),
bitrate = 0,
resolution = "1920x1080",
genre = "Funny",
rating = "G",
index = 1;
}
VideoResourceX(vrTable);
--the path field can also accept code, same as VideoResource.


===== VirtualFolder =====
nil VirtualFolder(string folderName, string folderAlias);
//creates a folder in the media device called folderName, folderAlias must be set as the function to be called when folder is clicked//
VirtualFolder("Test Folder", "testFolderClicked");
function testFolderClicked()
--do something here
end


===== VideoRestartServer =====
nil VideoRestartServer();
//plays a custom video, and restarts the playon server after a short delay//
VideoRestartServer();