Page 1 of 1

Film.tv.it script: new version (fixed)

Posted: 2008-08-14 14:13:31
by fiezul
Hi everybody.
Due to complete restyling of the site, the old Pivello's script doesn't function anymore.
I've rewritten the script, using some Pivello's functions.
Now it works.

Fiezul

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Fiezul (previous version: Pivello and others)
Title=FilmTV
Description=Get movie info from Film TV
Site=www.Film.TV.it
Language=IT
Version=10.08.2008
Requires=3.5.0
Comments=Old script by Pivello and others didn't work due to Filmtv site complete restyling
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
  //Query constants
  UrlBase = 'http://www.film.tv.it/';
  QueryBase = UrlBase + 'cerca.php?q=';
  QueryFilm = UrlBase + '';

  //Search page constants
  cStartFilmUrl = '<div class="thumb"><a href="/'; // ID start marker
  cEndFilmUrl = '"><span><img src=';           // ID end marker
  cStartTitle = 'title="';                      // Title start marker
  cEndTitle = '">';                     // Title end marker
  //Film page constants
  cStartTranslTitle = '<h1>';     // Translated title start marker
  cEndTranslTitle = '</h1>';                   // Translated title end marker
  cStartOrigTitle = '[<i>';     // Original title start marker
  cEndOrigTitle = '</i>';                   // Original title end marker
  cStartImgLink = 'title="immagini"><img src="';               // Image start marker
  cEndImgLink = '" width="166" border="0" alt="locandina"';   // Image end marker
  cStartListItem = ', ';
  cEndListItem = ', ';                        // Generic field marker
  cStartDirectors = 'Regia di';               // Director start marker
  cEndDirectors = '<br />';                         // Directors end marker
  cStartDirector = '">';               // Single Director start marker
  cEndDirector = '</a>';                         // Single Director end marker
  cStartCast = 'Con ';                   // Cast start marker
  cEndCast = '</div>';                   // Cast end marker
  cStartActor = '">';                      // Actor start marker
  cEndActor = '</a>';                      // Actor end marker
  cEndGeneric2 = '</td>';                        // Generic end marker 2
  cStartDesc = '<p class="trama">';              // Description start marker
  cEndDesc = '</p>';                             // Description end marker
  cStartComm = '<p class="commento">';           // Comment start marker
  cEndComm = '</p>';                         // Comment end marker
  cStartURL='<li id="sel"><a href="/';
  cEndURL='" title="scheda"';
var
  searchUrl,MovieUrl, MovieName, OriginalStr, TranslatedStr, PageStr:  string;

// --------------------------------------------------
// 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;
  imageLink: string;
  sep1,sep2: string;

begin
  // General movie description fields
  SetField(fieldTranslatedTitle, getTextDelimited(cStartTranslTitle, cEndTranslTitle,htmlStr));
  SetField(fieldOriginalTitle, getTextDelimited(cStartOrigTitle, cEndOrigTitle,htmlStr));

  if GetField(fieldOriginalTitle)='' then
    sep1:='['
  else
    sep1:= cStartListItem;

  SetField(fieldCountry, getTextDelimited(sep1, cEndListItem,htmlStr));
  SetField(fieldYear, getTextDelimited(cStartListItem, cEndListItem,htmlStr));
  SetField(fieldCategory, getTextDelimited(cStartListItem, cEndListItem,htmlStr));

  SetField(fieldLength, getTextDelimited(cStartListItem + 'durata ', ''']',htmlStr));
  //Get director
  temp:= getTextDelimited(cStartDirectors, cEndDirectors,htmlStr);
  SetField(fieldDirector, getCSVField(cStartDirector,cEndDirector,temp));
  //Get actors
  temp:= getTextDelimited(cStartCast,cEndCast ,htmlStr);
  SetField(fieldActors, getCSVField(cStartActor,cEndActor,temp));
  //Get URL
  SetField(fieldURL, URLBase + getTextDelimited(cStartURL, cEndURL,htmlStr));

  //Get image
  imageLink:= getTextDelimited(cStartImgLink,cEndImgLink,htmlStr);
  GetPicture(imageLink);
  //Get comments
  SetField(fieldDescription, getTextDelimited(cStartDesc,cEndDesc ,htmlStr));
  SetField(fieldComments, getTextDelimited(cStartComm,cEndComm ,htmlStr));


end;

//###############################################
//Returns a CSV list from an input string strIn where list items are
//separated by delIn and delOut strings
//##############################################
function getCSVField (delIn:string; delOut: string; Var strIn: string): string;
var
  tempOut: string;
begin
  result:='';
  repeat
    tempOut:=getTextDelimited(delIn, delOut,strIn);
    if tempOut<>'' then
      result:=result + tempOut + cStartListItem;
  until tempOut='';
  if length(result)>0 then result:=copy(result,1,1+length(result)-3);

end;

//###############################################
//##############################################
//Returns a text field from an input string strIn
//delIn and delOut: text field delimiters
//##############################################
function getTextDelimited(lIn:string; lOut:string;Var strIn:string): string;
var
  StartPos: integer;
  len:integer;
  tempStr: string;
begin
  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);
  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: string;
  StartPos: integer;
  EndPos: integer;
begin
      PickTreeClear;
      repeat
        partialUrl:= getTextDelimited(cStartFilmUrl,cEndFilmUrl,PageStr);
        filmUrl:=UrlBase + partialUrl;
        filmTitle:=getTextDelimited(cStartTitle,cEndTitle,PageStr);
        if partialUrl<>'' then
          PickTreeAdd(filmTitle, filmUrl);
      until(partialUrl='');
end;


// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN:  html of search page (string)
// OUT: movie url
// ---------------------------------
function getMovieUrl(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 not PickTreeExec(result) then exit; //Select one title
    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', 'Enter the title of the movie / Inserire titolo del film:', MovieName)) then
        begin
          //Get search page
          searchUrl := QueryBase + UrlEncode(MovieName);
          PageStr := RemoveExtraChars(searchUrl);

          //Analyze search page and get movie url (user choice)
          MovieUrl:=getMovieUrl(PageStr);

          // Get movie page
          PageStr := RemoveExtraChars(MovieUrl);
          
          //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 3.5.0)');
end.

Posted: 2008-08-14 16:22:25
by antp
Thanks ;)

Posted: 2008-08-28 21:28:52
by bagalin97
Thanks very much Fiezul: very appreciated!!!
Regards

Posted: 2010-08-18 14:38:00
by otreux
thank's but fon't import the image :(

Grazie ma non importa le immagini