(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=m a x Title=Videoguide.ru Description=Import data & picture from videoguide.ru Site=videoguide.ru Language=RU Version=1.02 Requires=3.5.0 Comments=Based on the script made for version 3.x by Yan Sorkin (ysorkin@mail.ru) License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GetInfo=1 [Options] ***************************************************) program VideoGuide; const BaseAddress = 'http://www.videoguide.ru/'; var MovieName: string; function GetTextBlockFrom(Text: string; StartAt: string): string; var TextBlock: string; StartPos, EndPos: Integer; begin TextBlock := Text; StartPos := pos(StartAt, TextBlock); if StartPos > 0 then begin Delete(TextBlock, 1, StartPos - 1); result := TextBlock; end; end; function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer; var i: Integer; begin result := -1; if StartAt < 0 then StartAt := 0; for i := StartAt to List.Count-1 do if Pos(Pattern, List.GetString(i)) <> 0 then begin result := i; Break; end; end; procedure AnalyzePage(Address: string); var Page: TStringList; LineNr: Integer; Line: string; TextBlock: string; begin Page := TStringList.Create; Page.Text := GetPage(Address); if pos('
';
LineNr := FindLine(Value2, Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos(Value2, Line) + Length(Value2);
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
Value := StringReplace(Value, '
', #13#10);
Value := StringReplace(Value, '
', #13#10);
Value := StringReplace(Value, '
-1 then begin Line := Page.GetString(LineNr); BeginPos := pos('src="', Line) + 4; Delete(Line, 1, BeginPos); EndPos := pos('"', Line); Value := copy(Line, 1, EndPos - 1); GetPicture(Value); // False = do not store picture externally ; store it in the catalog file end; // DisplayResults; end; procedure AnalyzeVideoPage(Page: TStringList); var Line, Value, Value2, FullValue: string; LineNr, MovieLength: Integer; BeginPos, EndPos: Integer; begin // Title, Original Title, Country, Year, Length, Category LineNr := FindLine('
', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
// Title
BeginPos := pos('">', Line) + 2;
EndPos := pos('', Line);
if EndPos = 0 then
EndPos := Length(Line);
FullValue := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(FullValue);
HTMLRemoveTags(FullValue);
FullValue := AnsiLowerCase(FullValue);
FullValue := AnsiUpFirstLetter(FullValue);
SetField(fieldOriginalTitle, FullValue);
// Original Title (if exists)
BeginPos := pos('
/', Line) + 12;
EndPos := pos('/ ', Line);
if (BeginPos > 0) and (EndPos > 0) then
begin
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
HTMLRemoveTags(Value);
Value := AnsiLowerCase(Value);
Value := AnsiMixedCase(Value, ' .-');
SetField(fieldOriginalTitle, Value);
SetField(fieldTranslatedTitle, FullValue);
Delete(Line, 1, EndPos + 7);
end;
// Country
BeginPos := pos('
', Line);
if BeginPos = 0 then
BeginPos := 1;
EndPos := pos(' ', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
HTMLRemoveTags(Value);
SetField(fieldCountry, Value);
Delete(Line, 1, EndPos + 6);
// Year and Length
BeginPos := 1;
EndPos := pos(' ', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldYear, Value);
BeginPos := pos(' ', Line) + 7;
EndPos := pos(' мин', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldLength, Value);
end;
//Category
LineNr := FindLine('
', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('/>', Line) + 2;
EndPos := Length(Line) + 1;
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
SetField(fieldCategory, Value);
end;
// Director
LineNr := FindLine('Режиссер:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos(' ', Line) + 5;
EndPos := Length(Line) + 1;
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
HTMLRemoveTags(Value);
SetField(fieldDirector, Value);
end;
// Actors
LineNr := FindLine('В ролях:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos(' ', Line) + 6;
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
HTMLRemoveTags(Value);
SetField(fieldActors, Value);
end;
//Description
LineNr := FindLine('
', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); BeginPos := pos('
', Line) + 19;
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
Value := StringReplace(Value, '
', #13#10);
Value := StringReplace(Value, '
', #13#10);
Value := StringReplace(Value, '
-1 then begin Line := Page.GetString(LineNr); BeginPos := pos('src="', Line) + 4; Delete(Line, 1, BeginPos); EndPos := pos('"', Line); Value := copy(Line, 1, EndPos - 1); GetPicture(Value); // False = do not store picture externally ; store it in the catalog file end; // DisplayResults; end; procedure AnalyzeRedirectPage(Page: TStringList); var Address: string; BeginPos, EndPos: Integer; begin BeginPos := pos('ReDirect("', Page.Text) + 10; EndPos := pos('")', Page.Text); Address := BaseAddress + copy(Page.Text, BeginPos, EndPos - BeginPos); AnalyzePage(Address); end; procedure AddFindMoreLink(Page: TStringList; var LineNr: Integer); var Line, Value, Address: string; StartPos, EndPos: Integer; begin Line := Page.GetString(LineNr); StartPos := pos('См. также: оставшиеся ', Value); Address := BaseAddress + copy(Value, StartPos, EndPos - StartPos); PickTreeMoreLink(Address); end; procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer); var Line: string; MovieTitle, MovieAddress: string; StartPos, EndPos: Integer; begin repeat LineNr := LineNr + 1; Line := Page.GetString(LineNr); StartPos := pos('="', Line); EndPos := pos('', Line); if (StartPos > 0) and (EndPos = 0) then begin StartPos := StartPos + 2; MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos); StartPos := pos('">', Line) + 2; MovieTitle := copy(Line, StartPos, pos('', Line) - StartPos); Line := Page.GetString(LineNr + 1); MovieTitle := MovieTitle + copy(Line, 1, pos('', Line) - 1); HTMLDecode(Movietitle); HTMLRemoveTags(MovieTitle); PickTreeAdd(MovieTitle, BaseAddress + MovieAddress); end; until EndPos > 0; end; procedure AddReleasesTitles(TextBlock: string); var MovieTitle, MovieAddress: string; StartPos, EndPos, EndTablePos: Integer; begin repeat StartPos := pos('