Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Pivello (see comments for changes authors)
Title=FilmTV
Description=Get movie info from Film TV
Site=www.Film.TV.it
Language=IT
Version=01.12.2007
Requires=3.5.0
Comments=Modified by:|02.02.2005 adapted to v.3.5.0 (Dinolib)|10.03.2005 Revised for pivlib.pas Library use (Pivello)|01.12.2007 fixed search results (admeis)
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]
LargePicture=1|1|0=Get a small picture|1=Try to get the big picture
***************************************************)
program FilmTVIt;
uses
Pivlib; // Pivello's scripts common library
const
UrlBase = 'http://www.film.tv.it';
QueryBase = UrlBase + '/cerca.php?ricerca=avanzata&titolo=';
QueryFilm = UrlBase + '/scheda.php?film=';
ImagePath = UrlBase + '/imgbank/';
cStartId = 'Verde"><a href="scheda.php?film='; // ID start marker
cEndId = '" class="fTitolettoFilm"'; // ID end marker
cStartTitle = 'style="margin: 2px 5px 40px 0; float: left; " />'; // Title start marker
cEndTitle = '</a></span>'; // Title end marker
cStartTranslTitle = 'fTitoloFilmBianco">'; // Translated title start marker
cEndTranslTitle = '</span>'; // Translated title end marker
cStartImg = 'img src="imgbank/'; // Image start marker
cEndImg = '" width="'; // Image end marker
cStartGeneric = 'Lite" bgcolor="#5B6E80" valign="top">';
cEndGeneric = ' '; // Generic field marker
cStartDirector = 'fLinkBianco>'; // Director start marker
cEndDirector = '</a>'; // Director end marker
cStartCast = 'fLinkBianco>'; // Actor start marker
cEndCast = '</a>'; // Actor end marker
cEndGeneric2 = '</td>'; // Generic end marker 2
cBeginDesc = '"La Trama" /></p>'; // Description begin marker
cStartDesc = '<p class="testo">'; // Description start marker
cEndDesc = '</p>'; // Description end marker
cStartComm = '<p class="testo"><i>'; // Comment start marker
cEndComm = '</i></p>'; // Comment end marker
var
MovieUrl, MovieName, OriginalStr, TranslatedStr, PageStr: string;
// ---------------------------------
// READ PICTURE
// OUT: none
// ---------------------------------
procedure ReadPicture;
var
ImageLink: string;
Begin
ImageLink := ImagePath + getValue(PageStr, cStartImg, cEndImg, true, true);
PageStr := GetPageStr;
if Pos('DUMMY/locandina.gif',ImageLink)>0 then
exit;
if GetOption('LargePicture')=1 then
ImageLink := StringReplace(ImageLink,'/LOC/','/GALLERY/');
GetPicture(ImageLink);
end;
// -----------------------
// ANALYZE MOVIE DATA PAGE
// IN: none
// OUT: set Ant fields
// -----------------------
procedure AnalyzeMoviePage;
var
i, h, m: integer;
Duration, Description, Cast, TempStr, TempImg, hh, mm: string;
begin
// Get packed title main page
PageStr := RemoveExtraChars(MovieUrl);
// Translated Title field
SetField(fieldTranslatedTitle, getValue(PageStr, cStartTranslTitle, cEndTranslTitle, true, true));
PageStr := GetPageStr;
// Get film image
ReadPicture;
// Original Title field
SetField(fieldOriginalTitle, getValue(PageStr, cStartGeneric, cEndGeneric, true, true));
PageStr := GetPageStr;
if(GetField(fieldOriginalTitle)='')then
SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
// Country field
SetField(fieldCountry, getValue(PageStr, cStartGeneric, cEndGeneric, true, true));
PageStr := GetPageStr;
// YearField
SetField(fieldYear, getValue(PageStr, cStartGeneric, cEndGeneric, true, true));
PageStr := GetPageStr;
// Director Field
SetField(fieldDirector, getValue(PageStr, cStartDirector, cEndDirector, true, true));
PageStr := GetPageStr;
// Actors Field
Cast := '';
repeat
TempStr := getValue(PageStr, cStartCast, cEndCast, true, true);
PageStr := GetPageStr;
if ((Cast<>'') and (TempStr<>'')) then
Cast := Cast + ', ';
Cast := Cast + TempStr;
until((TempStr='')or(Length(TempStr)>40));
SetField(fieldActors, Cast);
// Category Field
SetField(fieldCategory, getValue(PageStr, cStartGeneric, cEndGeneric2, true, true));
PageStr := GetPageStr;
// Duration field
TempStr := getValue(PageStr, cStartGeneric, cEndGeneric2, true, true);
PageStr := GetPageStr;
SetField(fieldLength, Copy(TempStr,1,Length(TempStr)-1));
// Producer Field
//SetField(fieldProducer, getValue(PageStr, , , true, true));
//PageStr := GetPageStr;
// Description Field
Delete(PageStr, 1, Pos(cBeginDesc, PageStr) + Length(cBeginDesc));
SetField(fieldDescription, getValue(PageStr, cStartDesc, cEndDesc, true, true));
PageStr := GetPageStr;
// Comments Field
SetField(fieldComments, getValue(PageStr, cStartComm, cEndComm, true, true));
PageStr := GetPageStr;
// Movie URL field
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
TempIdFilm: string;
TempTitle: string;
StartPos: integer;
EndPos: integer;
begin
if OneFilm then
begin
StartPos := pos(cStartId, PageStr);
EndPos := pos(cEndId, PageStr);
StartPos := StartPos + Length(cStartId);
TempIdFilm := copy(PageStr, StartPos, EndPos-Startpos); // Get ID
result := QueryFilm + TempIdFilm;
end
else
begin
PickTreeClear;
repeat
StartPos := pos(cStartId, PageStr);
EndPos := pos(cEndId, PageStr);
if StartPos > 0 then
begin
StartPos := StartPos + Length(cStartId);
TempIdFilm := copy(PageStr, StartPos, EndPos-Startpos); // Get ID
Delete(PageStr, 1, EndPos);
StartPos := pos(cStartTitle, PageStr);
EndPos := pos(cEndTitle, PageStr);
StartPos := StartPos + Length(cStartTitle);
TempTitle := copy(PageStr, StartPos, EndPos-Startpos); // Get Title
PickTreeAdd(TempTitle, QueryFilm + TempIdFilm);
end;
until(StartPos = 0);
result := '';
end
end;
// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN: page Url (string)
// OUT: none
// ---------------------------------
procedure AnalyzeSearchPage(Url: string);
var
FilmId: string;
begin
PageStr := RemoveExtraChars(Url);
if pos('Non ho trovato nessun film', PageStr) > 0 then
ShowMessage('Title not found / Nessun film trovato.')
else if pos('Si è verificato un errore',PageStr) > 0 then
ShowMessage('Server not available, try later / Server non disponibile, prova più tardi')
else
begin
if pos('Ho trovato 1 film', PageStr) <> 0 then
MovieUrl := PopulatePickTree(true) // One title found
else
begin
PopulatePickTree(false); // More titles found..
if not PickTreeExec(MovieUrl) then // ..select one
exit;
end;
AnalyzeMoviePage;
end;
end;
// ----------
// MAIN:
// IN: none
// OUT: none
// ----------
begin
if CheckVersion(3,5,0) then
begin
TranslatedStr := GetField(fieldTranslatedTitle);
OriginalStr := GetField(fieldOriginalTitle);
if (TranslatedStr <> '') then
MovieName := TranslatedStr
else
MovieName := OriginalStr;
if(Input('Film.TV.It - By Pivello (and others)', 'Enter the title of the movie / Inserire titolo del film:', MovieName)) then
begin
InitializePivLib;
MovieUrl := QueryBase + UrlEncode(MovieName);
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.
Best regards.