Code: Select all
program MovieMeter;
uses
StringUtils1;
var
MovieName: string;
procedure AnalyzeMoviePage(Address: string);
var
PageText, Line, Value: string;
begin
PageText := GetPage(Address);
// URL
SetField(fieldURL, Address);
// title & year
Line := TextBetween(PageText, '<h1>', '</h1>');
Value := TextBetween(Line, '(', ')');
SetField(fieldYear, Value);
Value := Trim(TextBefore(Line, '(', ''));
HTMLDecode(Value);
SetField(fieldOriginalTitle, Value);
// translated title
Line := TextBetween(PageText, 'Alternatieve titel', ' </p>');
if Line <> '' then
begin
Line := TextAfter(Line, ': ');
if Line <> '' then
begin
HTMLDecode(Line);
SetField(fieldTranslatedTitle, Line);
end;
end;
Value := TextBetween(PageText, '<div id="film_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '-->');
// Country
if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0) then
Value := TextBefore(Value, ' / ', '');
HTMLDecode(Value);
SetField(fieldCountry, Value);
// Category
Value := TextBefore(Line, '<br />', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldCategory, Value);
// Length
Value := TextBefore(Line, ' minuten', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldLength, Value);
// Director
Value := TextBetween(Line, 'geregisseerd door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDirector, Value);
// Actors
Value := TextBetween(Line, 'met ', '<br />');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldActors, Value);
// Description
Value := TextBetween(Line, '<br />', '</div>');
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDescription, Value);
// Picture
Value := TextBetween(PageText, '<img id="poster" class="poster" src="', '" ');
if Value <> '' then
begin
GetPicture(Value);
end;
// Rating
Value := TextBetween(PageText, '</span>gemiddelde <b>', '<');
Value := StringReplace(FloatToStr(StrToFloat(StringReplace(Value, ',', '.')) * 2), ',', '.');
SetField(fieldRating, Value);
// Comments
if GetOption('ImportComments') = 1 then
begin
Value := TextBetween(PageText, '<div class="forum_message_user">', '<div class="to_page entitypages" id="pages_bottom"></div>');
Value := StringReplace(Value, ' uur', ' uur : ' + #13#10);
// Value := StringReplace(Value, '<div class="forum_message_message">', #13#10);
Value := StringReplace(Value, '</div><div class="form_horizontal_divider" ', '-------------------------------------------------------------' + #13#10 + #13#10 + '<');
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldComments, Value);
end;
end;
procedure AnalyzeResultsPage(Address: string);
var
Page: TStringList;
Line: string;
MovieAddress: string;
MovieTitle: string;
aantal : integer;
begin
// get results page
aantal := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
// get redirect javascript
Line := Page.GetString(Page.Count-2);
// more than 1 movie found
if Pos('location.replace("http://www.moviemeter.nl/film/searchresults#results");', Line) <> 0 then
begin
PickTreeClear;
PickTreeAdd('Zoekresultaten voor ' + MovieName, '');
// get results page
Page.Text := GetPage('http://www.moviemeter.nl/film/searchresults#results');
if Pos('Populaire zoekresultaten in films:', Page.Text) > 0 then
Line := TextBetween(Page.Text, 'Populaire zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
if Pos('Alle zoekresultaten in films:', Page.Text) > 0 then
Line := TextBetween(Page.Text, 'Alle zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
if Pos('Zoekresultaten in films:', Page.Text) > 0 then
Line := TextBetween(Page.Text, 'Zoekresultaten in films:</p>', '<form action="http://www.moviemeter.nl/film/search/"');
Line := TextBetween(Line, '</p></div>', '<p><br /></p>');
while Pos('filmresults_row', Line) > 0 do
begin
MovieAddress := TextBetween(Line, 'href="', '" >');
MovieTitle := TextBefore(Line, '</p></div>', '');
Line := RemainingText;
HTMLRemoveTags(MovieTitle);
HTMLDecode(MovieTitle);
PickTreeAdd(Trim(MovieTitle), MovieAddress);
aantal := aantal + 1;
end;
if aantal = 0 then
begin
ShowMessage('Geen resultaten gevonden...');
Page.Free;
exit;
end;
// if user picks a movie from the results list, import movie details
if PickTreeExec(Address) then
AnalyzeMoviePage(Address);
end
else
begin
MovieAddress := TextBetween(Line, '("', '");');
if MovieAddress <> 'http://www.moviemeter.nl/film/' then
// if only 1 movie found --> redirect to movie page
AnalyzeMoviePage(MovieAddress)
else
// no movies found
ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
end;
Page.Free;
end;
begin
if CheckVersion(3,5,0) then
begin
if StringUtils1_Version >= 2 then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('MovieMeter.nl Import', 'Geef de titel van de film:', MovieName) then
begin
AnalyzeResultsPage('http://www.moviemeter.nl/film/search/'+UrlEncode(MovieName));
end;
end
else
ShowMessage('The file "StringUtils1.pas" is outdated, please find a new version of it (at least version 2)');
end
else
ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)');
exit;
end.