Script for AFdigitale.it

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
P2
Posts: 16
Joined: 2004-04-12 13:18:42

Script for AFdigitale.it

Post by P2 »

I have written a script for AFdigitale.it.

Regards
Pivello

Code: Select all

// GETINFO SCRIPTING 
// AFdigitale.it - by Pivello

(************************************************** 
*  Movie importation script for:                  * 
*  AFdigitale.it, http://www.AFdigitale.it        *
*                                                 * 
* (c) 2004 Pivello                                * 
*                                                 * 
*  14.04.2004 First Public Release                *
*                                                 *
*  For use with Ant Movie Catalog 3.4.1           * 
*  www.ant.be.tf/moviecatalog ··· www.buypin.com  * 
*                                                 * 
*  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               * 
***************************************************) 

program AFdigitale;

const
 UrlBase = 'http://www.afdigitale.it';
 QueryBase = UrlBase + '/edisport/afdigitale/dvd.nsf/DVDS?SearchView&Query=';

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; 

// -----------------------
// ANALYZE MOVIE DATA PAGE 
// IN:  none
// OUT: set Ant fields 
// -----------------------
procedure AnalyzeMoviePage; 
var
 TempStr: string;
begin 
 // Get packed title main page 
 PageStr := RemoveExtraChars(MovieUrl);
 // image
 GetPicture(UrlBase + getValue('ROWSPAN=2><IMG SRC="','" WIDTH=',true,true), False);
 // Translated Title field
 SetField(fieldTranslatedTitle, getValue('COLOR="000080" FACE="Verdana">','</FONT></B><BR>',true,true));
 // Original Title field
 SetField(fieldOriginalTitle, getValue('COLOR="000080" FACE="Verdana">','</FONT></TD>',true,true));
 if((GetField(fieldOriginalTitle)='id') or (GetField(fieldOriginalTitle)=''))then
  SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
 // Category Field
 SetField(fieldCategory, getValue('</B><B><FONT SIZE=1 COLOR="000080" FACE="Verdana">','</FONT></B><BR>',true,true));
 // Director Field
 SetField(fieldDirector, getValue('<B><FONT SIZE=1 COLOR="000080" FACE="Verdana">','</FONT></B><BR>',true,true));
 // Actors Field
 SetField(fieldActors, getValue('<B><FONT SIZE=1 COLOR="000080" FACE="Verdana">','</FONT></B><BR>',true,true));
 // YearField
  SetField(fieldYear, getValue('<B><FONT SIZE=1 COLOR="000080" FACE="Verdana">','</FONT></B><BR>',true,true));
 // Producer Field
 Delete (PageStr,1,pos('Distribuito da:',PageStr));
 SetField(fieldProducer, getValue('<B><FONT SIZE=1 COLOR="000080" FACE="Verdana">','</FONT></B>',true,true));
 // Duration field
 Delete (PageStr,1,pos('FACE="Verdana">Durata:</FONT>',PageStr));
 SetField(fieldLength, getValue('COLOR="ffffff" FACE="Verdana">','</FONT></B><B>',true,true));
 // Size Field
 Delete (PageStr,1,pos('FACE="Verdana">Supporto: </FONT>',PageStr));
 SetField(fieldSize, getValue('FACE="Verdana">','</FONT></B><BR>',true,true));
 // Description Field
 Delete (PageStr,1,pos('Qualità artistica:',PageStr));
 TempStr := getValue('<FONT SIZE=2 FACE="Verdana">','</FONT><BR>',true,true);
 HTMLDecode(TempStr);
 SetField(fieldDescription, TempStr);
 // Comments Field
 Delete (PageStr,1,pos('Qualità dell''edizione:',PageStr));
 TempStr := getValue('<FONT SIZE=2 FACE="Verdana">','</FONT><BR>',true,true);
 HTMLDecode(TempStr);
 SetField(fieldComments, TempStr);
 // Movie URL field
 SetField(fieldURL, MovieUrl);
 // Display search result
 DisplayResults;
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 
  TempUrl: string;
  TempTitle: string; 
  StartPos: integer; 
  EndPos: integer; 
begin 
 result := '';
 StartPos := pos('<A HREF="', PageStr);
 Delete(PageStr, 1, StartPos - 1);
 if OneFilm then
  begin 
   StartPos := pos('<A HREF="', PageStr);
   EndPos := pos('"><div', PageStr);
   if StartPos > 0 then
    begin 
     TempUrl := copy(PageStr, StartPos + 9, EndPos-Startpos - 9);
     result := UrlBase + TempUrl;
    end 
  end 
 else 
  begin 
   PickTreeClear; 
   repeat
    StartPos := pos('<A HREF="', PageStr);
    EndPos := pos('?OpenDocument', PageStr);
    if StartPos > 0 then
     begin 
      TempUrl := copy(PageStr, StartPos + 9, EndPos-Startpos + 4);
      Delete(PageStr, 1, EndPos + 1);
      StartPos := pos('''">', PageStr);
      EndPos := pos('</div>', PageStr);
      TempTitle := copy(PageStr, StartPos + 3, EndPos-Startpos - 3);
      Delete(PageStr, 1, EndPos + 1);
      PickTreeAdd(TempTitle, UrlBase + TempUrl);
     end; 
   until(StartPos = 0); 
  end
end; 

// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE: 
// IN:  none
// OUT: none 
// ---------------------------------
procedure AnalyzeSearchPage;
begin
 PageStr := RemoveExtraChars(MovieUrl);
 if pos('Nessun elemento trovato', 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('1 elemento trovato', 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,4,1) then 
  begin 
   TranslatedStr := GetField(fieldTranslatedTitle); 
   OriginalStr := GetField(fieldOriginalTitle); 
   if (TranslatedStr <> '') then MovieName := TranslatedStr else MovieName := OriginalStr; 
   if (Input('AFdigitale.it - By Pivello', 'Enter the title of the movie / Inserire titolo del film:', MovieName)) then
    begin 
     Page := TStringList.Create; 
     MovieUrl := QueryBase + UrlEncode(MovieName);
     AnalyzeSearchPage;
     Page.Free; 
    end; 
  end 
 else 
  ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.1)'); 
end.
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

nice ;)
TanATos
Posts: 5
Joined: 2004-02-29 13:16:35

Post by TanATos »

Thanks a lot !!!
:grinking:

Is possible to get more information ???
For example:

Audio Format, Language,Subtitles,....
:p
Post Reply