i'm posting a new release of KwCinema.it script.
It strip my debug instruction i left

Code: Select all
// GETINFO SCRIPTING
// KwCinema (IT) by SM
(**************************************************
* Movie importation script for: *
* KwCinema - http://www.kataweb.it/cinema *
* Ver. 1.0.1 - 26.09.2004 *
* (c) 2004 SM *
* stefano.mora@libero.it *
* *
* For use with Ant Movie Catalog 3.4.2 *
* 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 KwCinemaIt;
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;
// --------------------------------------------------
// Analizza la pagina e ricava i dati
procedure LeggeFilm(Page: TStringList);
var
strTmp, strTmp2, strTmp3: string;
LineNr: integer;
EndLine: integer;
BeginPos, EndPos: Integer;
bNome: boolean;
begin
// Titoli
LineNr := FindLine('box-tit-film', Page, 0);
strTmp := Page.GetString(LineNr);
HTMLRemoveTags(strTmp);
// Titolo originale === titolo tradotto
SetField( fieldTranslatedTitle, strTmp);
SetField( fieldOriginalTitle, strTmp);
// Immagine - Locandina
LineNr := FindLine('<div class="box-grigio">', Page, LineNr);
if LineNr <> -1 then
begin
strTmp := Page.GetString(LineNr+1);
BeginPos := pos('assente.gif', strTmp); // Verifica che ci sia l'immagine
//ShowMessage(IntToStr(BeginPos));
if BeginPos=0 then
begin
BeginPos := pos('src="', strTmp)+4;
delete( strTmp, 1, BeginPos); // cancella per poter trovare l'altro '"'
BeginPos := pos('"', strTmp)-1;
strTmp := copy( strTmp, 1, BeginPos);
// ShowMessage(strTmp);
GetPicture(strTmp, FALSE); // Richiede l'immagine
end
end
// Cast
LineNr := FindLine('<div class="header-tit-int">Cast</div>', Page, LineNr);
EndLine := FindLine('<div class="row"> </div>', Page, LineNr)-2;
strTmp :='';
//ShowMessage(IntToStr(LineNr)+' - '+IntToStr(EndLine));
while LineNr<EndLine do
begin
bNome := false;
// Controlla se deve aggiungere una virgola tra i nomi
if strTmp<>'' then strTmp := strTmp+', ';
//
LineNr := LineNr+2;
strTmp2 := Page.GetString(LineNr);
// Controlla se c'e' grassetto -> nome personaggio
BeginPos := pos('<b>', strTmp2)+3;
EndPos := pos('</b>', strTmp2);
if EndPos-BeginPos > 1 then
begin
strTmp3 := copy( strTmp2, BeginPos, EndPos-BeginPos);
strTmp := strTmp + strTmp3;
bNome := true;
end;
if bNome then strTmp := strTmp + ' (';
//
delete( strTmp2, 1, EndPos+3);
HTMLRemoveTags(strTmp2);
strTmp := strTmp + strTmp2;
if bNome then strTmp := strTmp + ')';
end;
SetField( fieldActors, strTmp);
// Descrizione
strTmp:='';
LineNr := FindLine('Trama', Page, LineNr)+2;
EndLine := FindLine('<div class="row"> </div>', Page, LineNr);
// Colleziona tutte le righe di descrizione
while LineNr<EndLine do
begin
strTmp2 := Page.GetString(LineNr);
// Potrebbe esserci l'immagine del Morandini
HTMLRemoveTags(strTmp2);
strTmp2 := StringReplace(strTmp2, #9, ''); // Toglie i tabs
strTmp2 := trim(strTmp2);
if strTmp2 <> '' then strTmp := strTmp + strTmp2 + ' ';
LineNr := LineNr+1;
end;
HTMLRemoveTags(strTmp);
SetField( fieldDescription, strTmp);
// Anno
LineNr := FindLine('Anno', Page, LineNr);
strTmp := Page.GetString(LineNr);
BeginPos := Pos('</b>', strTmp)+4;
EndPos := Pos('</p>', strTmp);
strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
SetField( fieldYear, strTmp);
// Nazione
LineNr := FindLine('Nazione', Page, LineNr);
strTmp := Page.GetString(LineNr);
BeginPos := Pos('</b>', strTmp)+4;
EndPos := Pos('</p>', strTmp);
strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
SetField( fieldCountry, strTmp);
// Produzione
LineNr := FindLine('Produzione', Page, LineNr);
strTmp := Page.GetString(LineNr);
BeginPos := Pos('</b>', strTmp)+4;
EndPos := Pos('</SP>', strTmp); // qui nella pagina c'e' un </SP> !!
strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
SetField( fieldProducer, strTmp);
// Durata
LineNr := FindLine('Durata', Page, LineNr);
strTmp := Page.GetString(LineNr);
BeginPos := Pos('</b>', strTmp)+4;
EndPos := Pos('''</p>', strTmp);
strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
//ShowMessage(strTmp);
SetField( fieldLength, strTmp);
// Genere
LineNr := FindLine('Genere', Page, LineNr);
strTmp := Page.GetString(LineNr);
BeginPos := Pos('</b>', strTmp)+4;
EndPos := Pos('</p>', strTmp);
strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
//ShowMessage(strTmp);
SetField( fieldCategory, trim(strTmp));
// Regia
LineNr := FindLine('Regia', Page, LineNr);
EndLine := FindLine('<div class="row"> </div>', Page, LineNr);
strTmp := Page.GetString(LineNr);
BeginPos := pos('ia:', strTmp)+2;
Delete(strTmp, 1, BeginPos);
//ShowMessage(strTmp);
LineNr := LineNr+1;
//while LineNr<EndLine do
// begin
// strTmp := strTmp + trim(Page.GetString(LineNr)) + ' ';
// LineNr := LineNr+1;
// end;
HTMLRemoveTags(strTmp);
//ShowMessage(strTmp);
SetField( fieldDirector, trim(strTmp));
// Link
LineNr := FindLine('Link:', Page, LineNr);
if LineNr<>-1 then
begin
strTmp := Page.GetString(LineNr+1);
if (strTmp = '') then strTmp := Page.GetString(LineNr+2);
if (strTmp = '') then strTmp := Page.GetString(LineNr+3);
//ShowMessage(strTmp);
BeginPos := pos('href="', strTmp)+6;
EndPos := pos('" ', strTmp);
//ShowMessage(IntTostr(BeginPos)+' '+IntToStr(EndPos));
strTmp := copy( strTmp, BeginPos, EndPos-BeginPos);
//ShowMessage(strTmp);
SetField( fieldURL, strTmp);
end
// Si sposta nella pagina dei risultati
DisplayResults;
end;
// -------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
strPage, MovieAddr, MovieTitle, MoviePlot, MovieID: string;
BeginPos, EndPos: Integer;
LineNr: Integer;
rigalista: string;
rigahtml: string;
strTmp: string;
begin
// Crea la lista
Page:= TStringList.Create;
// Riceve la pagina
Page.Text := GetPage(Address);
//Page.LoadFromFile('c:\Programmi\Ant Movie Catalog\Logs\Cube.htm');
BeginPos:= FindLine('Nessun film trovato', Page, 0);
if BeginPos <> -1 then
begin
ShowMessage('Film non trovato !');
exit;
end;
// Controllare che ci siano film !!
BeginPos:= FindLine('<div class="header-tit-int">Hai cercato <i>', Page, 0);
if(BeginPos = -1) then
begin
// Trovato il film
LeggeFilm(Page);
end
else // Lista di film
begin
PickTreeClear;
PickTreeAdd('Risultati ricerca per "' + MovieName + '":', '');
LineNr := FindLine('<td><b><a href="', Page, BeginPos);
while LineNr <> -1 do
begin
// Indirizzo e titolo del film
rigahtml:= Page.GetString(LineNr);
// ShowMessage(rigahtml);
BeginPos:= pos('href="', rigahtml)+6;
EndPos:= pos('" >', rigahtml);
MovieAddr:= copy( rigahtml, BeginPos, EndPos-BeginPos);
// ShowMessage(MovieAddr);
BeginPos:= EndPos+3;
EndPos:= pos('</a></b>', rigahtml);
MovieTitle:= copy( rigahtml, BeginPos, EndPos-BeginPos);
// ShowMessage(MovieTitle);
// Legge l'anno
strTmp := Page.GetString(LineNr+1);
HTMLRemoveTags(strTmp);
//ShowMessage(strTmp);
MovieTitle := MovieTitle + ' [' + trim(strTmp) + ']';
// Add to listbox
PickTreeAdd(MovieTitle, MovieAddr);
// Restart the process
LineNr := LineNr+1;
LineNr := FindLine('<td><b><a href="', Page, LineNr);
end;
// Visualizza la lista e fa scegliere
if(PickTreeExec(Address)) then
begin
Address := 'http://www.kataweb.it'+Address;
// ShowMessage(Address);
Page.text := GetPage(Address);
// Salva la pagina per debug
// Page.SaveToFile('c:\Programmi\Ant Movie Catalog\Logs\'+MovieName+'.htm');
LeggeFilm(Page);
end;
end;
Page.Free();
end;
// -------------------- main
begin
if CheckVersion(3,4,2) then
begin
// Considera il titolo tradotto, se vuoto il titolo originale
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then MovieName := GetField(fieldOriginalTitle);
// Chiede conferma del titolo
Input('KwCinema Import', 'Titolo del film :', MovieName);
if MovieName <> '' then
begin
AnalyzePage('http://www.kataweb.it/cinema/cerca.jsp?textfield='+ UrlEncode(MovieName) +'&select=film');
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
end.