I've already send to Antp the script for v.3.5.0 fixed (tested yesterday night, I suppose it is still ok
).
In the meanwhile he will publish it, here is whe code.
Let me know for ant problem.
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=2003 Andrea Cristaudo achris@tiscalinet.it; 2004 Stefano Mora stefano.mora@libero.it
Title=Cinematografo
Description=Get movie info from Cinematografo.it
Site=http://www.cinematografo.it
Language=IT
Version=1.02
Requires=3.5.0
Comments=Modified by Dino Librandi dinolib@libero.it (2005) for v 3.5.0;
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
[Options]
***************************************************)
program Cinematografo;
var
MovieName: string;
TheMovieAddress: string;
idx : integer;
const
PATHLOG = 'c:\Programmi\Ant Movie Catalog\Log\LogsCinematogr\';
MOVIE = 'leon';
SITE = 'http://www.cinematografo.it';
// -- Formatta la stringa rendendola tutto minuscolo a parte la prima lettera
function PrimaMaiu(str: string): string;
begin
str := AnsiLowerCase(str);
Result := AnsiUpFirstLetter(str);
end;
// -- Formatta la stringa cercando le prime lettere rendendole maiuscole
function PrimeMaiu(str: string): string;
begin
str := AnsiLowerCase(str);
str := AnsiMixedCase(str, ' -/');
Result := str;
end;
// ---
function RemoveTabs(Pattern: string): string;
begin
while (Pattern<>'') and (ord(copy(Pattern, 1, 1)) = 9) do
Delete(Pattern, 1, 1);
result := Pattern;
end;
function Space2html(Url: string): string;
var
Temp : string;
SpacePos : Integer;
begin
repeat
SpacePos := pos(' ', Url);
if SpacePos <> 0 then
begin
Temp := copy(Url, 1, SpacePos -1);
Delete(Url, 1, SpacePos);
Temp := Temp + '%20' + Url;
Url := Temp;
end;
until pos(' ', Url) = 0;
result := Url;
end;
// ---
function FillInput(Page: TStringList; LineNr: Integer; Salto: Integer; Field: Integer): Integer;
var
Line: string;
begin
LineNr := LineNr + Salto;
// Sostituzione <BR>
if (Field = fieldActors) or (Field=fieldDirector) then
begin
Line := StringReplace(Page.GetString(LineNr), '<BR>', ', ');
end
else
begin
if (Field = fieldCategory) or (Field = fieldCountry) then
begin
Line := StringReplace(Page.GetString(LineNr), '<BR>', '/');
end
else
begin
Line := StringReplace(Page.GetString(LineNr), '<BR>', #13#10);
end;
end;
HTMLRemoveTags(Line);
HTMLDecode(Line);
Line := Trim(RemoveTabs(Line));
// Correzione maiuscole/minuscole
if Field = fieldActors then
begin
Line := StringReplace(Line, ' ', ' : ');
Line := PrimeMaiu(Line);
end
else if (Field = fieldOriginalTitle) then
begin
Line := PrimaMaiu(Line);
end
else if (Field = fieldDirector) or (Field = fieldProducer) or (Field = fieldCountry) or (Field = fieldCategory) then Line := PrimeMaiu(Line);
Line := StringReplace(Line, ' ', ' ');
Line := StringReplace(Line, ' ', ' ');
SetField(Field, Line);
Result := LineNr;
end;
// ---
function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
i: Integer;
Line:string;
begin
result := -1;
if StartAt < 0 then
StartAt := 0;
for i := StartAt to List.Count-1 do
begin
Line :=List.GetString(i);
if Pos(Pattern, Line) <> 0 then
begin
result := i;
Break;
end;
end;
end;
// ----
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: integer;
BeginPos: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
idx := 0;
// Debug
//Page.SaveToFile(PATHLOG+MovieName+'.res0');
//Page.LoadFromFile(PATHLOG+MOVIE+'.res0');
LineNr := FindLine('DELLA RICERCA', Page, 0);
if LineNr = -1 then
begin
LineNr := FindLine('Affina la tua ricerca', Page, 0);
if LineNr = -1 then
begin
SetField(fieldURL, Address);
AnalyzeMoviePage(Page);
end
else
ShowMessage('Nessun film trovato');
end
else // Trovati film ! Nota: possono esserci + pagine -> non gestito !
begin
// Crea la lista di film
PickTreeClear;
PickTreeAdd('Risultati ricerca per "' + MovieName + '":', '');
AddMoviesTitles(Page);
if PickTreeExec(Address) then
begin
SetField(fieldURL, Address); // Memorizza il campo URL
Page.Text := GetPage(Address); // Richiede la pagina del film
AnalyzeMoviePage(Page); // Analizza la pagina del film
end;
end;
Page.Free;
end;
// ---
procedure AnalyzeMoviePage(Page: TStringList);
var
Fine: Integer;
Line: string;
Line2: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
Field: integer;
begin
//Debug
//Page.SaveToFile(PATHLOG+MovieName+'.film');
//Page.LoadFromFile(PATHLOG+MOVIE+'.film');
Fine := 0;
LineNr := FindLine('<font color="#ffffff">Titolo Film</font>', Page, 0);
if LineNr > -1 then
begin
//Translated Title
while Pos('<p align="left"><strong><font color="#ffffff" size="2">',Page.GetString(LineNr))=0 do
LineNr:=LineNr+1;
//LineNr := LineNr + 4;
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
Line := RemoveTabs(Line);
SetField(fieldTranslatedTitle, PrimaMaiu(Line) );
SetField(fieldOriginalTitle, PrimaMaiu(Line) );
// Immagine
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
if pos('<img border="0" src="', Line) <> 0 then
begin
BeginPos := pos('<img border="0" src="', Line);
Delete(Line, 1, BeginPos + 20);
EndPos := pos('" ', Line);
Line := copy(Line, 1, EndPos - 1);
Line := StringReplace(Line, ' ', '');
Line := 'http://www.cinematografo.it/bdcm/' + Line;
Line := Space2html(Line);
GetPicture(Line);
while (pos('</table>', Page.GetString(LineNr))=0) and
(pos('</html>', Page.GetString(LineNr))=0) do
LineNr := LineNr + 1;
end
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if pos('<font color="#ffffff">Anno</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldYear)
else if pos('<font color="#ffffff">Titolo originale</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldOriginalTitle)
else if pos('<font color="#ffffff">Durata</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldLength)
else if pos('<font color="#ffffff">Origine</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldCountry)
else if pos('<font color="#ffffff">Genere</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldCategory)
else if pos('<font color="#ffffff">Produzione</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldProducer)
else if pos('<font color="#ffffff">Regia</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldDirector)
else if pos('<font color="#ffffff">Trama</font>', Line) <> 0 then
begin
LineNr := LineNr+3;
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
Line := Trim(RemoveTabs(Line));
LineNr := LineNr+1;
if Left(Line, 6)='TRAMA ' then // Trama breve e lunga su + righe
begin
Line := Page.GetString(LineNr); // Tengo la trama breve
LineNr := LineNr+1;
end
Line2 := Page.GetString(LineNr); // Event. seconda riga
HTMLRemoveTags(Line2);
if trim(Line2)<> '' then Line := Line + Line2;
SetField(fieldDescription, Line);
end
else if pos('<font color="#ffffff">Critica</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldComments)
else if pos('<font color="#ffffff">Attori</font>', Line) <> 0 then
LineNr := FillInput(Page, LineNr, 3, fieldActors)
else if pos('<img align="right" border="0"', Line) <> 0 then
begin
BeginPos := pos('<img align="right" border="0" src="', Line);
Delete(Line, 1, BeginPos + 35);
EndPos := pos('">', Line);
Line := copy(Line, 1, EndPos - 1);
Line := 'http://www.cinematografo.it/' + Line;
Line := Space2html(Line);
GetPicture(Line);
end
else if pos('</table>', Line) <> 0 then
Fine := 1;
until Fine = 1;
end;
//DisplayResults;
end;
// ---
// Riempie la lista con i film trovati
procedure AddMoviesTitles(Page: TStringList);
var
LineNr: Integer;
Line: string;
MovieTitle, MovieAddress: string;
BeginPos, EndPos: Integer;
Pagina: TStringList;
begin
TheMovieAddress := '*';
LineNr := 0;
LineNr := FindLine('<a href="bancadati_scheda.asp?sch=',Page,LineNr);
while LineNr > -1 do
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<a href="',Line)+9; // Punta all'inizio url
Delete(Line, 1, BeginPos-1); // Cancella tutti i char precedenti
BeginPos := 1; // Nuovo inizio
EndPos := pos('">',Line); // Fine url
// Crea l'url per il film
MovieAddress := SITE + '/bdcm/' + copy(Line,BeginPos,EndPos-BeginPos);
// Riga successiva = titolo trovato
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
MovieTitle := AnsiUpFirstLetter(Line);
// Ripulisce il titolo
HTMLRemoveTags(MovieTitle);
HTMLDecode(MovieTitle);
MovieTitle := RemoveTabs(MovieTitle);
// Cerca l'anno del film
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
Line := RemoveTabs(Line);
Line := StringReplace( Line, ' ', '');
Line := StringReplace( Line, '-', '');
// Costruisce la riga con titolo + anno e mette in lista
MovieTitle := MovieTitle + ' (' + Line + ')';
PickTreeAdd(MovieTitle, MovieAddress);
// Prossimo film in lista ...
LineNr := FindLine('<a href="bancadati_scheda.asp?sch=',Page,LineNr+1);
end; // while
// Controlla se ci sono altre pagine di risultati
LineNr := FindLine('Succ.',Page,LineNr);
if LineNr<>-1 then
begin
idx := idx+1;
// PickTreeAdd('Ci sono altre pagine ...'+IntToStr(idx), '');
// LineNr := FindLine('Succ.',Page,LineNr);
Line := Page.GetString(LineNr);
// Estrae l'URL della pagina successiva
BeginPos := pos('href="', Line)+6;
EndPos := pos('">', Line);
Line := SITE + copy(Line, BeginPos, endPos-BeginPos);
// Richiama la pagina successiva e la analizza
Pagina := TStringList.Create;
Pagina.Text := GetPage(Line);
// Debug
//Page.SaveToFile(PATHLOG+MovieName+'.res'+IntToStr(idx));
//Page.LoadFromFile(PATHLOG+MOVIE+'.res');
AddMoviesTitles(Pagina);
Pagina.Free;
end;
end;
// ----- main()
Var
TempVar: String;
begin
if CheckVersion(3,5,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('Cinematografo.it', 'Inserire il nome del film:', MovieName) then
begin
TempVar := 'http://www.cinematografo.it/bdcm/bancadati_query.asp?fi='+UrlEncode(MovieName)+'&R1=TI&image1.x=24&image1.y=24';
analyzepage(TempVar);
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.