Page 1 of 2

[UPD][ITA] MyMovies.it

Posted: 2008-05-16 10:49:43
by seraphico
Hi everybody, i've make a little change on the script for mymovies.it to grab right the film's image. I've tested with the sample.amc and a few other films.
Hope someone ( other than me ) appreciate!! ;)

Seraphico

Code: Select all

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

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

[Infos]
Authors=Claudio Rinaldi ( rinaldiclaudio@gmail.com )
Title=MyMovies
Description=Get movie info from MyMovies.it
Site=www.mymovies.it
Language=IT
Version=1.1
Requires=3.5.1
Comments=
License=
GetInfo=1

[Options]

***************************************************)

program MyMoviesIT;

uses
  Pivlib; // Pivello's scripts common library

const
  UrlBase = 'http://www.mymovies.it';
  UrlRicerca = '&titolo_orig=&regista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=1&submit=Inizia+ricerca+%BB';
  QueryBase = UrlBase + '/database/ricerca/avanzata/?titolo=';
  QueryFilm = UrlBase + '/dizionario/recensione.asp?id=';
  ImagePath = UrlBase + '/filmclub/';

  cStartNumRis = 'nel Titolo. Ho trovato '; // Result Number start Marker
  cEndNumRis = ' film.</h2>';               // Result Number end Marker
  cStartId = 'recensione.asp?id=';   // ID start marker
  cEndId = '" title="';              // ID end marker
  cStartTitle = '<h2>(';             // Title start marker
  cEndTitle = ')</h2>';              // Title end marker
  cStartTranslTitle = '<h1>';        // Translated title start marker
  cEndTranslTitle = '</h1>';         // Translated title end marker
  cStartImage2 = '<img src="';               // Image start marker
  cEndImage2 = '"';             // Image end marker
  cStartDirector = 'Un film di ';    // Director start marker
  cStartCast = ' Con ';              // Actor start marker
  cStartCategory = ' Genere ';       // Catogory start marker
  cEndCategory = '</a>,';            // Category end marker
  cStartDuration = ' colore ';       // Duration start marker
  cStartDuration2 = ' b/n ';         // Duration2 start marker
  cEndDuration = ' minuti';          // Duration end marker
  cStartCountry = 'Produzione ';     // Country start Marker
  cEndCountry = ' <a';               // Country end marker
  cStartYear = 'href=';              // Year start marker
  cEndYear = '</a>';                 // Year end marker
  cStartDesc = '<p style="';         // Description start marker
  cEndDesc = '</p>';                 // Description end marker
  cStartComm = '<span style="';      // Comment start marker
  cEndComm = '</span>';              // Comment end marker
  cStartTitleList = '">';            // Title list start marker
  cEndTitleList = '</a>';            // Title list end marker
  cStartImage = 'src="http://www.mymovies.it/filmclub/';
  cEndImage = '"';
var
  MovieUrl, MovieName, TranslatedStr, PageStr:  string;

// -----------------------
// ANALYZE MOVIE DATA PAGE
// IN:  none
// OUT: set Ant fields
// -----------------------
procedure AnalyzeMoviePage;
var
  cImage : string;
begin
  // Get packed title main page
  PageStr := RemoveExtraChars(MovieUrl);
  
  // Translated Title field
  SetField(fieldTranslatedTitle, GetValueEx(PageStr, cStartTranslTitle, cEndTranslTitle,true,false));
  PageStr := GetPageStr;
  
  // Original Title field
  SetField(fieldOriginalTitle, GetValueEx(PageStr, cStartTitle, cEndTitle, true, false));
  if(GetField(fieldOriginalTitle)='')then
    SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));
  PageStr := GetPageStr;
  
  // Director Field
  SetField(fieldDirector, GetValueEx(PageStr, cStartDirector, cStartCast, false, false));
  PageStr := GetPageStr;

  // Actors Field
  SetField(fieldActors, GetValueEx(PageStr, cStartCast, cStartCategory, false, false));
  PageStr := GetPageStr;

  // Category Field
  SetField(fieldCategory, GetValueEx(PageStr, cStartCategory, cEndCategory, true, false));
  PageStr := GetPageStr;

  // Duration field
  SetField(fieldLength, GetValueEx(PageStr, cStartDuration, cEndDuration, true, false));
  if ( GetField(fieldLength) = '' ) then
    SetField(fieldLength, GetValueEx(PageStr, cStartDuration2, cEndDuration, true, false));
  PageStr := GetPageStr;

  // Country field
  SetField(fieldCountry, GetValueEx(PageStr, cStartCountry, cEndCountry, true, false));
  PageStr := GetPageStr;

  // YearField
  SetField(fieldYear, GetValueEx(PageStr, cStartYear, cEndYear, true, true));
  PageStr := GetPageStr;

  // Get film image
  cImage := GetValueEx(PageStr, cStartImage, cEndImage, true, false);
  if cImage = '' then
    cImage := GetValueEx(PageStr,cStartImage2, cEndImage2, true, false)
  else
    cImage := ImagePath + cImage;

  if cImage <> '' then
    GetPicture(cImage);
    
  PageStr := GetPageStr;

  // Description Field
  SetField(fieldDescription, GetValueEx(PageStr, cStartDesc, cEndDesc, true, true));
  PageStr := GetPageStr;

  // Comments Field
  SetField(fieldComments, GetValueEx(PageStr, cStartComm, cEndComm, true, true));
  PageStr := GetPageStr;

  //if cImage = '' then begin
  //  cImage := GetValueEx(PageStr,,,true,false);
  //end

  // 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
  cFilmId,cFilmTitle: string;
  StartPos,EndPos: integer;
begin
  if OneFilm then begin
    cFilmId := GetValueEx(PageStr,cStartId,cEndId,false,false);
    result := QueryFilm + cFilmId;
  end
  else begin
    PickTreeClear;
    repeat
      StartPos := pos(cStartTranslTitle, PageStr);
      if StartPos > 0 then begin
        Delete(PageStr, 1, StartPos - 1);
        cFilmId := GetValueEx(PageStr,cStartId,cEndId,true,false); // Get ID
        PageStr := GetPageStr;
        cFilmTitle := GetValueEx(PageStr,cStartTitleList,cEndTitleList,true,false); // Get Title
        PageStr := GetPageStr;
        PickTreeAdd(cFilmTitle, QueryFilm + cFilmId);
      end;
    until(StartPos = 0);
    result := '';
  end
end;

// ---------------------------------
// ANALYZE FIRST SEARCH RESULT PAGE:
// IN:  page Url (string)
// OUT: none
// ---------------------------------
procedure AnalyzeSearchPage(Url: string);
var
  NumRisultati : string;
begin
  PageStr := RemoveExtraChars(Url);
  NumRisultati := GetValueEx(PageStr, cStartNumRis, cEndNumRis, true, false);
  
  if ( (NumRisultati = '0') or (NumRisultati = '')) then
    begin
      ShowMessage('Title not found / Nessun film trovato.');
      exit;
    end

  if NumRisultati = '1' then
    MovieUrl := PopulatePickTree(true)
  else
    begin
      PopulatePickTree(false);
      if not PickTreeExec(MovieUrl) then // ..select one
        exit;
    end;

  AnalyzeMoviePage;
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 GetValueEx(MyPageStr,cStartMarker,cEndMarker: string;bCutEnd,bAdjust: boolean): string;
var
  StartPos: integer;
  EndPos: integer;
  Value: string;
begin
  Value := '';
  StartPos := pos(cStartMarker, MyPageStr);
  if ( StartPos = 0 ) then exit; // Not found

  StartPos := StartPos + length(cStartMarker);
  Delete(MyPageStr, 1, StartPos -1);
  EndPos := pos(cEndMarker, MyPageStr);

  if EndPos > 0 then begin
    Value := copy(MyPageStr, 0, EndPos-1);
    if bCutEnd then
      EndPos := EndPos + length(cEndMarker);
    Delete(MyPageStr, 1, EndPos -1);
    if bAdjust then
      Value := '<' + Value;
  end;
  TmpPageStr := MyPageStr;
  HTMLRemoveTags(Value);
  HTMLDecode(Value);
  result := Trim(Value);
end;

// ----------
// MAIN:
// IN:  none
// OUT: none
// ----------
begin
  if CheckVersion(3,5,0) then
    begin
      TranslatedStr := GetField(fieldTranslatedTitle);
      MovieName := GetField(fieldOriginalTitle);
      if (TranslatedStr <> '') then
        MovieName := TranslatedStr;

      if(Input('MyMovies.It', 'Enter the title of the movie', MovieName)) then
        begin
          InitializePivLib;
          MovieUrl := QueryBase + StringReplace(MovieName,' ','+') + UrlRicerca;
          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.


Posted: 2008-05-16 14:21:45
by antp
Thanks

Posted: 2008-09-15 15:29:13
by virgola
grazie

Posted: 2009-09-23 14:28:32
by squonk
For me this script doesn't work.
Every time I search a film (and I've tried many!) the script give me always "Title Not Found".
Is the script or something in my program settings?
Other script (cinematografo.it for example) works for me.
Many thanks for attention!

Posted: 2009-10-10 17:08:23
by simpic
For me this script doesn't work.
Every time I search a film (and I've tried many!) the script give me always "Title Not Found".
The same for me.

Posted: 2009-10-11 23:12:03
by simpic
How to update it?

Posted: 2009-10-21 08:18:40
by Pinonono
For me this script doesn't work.
Every time I search a film (and I've tried many!) the script give me always "Title Not Found".
idem

Posted: 2009-10-27 08:24:00
by Pinonono
E' un peccato.....non si può far nulla per aggiustarlo????......

Posted: 2009-10-28 06:24:41
by fulvio53s03
Ci sto lavorando.... abbiate pazienza.

I' working on..... be patient.

Posted: 2009-10-28 10:47:25
by Pinonono
:grinking:
Grazie fulvio53s03!!!!

Posted: 2009-10-28 14:35:43
by Dark_Wizard
grazie fulvio anche per questo script :p

Posted: 2010-02-04 16:00:53
by otreux
qualche novità? :(

Posted: 2010-02-05 14:30:42
by fulvio53s03
Sorry, I forgot.....
here you are the new script. let me know if you have any problem.

Code: Select all

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

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

[Infos]
Authors=Fulvio53s03 (Original by Claudio Rinaldi)
Title=MyMovies
Description=Get movie info from MyMovies.it
Site=www.mymovies.it
Language=IT
Version=1.2
Requires=3.5.2
Comments=
License=
GetInfo=1

[Options]

***************************************************)

program MyMoviesIT;

uses 
  Stringutils7552;

const 
  UrlBase = 'http://www.mymovies.it'; 
  UrlRicerca = '&titolo_orig=&regista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=1&submit=Inizia+ricerca+%BB'; 
  QueryBase = UrlBase + '/database/ricerca/avanzata/?titolo=';

  QueryFilm = UrlBase + '/dizionario/recensione.asp?id='; 
  ImagePath = UrlBase + '/filmclub/'; 
  NoCommento = '(Riceverai le informazioni pochi giorni prima della messa in onda)';  // commenti inutili  "(la recensione più amata dal pubblico)"
  Riceverai  = '(Riceverai le informazioni pochi giorni prima della messa in onda)';
  PiuAmata   = '(la recensione più amata dal pubblico)';
  cStartNumRis = 'nel Titolo. Ho trovato '; // Result Number start Marker
  cEndNumRis = ' film.</h3>';               // Result Number end Marker
  cStartId = 'recensione.asp?id=';   // ID start marker
  cEndId = '" title="';              // ID end marker 
  cStartTitle = 'Titolo originale <em>';             // Title start marker
  cEndTitle = '</em>';              // Title end marker
  cStartTranslTitle = '<h1 style="margin-bottom:3px;">';        // Translated title start marker
  cEndTranslTitle = '</h1>';         // Translated title end marker
  cStartImage2 = '<img src="';       // Image start marker
  cEndImage2 = '"';                  // Image end marker
  cStartDirector = 'Un film di <a href="';      // Director start marker
  cEndDirector = '</a>.';                       // Director end marker
  cStartCategory  = 'Titolo originale <em>';   // Catogory start marker
  cEndCategory = '</a>,';            // Category end marker
  cStartDuration = 'durata ';        // Duration start marker
  cEndDuration = ' min.';          // Duration end marker
  cStartYear = 'href=';              // Year start marker
  cEndYear = '</a>';                 // Year end marker
  cStartDesc = '<div id="recensione">';          // Description start marker
  cEndDesc = '<div style="text-align:right;">';  // Description end marker

  cStartCast = 'Con <a href="';              // Actor start marker
  cEndCast   = '<a title="';
  cEndCast2  = 'Titolo originale <em>';      // Actor end marker
  cStartImage = 'src="http://www.mymovies.it/filmclub/';
  cEndImage = '"'; 
var 
  MovieUrl, MovieName, Commento, TranslatedStr, PageStr:  string;
  Startchar, EndChar, UsePage, Addressnext: String;
  LgthVerify: integer;
  idx : integer;
  
function MyTrim(Value: string):string;
var
  ExitLoop: Boolean;
  NewField, OldField: String;
  OldLgthValue, NewLgthValue: integer;
begin
    NewField := ' ';
    OldField := #9;
    value := StringReplace(Value, OldField, NewField);
    OldField := #10;
    value := StringReplace(Value, OldField, NewField);
    OldField := #13;
    value := StringReplace(Value, OldField, NewField);
    OldField := '  ';
    value := StringReplace(Value, OldField, NewField);
    Newfield := '&';
    OldField := '&';
    value := StringReplace(Value, OldField, NewField);
    ExitLoop := False;
    OldLgthValue := length(Value);
    HTMLRemoveTags(Value);
    Value := FullTrim(Value);
    OldField := '  ';
    NewField := ' ';
    repeat
      value := StringReplace(Value, OldField, NewField);
      NewLgthValue := length(Value);
    if  OldLgthValue = NewLgthValue then
        ExitLoop := True
    else
        OldLgthValue := NewLgthValue;
    until ExitLoop;

  Result := Value;
end;

// ----------------------- 
// ANALYZE MOVIE DATA PAGE 
// IN:  none 
// OUT: set Ant fields 
// ----------------------- 
procedure AnalyzeMoviePage; 
var 
  cImage : string;
  SaveField, TempField, DelField : string;
  LgthLineToDrop, LgthLineToDelete: integer;

begin 
  // Get packed title main page 
  PageStr := getPage(MovieUrl);
  
  // Translated Title field 
  TempField := TextBetween(PageStr, cStartTranslTitle, cEndTranslTitle);
  TempField := MyTrim(TempField);
  SetField(fieldTranslatedTitle, TempField);

  // Original Title field 
  SetField(fieldOriginalTitle, TextBetween(PageStr, cStartTitle, cEndTitle));
  if(GetField(fieldOriginalTitle)='')then 
    SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle)); 

  // Director Field 
  TempField := TextBetween(PageStr, cStartDirector, cEndDirector) + cEndDirector;
  TempField := TextBetween(TempField, '>' , cEndDirector);
  HTMLRemovetags(tempfield);
  SetField(fieldDirector, TempField);

  // Actors Field 
  TempField := CstartCast + TextBetween(PageStr, cStartCast, cEndCast);     // da 'con:'   a Titolo
  LgthVerify := pos(cStartCast, PageStr) + length(TempField);
  SaveField := TempField;
  TempField := TextBetween(PageStr, cStartCast, cEndCast2);   // da 'con:'   a Titolo Originale
  if length(tempField) > 0 then
      TempField := '<a href="' + TempField
  else
    TempField := '<a href="' + SaveField;

  DelField  := '<div id="attori_espandi"' + TextBetween(TempField, '<div id="attori_espandi"', '</div>');
  TempField := StringReplace(TempField, DelField, '');
  DelField  := '<div id="attori_comprimi"' + TextBetween(TempField, '<div id="attori_comprimi"', '</div>');
  TempField := StringReplace(TempField, DelField, '');
  TempField := MyTrim(TempField);
  SetField(fieldActors, TempField);

  // Category Field 
  TempField := TextBetween(PageStr, cStartCategory, cEndcategory);
  LgthLineToDrop := pos(cStartCategory, PageStr) + length(TempField);
  TempField := TempField + cEndcategory;
  TempField := TextBetween(TempField, '">' , cEndcategory);
  SetField(fieldCategory, TempField);

  // Duration field
  TempField := TextBetween(PageStr, cStartDuration, cEndDuration);
  LgthLineToDelete := pos(cStartDuration, PageStr) + length(TempField);
  SetField(fieldLength, TempField);

  // Country field   & Year (keep these fields consecutive)
  TempField := PageStr;
  if LgthLineToDrop > 0 then
     Delete(TempField, 1, LgthLineToDrop - 1)
     else
     if LgthLineToDelete > 0 then
        Delete(TempField, 1, LgthLineToDelete - 1)
     else
        if  LgthVerify > 0 then
            Delete(TempField, 1, LgthVerify - 1);

  Tempfield := TextBetween(TempField, '-', '<strong>');
  TempField  := MyTrim(TempField);
  SetField(fieldCountry, TempField);

  // YearField
  TempField := PageStr;
  if  Pos(cStartCast, TempField) > 0 then
     begin
     Delete(TempField, 1, Pos(cStartCast, TempField) - 1);
     Tempfield := TextBetween(TempField, 'href="http://www.mymovies.it/film/?anno=', '">');
     end
     else
     tempField := '';
  SetField(fieldYear, TempField);

  // Get film image 
  cImage := TextBetween(PageStr, cStartImage, cEndImage);
  if cImage = '' then 
    cImage := TextBetween(PageStr,cStartImage2, cEndImage2)
  else 
    cImage := ImagePath + cImage; 

  if cImage <> '' then 
    GetPicture(cImage); 

// Description Field
   TempField := TextBetween(PageStr, cStartDesc, cEndDesc) + cEndDesc;
   TempField := MyTrim(TempField);
   SetField(fieldDescription, TempField);

// Movie URL field
   SetField(fieldURL, MovieUrl);
   SetField(fieldDate, DateToStr(Date));
   
// Commento
//   TempField := Textbetween(PageStr, '<p style="padding-right:3px; margin-top:15px;">', '<a href="http://www.mymovies.it/dizionario/critica');
   TempField := Textbetween(PageStr, '">Rassegna stampa</a>', '</td>') + '</td>';
   TempField := Textbetween(TempField, '<p style="padding-right:3px; margin-top:15px;">', '<a href="http://www.mymovies.it/dizionario/critica');
   TempField := MyTrim(TempField);
   SetField(fieldComments, TempField);
end;

procedure CalcLgthToDelete;
begin
  StartChar :=  '<div class="linkblu" style="padding:3px;"';
  EndChar   :=  '<div class="linkblu" style="padding:3px;"';
  LgthVerify := Length(startChar) + Length(Textbetween(UsePage, StartChar, EndChar));
  if LgthVerify  = 0 then
     begin
     EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
     LgthVerify := Length(startChar) + Length(Textbetween(UsePage, StartChar, EndChar));
     end;
end;

// ------------------------------------------------------------------
// FILL PICKTREE CONTROL WITH LINKS & TITLES or RETURN ONE PAGE LINK
// da 35mm.it
// ------------------------------------------------------------------
function PopulatePickTree(OneFilm: boolean): string;
var
  TempIdFilm, TempTitle: string;
  TempAuthor, TempYear: string;
  LineToDrop, LineToUse, LineTodelete, LineTxt: string;
  LengthFilm, LgthTitle, LineNr: integer;
  LgthLineToDrop, LgthLineToUse, LgthLineToDelete: integer;
  PageAll, PageLoop: string;
  cFilmYear, CYearId: string;
  StartPos, EndPos: integer;
begin
  if OneFilm then                                                           // per un solo film trovato è OK
    begin
      StartChar := 'http://www.mymovies.it/dizionario/recensione.asp?id=';
      EndChar   := '" title=';
      UsePage  := Textbetween(Pagestr, StartChar, EndChar);
      if length(UsePage) > 0 then
        begin
          TempIdFilm := StartChar + Usepage;
          result := TempIdFilm;
        end
    end
  else
    begin
      PickTreeClear;                                               // per più pagine di film
      PageLoop := PageStr;
      StartChar := '<a title="Database MYmovies" href="http://www.mymovies.it/film/"><strong>Film</strong></a>';
      EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
      UsePage := TextBetween(PageStr, StartChar, EndChar) + EndChar;

      repeat                     // inizio gestione pagina multipla
        LineNr  := Pos('>Pagina successiva', PageStr);
        PageAll := UsePage;
        StartChar :=  '<div class="linkblu" style="padding:3px;"';
        LgthVerify := Pos(StartChar, UsePage);
        Delete(UsePage, 1, Lgthverify - 1)
        CalcLgthToDelete;

        repeat
          CalcLgthToDelete;
          StartChar :=  '<div class="linkblu" style="padding:3px;"';
          EndChar   :=  '<div class="linkverde">';
          LineToUse := StartChar + textbetween(UsePage, StartChar, EndChar) + EndChar;
          StartChar := '<div class="linkverde">';
           EndChar   := '<div class="linkblu" style="padding:3px;"';
          LineToDrop := textbetween(UsePage, StartChar, EndChar);
          if Length(LineToDrop) = 0 then
             begin
             EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
             LineToDrop := textbetween(UsePage, StartChar, EndChar);
             end;
          LineToDelete := LineToUse + LineToDrop;
          LgthLineToDelete := Length(LineToDelete);
          StartPos := pos(StartChar, UsePage);
          StartChar :=  'http://www.mymovies.it/dizionario/recensione.asp?id=';
          EndChar := '" title="';
          if StartPos > 0 then
            begin
              TempIdFilm := StartChar + TextBetween(UsePage, Startchar, EndChar);
              LengthFilm := length(StartChar) + length(TempIdFilm);
              Delete(UsePage, 1, LengthFilm);

              StartChar := 'title="';
              EndChar := '">';
              TempTitle := TextBetween(UsePage, Startchar, EndChar);
              LgthTitle := Length(TempTitle) + length(StartChar) + length(EndChar);
              TempTitle := FullTrim(TempTitle);
              LgthTitle := length(StartChar) + LgthTitle + length(EndChar);
              TempAuthor := Textbetween (UsePage, 'Un film di <b>', '</b>');
              TempAuthor := Textbetween (TempAuthor, '">', '</a>');
              TempYear   := Textbetween (UsePage, '<a href="http://www.mymovies.it/film/?anno=', '">');
              TempTitle  := TempTitle + ' (' + TempAuthor + ') ' + TempYear;
              PickTreeAdd(TempTitle, TempIdFilm);

              StartChar :=  'http://www.mymovies.it/dizionario/recensione.asp?id=';
              EndChar := '" title="';
              StartPos := pos(StartChar, UsePage);
             Delete(PageAll, 1, LgthVerify - 1);
             UsePage := PageAll;
            end;
        until(LgthVerify < 100);
        result := '';

// Controlla se ci sono altre pagine di risultati
        StartPos := Pos('Ricerca MYmovies', PageLoop);
        Delete(PageLoop, 1, StartPos - 1);
        StartChar := '<a href="?titolo=';
        EndChar := '">Pagina successiva';
        LineTxt := StartChar + TextBetween(PageLoop, StartChar, EndChar) + EndChar;
        repeat
           if Length(LineTxt) > 1 then
              begin
              AddressNext := QueryBase + LineTxt;
              LineTxt := LineTxt + EndChar;
              end
          LineTxt := TextBetween(LineTxt, StartChar, EndChar);
        until length(LineTxt) < length(EndChar);
        SetField(fieldcomments, AddressNext);
        Pagestr  := GetPage(Addressnext);
        PageLoop := PageStr;
        StartChar := '<a title="Database MYmovies" href="http://www.mymovies.it/film/"><strong>Film</strong></a>';
        EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
        UsePage := TextBetween(PageStr, StartChar, EndChar) + EndChar;
      until (LineNr < 1); // repeat
    end
end;

//
// --------------------------------- 
// ANALYZE FIRST SEARCH RESULT PAGE: 
// IN:  page Url (string) 
// OUT: none 
// --------------------------------- 
procedure AnalyzeSearchPage(Url: string); 
var 
  NumRisultati : string; 
begin 
  PageStr := getpage(Url);
//  SetField(fieldURL, URL);
  NumRisultati := Textbetween(PageStr, cStartNumRis, cEndNumRis);
  
  if ( (NumRisultati = '0') or (NumRisultati = '')) then 
    begin 
      ShowMessage('Title not found / Nessun film trovato.');
         SetField(fieldURL, MovieUrl);
      exit; 
    end 

  if NumRisultati = '1' then 
    MovieUrl := PopulatePickTree(true) 
  else 
    begin 
      PopulatePickTree(false); 
      if not PickTreeExec(MovieUrl) then // ..select one 
        exit; 
    end; 

  AnalyzeMoviePage; 
end; 

begin
  if (CheckVersion(3,5,1)) and (StringUtils1_Version > 5) then
    begin 
      TranslatedStr := GetField(fieldTranslatedTitle); 
      MovieName := GetField(fieldOriginalTitle); 
      if (TranslatedStr <> '') then 
        MovieName := TranslatedStr; 

      if(Input('MyMovies.It', 'Enter the title of the movie', MovieName)) then 
        begin 
          MovieUrl := QueryBase + StringReplace(MovieName,' ','+') + UrlRicerca;
          AnalyzeSearchPage(MovieUrl);
        end;
    end 
  else 
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.1) and StringUtils1 version 6');
end. 
As you can see, Pivlib has been substituted by StringUtils7552 and now the script is "more standard" and looks to be faster.
Please, Antp, would you update scrits' library?

bye

Posted: 2010-02-05 23:01:08
by antp
Thanks, I updated it on the server

Posted: 2010-02-08 11:39:03
by fulvio53s03
Sorry, I was noticed about an error; movie's year was not extracted.
:sleep:
Here is the new script:

Code: Select all

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

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

[Infos]
Authors=Fulvio53s03  (Original by Claudio Rinaldi)
Title=MyMovies
Description=Get movie info from MyMovies.it
Site=www.mymovies.it
Language=IT
Version=1.2
Requires=3.5.2
Comments=
License=
GetInfo=1

[Options]

***************************************************)

program MyMoviesIT;

uses 
  Stringutils7552;

const 
  UrlBase = 'http://www.mymovies.it'; 
  UrlRicerca = '&titolo_orig=&regista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=1&submit=Inizia+ricerca+%BB'; 
  QueryBase = UrlBase + '/database/ricerca/avanzata/?titolo=';

  QueryFilm = UrlBase + '/dizionario/recensione.asp?id='; 
  ImagePath = UrlBase + '/filmclub/'; 
  NoCommento = '(Riceverai le informazioni pochi giorni prima della messa in onda)';  // commenti inutili  "(la recensione più amata dal pubblico)"
  Riceverai  = '(Riceverai le informazioni pochi giorni prima della messa in onda)';
  PiuAmata   = '(la recensione più amata dal pubblico)';
  cStartNumRis = 'nel Titolo. Ho trovato '; // Result Number start Marker
  cEndNumRis = ' film.</h3>';               // Result Number end Marker
  cStartId = 'recensione.asp?id=';   // ID start marker
  cEndId = '" title="';              // ID end marker 
  cStartTitle = 'Titolo originale <em>';             // Title start marker
  cEndTitle = '</em>';              // Title end marker
  cStartTranslTitle = '<h1 style="margin-bottom:3px;">';        // Translated title start marker
  cEndTranslTitle = '</h1>';         // Translated title end marker
  cStartImage2 = '<img src="';       // Image start marker
  cEndImage2 = '"';                  // Image end marker
  cStartDirector = 'Un film di <a href="';      // Director start marker
  cEndDirector = '</a>.';                       // Director end marker
  cStartCategory  = 'scheda;genere=';   // Catogory start marker
  cEndCategory = ';';            // Category end marker
//  cEndCategory = ';tile=1;sz=';            // Category end marker

  cStartDuration = 'durata ';        // Duration start marker
  cEndDuration = ' min.';          // Duration end marker
  cStartYear = '<title>';              // Year start marker
  cEndYear = ' | MYmovies</title>';                 // Year end marker
  cStartDesc = '<div id="recensione">';          // Description start marker
  cEndDesc = '<div style="text-align:right;">';  // Description end marker

  cStartCast = 'Con <a href="';              // Actor start marker
  cEndCast   = '<a title="';
  cEndCast2  = 'Titolo originale <em>';      // Actor end marker
  cStartImage = 'src="http://www.mymovies.it/filmclub/';
  cEndImage = '"'; 
var 
  MovieUrl, MovieName, Commento, TranslatedStr, PageStr:  string;
  Startchar, EndChar, UsePage, Addressnext: String;
  Positioncast: integer;
  idx : integer;
  
function MyTrim(Value: string):string;
var
  ExitLoop: Boolean;
  NewField, OldField: String;
  OldLgthValue, NewLgthValue: integer;
begin
    NewField := ' ';
    OldField := #9;
    value := StringReplace(Value, OldField, NewField);
    OldField := #10;
    value := StringReplace(Value, OldField, NewField);
    OldField := #13;
    value := StringReplace(Value, OldField, NewField);
    OldField := '  ';
    value := StringReplace(Value, OldField, NewField);
    Newfield := '&';
    OldField := '&';
    value := StringReplace(Value, OldField, NewField);
    ExitLoop := False;
    OldLgthValue := length(Value);
    HTMLRemoveTags(Value);
    Value := FullTrim(Value);
    OldField := '  ';
    NewField := ' ';
    repeat
      value := StringReplace(Value, OldField, NewField);
      NewLgthValue := length(Value);
    if  OldLgthValue = NewLgthValue then
        ExitLoop := True
    else
        OldLgthValue := NewLgthValue;
    until ExitLoop;

  Result := Value;
end;

// ----------------------- 
// ANALYZE MOVIE DATA PAGE 
// IN:  none 
// OUT: set Ant fields 
// ----------------------- 
procedure AnalyzeMoviePage; 
var 
  cImage : string;
  SaveField, TempField, DelField : string;
  PositionCategory, PositionDuration: integer;

begin 
  // Get packed title main page 
  PageStr := getPage(MovieUrl);
  
  // Translated Title field 
  TempField := TextBetween(PageStr, cStartTranslTitle, cEndTranslTitle);
  TempField := MyTrim(TempField);
  SetField(fieldTranslatedTitle, TempField);

  // Original Title field 
  SetField(fieldOriginalTitle, TextBetween(PageStr, cStartTitle, cEndTitle));
  if(GetField(fieldOriginalTitle)='')then 
    SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle)); 

  // Director Field 
  TempField := TextBetween(PageStr, cStartDirector, cEndDirector) + cEndDirector;
  TempField := TextBetween(TempField, '>' , cEndDirector);
  HTMLRemovetags(tempfield);
  SetField(fieldDirector, TempField);

  // Actors Field 
  TempField := CstartCast + TextBetween(PageStr, cStartCast, cEndCast);     // da 'con:'   a Titolo
  Positioncast := pos(cStartCast, PageStr) + length(TempField);
  SaveField := TempField;
  TempField := TextBetween(PageStr, cStartCast, cEndCast2);   // da 'con:'   a Titolo Originale
  if length(tempField) > 0 then
      TempField := '<a href="' + TempField
  else
    TempField := '<a href="' + SaveField;

  DelField  := '<div id="attori_espandi"' + TextBetween(TempField, '<div id="attori_espandi"', '</div>');
  TempField := StringReplace(TempField, DelField, '');
  DelField  := '<div id="attori_comprimi"' + TextBetween(TempField, '<div id="attori_comprimi"', '</div>');
  TempField := StringReplace(TempField, DelField, '');
  TempField := MyTrim(TempField);
  SetField(fieldActors, TempField);

  // Category Field 
  TempField := TextBetween(PageStr, cStartCategory, cEndcategory);
  PositionCategory := pos(cStartCategory, PageStr) + length(TempField);
//  TempField := TempField + cEndcategory;
//  TempField := TextBetween(TempField, '">' , cEndcategory);
  SetField(fieldCategory, TempField);

  // Duration field
  TempField := TextBetween(PageStr, cStartDuration, cEndDuration);
  PositionDuration := pos(cStartDuration, PageStr) + length(TempField);
  SetField(fieldLength, TempField);

  // Country field
  TempField := PageStr;
  if PositionDuration > 0 then
     Delete(TempField, 1, PositionDuration - 1)
     else
        if  Positioncast > 0 then
            Delete(TempField, 1, Positioncast - 1)
     else
     if PositionCategory > 0 then
        Delete(TempField, 1, PositionCategory - 1);

  Tempfield := TextBetween(TempField, '-', ' <strong>');
  TempField  := MyTrim(TempField);
  SetField(fieldCountry, TempField);

//  Year
  TempField := PageStr;
  TempField := Textbetween (tempField, cStartYear, cEndYear);
  TempField := Textbetween (TempField, '(', ')');
  SetField(fieldYear, TempField);

  // Get film image 
  cImage := TextBetween(PageStr, cStartImage, cEndImage);
  if cImage = '' then 
    cImage := TextBetween(PageStr,cStartImage2, cEndImage2)
  else 
    cImage := ImagePath + cImage; 

  if cImage <> '' then 
    GetPicture(cImage); 

// Description Field
   TempField := TextBetween(PageStr, cStartDesc, cEndDesc) + cEndDesc;
   TempField := MyTrim(TempField);
   SetField(fieldDescription, TempField);

// Movie URL field
   SetField(fieldURL, MovieUrl);
   SetField(fieldDate, DateToStr(Date));
   
// Commento
//   TempField := Textbetween(PageStr, '<p style="padding-right:3px; margin-top:15px;">', '<a href="http://www.mymovies.it/dizionario/critica');
   TempField := Textbetween(PageStr, '">Rassegna stampa</a>', '</td>') + '</td>';
   TempField := Textbetween(TempField, '<p style="padding-right:3px; margin-top:15px;">', '<a href="http://www.mymovies.it/dizionario/critica');
   TempField := MyTrim(TempField);
   SetField(fieldComments, TempField);
end;

procedure CalcLgthToDelete;
begin
  StartChar :=  '<div class="linkblu" style="padding:3px;"';
  EndChar   :=  '<div class="linkblu" style="padding:3px;"';
  Positioncast := Length(startChar) + Length(Textbetween(UsePage, StartChar, EndChar));
  if Positioncast  = 0 then
     begin
     EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
     Positioncast := Length(startChar) + Length(Textbetween(UsePage, StartChar, EndChar));
     end;
end;

// ------------------------------------------------------------------
// FILL PICKTREE CONTROL WITH LINKS & TITLES or RETURN ONE PAGE LINK
// da 35mm.it
// ------------------------------------------------------------------
function PopulatePickTree(OneFilm: boolean): string;
var
  TempIdFilm, TempTitle: string;
  TempAuthor, TempYear: string;
  LineToDrop, LineToUse, LineTodelete, LineTxt: string;
  LengthFilm, LgthTitle, LineNr: integer;
  PositionCategory, LgthLineToUse, PositionDuration: integer;
  PageAll, PageLoop: string;
  cFilmYear, CYearId: string;
  StartPos, EndPos: integer;
begin
  if OneFilm then                                                           // per un solo film trovato è OK
    begin
      StartChar := 'http://www.mymovies.it/dizionario/recensione.asp?id=';
      EndChar   := '" title=';
      UsePage  := Textbetween(Pagestr, StartChar, EndChar);
      if length(UsePage) > 0 then
        begin
          TempIdFilm := StartChar + Usepage;
          result := TempIdFilm;
        end
    end
  else
    begin
      PickTreeClear;                                               // per più pagine di film
      PageLoop := PageStr;
      StartChar := '<a title="Database MYmovies" href="http://www.mymovies.it/film/"><strong>Film</strong></a>';
      EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
      UsePage := TextBetween(PageStr, StartChar, EndChar) + EndChar;

      repeat                     // inizio gestione pagina multipla
        LineNr  := Pos('>Pagina successiva', PageStr);
        PageAll := UsePage;
        StartChar :=  '<div class="linkblu" style="padding:3px;"';
        Positioncast := Pos(StartChar, UsePage);
        Delete(UsePage, 1, Positioncast - 1)
        CalcLgthToDelete;

        repeat
          CalcLgthToDelete;
          StartChar :=  '<div class="linkblu" style="padding:3px;"';
          EndChar   :=  '<div class="linkverde">';
          LineToUse := StartChar + textbetween(UsePage, StartChar, EndChar) + EndChar;
          StartChar := '<div class="linkverde">';
           EndChar   := '<div class="linkblu" style="padding:3px;"';
          LineToDrop := textbetween(UsePage, StartChar, EndChar);
          if Length(LineToDrop) = 0 then
             begin
             EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
             LineToDrop := textbetween(UsePage, StartChar, EndChar);
             end;
          LineToDelete := LineToUse + LineToDrop;
          PositionDuration := Length(LineToDelete);
          StartPos := pos(StartChar, UsePage);
          StartChar :=  'http://www.mymovies.it/dizionario/recensione.asp?id=';
          EndChar := '" title="';
          if StartPos > 0 then
            begin
              TempIdFilm := StartChar + TextBetween(UsePage, Startchar, EndChar);
              LengthFilm := length(StartChar) + length(TempIdFilm);
              Delete(UsePage, 1, LengthFilm);

              StartChar := 'title="';
              EndChar := '">';
              TempTitle := TextBetween(UsePage, Startchar, EndChar);
              LgthTitle := Length(TempTitle) + length(StartChar) + length(EndChar);
              TempTitle := FullTrim(TempTitle);
              LgthTitle := length(StartChar) + LgthTitle + length(EndChar);
              TempAuthor := Textbetween (UsePage, 'Un film di <b>', '</b>');
              TempAuthor := Textbetween (TempAuthor, '">', '</a>');
              TempYear   := Textbetween (UsePage, '<a href="http://www.mymovies.it/film/?anno=', '">');
              TempTitle  := TempTitle + ' (' + TempAuthor + ') ' + TempYear;
              PickTreeAdd(TempTitle, TempIdFilm);

              StartChar :=  'http://www.mymovies.it/dizionario/recensione.asp?id=';
              EndChar := '" title="';
              StartPos := pos(StartChar, UsePage);
             Delete(PageAll, 1, Positioncast - 1);
             UsePage := PageAll;
            end;
        until(Positioncast < 100);
        result := '';

// Controlla se ci sono altre pagine di risultati
        StartPos := Pos('Ricerca MYmovies', PageLoop);
        Delete(PageLoop, 1, StartPos - 1);
        StartChar := '<a href="?titolo=';
        EndChar := '">Pagina successiva';
        LineTxt := StartChar + TextBetween(PageLoop, StartChar, EndChar) + EndChar;
        repeat
           if Length(LineTxt) > 1 then
              begin
              AddressNext := QueryBase + LineTxt;
              LineTxt := LineTxt + EndChar;
              end
          LineTxt := TextBetween(LineTxt, StartChar, EndChar);
        until length(LineTxt) < length(EndChar);
        SetField(fieldcomments, AddressNext);
        Pagestr  := GetPage(Addressnext);
        PageLoop := PageStr;
        StartChar := '<a title="Database MYmovies" href="http://www.mymovies.it/film/"><strong>Film</strong></a>';
        EndChar := '<a href="http://www.mymovies.it/prossimamente/">';
        UsePage := TextBetween(PageStr, StartChar, EndChar) + EndChar;
      until (LineNr < 1); // repeat
    end
end;

//
// --------------------------------- 
// ANALYZE FIRST SEARCH RESULT PAGE: 
// IN:  page Url (string) 
// OUT: none 
// --------------------------------- 
procedure AnalyzeSearchPage(Url: string); 
var 
  NumRisultati : string; 
begin 
  PageStr := getpage(Url);
//  SetField(fieldURL, URL);
  NumRisultati := Textbetween(PageStr, cStartNumRis, cEndNumRis);
  
  if ( (NumRisultati = '0') or (NumRisultati = '')) then 
    begin 
      ShowMessage('Title not found / Nessun film trovato.');
         SetField(fieldURL, MovieUrl);
      exit; 
    end 

  if NumRisultati = '1' then 
    MovieUrl := PopulatePickTree(true) 
  else 
    begin 
      PopulatePickTree(false); 
      if not PickTreeExec(MovieUrl) then // ..select one 
        exit; 
    end; 

  AnalyzeMoviePage; 
end; 

begin
  if (CheckVersion(3,5,1)) and (StringUtils1_Version > 5) then
    begin 
      TranslatedStr := GetField(fieldTranslatedTitle); 
      MovieName := GetField(fieldOriginalTitle); 
      if (TranslatedStr <> '') then 
        MovieName := TranslatedStr; 

      if(Input('MyMovies.It', 'Enter the title of the movie', MovieName)) then 
        begin 
          MovieUrl := QueryBase + StringReplace(MovieName,' ','+') + UrlRicerca;
          AnalyzeSearchPage(MovieUrl);
        end;
    end 
  else 
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.1) and StringUtils1 version 6');
end. 
Let's hope this could be the definitive one.

Posted: 2010-02-08 15:12:55
by Pinonono
Grazie......ottimo lavoro

Posted: 2010-02-08 20:11:51
by antp
Thanks, but why posting 3 times the script? :D (maybe delete the two erroneous posts)
I changed the version to 1.2.1

Posted: 2010-02-08 21:07:17
by fulvio53s03
Sorry, 3 times caused by a mistake :sleep:
Is it still possible to delete first two posts? I'm not so expert to do it... :??:

Posted: 2010-02-09 19:44:31
by antp
done ;)

Posted: 2010-05-07 10:26:05
by Pinonono
Uffa, ora non acquisisce più la categoria......

Ugh, now no longer fits the category ....