Ante las nuevas modificaciones que se han llevado a cabo en la página de FilmAffinity, aqui os traigo el nuevo script...
Espero que con ello se resuelvan todos los problemas...
Un saludo
aviloria
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=aviloria (aviloria@yahoo.com)
Title=FilmAffinity (ES)
Description=Movie importation script for FilmAffinity Spain
Site=http://www.filmaffinity.com
Language=ES
Version=1.0
Requires=3.5.0
Comments=Updated by folgui to: | - Separate import of Category and Description | - Search only by title to improve speed|
License=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.|
GetInfo=1
[Options]
***************************************************)
program FilmAffinity;
const
SearchBaseURL = 'http://www.filmaffinity.com/es/res.php?stext=';
SearchPostFix = '&stype=tit';
BaseURL1 = 'http://www.filmaffinity.com/es/';
BaseURL2 = 'http://www.filmaffinity.com';
var
MovieName: string;
MovieURL: 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;
//------------------------------------------------------------------------------------
function TextBetween(var S: string; StartTag: string; EndTag: string): string;
var
InitialPos: Integer;
begin
InitialPos := Pos(StartTag, S);
Delete(S, 1, InitialPos + Length(StartTag) - 1);
InitialPos := Pos(EndTag, S);
result := copy(S, 1, InitialPos - 1);
Delete(S, 1, InitialPos + 1);
end;
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
MovieTitle, MovieAddress: string;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if Pos('<title>FilmAffinity', Page.Text) = 0 then
begin
ShowMessage('No se ha podido establecer la conexion.');
end else
begin
LineNr := FindLine('<td class="tt1" align="center">Resultados por Título</td>', Page, 0);
LineNr := LineNr + 6;
Line := Page.GetString(LineNr);
if Pos ('No se han encontrado coincidencias', Line) <> 0 then
begin
ShowMessage('No se han encontrado resultados para "' + MovieName + '"');
end else
begin
PickTreeClear;
Line := TextBetween (Line, '<b>', '</b>');
PickTreeAdd('Encontrados ' + Line + ' resultados para "' + MovieName + '"', '');
LineNr := LineNr + 9;
Line := Page.GetString(LineNr);
repeat
MovieTitle := TextBetween (Line, '<span class="ntext">', '</span>');
HTMLDecode(MovieTitle);
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
MovieAddress := TextBetween (Line, '.href = ''', ''';</script>');
PickTreeAdd(MovieTitle, BaseURL1 + MovieAddress);
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
until Pos('</ol>', Line) > 0;
if PickTreeExec(Address) then
AnalyzeMoviePage(Address);
end;
end;
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr, aux: Integer;
Line: string;
Item: string;
Comments: string;
Actors: string;
Directors: string;
Description: string;
begin
Comments := '';
Actors := '';
Description := '';
// URL
SetField(fieldURL, Address);
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Translated Title
LineNr := FindLine('<td align="center" class="tt1">', Page, 0);
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td align="center" class="tt1">', ' <img src=');
HTMLDecode(Item);
SetField(fieldTranslatedTitle, Trim (Item));
LineNr := LineNr + 8;
Line := Page.GetString(LineNr);
// Original Title
if Pos ('TITULO ORIGINAL', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext">', '</td>');
HTMLDecode(Item);
SetField(fieldOriginalTitle, Trim (Item));
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
end;
// Picture
if Pos ('owned by Studio', Line) > 0 then
begin
Item := TextBetween (Line, '<img src="', '" >');
GetPicture (BaseURL2 + Item);
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Year
if Pos ('AÑO', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext">', '</td>');
HTMLDecode(Item);
SetField(fieldYear, Trim (Item));
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Length
if Pos ('DURACIÓN', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext">', '</td>');
HTMLDecode(Item);
aux := Pos (' min', Item);
if aux > 0 then
Delete (Item, aux, aux + 3);
SetField(fieldLength, Trim (Item));
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Country
if Pos ('PAÍS', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, 'alt="', '">');
HTMLDecode(Item);
SetField(fieldCountry, Trim (Item));
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Director
if Pos ('DIRECTOR', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Directors := '';
while Pos ('&stype=dir">', Line) > 0 do
begin
Item := TextBetween (Line, '&stype=dir">', '</a>');
HTMLDecode(Item);
if Directors = '' then
Directors := Item
else
Directors := Directors + ', ' + Item;
end;
SetField(fieldDirector, Trim (Directors));
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Script writer
if Pos ('GUIÓN', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext">', '</td>');
Comments := Comments + 'Guión: ' + Item + #13#10;
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Musician
if Pos ('MUSICA', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext" >', '</td>');
Comments := Comments + 'Música: ' + Item + #13#10;
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Photography
if Pos ('FOTOGRAFÍA', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext" >', '</td>');
Comments := Comments + 'Fotografía: ' + Item + #13#10;
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Actors
if Pos ('REPARTO', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Actors := Actors + TextBetween (Line, '&stype=rep">', '</a>') + #13#10;
while Pos ('&stype=rep"> ', Line) > 0 do
Actors := Actors + TextBetween (Line, '&stype=rep"> ', '</a>') + #13#10;
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Productor
if Pos ('PRODUCTORA', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<td class="ntext" colspan="2">', '</td>');
HTMLDecode(Item);
SetField(fieldProducer, Trim (Item));
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Genere & Critic
if Pos ('GÉNERO Y CRÍTICA', Line) > 0 then
begin
Line := Copy (Page.Text, 1, Length (Page.Text));
Line := StringReplace(Line, '<br />', #13#10);
Line := TextBetween (Line, 'GÉNERO Y CRÍTICA', '</tr>');
Item := TextBetween (Line, '<td class="ntext" colspan="2">', '/ SINOPSIS:');
HTMLDecode(Item);
SetField(fieldCategory, Trim(Item));
Description := TextBetween (Line, '/ SINOPSIS:', '</td>');
LineNr := FindLine('WEB OFICIAL', Page, LineNr);
Line := Page.GetString(LineNr);
end;
// Official Webpage
if Pos ('WEB OFICIAL', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Comments := Comments + 'Web oficial: ' + TextBetween (Line, '<a href="', '" target="_blank">') + #13#10;
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
// Rating
if Pos ('PUNTUACIÓN MEDIA', Line) > 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Item := TextBetween (Line, '<b>', '</b>');
HTMLDecode(Item);
if Length(Item) = 3 then
// begin
// Item := IntToStr(Round(StrToInt(StrGet(Item, 1), 0) + (StrToInt(StrGet(Item, 3), 0) / 10)));
// end else
// begin
// Item := IntToStr(Round(StrToInt(StrGet(Item, 1), 0)));
// end;
SetField(fieldRating, Item);
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
end;
HTMLDecode(Comments);
SetField(fieldComments, Comments);
HTMLDecode(Actors);
SetField(fieldActors, Actors);
HTMLDecode(Description);
SetField(fieldDescription, Description);
end;
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
begin
if CheckVersion(3,5,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('Importar de FilmAffinity', 'Introduzca el titulo de la pelicula:', MovieName) then
begin
AnalyzePage(SearchBaseURL + UrlEncode(MovieName) + SearchPostfix);
end;
end
else
ShowMessage('Este script requiere una version mas reciente de Ant Movie Catalog (por lo menos la version 3.5.0)');
end.