Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Claudio Rinaldi ( rinaldiclaudio@gmail.com )
Title=AlCinemaInCasa
Description=Get movie info from alcinemincasa.it
Site=www.alcinemaincasa.it
Language=IT
Version=1.0
Requires=3.5.1
Comments=
License=
GetInfo=1
[Options]
***************************************************)
program AlCinemaInCasaIT;
uses
Pivlib; // Pivello's scripts common library
const
UrlBase = 'http://www.alcinemaincasa.it';
UrlRicerca = '&ORDER=prodottoasc';
QueryBase = UrlBase + '/commy/prodotti_lista_public.asp?action=Cerca&TX_CM_PRODOTTO=';
QueryFilm = UrlBase + '/commy/prodotti_view.asp?PRODOTTO_ID=';
ImagePath = UrlBase + '/locandine/';
cStartNumRis = '</span> di ';
cEndNumRis = '</td>';
cStartId = 'PRODOTTO_ID=';
cEndId = '"';
cStartTitle = 'CommyHeading4';
cEndTitle = '</h1>';
cStartTranslTitle = 'Titolo Originale</strong>: ';
cEndTranslTitle = '</h2>';
cStartImg = 'CommyThumbsAna" src="';
cEndImg = '" alt';
cStartDirector = 'Regista</li>';
cEndDirector = '</li>';
cStartCast = 'Attori</li>';
cEndCast = '</li>';
cStartCategory = 'Genere</li>';
cEndCategory = '</li>';
cStartDuration = 'Durata</li>';
cEndDuration = '</li>';
cStartCountry = 'Nazionalità</strong>:';
cEndCountry = ' ';
cStartYear = 'Anno di produzione</li>';
cEndYear = '</li>';
cStartDesc = '<p class="CommyDesc4">';
cEndDesc = '</p>';
cStartTitleList = 'title=';
cEndTitleList = '</a>';
var
MovieUrl, MovieName, TranslatedStr, PageStr: string;
// -----------------------
// ANALYZE MOVIE DATA PAGE
// IN: none
// OUT: set Ant fields
// -----------------------
procedure AnalyzeMoviePage;
var
cImage,cValue : string;
begin
// Get packed title main page
PageStr := RemoveExtraChars(MovieUrl);
// ORIGINAL TITLE
SetField(fieldOriginalTitle, GetValueEx(PageStr, cStartTitle, cEndTitle,true,true));
PageStr := GetPageStr;
// FILM IMAGE
cImage := GetValueEx(PageStr, cStartImg, cEndImg, true, false);
PageStr := GetPageStr;
if cImage <> '' then
GetPicture(cImage);
// YEAR
SetField(fieldYear, GetValueEx(PageStr, cStartYear, cEndYear, true, false));
PageStr := GetPageStr;
// ACTORS
SetField(fieldActors, GetValueEx(PageStr, cStartCast, cEndCast, false, false));
PageStr := GetPageStr;
// DURATION
SetField(fieldLength, GetValueEx(PageStr, cStartDuration, cEndDuration, true, false));
PageStr := GetPageStr;
// CATEGORY
cValue := GetValueEx(PageStr, cStartCategory, cEndCategory, true, false);
SetField(fieldCategory, AnsiUpFirstLetter(AnsiLowerCase(cValue)));
PageStr := GetPageStr;
// DIRECTOR
SetField(fieldDirector, GetValueEx(PageStr, cStartDirector, cEndDirector, false, false));
PageStr := GetPageStr;
// DESCRIPTION
SetField(fieldDescription, GetValueEx(PageStr, cStartDesc, cEndDesc, true, false));
PageStr := GetPageStr;
// COMMENTS
// URL
SetField(fieldURL, MovieUrl);
end;
// ------------------------------------------------------------------
// FILL PICKTREE CONTROL WITH LINKS & TITLES or RETURN ONE PAGE LINK
// if OneFilm flag true return Film Id else populate PickTree
// IN: OneFilm flag (bool)
// OUT: one page ID (string)
// ------------------------------------------------------------------
function PopulatePickTree(OneFilm: boolean): string;
var
cFilmId,cFilmTitle: string;
StartPos,EndPos: integer;
begin
if OneFilm then begin
cFilmId := GetValueEx(PageStr,cStartId,cEndId,false,false);
result := QueryFilm + cFilmId;
end
else begin
PickTreeClear;
repeat
StartPos := pos(cStartId, PageStr);
if StartPos > 0 then begin
Delete(PageStr, 1, StartPos - 1);
cFilmId := GetValueEx(PageStr,cStartId,cEndId,true,false); // Get ID
cFilmTitle := GetValueEx(PageStr,cStartTitleList,cEndTitleList,true,true); // Get Title
if cFilmTitle <> '' then
PickTreeAdd(cFilmTitle, QueryFilm + cFilmId);
EndPos := pos(cStartId,PageStr);
Delete(PageStr, 1, EndPos);
end;
until(StartPos = 0);
result := '';
end
end;
// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN: page Url (string)
// OUT: none
// ---------------------------------
procedure AnalyzeSearchPage(Url: string);
var
NumRisultati : string;
begin
PageStr := RemoveExtraChars(Url);
NumRisultati := GetValueEx(PageStr, cStartNumRis, cEndNumRis, true, false);
if ( (NumRisultati = '0') or (NumRisultati = '')) then
begin
ShowMessage('Title not found / Nessun film trovato.');
exit;
end
if NumRisultati = '1' then
MovieUrl := PopulatePickTree(true)
else
begin
PopulatePickTree(false);
if not PickTreeExec(MovieUrl) then // ..select one
exit;
end;
AnalyzeMoviePage;
end;
// --------------------------------------------------
// GET FIELD VALUES FROM PACKED PAGE
// IN: Start marker (String)
// End marker (string)
// Cut Start Marker (bool)
// Cut End Marker (bool)
// OUT: value (string)
// --------------------------------------------------
function GetValueEx(MyPageStr,cStartMarker,cEndMarker: string;bCutEnd,bAdjust: boolean): string;
var
StartPos: integer;
EndPos: integer;
Value: string;
begin
Value := '';
StartPos := pos(cStartMarker, MyPageStr);
if ( StartPos = 0 ) then exit; // Not found
StartPos := StartPos + length(cStartMarker);
Delete(MyPageStr, 1, StartPos -1);
EndPos := pos(cEndMarker, MyPageStr);
if EndPos > 0 then begin
Value := copy(MyPageStr, 0, EndPos-1);
if bCutEnd then
EndPos := EndPos + length(cEndMarker);
Delete(MyPageStr, 1, EndPos -1);
if bAdjust then
Value := '<' + Value;
end;
TmpPageStr := MyPageStr;
HTMLRemoveTags(Value);
HTMLDecode(Value);
result := Trim(Value);
end;
// ----------
// MAIN:
// IN: none
// OUT: none
// ----------
begin
if CheckVersion(3,5,0) then
begin
TranslatedStr := GetField(fieldTranslatedTitle);
MovieName := GetField(fieldOriginalTitle);
if (TranslatedStr <> '') then
MovieName := TranslatedStr;
if(Input('MyMovies.It', 'Enter the title of the movie', MovieName)) then
begin
InitializePivLib;
MovieUrl := QueryBase + StringReplace(MovieName,' ','+') + UrlRicerca;
AnalyzeSearchPage(MovieUrl);
FinalizePivLib;
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.