Lo script richiede AMC 4.2.0 o superiore
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Fulvio53s03 (based on Fiezul, PIvello, Valerino & others works).
Title=FilmTV
Description=Get movie info from Film TV
Site=www.Film.TV.it
Language=IT
Version=3.3.1 18.6.2014
Requires=4.2.0
Comments=
License=
GetInfo=1
RequiresMovies=1
[Options]
[Parameters]
***************************************************)
program FilmTVIt;
uses
StringUtils7552; // Script needs external unit StringUtils7552.pas in scripts folder !
const
//Query constants
UrlBase = 'http://www.film.tv.it';
QueryBase = UrlBase + '/cerca/?q=';
QueryFilm = UrlBase + '';
//Search page constants
Apice = #39;
cStartFilmUrl = '<a class="pic" href="'; // ID start marker //fs2014.04.21
cEndFilmUrl = '">'; // ID end marker //fs2014.04.21
cStartTitle = '<img alt="'; // Title start marker //fs2014.04.21
cEndTitle = '" src="'; // Title end marker //fs2014.04.21
//Film page constants
cStartTranslTitle = '<div class="wrap-head">'; // Translated title start marker
cEndTranslTitle = '<div class='; // Translated title end marker
cStartOrigTitle = '[<i>'; // Original title start marker
cEndOrigTitle = '</i>'; // Original title end marker
cStartImgLink_ext = '<figure class="locandina">'; // Image start marker
cStartImgLink_int = '<img src="'; // Image start marker
cEndImgLink_int = '"'; // Image end marker
cEndImgLink_ext = '</figure>'; // Image end marker
cStartListItem = ', ';
cEndCountry = '<a href="/film/anno';
cEndListItem = ', '; // Generic field marker
cStartCategory = '/">'; // Category start marker
cEndCategory = '</a>'; // Single Director end marker
cEndDirectors = '</p>'; // Directors end marker
cStartDirector = 'Regia di'; // Single Director start marker
cEndDirector = '</p>'; // Single Director end marker
cStartCast = 'Con</span>'; // Cast start marker
cEndCast = '<strong>'; // Cast end marker
cStartActor = '">'; // Actor start marker
cEndActor = '</a>'; // Actor end marker
cEndGeneric2 = '</td>'; // Generic end marker 2
cStartDesc = '<h1>Trama</h1>'; // Description start marker //FS2012-11-11
cEndDesc = '</p>'; // Description end marker
cStartComm = '<blockquote>'; //fs2013-02-11
cEndComm = '</blockquote>'; // Comment end marker
cStartURL='<li id="sel"><a href="/';
cEndURL='" title="scheda"';
InitYear = '<h2>'; //fs2014.04.22
// EndYear = '</h2>'; //fs2014.04.22
EndYear = ', con '; //fs2014.06.03
var
searchUrl, MovieUrl, MovieName, OriginalStr, TranslatedStr, File_name, PageStr: string;
MoviesFound: integer;
// --------------------------------------------------
// PAGE PACKING (remove extra spaces, tabs & CR) by Pivello
// IN: page Url (string)
// OUT: compact page (string)
// --------------------------------------------------
function RemoveExtraChars(Url: string): string;
var
Page: TStringList;
TmpPageStr: string;
Temp: string;
PackedPage: string;
CharPos: Integer;
n: Integer;
begin
Page := TStringList.Create;
TmpPageStr := '';
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;
Page.Free;
end;
// -----------------------
// ANALYZE MOVIE DATA PAGE
// IN: none
// OUT: set Ant fields
// -----------------------
procedure SetMovieFields (htmlStr: string);
var
i, h, m: integer;
Duration, Description, Cast, TempStr, TempImg, hh, mm,temp: string;
tempDirector, director: string;
PosParAperta, PosParChiusa: integer;
imageLink: string;
sep1, sep2: string;
SaveHtmlstr, tempvar : string;
dati_generali, Title_orig, Paese, Anno, Categoria, durata : string;
begin
SetField(fieldDate, DateToStr(Date));
// General movie description fields
anno := '';
TranslatedStr := TextBetween(htmlStr, cStartTranslTitle, cEndTranslTitle);
TranslatedStr := TextBetween(TranslatedStr, '<h1>', '</h1>');
if length(Translatedstr) < 1 then
begin
TranslatedStr := TextBetween(htmlStr, cStartTranslTitle, cEndTranslTitle);
TranslatedStr := TextBetween(TranslatedStr, '<h1 >', '</h1>');
end;
SetField(fieldTranslatedTitle, AnsiMixedCase(AnsiLowerCase(TranslatedStr), ' ')); //Titolo Tradotto
//Dati Generali (tit.orig, paese, anno, genere, durata ecc.)
Dati_generali := TextBetween(htmlStr, '<div class="wrap-head-content cf"', '<div class="visione cf">');
Title_orig := FullTrim(TextBetween(Dati_generali, '<li><h2>', '</h2></li>'));
SetField(fieldOriginalTitle, Title_orig);
if length(Title_orig) > 0 then
begin
Paese := TextBetween(Dati_generali, '</li> <li>', '<time>');
Anno := TextBetween(Dati_generali, '<time>', '</time>');
Categoria := fulltrim(Textbetween(Dati_generali, '<span>Genere:</span>', '</li>'));
durata := fulltrim(Textbetween(Dati_generali, '<span>durata</span>', '</li>'));
end
else
begin
Paese := TextBetween(Dati_generali, '<li>', '<time>');
Anno := TextBetween(Dati_generali, '<time>', '</time>');
Categoria := fulltrim(Textbetween(Dati_generali, '<span>Genere:</span>', '</li>'));
durata := fulltrim(Textbetween(Dati_generali, '<span>durata</span>', '</li>'));
end;
SetField(fieldCountry, Paese);
SetField(fieldYear, Anno);
SetField(fieldCategory, Categoria);
temp := Textbefore(durata, apice, '');
SetField(fieldLength, temp);
//Get Director
temp:= TextBetween(htmlstr, cStartDirector,cEndDirector);
HTMLRemoveTags(temp);
HTMLDecode(temp);
temp:= fulltrim(temp);
setfield(FieldDirector, Temp);
//Get Actors
temp:= TextBetween(htmlStr, cStartCast,cEndCast);
HTMLRemoveTags(temp); //fs 2012-04-03
HTMLDecode(temp);
SetField(fieldActors, FullTrim(temp))
//Get comments
SaveHtmlstr:= htmlstr;
temp:= Textbetween(htmlStr, cStartDesc, cEndDesc);
HTMLRemoveTags(temp); //fs 2012-04-03
HTMLDecode(temp);
SetField(fieldDescription, FullTrim(temp));
temp := TextBetween(HtmlStr, cStartComm, cEndComm);
HTMLRemoveTags(temp);
HTMLDecode(temp);
SetField(fieldComments, FullTrim(temp));
htmlstr:= SaveHtmlstr;
//Get URL
SetField(fieldURL, movieurl);
//Get image http://ftv01.stbm.it/imgbank/GALLERYXL/R201404/the_english_teacher_poster_ita.jpg
imagelink := TextBetween(htmlStr, cStartImgLink_ext, cEndImgLink_ext);
imagelink := TextBetween(imagelink, cStartImgLink_int, cEndImgLink_int);
// setfield(FieldSubTitles, imagelink);
// if imagelink <> 'http://www.film.tv.it/imgbank/DUMMY/no_locandina.jpg' then
if imagelink <> 'http://ftv01.stbm.it/imgbank/DUMMY/no_locandina.jpg' then
GetPicture2(imagelink, movieurl);
// GetPicture(imagelink);
end;
//###############################################
//##############################################
//Returns a text field from an input string strIn (pagestr)
//delIn and delOut: text field delimiters
//##############################################
function getTextDelimited(lIn:string; lOut:string;Var strIn:string): string;
var
StartPos: integer;
len:integer;
tempStr: string;
lgth_pagestr: integer;
begin
lgth_pagestr:= length(strIn);
StartPos := pos(lIn, strIn);
if startPos<>0 then
begin
StartPos:=StartPos+Length(lIn);
tempStr:= copy(strIn,StartPos,StartPos+length(strIn));
len := pos(lOut, tempStr);
if len=0 then
result:=''
else
result := copy(strIn, StartPos, len-1); // get Text Out
Delete(strIn, 1, StartPos-1 + len-1 + length(lOut)-2);
lgth_pagestr:= length(strIn);
end
else
result := '';
HTMLDecode(result);
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)
// ------------------------------------------------------------------
procedure PopulatePickTree();
var
filmUrl, partialUrl: string;
filmTitle, filmYear: string;
StartPos, EndPos: integer;
Lgth_pagestr: integer;
begin
PickTreeClear;
// PickTreeAdd('Risultati ricerca per "' + File_name + '":', '');
PickTreeAdd('Risultati ricerca per "' + getfield(fieldFilePath) + '":', '');
repeat
partialUrl:= getTextDelimited(cStartFilmUrl,cEndFilmUrl,PageStr);
filmUrl:=UrlBase + partialUrl;
filmTitle:=getTextDelimited(cStartTitle,cEndTitle,PageStr);
filmYear:=getTextDelimited(InitYear, EndYear,PageStr);
//fs20140603 filmYear:= copy(filmYear, 1, 42);
filmYear:= ' ' + '(' + filmYear + ')';
filmTitle := filmtitle + ' ' + filmYear;
MoviesFound := MoviesFound + 1;
if partialUrl<>'' then
begin
PickTreeAdd(filmTitle, filmUrl);
end;
until(partialUrl='');
end;
// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN: html of search page (string)
// OUT: movie url
// ---------------------------------
function analyzePage(htmlSearchPage: string): string;
var
FilmId: string;
begin
result:='';
if pos('Non ho trovato nulla!', htmlSearchPage) > 0 then
ShowMessage('Title not found / Nessun film trovato.')
else
begin
PopulatePickTree();
if MoviesFound > 1 then
begin
if not PickTreeExec(result) then
begin
MoviesFound := 0;
exit;
end
end;
if MoviesFound <= 1 then
// begin
// if not PickTreeExec(result) then
exit; //Select one title
// end;
end;
end;
// ----------
// MAIN:
// IN: none
// OUT: none
// ----------
begin
if CheckVersion(4,2,0) then
begin
TranslatedStr := GetField(fieldTranslatedTitle);
OriginalStr := GetField(fieldOriginalTitle);
if (TranslatedStr <> '') then
MovieName := TranslatedStr
else
MovieName := OriginalStr;
File_name := MovieName;
if(Input('Film.TV.It', 'Enter the title of the movie / Inserire titolo del film:', MovieName)) then
begin
//Get search page
MoviesFound := 0;
// http://www.filmtv.it/cerca/?q=dalle+9+alle+5+orario+continuato
// searchUrl := QueryBase + UrlEncode(MovieName);
searchUrl := QueryBase + Stringreplace(MovieName, ' ', '+');
PageStr := RemoveExtraChars(searchUrl);
PageStr := UTF8Decode(PageStr);
//Analyze search page and get movie url (user choice)
MovieUrl:=analyzePage(PageStr);
// Get movie page
if MoviesFound = 0 then
exit;
PageStr := RemoveExtraChars(MovieUrl);
PageStr := UTF8Decode(PageStr);
Pagestr := Stringreplace(Pagestr, '’', '´');
//Analyze movie page and set movie fields
SetMovieFields(PageStr);
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 4.2.0)');
end.