I've updated the script due to changes in the page that make the previous version not working anymore.
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=japg2000 (japg2000@terra.es)
Title=CaratulasDeCine
Description=Picture importation script for www.caratulasdecine.com
Site=www.caratulasdecine.com
Language=ES
Version=1.7
Requires=3.5.0
Comments=
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 CaratulasdecineImport;
var
Title: 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 EliminaInicio(S: string; CR: string): string;
begin
result := S;
while Pos(CR, result) = 1 do
begin
Delete(result, 1, Length(CR));
end;
end;
function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
var
InicioPos: Integer;
begin
InicioPos := Pos(StartTag, S);
Delete(S, 1, InicioPos + Length(StartTag) - 1);
InicioPos := Pos(EndTag, S);
result := copy(S, 1, InicioPos - 1);
Delete(S, 1, InicioPos + 1);
end;
function PreparaTitulo(T: string): string;
var
i: Integer;
begin
result := AnsiLowerCase(T);
HTMLDecode(result);
result := StringReplace(result, chr(146), '');
result := StringReplace(result, chr(39), '');
result := StringReplace(result, '´', '');
result := StringReplace(result, '`', '');
result := StringReplace(result, '"', '');
result := StringReplace(result, '¿', '');
result := StringReplace(result, '?', '');
result := StringReplace(result, '¡', '');
result := StringReplace(result, '!', '');
result := StringReplace(result, '.', '');
result := StringReplace(result, ',', '');
result := StringReplace(result, ':', '');
result := StringReplace(result, ';', '');
result := StringReplace(result, '-', '');
result := StringReplace(result, '/', '');
result := StringReplace(result, '\', '');
result := StringReplace(result, '_', '');
result := StringReplace(result, 'á', 'a');
result := StringReplace(result, 'é', 'e');
result := StringReplace(result, 'í', 'i');
result := StringReplace(result, 'ó', 'o');
result := StringReplace(result, 'ú', 'u');
result := StringReplace(result, 'ä', 'a');
result := StringReplace(result, 'ë', 'e');
result := StringReplace(result, 'ï', 'i');
result := StringReplace(result, 'ö', 'o');
result := StringReplace(result, 'ü', 'u');
result := StringReplace(result, 'ñ', 'n');
end;
function GetCaratulasDeCineDir(MovieTitle: string): string;
var
PageOfLetter: Array of string;
C: Char;
Index: Integer;
begin
Setarraylength(PageOfLetter,36);
PageOfLetter[0]:='0'; PageOfLetter[1]:='1'; PageOfLetter[2]:='2'; PageOfLetter[3]:='3';
PageOfLetter[4]:='4'; PageOfLetter[5]:='5'; PageOfLetter[6]:='6'; PageOfLetter[7]:='7';
PageOfLetter[8]:='8'; PageOfLetter[9]:='9'; PageOfLetter[10]:='a'; PageOfLetter[11]:='b';
PageOfLetter[12]:='c'; PageOfLetter[13]:='d'; PageOfLetter[14]:='e'; PageOfLetter[15]:='f';
PageOfLetter[16]:='g'; PageOfLetter[17]:='h'; PageOfLetter[18]:='i'; PageOfLetter[19]:='j';
PageOfLetter[20]:='k'; PageOfLetter[21]:='l'; PageOfLetter[22]:='m'; PageOfLetter[23]:='n';
PageOfLetter[24]:='o'; PageOfLetter[25]:='p'; PageOfLetter[26]:='q'; PageOfLetter[27]:='r';
PageOfLetter[28]:='s'; PageOfLetter[29]:='t'; PageOfLetter[30]:='u'; PageOfLetter[31]:='v';
PageOfLetter[32]:='w'; PageOfLetter[33]:='x'; PageOfLetter[34]:='y'; PageOfLetter[35]:='z';
C := copy(MovieTitle, 1, 1);
if (C >= '0') and (C <= '9') then
begin
Index := Ord(C) - Ord('0');
end
else
begin
Index := 10 + Ord(C) - Ord('a');
end;
result:='http://www.caratulasdecine.com/listado.php?inicial=' + PageOfLetter[Index];
end;
procedure AnalyzePageCaratulasDeCine(PageDir: string);
var
CaratulasdecinePage, MoviePage: TStringList;
MovieDir, Line, LineTmp, TitleWeb, PageWeb: string;
Encontrado, Salir, BeginPos, EndPos, LineNr, LineMov: Integer;
begin
CaratulasdecinePage := TStringList.Create;
CaratulasdecinePage.Text := GetPage(PageDir);
LineNr := FindLine('</big></big></big></big></big></big>', CaratulasdecinePage, 0);
LineNr := LineNr + 2;
Line := CaratulasdecinePage.GetString(LineNr);
Line := EliminaInicio(Line, ' ');
Salir := 0;
Encontrado := 0;
PickTreeClear;
PickTreeAdd('Resultados de la búsqueda para "' + Title + '" (www.caratulasdecine.com):', '');
while (Pos('<br>', Line) = 0) and (Pos('</td>', Line) = 0) and (LineNr < 20000) do
begin
if copy(Line, Length(Line), 1) <> ' ' then
Line := Line + ' ';
LineNr := LineNr + 1;
LineTmp := CaratulasdecinePage.GetString(LineNr);
LineTmp := EliminaInicio(LineTmp, ' ');
Line := Line + LineTmp;
end;
repeat
if Pos('<a class="A" href="', Line) > 0 then
begin
MovieDir := 'http://www.caratulasdecine.com/' + CadenaEntre(Line, '<a class="A" href="', '"');
TitleWeb := CadenaEntre(Line, '">', '<');
LineTmp := PreparaTitulo(TitleWeb);
if Pos(Title, LineTmp) > 0 then
begin
PageWeb := MovieDir;
PickTreeAdd(TitleWeb, PageWeb);
Encontrado := Encontrado + 1;
end;
end
else
begin
MovieDir := '';
Salir := 1;
end;
until Salir = 1;
CaratulasdecinePage.Free;
if (Encontrado > 1) then begin
if PickTreeExec(PageWeb) then begin
MoviePage := TStringList.Create;
MoviePage.Text := GetPage(PageWeb);
LineMov := FindLine('<td><img src="', MoviePage, 0);
LineTmp := MoviePage.GetString(LineMov);
LineTmp := CadenaEntre(LineTmp, '<td><img src="', '" ');
PageWeb := 'http://www.caratulasdecine.com/' + LineTmp;
MoviePage.Free;
GetPicture(PageWeb);
end;
end else if (Encontrado = 1) then begin
MoviePage := TStringList.Create;
MoviePage.Text := GetPage(PageWeb);
LineMov := FindLine('<td><img src="', MoviePage, 0);
LineTmp := MoviePage.GetString(LineMov);
LineTmp := CadenaEntre(LineTmp, '<td><img src="', '" ');
PageWeb := 'http://www.caratulasdecine.com/' + LineTmp;
MoviePage.Free;
GetPicture(PageWeb);
end else
ShowMessage('Titulo ' + Title + ' no encontrado en ' + PageDir)
end;
begin
if CheckVersion(3,5,0) then
begin
Title := GetField(fieldTranslatedTitle);
if Title = '' then Title := GetField(fieldOriginalTitle);
Title := PreparaTitulo(Title);
if Input('Importar de caratulasdecine.com', 'Por favor, introduce el titulo:', Title) then begin
Title := PreparaTitulo(Title);
AnalyzePageCaratulasDeCine(GetCaratulasDeCineDir(Title));
end;
end else
ShowMessage('Este script necesita una versión superior de Ant Movie Catalog (al menos la version 3.5.0)');
end.