well i tried to add a function (Rating) to dino's script.
ottimo (excellent).
i've "translated" these ratings into 3, 5, 7, 9 into Rating field.
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Pivello
Title=FilmTV
Description=Get movie info from Film TV
Site=www.Film.TV.it
Language=IT
Version=02.02.2005
Requires=3.5.0
Comments=Modified by: 02.02.2005 dinolib; 03feb2004 ABN
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;
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 = '/> '; // 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
cStartVal = 'class="fTestoBiancoLite">';
cEndVal = '</td>';
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
Page: TStringList;
MovieUrl, MovieName, OriginalStr, TranslatedStr, PageStr: string;
// ---------------------------------------------
// PAGE PACKING (remove extra spaces, tabs & CR)
// IN: page Url (string)
// OUT: compact page (string)
// ---------------------------------------------
function RemoveExtraChars(Url: string): string;
var
Temp: string;
PackedPage: string;
CharPos: Integer;
n: Integer;
begin
Page.Text := GetPage(Url);
for n:=0 to Page.Count-1 do
PackedPage := PackedPage + ' ' + Page.GetString(n);
repeat
CharPos := pos(' ', PackedPage);
if CharPos = 0 then
CharPos := pos(#9, PackedPage);
if CharPos <> 0 then
begin
Temp := copy(PackedPage, 1, CharPos -1);
Delete(PackedPage, 1, CharPos);
PackedPage := Temp + PackedPage;
end;
until((pos(' ', PackedPage) = 0) and (pos(#9, PackedPage) = 0));
result := PackedPage;
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 GetValue(StartMarker, EndMarker: string; CutStartMarker, CutEndMarker: boolean): string;
var
StartPos: integer;
EndPos: integer;
Value: string;
begin
Value := '';
StartPos := pos(StartMarker, PageStr);
if (StartPos > 0) then
Delete(PageStr, 1, StartPos-1);
StartPos := pos(StartMarker, PageStr);
EndPos := pos(EndMarker, PageStr);
if ((StartPos > 0)and(EndPos > 0)) then
begin
if CutStartMarker then
StartPos := StartPos + length(StartMarker);
if not CutEndMarker then
EndPos := EndPos + length(EndMarker);
Value := copy(PageStr, StartPos, EndPos-Startpos);
Delete(PageStr, 1, EndPos);
end;
result := Value;
end;
procedure ReadPicture;
var
ImageLink: string;
Begin
ImageLink := ImagePath + getValue(cStartImg, cEndImg, true, true);
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;
Valutaz, Val2, Duration, Description, Cast, TempStr, TempImg, hh, mm: string;
begin
// Get packed title main page
PageStr := RemoveExtraChars(MovieUrl);
// Translated Title field
SetField(fieldTranslatedTitle, getValue(cStartTranslTitle, cEndTranslTitle, true, true));
// Get film image
//GetPicture(ImagePath + getValue(cStartImg, cEndImg, true, true));
ReadPicture;
// Original Title field
SetField(fieldOriginalTitle, getValue(cStartGeneric, cEndGeneric, true, true));
if(GetField(fieldOriginalTitle)='')then
SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
// Country field
SetField(fieldCountry, getValue(cStartGeneric, cEndGeneric, true, true));
// YearField
SetField(fieldYear, getValue(cStartGeneric, cEndGeneric, true, true));
// Director Field
SetField(fieldDirector, getValue(cStartDirector, cEndDirector, true, true));
SetField(fieldRating, Val2);
// Actors Field
Cast := '';
repeat
TempStr := getValue(cStartCast, cEndCast, true, true);
if ((Cast<>'') and (TempStr<>'')) then
Cast := Cast + ', ';
Cast := Cast + TempStr;
until((TempStr='')or(Length(TempStr)>40));
SetField(fieldActors, Cast);
// Category Field
SetField(fieldCategory, getValue(cStartGeneric, cEndGeneric2, true, true));
// Duration field
TempStr := getValue(cStartGeneric, cEndGeneric2, true, true);
SetField(fieldLength, Copy(TempStr,1,Length(TempStr)-1));
//Rating - Added by ABNormal
Valutaz := (getValue(cStartVal, cEndVal, true, true));
if (Valutaz='mediocre') then
Val2 := '3';
if (Valutaz='sufficiente') then
Val2 := '5';
if (Valutaz='buono') then
Val2 := '7';
if (Valutaz='ottimo') then
Val2 := '9';
if (Valutaz='') then
Valutaz := '0';
// Producer Field
//SetField(fieldProducer, getValue( , , true, true));
// Description Field
Delete(PageStr, 1, Pos(cBeginDesc, PageStr) + Length(cBeginDesc));
SetField(fieldDescription, getValue(cStartDesc, cEndDesc, true, true));
// Comments Field
SetField(fieldComments, getValue(cStartComm, cEndComm, true, true));
// 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', 'Enter the title of the movie / Inserire titolo del film:', MovieName)) then
begin
Page := TStringList.Create;
MovieUrl := QueryBase + UrlEncode(MovieName);
AnalyzeSearchPage(MovieUrl);
Page.Free;
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.