Is possible (as usual) to search for a title and also for barcode..
@sCeRiFz: Please Test this version (changed from the first I sent you..)
Ciao,in allegato lo script per il sito http://www.lafeltrinelli.it.
E' possibile (come al solito) ricercare per titolo, ma anche per codice a barre..
@sCeRiFz: Testa questa versione (diversa da quella che ti ho mandato..)
Test & Feedback are welcome..
Ciao!
LaFeltrinelli.it.ifs
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Gigibop (luca.marcato@gmail.com)
Title=LaFeltrinelli
Description=Get movie info from http://www.lafeltrinelli.it
Site=http://www.lafeltrinelli.it
Language=IT
Version=1.0 - 27.08.2010
Requires=3.5.0
Comments=Changes|27.08.2010 v. 1.0: First revision (Gigibop)
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 LaFeltrinelli;
uses
GiLib,StringUtils1;
var
MovieName: string;
TheMovieAddress: string;
const
UrlBase = 'http://www.lafeltrinelli.it';
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: integer;
BeginPos: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<div class="informazioniProdotto">', Page, 0);
if LineNr = -1 then
begin
SetField(fieldURL, Address);
AnalyzeMoviePage(Page);
end
else
begin
PickTreeClear;
AddMoviesTitles(Page);
if TheMovieAddress='' then
begin
if PickTreeExec(Address) then AnalyzePage(Address);
end
else
begin
SetField(fieldURL, TheMovieAddress);
Page.Text := GetPage(TheMovieAddress);
AnalyzeMoviePage(Page);
end;
end;
Page.Free;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Line: String;
LineNr: Integer;
begin
// Translated Title
LineNr := FindLine('<div id="schedaProdotto">', Page, 0);
if LineNr > -1 then
begin
Line:= Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<div id="schedaProdotto">', '</a>'),True,True);
SetField(fieldTranslatedTitle, Line);
end;
// Original Title
LineNr := FindLine('<dt>Titolo in lingua originale</dt>', Page, 0);
if LineNr > -1 then
begin
Line:= Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<dt>Titolo in lingua originale</dt>', '</dd>'),True,True);
SetField(fieldOriginalTitle, Line);
end;
// Director
LineNr := FindLine('<h4 id="regista">', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '</em>', '</h4>'),True,True);
SetField(fieldDirector,Line);
end;
// Cast
LineNr := FindLine('<h4 id="attori">', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<h4 id="attori"><em>Con: </em>', '</h4>'),True,True);
SetField(fieldActors,Line);
end;
// Production
LineNr := FindLine('<dt>Produzione</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<dt>Produzione</dt>', '</dd>'),True,True);
SetField(fieldProducer,Line);
end;
// Genre
LineNr := FindLine('<dt>Genere</dt>', Page, 0);
if LineNr > -1 then
begin
Line := GJoinMultipleLines(Page, '<dt>Genere</dt>','</dd></dl>' , LineNr);
Line := GHtmlDecodeAndClean(TextBetween(Line, '<dt>Genere</dt><dd>', '</dd>'),True,True);
SetField(fieldCategory,Line);
end;
// Year
LineNr := FindLine('<dt>Data uscita</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := TextAfter(GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<dt>Data uscita</dt>', '</dd>'),True,True),'/');
SetField(fieldYear,Line);
end;
// Lenght
LineNr := FindLine('<dt>Durata</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<dt>Durata</dt>', '</dd>'),True,True);
SetField(fieldLength,Line);
end;
// Disks Number
LineNr := FindLine('<dt>N. DVD</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line:= GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<dt>N. DVD</dt>', '</dd>'),True,True);
SetField(fieldDisks,Line);
end;
// Description
LineNr := FindLine('<p class="abstract">', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line:= UTF8Decode(GHtmlDecodeAndClean(TextBetween(Page.GetString(LineNr), '<p class="abstract">', '</p>'),True,True));
SetField(fieldDescription,Line);
end;
// Picture
LineNr := FindLine('<p class="copertina copertinal">', Page, 0);
if LineNr > -1 then
begin
Line := GJoinMultipleLines(Page, '<p class="copertina copertinal">','</p>' , LineNr);
Line := TextBetween(Line,'src="','"/>');
Line := GHtmlDecodeAndClean(Line,false,false);
GetPicture(UrlBase + Line);
end;
// Audio Tracks
LineNr := FindLine('<dt>Lingue</dt>', Page, 0);
if LineNr > -1 then
begin
Line := GJoinMultipleLines(Page, '<dt>Lingue</dt>','<dt>Sottotitoli</dt>' , LineNr);
Line := GHtmlDecodeAndClean(TextBetween(Line, '<dt>Lingue</dt>', '</dd>'),True,True);
SetField(fieldLanguages, Line);
end
// SubTitles
LineNr := FindLine('<dt>Sottotitoli</dt>', Page, 0);
if LineNr > -1 then
begin
Line := GJoinMultipleLines(Page, '<dt>Sottotitoli</dt>','<dt>Genere</dt>' , LineNr);
Line := GHtmlDecodeAndClean(TextBetween(Line, '<dt>Sottotitoli</dt>', '</dd>'),True,True);
SetField(fieldSubtitles, Line);
end;
// MediaLabel --> Barcode
LineNr := FindLine('<dt>EAN</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := GHtmlDecodeAndClean(TextBetween(Line, '<dt>EAN</dt>', '</dd>'),True,True);
SetField(fieldMedia, Line);
end;
// Media Type
LineNr := FindLine('<dt>Supporto</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := GHtmlDecodeAndClean(TextBetween(Line, '<dt>Supporto</dt>', '</dd>'),True,True);
Line := TextBefore(Line, ' FILM', '');
SetField(fieldMediaType, Line);
end;
// Country
LineNr := FindLine('<dt>Paese</dt>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := GHtmlDecodeAndClean(TextBetween(Line, '<dt>Paese</dt>', '</dd>'),True,True);
SetField(fieldCountry, Line);
end;
end;
procedure AddMoviesTitles(Page: TStringList);
var
LineNr: Integer;
Line: string;
i: Integer;
MovieTitle, MovieAddress, Description: string;
BeginPos, EndPos: Integer;
begin
LineNr := 0;
LineNr := FindLine('<div class="informazioniProdotto">',Page,LineNr);
while LineNr > -1 do
begin
Line:= GJoinMultipleLines(Page, '<div class="informazioniProdotto">','</h4>' , LineNr);
MovieAddress:= GHtmlDecodeAndClean(TextBetween(Line, 'a href="', '"'),True,True);
MovieTitle:= GHtmlDecodeAndClean(TextBefore(Line, '</a>', ''),True,True);
Description := TextBetween(Line, '<p class="supporto">', '</p>');
if Description = '' then Description := TextBefore(Line, 'Non disponibile', '</A>');
if MovieTitle > '' then PickTreeAdd(MovieTitle + ' (' + Description + ')', MovieAddress);
if TheMovieAddress='*' then
TheMovieAddress := MovieAddress
else
TheMovieAddress := '';
LineNr := FindLine('<div class="informazioniProdotto">',Page,LineNr+1);
end;
LineNr := FindLine('<p style="height: auto;" class="pagine">',Page,LineNr);
Line := Page.GetString(LineNr);
Line := TextBetween(Line, '<p style="height: auto;" class="pagine">', '</p>');
BeginPos := pos('href',Line);
if BeginPos>0 then
begin
Delete(Line,1,BeginPos + 5);
EndPos := pos('"',Line);
MovieAddress := copy(Line,1,EndPos-1);
PickTreeMoreLink('http://www.lafeltrinelli.it' + GHtmlDecode(MovieAddress,true));
end;
if TheMovieAddress='*' then TheMovieAddress := '';
end;
// -----------------------------
// Questo è il main dello script
// -----------------------------
begin
if CheckVersion(3,5,0) then
begin
NewGiLib;
TheMovieAddress := '*';
MovieName := StringReplace(GetField(fieldTranslatedTitle), '.', ' ');
if MovieName = '' then
MovieName := StringReplace(GetField(fieldOriginalTitle), '.', ' ');
While pos ('[', MovieName) > 0 Do begin
MovieName := TextBefore(MovieName, '[', '') + TextAfter(MovieName, ']');
end;
if Input('LaFeltrinelli Importazione Film', 'Digitare il titolo del film / Codice a Barre:', MovieName) then
begin
AnalyzePage(UrlBase + '/fcom/it/home/pages/catalogo/searchresults.html?prkw='+UrlEncode(MovieName)+'&srch=0&Cerca.x=0&Cerca.y=0&cat1=5&prm=');
end;
FinalizeGiLib;
end
else
ShowMessage('Questo script richiede una versione più nuova di Ant Movie Catalog (almeno la versione 3.5.0)');
end.
GiLib.pas
Code: Select all
(*=============================================================
Gigibop's Library
Authors=Gigibop (luca.marcato@gmail.com)
Description= Useful Procedures and Functions
Version=1.0
ChangeLog:
27.08.2010 v. 1.0: First revision (Gigibop)
Joyride... Si o no??? Ma anche no!!!
=============================================================*)
Unit GiLib;
uses
StringUtils1;
Var
TPage: TStringList;
//===================================================
// Constructor/Finalize lib
//===================================================
Procedure NewGiLib;
Begin
TPage := TStringList.Create;
End;
Procedure FinalizeGiLib;
Begin
TPage.Free;
End;
//===================================================
// Remove Tabs from a string
//===================================================
Function GRemoveTabs(sVal : String) : String;
Begin
Repeat
sVal:= StringReplace(sVal, ' ', '');
Until (pos(' ',sVal) = 0);
result := sVal;
end;
//===================================================
// Left and Right Trim from a string
//===================================================
Function GLeftRightTrim(sVal: String): String;
Var
bExit: Boolean;
Begin
bExit := False;
Repeat
Case copy(sVal, 1, 1) Of ' ', #9, #10, #13:
sVal := copy(sVal, 2, Length(sVal)-1);
Else
bExit := True;
End;
Until bExit;
bExit := False;
Repeat
Case copy(sVal, Length(sVal), 1) Of ' ', #9, #10, #13:
sVal := copy(sVal, 1, Length(sVal)-1);
Else
bExit := True;
End;
Until bExit;
result := sVal;
End;
//===================================================
// Html Decode and Trim
//===================================================
Function GHtmlDecode(sVal: String ; bTrim: boolean) :String;
Begin
HTMLDecode(sVal);
If bTrim = True Then
sVal := GLeftRightTrim(sVal);
result := sVal;
End;
//===================================================
// Html Decode, Trim and Remove Tabs
//===================================================
Function GHtmlDecodeAndClean(sVal: String; bTabs: Boolean; bTrim: Boolean) :String;
Begin
HTMLRemoveTags(sVal);
HTMLDecode(sVal);
If bTabs = True Then
sVal := GRemoveTabs(sVal);
If bTrim = True Then
sVal := GLeftRightTrim(sVal);
result := sVal;
End;
//===================================================
// Join Multiple Lines in a String
//===================================================
Function GJoinMultipleLines(sPage: TStringList; sTextFrom: String; sTextTo: String; iStartLine: Integer) :String;
Var
IEnd,I : Integer;
sLine: String;
Begin
IEnd := 0;
sLine := '';
iStartLine := FindLine(sTextFrom,sPage,iStartLine);
If iStartLine > 0 Then IEnd := FindLine(sTextTo,sPage,iStartLine);
For I:= iStartLine To IEnd Do
Begin
sLine:= sLine + sPage.GetString(i);;
End;
result := sLine;
End;
Procedure GDebug(sVal: String; sFileName: String);
Begin
TPage.Text := sVal;
TPage.SaveToFile(sFileName);
TPage.Free;
End;
End.