(* Additional types and functions that can be used in scripts: //Types TWIDEARRAY : array of String //Field functions procedure AddSearchResult(Title1, Title2, Year, URL, PreviewURL : String) procedure AddFieldValue(AField: Integer; AValue : String) procedure AddMoviePerson(Name, TransName, Role, URL : String; AType : Byte) procedure AddPersonMovie(Title, OrigTitle, Role, Year, URL : String; AType : Byte) procedure AddAward(Event, Award, Category, Recipient, Year: String; const Won : Boolean) procedure AddConnection(Title, OrigTitle, Category, URL, Year: String) procedure AddEpisode(Title, OrigTitle, Description, URL, Year, Season, Episode : String) //String functions function Pos(Substr : String; Str: String): Integer function PosFrom(const SubStr, Str : String; FromIndex : Integer) : Integer function LastPos(const SubStr, Str : String) : Integer function PrevPos(const SubStr, Str : String; APos : Integer) : Integer function RemoveTags(AText : String; doLineBreaks : Boolean) : String function ExplodeString(AText : String; var Items : TWideArray; Delimiters : String) : Integer function Copy(S: String; Index, Count: Integer): String procedure Delete(var S: String; Index, Count: Integer) procedure Insert(Source: String; var Dest: String; Index: Integer) function Length(S: String): Integer function Trim(S: String): String function CompareText(S1, S2: String): Integer function CompareStr(S1, S2: String): Integer function UpperCase(S: String): String function LowerCase(S: String): String function StringReplace(S, OldPattern, NewPattern: String; ReplaceAll : Boolean; IgnoreCase : Boolean; WholeWord: Boolean): String function StrToInt(const S: String): Integer function IntToStr(const Value: Integer): String function StrToFloat(const S: String): Extended function FloatToStr(const Value: Extended): String function HTMLValues(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String function HTMLValues2(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String function TextBetween(const HTML : String; ABegin, AEnd : String; doLineBreaks : Boolean; var Pos : Integer) : String function HTMLToText(const HTML : String) : String procedure ShowMessage(const Msg, Head : String) *) //Some useful constants const //Script types stMovies = 0; stPeople = 1; stPoster = 2; //Script modes smSearch = 0; smNormal = 1; //Parse results prError = 0; prFinished = 1; prList = 2; prListImage = 3; prDownload = 4; //Movie fields mfURL = 0; mfTitle = 1; mfOrigTitle = 2; mfAka = 3; mfYear = 4; mfGenre = 5; mfCategory = 6; mfCountry = 7; mfStudio = 8; mfMPAA = 9; mfRating = 10; mfTags = 11; mfTagline = 12; mfDescription = 13; mfDuration = 14; mfFeatures = 15; //People fields pfURL = 0; pfName = 1; pfTransName = 2; pfAltNames = 3; pfBirthday = 4; pfBirthplace = 5; pfGenre = 6; pfBio = 7; pfDeathDate = 8; //Credits types ctActors = 0; ctDirectors = 1; ctWriters = 2; ctComposers = 3; ctProducers = 4; //Script data SCRIPT_VERSION = '0.1.1.1'; SCRIPT_NAME = 'Text file 1a'; SCRIPT_DESC = '[EN] Get movie information from text file 1a'; SCRIPT_LANG = $09; //English SCRIPT_LANG1 = $07; //Deutsch, German SCRIPT_TYPE = stMovies; CODE_PAGE = 0; //Use 0 for Autodetect //Global variables var Mode : Byte; //Functions function GetScriptVersion : String; begin Result := SCRIPT_VERSION; end; function GetScriptName : String; begin Result := SCRIPT_NAME; end; function GetScriptDesc : String; begin Result := SCRIPT_DESC; end; function GetScriptLang: Cardinal; begin Result := SCRIPT_LANG; end; function GetCodePage : Cardinal; begin Result := CODE_PAGE; end; function GetBaseURL : AnsiString; begin Result := ''; end; function GetDownloadURL : AnsiString; var Path : String; P : Integer; begin Path := GetFieldValue(31); P := Pos('|', Path); if P < 1 then P := Length(Path) + 1; Path := Copy(Path, 1, P - 1); if Path <> '' then Path := ChangeFileExt(Path, '.txt') else Path := 'C:\dummy.txt'; Result := Path; end; function GetScriptType : Byte; begin Result := SCRIPT_TYPE; end; function GetCurrentMode : Byte; begin Result := Mode; end; function RemoveTagsEx(AText : String) : String; var B, E : Integer; begin Result := AText; B := PosFrom('(', Result, 1); E := PosFrom(')', Result, B); while (B > 0) AND (B < E) do begin Delete(Result, B, E - B + 1); B := Pos('(', Result); E := Pos(')', Result); end; end; procedure ParseMovie(HTML : String); var curPos, EndPos, debug_pos1 : Integer; Country, Description, Years, Years1, Years2, Darsteller, Regie, Drehbuch, Musik : String; // Produktion : String; P : Integer; V : TWideArray; I : Integer; begin // Years EndPos := Pos('Darsteller', HTML); if endPos > 0 then begin curPos := PrevPos(#28, HTML, EndPos) + Length(#28); EndPos := PosFrom(#13, HTML, curPos); Years2 := Trim(Copy(HTML, curPos - 1, EndPos - curPos + 1)); //if Years2 <> '' then AddFieldValue(mfAka, Years2); end; // Description EndPos := PosFrom(#13, HTML, curPos); curPos := PosFrom(#13, HTML, EndPos); curPos := curPos + Length(#13); EndPos := PosFrom(#13, HTML, curPos) + 10000; curPos := curPos; Description := Trim(Copy(HTML, curPos - 1, EndPos - curPos + 1)); Description := StringReplace(Description, #32#47#32, #32#38#32, true, false, true); Description := StringReplace(Description, #32#47, #32, true, false, true); // AddFieldValueXML('comment', Description); if (Description <> '') AND (Years2 <> '') then AddFieldValueXML('comment', Years2+#13+Description); // Country EndPos := Pos('Darsteller', HTML); if EndPos > 0 then begin curPos := PrevPos(#41, HTML, EndPos) + Length(#41); EndPos := PosFrom('Darsteller', HTML, curPos) - 8; Country := Trim(Copy(HTML, curPos, EndPos - curPos)); Country := StringReplace(Country, #32#47#32, #44#32, true, false, true); Country := StringReplace(Country, 'Direktaufnahme vom Fernsehen', '', true, false, true); debug_pos1:=Pos('von ',Country); if debug_pos1 >0 then Country := Copy(Country,0,debug_pos1-1); debug_pos1:=Pos(', 1957',Country); if debug_pos1 >0 then Country := Copy(Country,0,debug_pos1-1); AddFieldValue(mfCountry, Country); end; // Years EndPos := Pos('Darsteller', HTML); if endPos > 0 then begin curPos := PrevPos(#40, HTML, EndPos) + Length(#40); EndPos := PosFrom(#41, HTML, curPos); Years1 := Trim(Copy(HTML, curPos, EndPos - curPos)); if Years1 <> '' then AddFieldValue(mfYear, Years1); end; // Years EndPos := Pos('Darsteller', HTML); if endPos > 0 then begin curPos := PrevPos(', ', HTML, EndPos) + Length(', '); EndPos := PosFrom(#13, HTML, curPos); Years:= Trim(Copy(HTML, curPos, EndPos - curPos)); if Years <> '' then AddFieldValue(mfYear, Years); end; // Produktion curPos := PosFrom('Produktion: ', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Produktion: '); EndPos := PosFrom('Darsteller: ', HTML, curPos); // EndPos := PosFrom(#13, HTML, curPos); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Trim(Copy(HTML, curPos, EndPos - curPos)), V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctProducers); end; // Darsteller/innen curPos := PosFrom('Darsteller/innen:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Darsteller/innen:'); EndPos := PosFrom(#13, HTML, curPos); Darsteller := Trim(Copy(HTML, curPos, EndPos - curPos)); Darsteller := RemoveTagsEx(Darsteller); Darsteller := StringReplace(Darsteller, ' u.a.', '', true, false, true); Darsteller := StringReplace(Darsteller, '­', '', true, false, true); Darsteller := StringReplace(Darsteller, ' und ', ', ', true, false, true); ExplodeString(Darsteller, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctActors); end; // Darsteller curPos := PosFrom('Darsteller:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Darsteller:'); EndPos := PosFrom(#13, HTML, curPos); Darsteller := Trim(Copy(HTML, curPos, EndPos - curPos)); Darsteller := RemoveTagsEx(Darsteller); Darsteller := StringReplace(Darsteller, ' u.a.', '', true, false, true); Darsteller := StringReplace(Darsteller, '­', '', true, false, true); Darsteller := StringReplace(Darsteller, ' und ', ', ', true, false, true); ExplodeString(Darsteller, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctActors); end; // Musik curPos := PosFrom('Musik:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Musik:'); EndPos := PosFrom(#13, HTML, curPos); Musik := Trim(Copy(HTML, curPos, EndPos - curPos)); Musik := RemoveTagsEx(Musik); Musik := StringReplace(Musik, ' und ', ', ', true, false, true); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Musik, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctComposers); end; // Buch und Regie curPos := PosFrom('Buch und Regie: ', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Buch und Regie: '); EndPos := PosFrom(#13, HTML, curPos); Drehbuch := Trim(Copy(HTML, curPos, EndPos - curPos)); Drehbuch := RemoveTagsEx(Drehbuch); Drehbuch := StringReplace(Drehbuch, ' und ', ', ', true, false, true); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Drehbuch, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctWriters); ExplodeString(Trim(Copy(HTML, curPos, EndPos - curPos)), V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctDirectors); end; // Buch curPos := PosFrom('Buch:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Buch:'); EndPos := PosFrom(#13, HTML, curPos); Drehbuch := Trim(Copy(HTML, curPos, EndPos - curPos)); Drehbuch := RemoveTagsEx(Drehbuch); Drehbuch := StringReplace(Drehbuch, ' und ', ', ', true, false, true); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Drehbuch, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctWriters); end; // Drehbuch und Produktion curPos := PosFrom('Drehbuch und Produktion: ', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Drehbuch und Produktion: '); EndPos := PosFrom(#13, HTML, curPos); Drehbuch := Trim(Copy(HTML, curPos, EndPos - curPos)); Drehbuch := RemoveTagsEx(Drehbuch); Drehbuch := StringReplace(Drehbuch, ' und ', ', ', true, false, true); ExplodeString(Drehbuch, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctWriters); ExplodeString(Drehbuch, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctProducers); end; // Drehbuch curPos := PosFrom('Drehbuch:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Drehbuch:'); EndPos := PosFrom(#13, HTML, curPos); Drehbuch := Trim(Copy(HTML, curPos, EndPos - curPos)); Drehbuch := RemoveTagsEx(Drehbuch); Drehbuch := StringReplace(Drehbuch, ' und ', ', ', true, false, true); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Drehbuch, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctWriters); end; // Produktion und Regie curPos := PosFrom('Produktion und Regie: ', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Produktion und Regie: '); EndPos := PosFrom(#13, HTML, curPos); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Trim(Copy(HTML, curPos, EndPos - curPos)), V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctProducers); ExplodeString(Trim(Copy(HTML, curPos, EndPos - curPos)), V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctDirectors); end; // Regie // EndPos := PosFrom('Regie: ', HTML, curPos); curPos := PosFrom('Regie:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Regie:'); EndPos := PosFrom(#32#47, HTML, curPos); P := PosFrom(' ...', HTML, curPos); if (P > 0) AND (P < EndPos) then EndPos := P; ExplodeString(Trim(Copy(HTML, curPos, EndPos - curPos)), V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctDirectors); end; // Regie // EndPos := PosFrom('Regie: ', HTML, curPos); curPos := PosFrom('Regie:', HTML, EndPos); if curPos > 0 then begin curPos := curPos + Length('Regie:'); EndPos := PosFrom(#13, HTML, curPos); Regie := Trim(Copy(HTML, curPos, EndPos - curPos)); Regie := StringReplace(Regie, ' und ', ', ', true, false, true); ExplodeString(Regie, V, ','); for I := Low(V) to High(V) do AddMoviePerson(V[I], '', '', '', ctDirectors); end; end; function ParsePage(HTML : String; URL : AnsiString) : Cardinal; begin ParseMovie(HTML); Result := prFinished; end; begin Mode := smSearch; end.