(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=micmic, bad4u, bhilam Title=IMP Awards Description=Movie importation script for IMP Awards Site=http://www.impawards.com/ Language=EN Version=2.5 Requires=3.5.0 Comments= 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 RequiresMovies=1 [Options] [Parameters] ***************************************************) program impawards; uses StringUtils1; var MovieName: string; tmpMovieName: string; // used to replace spaces with period const BaseURL = 'http://impawards.com/search.php?search_data='; procedure AnalyzeFirstPage(IMPAwardsURL: string); var AFPPageText: string; AFPPriliminarySearchValue: string; AFPSecondarySearchValue: string; AFPSecondaryURLValue: string; Address: string; begin AFPPageText := GetPage(IMPAwardsURL); Address := 'http://www.impawards.com/'; //ShowMessage('1st Page Text:' + AFPPageText); if Pos('sorry, but the search you performed did not return any results.', AFPPageText) > 0 then begin ShowMessage('No movie found for this search'); Exit; end; PickTreeClear; PickTreeAdd('Search results for "' + MovieName + '" on IMP Awards :', ''); // loop through the page for the first time if the movie is found and pick each one of them for display AFPPriliminarySearchValue := TextBetween(AFPPageText, '
', '(') + ' (' + ASPGetYear + ') " on IMP Awards :', ''); // Note: Added '/' at the end of the string as a trick to getting around searching for the text until i understand better how to program in delphi ASPPriliminarySearchValue := TextBetween(ASPPageText, '
', '('); //ShowMessage('Zero First link: ' + ASPFirstLink); PickTreeAdd(ASPFirstLink , ASPPriliminarySearchValue); end else begin //ShowMessage('Non-Zero First link: ' + ASPFirstLink); PickTreeAdd(TextBetween(ASPPriliminarySearchValue, 'http://www.impawards.com/' + ASPGetYear + '/', '/') , Address + ASPFirstLink); end; //ShowMessage('3rd Page Text:' + ASPPageText); ASPSecondarySearchValue := TextBetween(ASPPageText, '', '> ');
//ShowMessage('ASP Secondary Search Value: ' + ASPSecondarySearchValue);
if Length(ASPSecondarySearchValue) > 0 then
begin
repeat
//ShowMessage('ASP Secondary Search Value: ' + ASPSecondarySearchValue);
ASPSecondaryURLValue:= TextBetween(ASPSecondarySearchValue, '
0 then
PickTreeAdd(ASPSecondaryURLValue, Address + ASPSecondaryURLValue);
until ASPSecondaryURLValue = '';
// end
// else
// begin
// ShowMessage('No alternate posters found');
end;
if PickTreeExec(IMPAwardsURL) then
AnalyzeThirdPage(IMPAwardsURL);
end;
procedure AnalyzeThirdPage(IMPAwardsURL: string);
var
ATPPageText: string;
ATPGetYear: string;
ATPPrePriliminarySearchValue: string;
ATPPriliminarySearchValue: string;
ATPSecondarySearchValue: string;
ATPSecondaryURLValue: string;
Address: string;
PosterCount: integer;
result: integer;
ATPFirstLink: string;
begin
PosterCount := 0; //assume no posters are found
ATPPageText := GetPage(IMPAwardsURL);
//ShowMessage('4th Page Text:' + ATPPageText);
if Pos('sorry, but the search you performed did not return any results.', ATPPageText) > 0 then
begin
ShowMessage('No movie found for this search');
Exit;
end;
PickTreeClear;
ATPGetYear := TextBetween(ATPPageText, '(', ')
'); //ShowMessage('ASP Get Year: ' + ATPGetYear); Address := TextBetween(ATPPageText, '', '(') + ' (' + ATPGetYear + ') " on IMP Awards :', ''); //ShowMessage('5th Page Text:' + ATPPageText); ATPPrePriliminarySearchValue := TextBetween(ATPPageText, '
',' border="0" />'); //ShowMessage('ATP Pre-Priliminary Search Value: ' + ATPPrePriliminarySearchValue); ATPPriliminarySearchValue := TextBetween(ATPPageText, '
0 then
begin
//ShowMessage('Multiple size poster found.');
// handle the current page poster which is smaller size as everyone may not want to grab the biggest size poster
//ShowMessage('ATP Pre-Priliminary Search Value: ' + ATPPrePriliminarySearchValue);
ATPFirstLink := StringReplace(TextBetween(ATPPrePriliminarySearchValue, '
');
//ShowMessage('ATP Secondary Search Value:' + ATPSecondarySearchValue);
ATPSecondarySearchValue:= StringReplace(ATPSecondarySearchValue, '>', ': ');
//ShowMessage('ATP Secondary Search Value:' + ATPSecondarySearchValue);
ATPSecondaryURLValue := TextBetween(ATPPrePriliminarySearchValue, '');
//ShowMessage('ATP Secondary URL Value:' + ATPSecondaryURLValue);
ATPPrePriliminarySearchValue:= RemainingText;
HTMLRemoveTags(ATPSecondarySearchValue);
HTMLDecode(ATPSecondarySearchValue);
if Length(ATPSecondarySearchValue) > 0 then
PickTreeAdd(ATPSecondarySearchValue, Address + ATPSecondaryURLValue);
//ShowMessage('ATP Secondary Search Value Cleaned Up:' + ATPSecondarySearchValue);
until ATPSecondarySearchValue = '';
end
else
begin
//ShowMessage('Only one size poster found');
//ShowMessage('ATP Pre-Priliminary Search Value:' + ATPPrePriliminarySearchValue);
ATPSecondarySearchValue := TextBetween(ATPPrePriliminarySearchValue, 'alt = "','"');
//ShowMessage('ATP Secondary Search Value:' + ATPSecondarySearchValue);
ATPSecondaryURLValue := TextBetween(ATPPrePriliminarySearchValue, '
0 do
begin
Inc(Result);
lPosition := PosEx(aSubstring, aString, lPosition + Length(aSubstring));
end;
end;
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
PosIni, PosFin: Integer;
dirBase: string;
txtTemp: string;
ImgTMP: string;
begin
Page := TStringList.Create;
//ShowMessage('Text:' +StringReplace(GetPage(Address), '
0 then
begin
txtTemp := Copy(Page.Text, PosIni + Length(txtTemp), 100);
PosFin := pos('"', txtTemp);
ImgTMP := Copy(txtTemp, 1, PosFin - 1);
//ShowMessage('Getting: ' + dirBase + 'posters/' + ImgTMP);
GetPicture(dirBase + 'posters/' + ImgTMP);
end
end;
Page.Free;
//DisplayResults;
end;
// bmicmic: Bucle Principal
begin
if CheckVersion(3,5,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
Input('Import of IMP Awards', 'Enter the title of the movie:', MovieName);
//replace spaces with period to accomodate IMPAwards search string changes
tmpMovieName := StringReplace(MovieName, ' ', '.');
MovieName := tmpMovieName;
//ShowMessage('URL: ' + BaseURL + UrlEncode(MovieName));
AnalyzeFirstPage(BaseURL + UrlEncode(MovieName));
end
else
ShowMessage('This scripts requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.
', #13#10)); Page.Text := StringReplace(GetPage(Address), '
', #13#10); //obtenemos directorio base PosFin := 0; dirBase := Address; PosIni := pos('/', dirBase); while PosIni > 0 do begin PosFin := PosFin + PosIni; dirBase := Copy(dirBase, PosIni + 1, Length(DirBase)); PosIni := pos('/', dirBase); end; dirBase := Copy(Address, 1, PosFin); //ShowMessage('dirBase: ' + dirBase); //ShowMessage('Page Text: ' + Page.Text); //buscamos la imagen txtTemp := '