English > Development

Creating own scripts

<< < (2/2)

nostra:
9. Built in parsing functions

function Pos(Substr : WideString; Str: WideString): Integer
Returns the index value of the first character in a specified substring that occurs in a given string.


function PosFrom(const SubStr, Str : WideString; FromIndex : Integer) : Integer
Returns the index value of the first character in a specified substring that occurs in a given string. Search starts from FromIndex[/b]


function LastPos(const SubStr, Str : WideString) : Integer
Returns the last index value of the first character in a specified substring that occurs in a given string.


function PrevPos(const SubStr, Str : WideString; APos : Integer) : Integer
Returns the index value of the first character in a specified substring that occurs in a given string before APos.


function RemoveTags(AText : WideString; doLineBreaks : Boolean) : WideString
Removes all HTML tags from AText. Ex.: <a href="http://test.com">Test</a> will be converted to Test. If doLineBreaks is set to True, then <br> will be converted to a line break.


function ExplodeString(AText : WideString; var Items : TWideArray; Delimiters : WideString) : Integer
Splits a string AText  into separate values using Delimiters. The values are written into a dynamic array Items.


function Copy(S: WideString; Index, Count: Integer): WideString
Returns a substring of a string.


procedure Delete(var S: WideString; Index, Count: Integer)
Removes a substring from a string.


procedure Insert(Source: WideString; var Dest: WideString; Index: Integer)
Inserts a substring into a string beginning at a specified point.


function Length(S: WideString): Integer
Returns the number of characters in a string.


function Trim(S: WideString): WideString
Trims leading and trailing spaces and control characters from a string.


function CompareText(S1, S2: WideString): Integer
Compares two strings by ordinal value without case sensitivity.
The function returns 0 if both strings are equal, a value > 0 if S1 > S2 and a value < 0 if S1 < S2.


function CompareStr(S1, S2: WideString): Integer
Compares two strings by ordinal value with case sensitivity.
The function returns 0 if both strings are equal, a value > 0 if S1 > S2 and a value < 0 if S1 < S2.


function UpperCase(S: WideString): WideString
Returns a copy of a string in uppercase.


function LowerCase(S: WideString): WideString
Returns a copy of a string in lowercase.


function StringReplace(S, OldPattern, NewPattern: WideString; ReplaceAll : Boolean; IgnoreCase : Boolean; WholeWord: Boolean): WideString 
Returns a string with occurrences of one substring replaced by another substring. If ReplaceAll is set to True, the all occurrences of OldPattern will be replaced. If IgnoreCase is set to True, then the comparison operation is case insensitive.


function StrToInt(const S: WideString): Integer
Converts a string that represents an integer (decimal or hex notation) to a number.


function IntToStr(const Value: Integer): WideString
Converts an integer number to a string.


function StrToFloat(const S: WideString): Extended
Converts a given string to a floating-point value.


  function FloatToStr(const Value: Extended): WideString
Converts a floating point value to a string.


function HTMLValues(const HTML : WideString; ABegin, AEnd, ItemBegin, ItemEnd : WideString; ValDelim : WideString; var Pos : Integer) : WideString
Gathers all values from HTML into a string using ValDelim as delimiter. The function searches for ABegin first starting from Pos, from this point it gathers values between ItemBegin and ItemEnd until AEnd is found. The last position is returned in Pos variable.


function HTMLValues2(const HTML : WideString; ABegin, AEnd, ItemBegin, ItemEnd : WideString; ValDelim : WideString; var Pos : Integer) : WideString
The same as HTMLValues, but this version searches for an end tag character > after each ItemBegin.


function TextBetween(const HTML : WideString; ABegin, AEnd : WideString; doLineBreaks : Boolean; var Pos : Integer) : WideString
Returns plain text without HTML tags from HTML, between ABegin and AEnd. The function searches for ABegin from position Pos.


function HTMLToText(const HTML : WideString) : WideString
Replaces all escaped HTML characters (like &lt;&gt;&amp;&quot;) with normal characters (like <, >, $, ")

nostra:
10. Functions for filling fields (at last :) )


10.1. Functions for filling standard fields (for information import plugins)

procedure AddSearchResult(Title1, Title2, Year, URL, PreviewURL : WideString)
Adds search result. You do not need to provide information for all the variables. Most import is to assign at least Title1 or Title2 and URL. If you do not have information to assign to a certain variable just pass ''. Ex.: AddSearchResult('Terminator', '', '', 'http://www.web-site.com/terminator.html', ''); //passes Title and URL only


procedure AddFieldValue(AField: Integer; AValue : WideString)
Fill a certain standard field with (AValue). AField can have following values:
For movies:
0URL1Title2Original Title3Aka4Year5Genre6Category7Country8Studio9MPAA10Additional rating11Tags12Tagline13Description14Duration15Features
For persons:
0URL1Name2Translated name3Alternative names4Date of birth5Place of birth6Genre7Biography8Date of death

procedure AddMoviePerson(Name, TransName, Role, URL : WideString; AType : Byte)
Adds movie credits (Actor, director, etc.). AType can have one of the following values:
0Actor1Director2Writer3Composer4Producer

procedure AddPersonMovie(Title, OrigTitle, Role, Year, URL : WideString; AType : Byte)
Adds a movie to a person's filmography. AType can have one of the following values:
0Actor1Director2Writer3Composer4Producer
procedure AddAward(Event, Award, Category, Recipient, Year: WideString; const Won : Boolean)
Adds an award. If you do not have information to assign to a certain variable just pass ''.


procedure AddConnection(Title, OrigTitle, Category, URL, Year: WideString)
Adds movie connection. If you do not have information to assign to a certain variable just pass ''.


procedure AddEpisode(Title, OrigTitle, Description, URL, Year, Season, Episode : WideString)
Adds an episode. If you do not have information to assign to a certain variable just pass ''.


10.2. Functions for filling other fields

procedure AddFieldValueXML(AField: WideString; AValue : WideString)
This function can be used to fill all fields except custom fields and structured fields like (credits, connections, episodes, filmography). Pass field value in AValue variable. AField is a name of the field and can have one of the following values:

For movies:
numtitleorigtitleakayeargenrecountrystudioreleasempaalocationcategorytaglinedescriptioncounttyperatingimdbratingoratingornameriplengthlangstranslationresolutionvideocodecvideobitrateaudiocodecaudiobitratesizeurlpathcommentdateaddedcodelabelloansubsframeratelabelfeaturesviewedbookmarkwishloandateviewdatetags

For persons:
nametransnamealtnamesbirthdaybirthplacebiodeath


procedure AddCustomFieldValueByNumber(CustomNumber: Integer; AValue : WideString)
Sets value of a custom field by field number.
CustomNumber - number of a custom field
AValue - field value (use '-1' for True(checked) and '0' for False)


procedure AddCustomFieldValueByName(CustomName: WideString; AValue : WideString)
Sets value of a custom field by field name.
CustomName - field name
AValue - field value (use '-1' for True(checked) and '0' for False)

nostra:
11. Other built in functions

procedure ShowMessage(const Msg, Head : WideString)
Show a message box with OK button.
Head - Window title
Msg - Message text


12. Debugging the script (check for errors)

Before you can tell the script is ready you must test it first. Start PVD with -debug command line parameter, like this: viddb.exe -debug
When you do this an additional menu item will become visible in "Help" menu called "Log".
In the log you can track following information:

* what plugins are loaded by PVD
* what scripts are compiled and executed
* what errors were found while compiling a script
* what URLs are downloaded by PVD
If a script is wrong (contains errors) it will not be loaded into the program, so it can not be selected from the Import menu or visible in Preferences -> Plugins.

If an error acquired while compiling a script, an error message apears in log with detailed information about the wrong line in script code and type of an error.
Ex.: [Error] (366:2): Semicolon (';') expected

Sometimes you can find hints produced by script compiler.
Ex.: [Hint] (368:2): Variable 'TEST' never used

If a script can be compiled but does not work as it should you could use the ShowMessage function to output variable values and check the URLs PVD downloads in program log.

The last page downloaded is save into a file page.html in program directory while in -debug mode.

Navigation

[0] Message Index

[*] Previous page

Go to full version