un saludo al foro
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Legrad
Title=Filmaffinity Legrad's (ES)
Description=
Site=www.Filmaffinity.com
Language=ES
Version=1.0
Requires=3.5.0
Comments=
License=
GetInfo=1
[Options]
***************************************************)
program FilmaffinityLegrads;
var
MovieName: string;
MovieURL: string;
//------------------------------------------------------------------------------------
function UpFirstLetterWord(texto:string):string;
var espaco:integer;
sst:string;
begin
texto:=AnsiUpFirstLetter(AnsiLowerCase(texto));
repeat
espaco:=Pos(' ',texto);
sst:=AnsiUpperCase(Copy(texto,espaco+1,1));
texto:=Copy(texto,1,espaco-1)+'/|\'+sst+Copy(texto,espaco+2,length(texto));
until Pos(' ',texto)=0;
texto := StringReplace(texto, '/|\', ' ');
if Copy(texto,1,1)=' ' then
texto:=Copy(texto,2,length(texto));
result:=texto;
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;
//------------------------------------------------------------------------------------
function Caracter(str1: string) :string;
begin
str1 := StringReplace(str1, 'á' , 'à');
str1 := StringReplace(str1, 'é' , 'é');
str1 := StringReplace(str1, 'Ã', 'í');
Str1 := StringReplace(Str1, 'ó', 'ó');
str1 := StringReplace(str1, 'ú' , 'ú');
str1 := StringReplace(str1, 'ñ' , 'ñ');
str1 := StringReplace(str1, 'Ã�', 'Á');
str1 := StringReplace(str1, 'É', 'É');
str1 := StringReplace(str1, 'Ã�', 'Í');
str1 := StringReplace(str1, 'Ó', 'Ó');
str1 := StringReplace(str1, 'Ú', 'Ú');
str1 := StringReplace(str1, 'Ñ', 'Ñ');
str1 := StringReplace(str1, 'Â', '');
result := str1;
end;
//-------------------------------------------------------------------------------------
function TextBetween(var S: string; StartTag: string; EndTag: string): string;
var
InitialPos: Integer;
begin
InitialPos := Pos(StartTag, S);
if InitialPos = 0 then
result := ''
else
begin
Delete(S, 1, InitialPos + Length(StartTag) - 1);
InitialPos := Pos(EndTag, S);
if InitialPos = 0 then
result := S
else
begin
result := copy(S, 1, InitialPos - 1);
Delete(S, 1, InitialPos + 1);
end;
end;
end;
//------------------------------------------------------------------------------------
function DeleteTags(var S: string): string;
var
n,len, tag: Integer;
c: char;
t: String;
begin
tag := 0;
t := '';
len := length(s);
for n :=1 to len do
begin
c := Copy(s,n,1);
if c = #9 then
c := ' ';
if(tag=1) then
begin
if(c='>') then tag := 0;
continue;
end
else
begin
if(c='<') then
begin
tag := 1;
continue;
end;
t := t + c;
end;
end
s := t;
result := t;
end;
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
strPage, MovieAddr, MovieTitle, MovieDate, MovieID, Movie: string;
BeginPos, EndPos: Integer;
BeginPoss, EndPoss: Integer;
begin
strPage := GetPage(Address);
BeginPos := Pos('resultados.</b></td></tr>', strPage);
if(BeginPos > -1)then
begin
PickTreeClear;
Delete(strPage, 1, BeginPos);
BeginPos := Pos('<b><a href="/es/film', strPage);
EndPos := 1;
while ((BeginPos > 0) and (EndPos > 0)) do
begin
Delete(strPage, 1, BeginPos);
EndPos := Pos('.html', strPage);
MovieId := Copy(strPage,+20, EndPos-20);
MovieAddr := 'http://www.filmaffinity.com/es/film' + MovieId+'.html';
BeginPoss := Pos('">',strPage);
EndPoss := Pos('<img src=', strPage);
MovieTitle := Copy(strPage,BeginPoss, EndPoss);
MovieTitle := TextBetween(MovieTitle , '">', '<');
MovieTitle := Caracter(MovieTitle);
DeleteTags(MovieTitle);
PickTreeAdd(MovieTitle, MovieAddr);
PickTreeSort;
BeginPos := Pos('<b><a href="/es/film', strPage);
if(Pos('</body>', strPage) < BeginPos) then
BeginPos := -1;
end;
end;
PickTreeExec(Address)
AnalyzeMoviePage(Address);
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Item: string;
Comments: string;
Actors: string;
Directors: string;
Description: string;
Busca: integer;
begin
Description := '';
Comments := '';
// URL
SetField(fieldURL, Address);
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Titulo traducido
LineNr := FindLine('<title>', Page, 0);
Line := Page.GetString(LineNr);
Line := UTF8Encode(Line);
Item := TextBetween (Line, '<title>', '(');
HTMLDecode(Item);
Item := Caracter(Item);
SetField(fieldTranslatedTitle, Trim (Item));
// Titulo Original
LineNr := FindLine('<b>TÍTULO ORIGINAL</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>TÍTULO ORIGINAL</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<td ><b>', '</b></td>');
HTMLDecode(Item);
Item := Caracter(Item);
SetField(fieldOriginalTitle, Trim (Item));
end;
// año
LineNr := FindLine('<title>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '(', ')');
DeleteTags (Item);
HTMLDecode(Item);
SetField(fieldYear, Trim (Item));
end;
// Duracion
LineNr := FindLine('<b>DURACIÓN</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>DURACIÓN</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>', 'min.</td>');
Item := TextBetween (Item, '<td>', 'min');
HTMLDecode(Item);
SetField(fieldLength, Trim (Item));
end;
// pais
LineNr := FindLine('<b>PAÍS</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>PAÍS</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, 'title="', '"');
HTMLDecode(Item);
Item := Caracter(Item);
SetField(fieldCountry, Trim (Item));
end;
// director
LineNr := FindLine('<b>DIRECTOR</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>DIRECTOR</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, 'href="search.php?stype=director&stext=', '"</td>');
Item := TextBetween (Item, '">', '</a>');
HTMLDecode(Item);
Item := Caracter(Item);
SetField(fieldDirector, Trim (Item));
end;
// Reparto
LineNr := FindLine('<b>REPARTO</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>REPARTO</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, 'href="search.php?stype=', '</tr>');
Item := TextBetween (Item, '">', '</a></td>');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
SetField(fieldActors, Trim (Item));
end;
// productor
LineNr := FindLine('<b>PRODUCTORA</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>PRODUCTORA</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<td >', '</td>');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
SetField(fieldProducer, Trim (Item));
end;
// Categoria
LineNr := FindLine('<b>GÉNERO Y CRÍTICA</b>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>GÉNERO Y CRÍTICA</b>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<td valign="top">', '/ SINOPSIS:');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
SetField(fieldCategory, Trim (Item));
end;
// sinopsis
LineNr := FindLine('<b>GÉNERO Y CRÍTICA</b>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>GÉNERO Y CRÍTICA</b>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '/ SINOPSIS: ', '(FILMAFFINITY)');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
SetField(fieldDescription, Trim (Item));
end;
// Calificación
LineNr := FindLine('<tr><td align="center" style="color:#990000; font-size:22px; font-weight: bold;">', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<tr><td align="center" style="color:#990000; font-size:22px; font-weight: bold;">',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<tr><td align="center" style="color:#990000; font-size:22px; font-weight: bold;">', '</td></tr>');
HTMLDecode(Item);
DeleteTags (Item);
SetField(fieldRating, Trim (Item));
end;
// Guión
LineNr := FindLine('<b>GUIÓN</b></td>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>GUIÓN</b></td>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<td >', '</td>');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
Comments := Comments + 'Guión: ' + Item +#13#10;
end;
// fotografia
LineNr := FindLine('<b>FOTOGRAFÍA</b>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>FOTOGRAFÍA</b>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<td >', '</td>');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
Comments := Comments + 'Fotografía: ' + Item +#13#10;
end;
// Musica
LineNr := FindLine('<b>MÚSICA</b>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>MÚSICA</b>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<td >', '</td>');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
Comments := Comments + 'Música: ' + Item +#13#10#13#10;
end;
// Critica
LineNr := FindLine('<b>GÉNERO Y CRÍTICA</b>', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('<b>GÉNERO Y CRÍTICA</b>',Page.Text), length(Page.Text));
Item := TextBetween (Item, '--<br />', '--</td>');
HTMLDecode(Item);
DeleteTags (Item);
Item := Caracter(Item);
Item := StringReplace(Item, '-', '');
Comments := Comments + 'CRITICAS: ' + Item +#13#10;
end;
// Caratula
LineNr := FindLine('src="/images/enlarge.gif"', Page, 0);
if LineNr <> -1 then
begin
Item := copy(Page.Text, pos('src="/images/enlarge.gif"',Page.Text), length(Page.Text));
Item := TextBetween (Item, '<a class="lightbox" href="http://pics.filmaffinity.com/', '.jpg');
HTMLDecode(Item);
GetPicture ('http://pics.filmaffinity.com/'+Item+'.jpg');
end;
SetField(fieldComments, Comments);
end;
//end;
//-------------------------------------------------------------------------
begin
if (CheckVersion(3,5,0)=FALSe) then
begin
ShowMessage('Se requiere Ant Movie Catalog versión 3.5 o superior');
exit;
end;
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
Input('Filmaffinity', 'Buscar:', MovieName);
if(GetOption('Sin resultado') = 0) then Input('Filmaffinity', 'Buscar:', MovieName);
AnalyzePage('http://www.filmaffinity.com/es/search.php?stext=' + UrlEncode(MovieName) + '&stype=Title');
end.