Script Request for www.CineGuia.com.br
Posted: 2002-12-07 18:26:01
Code: Select all
// GETINFO SCRIPTING
// Cine Guia (BR) import
(***************************************************
* Movie importation script for: *
* Cine Guia (BR), http://www.cineguia.com.br *
* *
* (c) 2003 Louis Francisco ork@everydayangels.net *
* *
* For use with Ant Movie Catalog 3.4.1 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
* *
* The source code of the script can be used in *
* another program only if full credits to *
* script author and a link to Ant Movie Catalog *
* website are given in the About box or in *
* the documentation of the program *
***************************************************)
program CineGuia;
var
MovieName: string;
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;
BeginPos: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
//Added this line, thought it could be useful...
LineNr := FindLine('Foram encontrados muitos resultados para sua pesquisa, você precisa fazer um pesquisa mais precisa', Page, 0);
if LineNr <> -1 then
begin
Page.Free;
//Too much titles, wanna retry?
ShowMessage('Foram encontrados muitos resultados para sua pesquisa, você precisa fazer um pesquisa mais precisa');
if Input('Cine Guia Import', 'Enter the title of the movie:', MovieName) then
begin
AnalyzePage('http://www.cineguia.com.br/index.shtml?search='+UrlEncode(MovieName)+'&Submit=++Busca++&op=filmes');
end;
end
else
begin
LineNr := FindLine('--> Resultado da busca para:', Page, 0);
if LineNr = -1 then
begin
//Almost forgot about that javascript redirection
LineNr := FindLine('location.href="', Page, 0);
if LineNr <> -1 then
begin
Address := Page.GetString(LineNr);
delete(Address, 1, pos('location.href="', Address)+14);
Address := 'http://www.cineguia.com.br/' + copy(Address, 1, pos('"', Address)-1);
SetField(fieldURL, Address);
Page.Text := GetPage(Address);
AnalyzeMoviePage(Page);
end;
end
else
begin
PickTreeClear;
AddMoviesTitles(Page, LineNr);
if PickTreeExec(Address) then
begin
SetField(fieldURL, Address);
Page.Text := GetPage(Address);
AnalyzeMoviePage(Page);
end;
end;
Page.Free;
end;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Line, Value: string;
LineNr, IntValue: Integer;
BeginPos, EndPos: Integer;
Field: integer;
begin
LineNr := FindLine('function trl(link) {', Page, 0);
if LineNr > -1 then LineNr := FindLine('<td>', Page, LineNr);
// Translated Title
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<b>', Line) + 3;
EndPos := pos('</b>', Line);
if EndPos=0 then EndPos := length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldTranslatedTitle, Value);
end;
//Fly over external links
LineNr := FindLine('Site Oficial', Page, LineNr);
if LineNr > -1 then
begin
LineNr := FindLine('<font size="2"', Page, LineNr+1);
if LineNr > -1 then
begin
Value := '';
repeat
Value := Value + Page.GetString(LineNr);
LineNr := LineNr + 1;
until pos('</font>', Value)>0;
HTMLRemoveTags(Value);
SetField(fieldDescription, Value);
end;
end;
LineNr := FindLine('Ficha Técnica', Page, LineNr);
if LineNr > -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
repeat
//May have multiple lines of table in one line of html
while pos('<tr>', Line) > 0 do
begin
//Get a full line
while pos('</tr>', Line) = 0 do
begin
LineNr := LineNr + 1;
Line := Line + Page.GetString(LineNr);
end;
//Look for type of line
EndPos := pos('</td>', Line);
if EndPos > 0 then
begin
Value := copy(Line, 1, EndPos - 1);
HTMLRemoveTags(Value);
Delete(Line, 1, EndPos + 4);
if Value = 'Título Original:' then
Field := fieldOriginalTitle
else if Value = 'Direção:' then
Field := fieldDirector
else if Value = 'Produtor:' then
Field := fieldProducer
else if Value = 'Produção:' then
Field := fieldCountry //Special case: <country> <year>
else if Value = 'Gênero:' then
Field := fieldCategory
else if Value = 'Duração:' then
Field := fieldLength //Special case: <length> minutos
else if Value = 'Elenco (Personagem):' then
Field := fieldActors
else if Value = 'Formato de Tela:' then
Field := fieldVideoFormat
else if Value = 'Formato de Som:' then
Field := fieldAudioFormat
else if Value = 'Idiomas:' then
Field := fieldLanguages
else if Value = 'Legendas:' then
Field := fieldSubtitles
else
Field := 0;
//Get values
EndPos := pos('</td>', Line);
if EndPos > 0 then
begin
Value := copy(Line, 1, EndPos - 1);
//Special case: <actor> (<character>)
if Field = fieldActors then
Value := StringReplace(Value, '</a><br><font color=#339900>',' ');
Value := StringReplace(Value, '<br>', ', ');
HTMLRemoveTags(Value);
Delete(Line, 1, EndPos + 4);
if Field = fieldCountry then
begin
EndPos := pos(' ', Value);
if EndPos > 0 then //Can this happen?
begin
SetField(fieldYear, copy(Value, EndPos+1, 4));
Value := copy(Value, 1, EndPos-1);
end;
end
else if Field = fieldLength then
begin
EndPos := pos(' ', Value);
if EndPos > 0 then Value := copy(Value, 1, EndPos-1);
end;
if copy(Value, length(Value)-1, 2)=', ' then Delete(Value, length(Value)-1, 2);
HTMLDecode(Value);
if Field<>0 then SetField(Field, Value);
end;
end;
Delete(Line, 1, pos('</tr>', Line)+4);
end;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
until pos('</table>', Line) <> 0;
end;
DisplayResults;
end;
procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
Line: string;
MovieTitle, MovieAddress: string;
hrefPos, hrefType: Integer;
begin
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if pos('<li>', Line) > 0 then
begin
repeat
Delete(Line,1,pos('>',Line));
until copy(Line,1,1)<>'<';
MovieTitle:=copy(Line,1,pos('<',Line)-1);
HTMLDecode(Movietitle);
hrefpos := pos('<a href=',Line);
while hrefPos<>0 do
begin
Delete(Line,1,hrefPos+7);
hrefType:=pos('>',Line)+1;
MovieAddress := copy(Line, 1, hrefType-2);
PickTreeAdd(MovieTitle+' ('+copy(Line,hrefType,pos('</a>',Line)-hrefType)+')', 'http://www.cineguia.com.br/' + MovieAddress);
hrefpos := pos('<a href=',Line);
end;
end;
until pos('</ul>', Line) > 0;
end;
begin
if CheckVersion(3,4,1) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('Cine Guia Import', 'Enter the title of the movie:', MovieName) then
begin
AnalyzePage('http://www.cineguia.com.br/index.shtml?search='+UrlEncode(MovieName)+'&Submit=++Busca++&op=filmes');
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.1)');
end.
Code: Select all
// GETINFO SCRIPTING
// Cine Guia (BR) import
(***************************************************
* Movie importation script for: *
* Cine Guia (BR), http://www.cineguia.com.br *
* *
* (c) 2003 Louis Francisco ork@everydayangels.net *
* *
* For use with Ant Movie Catalog 3.4.1 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
* *
* The source code of the script can be used in *
* another program only if full credits to *
* script author and a link to Ant Movie Catalog *
* website are given in the About box or in *
* the documentation of the program *
***************************************************)
program CineGuia;
const
ImportOfficialSiteURL = True;
var
MovieName: string;
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;
BeginPos: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
//Added this line, thought it could be useful...
LineNr := FindLine('Foram encontrados muitos resultados para sua pesquisa, você precisa fazer um pesquisa mais precisa', Page, 0);
if LineNr <> -1 then
begin
Page.Free;
//Too much titles, wanna retry?
ShowMessage('Foram encontrados muitos resultados para sua pesquisa, você precisa fazer um pesquisa mais precisa');
if Input('Cine Guia Import', 'Enter the title of the movie:', MovieName) then
begin
AnalyzePage('http://www.cineguia.com.br/index.shtml?search='+UrlEncode(MovieName)+'&Submit=++Busca++&op=filmes');
end;
end
else
begin
LineNr := FindLine('--> Resultado da busca para:', Page, 0);
if LineNr = -1 then
begin
//Almost forgot about that javascript redirection
LineNr := FindLine('location.href="', Page, 0);
if LineNr <> -1 then
begin
Address := Page.GetString(LineNr);
delete(Address, 1, pos('location.href="', Address)+14);
Address := 'http://www.cineguia.com.br/' + copy(Address, 1, pos('"', Address)-1);
SetField(fieldURL, Address);
Page.Text := GetPage(Address);
AnalyzeMoviePage(Page);
end;
end
else
begin
PickTreeClear;
AddMoviesTitles(Page, LineNr);
if PickTreeExec(Address) then
begin
SetField(fieldURL, Address);
Page.Text := GetPage(Address);
AnalyzeMoviePage(Page);
end;
end;
Page.Free;
end;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Line, Value: string;
LineNr, IntValue: Integer;
BeginPos, EndPos: Integer;
Field: integer;
begin
LineNr := FindLine('function trl(link) {', Page, 0);
if LineNr > -1 then LineNr := FindLine('<td>', Page, LineNr);
// Translated Title
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<b>', Line) + 3;
EndPos := pos('</b>', Line);
if EndPos=0 then EndPos := length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldTranslatedTitle, Value);
end;
//Find Official Site URL
LineNr := FindLine('Site Oficial', Page, LineNr);
if LineNr > -1 then
begin
if ImportOfficialSiteURL then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('href=',Line);
EndPos := pos(' target=_blank>Site Oficial', Line);
if (BeginPos > -1) and (BeginPos < EndPos) then
SetField(fieldURL, copy(Line, BeginPos+5, EndPos-BeginPos-5));
end;
LineNr := FindLine('<font size="2"', Page, LineNr+1);
if LineNr > -1 then
begin
Value := '';
repeat
Value := Value + Page.GetString(LineNr);
LineNr := LineNr + 1;
until pos('</font>', Value)>0;
HTMLRemoveTags(Value);
SetField(fieldDescription, Value);
end;
end;
LineNr := FindLine('Ficha Técnica', Page, LineNr);
if LineNr > -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
repeat
//May have multiple lines of table in one line of html
while pos('<tr>', Line) > 0 do
begin
//Get a full line
while pos('</tr>', Line) = 0 do
begin
LineNr := LineNr + 1;
Line := Line + Page.GetString(LineNr);
end;
//Look for type of line
EndPos := pos('</td>', Line);
if EndPos > 0 then
begin
Value := copy(Line, 1, EndPos - 1);
HTMLRemoveTags(Value);
Delete(Line, 1, EndPos + 4);
if Value = 'Título Original:' then
Field := fieldOriginalTitle
else if Value = 'Direção:' then
Field := fieldDirector
else if Value = 'Produtor:' then
Field := fieldProducer
else if Value = 'Produção:' then
Field := fieldCountry //Special case: <country> <year>
else if Value = 'Gênero:' then
Field := fieldCategory
else if Value = 'Duração:' then
Field := fieldLength //Special case: <length> minutos
else if Value = 'Elenco (Personagem):' then
Field := fieldActors
else if Value = 'Formato de Tela:' then
Field := fieldVideoFormat
else if Value = 'Formato de Som:' then
Field := fieldAudioFormat
else if Value = 'Idiomas:' then
Field := fieldLanguages
else if Value = 'Legendas:' then
Field := fieldSubtitles
else
Field := 0;
//Get values
EndPos := pos('</td>', Line);
if EndPos > 0 then
begin
Value := copy(Line, 1, EndPos - 1);
//Special case: <actor> (<character>)
if Field = fieldActors then
Value := StringReplace(Value, '</a><br><font color=#339900>',' ');
Value := StringReplace(Value, '<br>', ', ');
HTMLRemoveTags(Value);
Delete(Line, 1, EndPos + 4);
if Field = fieldCountry then
begin
EndPos := pos(' ', Value);
if EndPos > 0 then //Can this happen?
begin
SetField(fieldYear, copy(Value, EndPos+1, 4));
Value := copy(Value, 1, EndPos-1);
end;
end
else if Field = fieldLength then
begin
EndPos := pos(' ', Value);
if EndPos > 0 then Value := copy(Value, 1, EndPos-1);
end;
if copy(Value, length(Value)-1, 2)=', ' then Delete(Value, length(Value)-1, 2);
HTMLDecode(Value);
if Field<>0 then SetField(Field, Value);
end;
end;
Delete(Line, 1, pos('</tr>', Line)+4);
end;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
until pos('</table>', Line) <> 0;
end;
DisplayResults;
end;
procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
Line: string;
MovieTitle, MovieAddress: string;
hrefPos, hrefType: Integer;
begin
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if pos('<li>', Line) > 0 then
begin
repeat
Delete(Line,1,pos('>',Line));
until copy(Line,1,1)<>'<';
MovieTitle:=copy(Line,1,pos('<',Line)-1);
HTMLDecode(Movietitle);
hrefpos := pos('<a href=',Line);
while hrefPos<>0 do
begin
Delete(Line,1,hrefPos+7);
hrefType:=pos('>',Line)+1;
MovieAddress := copy(Line, 1, hrefType-2);
PickTreeAdd(MovieTitle+' ('+copy(Line,hrefType,pos('</a>',Line)-hrefType)+')', 'http://www.cineguia.com.br/' + MovieAddress);
hrefpos := pos('<a href=',Line);
end;
end;
until pos('</ul>', Line) > 0;
end;
begin
if CheckVersion(3,4,1) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('Cine Guia Import', 'Enter the title of the movie:', MovieName) then
begin
AnalyzePage('http://www.cineguia.com.br/index.shtml?search='+UrlEncode(MovieName)+'&Submit=++Busca++&op=filmes');
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.1)');
end.