Page 1 of 1

[Fr] Ultimate Import FR V1

Posted: 2003-01-07 18:22:17
by 3xodus alias Procat
Voici un script qui réuni les importations :
1 - Allociné.fr pour :
-> la description du film
-> l'url du film

2 - DVDFR V3 pour :
-> le Titre
-> le Titre traduit
-> le realisateur
-> le producteur
-> les acteurs
-> le pays
-> la catégorie
-> l'année
-> la durée
-> les suplements (classé dans commentaire)
-> le format video
-> le bitrate
-> le ration video (classé dans résolution)
-> le format audio
-> les langages
-> les sous-titres
-> le nombre de disque

Code: Select all

// GETINFO SCRIPTING
// ULTIMATE Import FR V1 - import with Picture,url, describe and Rate

(***************************************************
 *  Movie importation script for:                  *
 *                DVDFR.com, http://www.dvdfr.com  *
 *                                                 *
 *  (c) 2002 Antoine Potten    antoine@buypin.com  *
 *                                                 *
 *  For use with Ant Movie Catalog 3.4.1           *
 *    (there is a bug in the 3.4.0 that prevents   *
 *     from using this script without serious      *
 *     problems. Please upgrade if you have an     *
 *     old version)                                *
 *  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               *
 ***************************************************
    DVDFR_V3 Script by Fabrice FERT
    Using :
            - DVDFR V3 script
            - Allociné FR (Movie URL & describe)

 ***************************************************)
 
 
program UltimateIFR_V1;
var
  MovieName: string;

function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i: Integer;
begin
  result := -1;
  if StartAt < 0 then
    StartAt := 0;
  for i := StartAt to List.Count-1 do
    if Pos(Pattern, List.GetString(i)) <> 0 then
    begin
      result := i;
      Break;
    end;
end;

procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr: Integer;
  Line, Tags, Caption: string;
  BeginPos, EndPos: Integer;
begin
  Line := GetPage(Address);
  if Pos('<title>Dvdfr.com - Recherche DVDFr', Line) > 0 then
  begin
    PickTreeClear;
    if Pos('Vos critères de recherche n''ont produit aucun résultat.', Line) = 0 then
    begin
      Page := TStringList.Create;
      EndPos := Pos('TITLE="Page précédente"', Line) + 5;
      if EndPos > 5 then
      begin
        BeginPos := EndPos - 70;
        Tags := Copy(Line, BeginPos, EndPos - BeginPos);
        BeginPos := Pos('="..', Tags) + 4;
        EndPos := Pos('" TITLE', Tags);
        PickTreeAdd('Page précédente', 'http://www.dvdfr.com' + Copy(Tags, BeginPos, EndPos - BeginPos));
      end;
      EndPos := Pos('TITLE="Page suivante"', Line) + 5;
      if EndPos > 5 then
      begin
        BeginPos := EndPos - 70;
        Tags := Copy(Line, BeginPos, EndPos - BeginPos);
        BeginPos := Pos('="..', Tags) + 4;
        EndPos := Pos('" TITLE', Tags);
        PickTreeAdd('Page suivante', 'http://www.dvdfr.com' + Copy(Tags, BeginPos, EndPos - BeginPos));
      end;
      BeginPos := Pos('<table class="tableSearchResult"', Line);
      Delete(Line, 1, BeginPos + Length(Tags) - 1);
      BeginPos := Pos('</TR>', Line);
      Delete(Line, 1, BeginPos + 5);
      EndPos := Pos('</table>', Line);
      Delete(Line, EndPos, Length(Line));
      while Pos('<TR', Line) > 0 do
      begin
        BeginPos := Pos('<TR', Line);
        EndPos := Pos('</TR>', Line);
        Tags := Copy(Line, BeginPos, EndPos - BeginPos);
        if Pos('CLASS="tableHeaderLine"', Tags) > 0 then
        begin // "Letter"
          EndPos := Pos('</span>', Tags);
          PickTreeAdd('Films commençant par "' + Copy(Tags, EndPos - 1, 1) + '" :', '');
        end else
        begin // Movie
          Page.Text := Tags;
          Tags := Page.GetString(2);
          Delete(Tags, 1, 1);
          BeginPos := Pos('="..', Tags) + 4;
          EndPos := Pos('">', Tags);
          Address := Copy(Tags, BeginPos, EndPos - BeginPos);
          HTMLRemoveTags(Tags);
          Caption := Trim(Tags);
          Tags := Page.GetString(3);
          Delete(Tags, 1, 1);
          HTMLRemoveTags(Tags);
          Tags := Trim(Tags);
          if Tags <> ' ' then
            Caption := Caption + ' (' + Tags + ')';
          Tags := Page.GetString(4);
          Delete(Tags, 1, 1);
          HTMLRemoveTags(Tags);
          Tags := Trim(Tags);
          if Tags <> ' ' then
            Caption := Caption + ', ' + Tags;
          PickTreeAdd(Caption, 'http://www.dvdfr.com' + Address);
        end;
        Delete(Line, 1, Pos('</TR>', Line) + 5);
      end;
      Page.Free;
    end;
    if PickTreeExec(Address) then
    begin
      AnalyzePage(Address);
    end;
  end else
  if Pos('<title>Dvdfr.com - Fiche DVD', Line) > 0 then
  begin
    AnalyzeMoviePage(Line);
  end;
end;

procedure AnalyzeMoviePage(PageContents: string);
var
  Line, Value: string;
  LineNr, BeginPos, EndPos, BeginPos2, EndPos2, i : Integer;
  Page: TStringList;
begin
  // Picture
  BeginPos := Pos('src="../images/dvd/cover', PageContents);
  EndPos := Pos('<div class="dvd_categorie">', PageContents);
  Line := Copy(PageContents, BeginPos, EndPos - BeginPos);
  EndPos := Pos('" ', Line);
  Value := Copy(Line, 8, EndPos - 8);
  GetPicture('http://www.dvdfr.com' + Value, False);
  // Category
  BeginPos := Pos('<A class="home_a" TITLE="Rechercher les autres films de même catégorie"', PageContents);
  EndPos := Pos('<br><img src="../images/filet_categoriedvd.gif"', PageContents);
  Value := Copy(PageContents, BeginPos, EndPos - BeginPos);
  HTMLRemoveTags(Value);
  SetField(fieldCategory, Trim(AnsiMixedCase(AnsiLowerCase(Value), ' ')));
  //
  Page := TStringList.Create;
  BeginPos := Pos('<!-- Center main area -->', PageContents);
  EndPos := Pos('<IMG SRC="../images/tit_pepins.gif"', PageContents);
  Page.Text := Copy(PageContents, BeginPos, EndPos);
  // Titles
  LineNr := FindLine('<div class="dvd_title">', Page, 0);
  if LineNr > -1 then
  begin
    Value := Trim(Page.GetString(LineNr + 1));
    HTMLRemoveTags(Value);
    SetField(fieldOriginalTitle, Value);
    Value := Trim(Page.GetString(LineNr));
    HTMLRemoveTags(Value);
    Value := AnsiUpFirstLetter(AnsiLowerCase(Value));
    if GetField(fieldOriginalTitle) = '' then
    begin
      SetField(fieldOriginalTitle, Value);
      SetField(fieldTranslatedTitle, Value);
    end else
      SetField(fieldTranslatedTitle, Value);
    // Country
    Line := Page.GetString(LineNr + 2);
    BeginPos := Pos('">', Line) + 2;
    EndPos := Pos(' , ', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldCountry, Value);
    BeginPos := EndPos + 3;
    // Year
    EndPos := Pos('<br>', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldYear, Value);
    // Producer
    Delete(Line, 1, EndPos - 1);
    HTMLRemoveTags(Line);
    SetField(fieldProducer, Line);
  end;
  // Note
  LineNr := FindLine('/images/vote_dvdfr.gif', Page, LineNr);
  if LineNr > -1 then
  begin
    Value := Trim(Page.GetString(LineNr));
    HTMLRemoveTags(Value);
    Value := StringReplace(Value, ' ', '');
    EndPos := Pos(',', Value);
    Line := value;
    if EndPos > 0 then
      Line := Copy(Value, 1, EndPos - 1);
    SetField(fieldRating, Line);
  end;
  // Director
  LineNr := FindLine('<div class="dvd_subtitle">Réalisation</div>', Page, LineNr);
  if LineNr > -1 then
  begin
    Value := Trim(Page.GetString(LineNr + 1));
    HTMLRemoveTags(Value);
    SetField(fieldDirector, Value);
  end;
  // Actors
  LineNr := FindLine('<div class="dvd_subtitle">Avec...</div>', Page, LineNr);
  if LineNr > -1 then
  begin
    Value := StringReplace(Trim(Page.GetString(LineNr + 1)), '<br> ', #13#10);
    HTMLRemoveTags(Value);
    SetField(fieldActors, Value);
  end;
  // LABEL DU SUPPORT - Ref commerciale
  LineNr := FindLine('<div class="dvd_subtitle">Référence</div>', Page, LineNr);
  if LineNr > -1 then
  begin
    Value := Trim(Page.GetString(LineNr + 1));
    HTMLRemoveTags(Value);
    SetField(fieldMedia, Value);
  end;
  // Length
  LineNr := FindLine('<img alt="Durée"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := Pos('>', Line) + 1;
    EndPos := Pos(' min', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldLength, Value);
  end;
  // Discs
  LineNr := FindLine('<img alt="Nombre de disques"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := Pos('>', Line) + 1;
    EndPos := Pos('</', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldDisks, Value);
  end;
  // Bitrate
  LineNr := FindLine('<img alt="Bitrate moyen"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := Pos('<td>', Line) + 4;
    EndPos := Pos('&nbsp', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    Value := StringReplace(Value, ',', '') + '0';
    SetField(fieldVideoBitrate, Value);
  end;
  // Media type
  LineNr := FindLine('<img alt="Format DVD"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    BeginPos := Pos('>', Line) + 1;
    EndPos := Pos('</', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldMediaType, Value);
  end;
  // Comments
  Line := Page.Text;
  BeginPos := Pos('</span><br>', Line) + 12;
  Delete(Line, 1, BeginPos);
  EndPos := Pos('<br>', Line);
  Value := Copy(Line, 1, EndPos - 1);
  HTMLRemoveTags(Value);
  Value := 'Suppléments:' + #13#10 + Trim(Value);
  SetField(fieldComments, Value);

  // Formats video
  LineNr := FindLine('title="Format vidéo"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 2);
    BeginPos := Pos('alt="', Line) + 17;
    EndPos := Pos('" title=', Line);
    Value := Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldResolution, Value);
  end;
  // Zone
  LineNr := FindLine('title="Zone(s) du DVD"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 2);
    BeginPos := Pos('alt="', Line) + 5;
    EndPos := Pos('" title=', Line);
    Value := 'DVD ' + Copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldVideoFormat, Value);
  end;
  // Standard
  LineNr := FindLine('title="Standard vidéo du DVD"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := StringReplace(Trim(Page.GetString(LineNr + 2)), #9, '');
    HTMLRemoveTags(Line);
    Value := Value + ' - Standard ' + Line;
    SetField(fieldVideoFormat, Value);
  end;
  
  // Formats audio
  LineNr := FindLine('title="Spécifications audio"', Page, LineNr);
  if LineNr > -1 then
  begin
    BeginPos := LineNr + 2;
    LineNr := FindLine('</table></td></tr>', Page, LineNr);
    if LineNr > -1 then
    begin
      EndPos := LineNr;
      Value := '';
      Line := 'DVD ';
      for i := BeginPos to EndPos do
      begin
        BeginPos2 := Pos('<small>', Page.GetString(i));
        EndPos2 := Pos('</small>', Page.GetString(i));
        if ((BeginPos2 > 0) and (EndPos2 > 0)) then
        begin
            if not(Value = '') then
                Value := Value + ' - ';
            Value := Value + Copy(Page.GetString(i), BeginPos2 + 7, EndPos2 - (BeginPos2 + 7));
        end;
        BeginPos2 := Pos('alt="', Page.GetString(i));
        EndPos2 := Pos('" title="', Page.GetString(i));
        if ((BeginPos2 > 0) and (EndPos2 > 0)) then
        begin
            if not(Line = 'DVD ') then
                Line := Line + ' - ';
            Line := Line + Copy(Page.GetString(i), BeginPos2 + 5, EndPos2 - (BeginPos2 + 5));
        end;
      end;
      SetField(fieldAudioFormat, Line);
      SetField(fieldLanguages, Value);
    end;
  end;
  
  // Sous-Titre
  LineNr := FindLine('title="Sous-titres disponibles"', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := StringReplace(Trim(Page.GetString(LineNr + 3)), #9, '');
    HTMLRemoveTags(Line);
    SetField(fieldSubtitles, Line);
  end;
  //
  Page.Free;
  DisplayResults;
end;

procedure AnalyzePage2(Address: string);
var
  Page: TStringList;
  LineNr: Integer;
  Line: string;
  BeginPos: Integer;
begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if pos('<TITLE>Recherche', Page.Text) = 0 then
    AnalyzeMoviePage2(Page)
  else
  begin
    PickTreeClear;
    LineNr := FindLine('AlloCiné</A> : <b>Recherche</b>', Page, 0);
    if LineNr > -1 then
    begin
      Line := Page.GetString(LineNr);
      BeginPos := pos('dans les titres de films', Line);
      if BeginPos > 0 then
      begin
        Delete(Line, 1, BeginPos);
        PickTreeAdd('Films déjà sortis', '');
        AddMoviesTitles(Line);
      end;
      BeginPos := pos('dans les films déjà sortis (de ou avec)', Line);
      if BeginPos > 0 then
      begin
        Delete(Line, 1, BeginPos);
        PickTreeAdd('Films déjà sortis (de ou avec)', '');
        AddMoviesTitles(Line);
      end;
      BeginPos := pos('dans les prochaines sorties de films', Line);
      if BeginPos > 0 then
      begin
        Delete(Line, 1, BeginPos);
        PickTreeAdd('Prochaines sorties', '');
        AddMoviesTitles(Line);
      end;
      BeginPos := pos('dans les prochaines sorties de films (de ou avec)', Line);
      if BeginPos > 0 then
      begin
        Delete(Line, 1, BeginPos);
        PickTreeAdd('Prochaines sorties (de ou avec)', '');
        AddMoviesTitles(Line);
      end;
      Line := Page.GetString(LineNr);
      BeginPos := pos('<LI><A HREF="rubrique.html?typerecherche=3&', Line);
      if BeginPos > 0 then
      begin
        Delete(Line, 1, BeginPos + 12);
        PickTreeMoreLink('http://www.allocine.fr/recherche/' + copy(Line, 1, pos('"', Line) - 1));
      end;
      if PickTreeExec(Address) then
        AnalyzePage2(Address);
    end;
  end;
  Page.Free;
end;

procedure AnalyzeMoviePage2(Page: TStringList);
var
  Line, Value: string;
  LineNr, IntValue: Integer;
  BeginPos, EndPos: Integer;
begin
  // Description
  LineNr := FindLine('>Synopsis<', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    Value := '';
    repeat
      BeginPos := pos('"size2">', Line);
      if BeginPos > 0 then
        BeginPos := BeginPos + 8
      else
        BeginPos := 1;
      EndPos := pos('</FONT></DIV>', Line);
      if EndPos = 0 then
        EndPos := pos('<br>', Line);
      if EndPos = 0 then
        EndPos := Length(Line) + 1;
      if EndPos > 0 then
        Value := Value + copy(Line, BeginPos, EndPos - BeginPos) + #13#10;
      EndPos := pos('</FONT></DIV>', Line);
      if EndPos = 0 then
      begin
        LineNr := LineNr + 1;
        Line := Page.GetString(LineNr);
        EndPos := Pos('<SCRIPT', Line);
      end;
    until EndPos > 0;
    HTMLRemoveTags(Value);
    SetField(fieldDescription, Value);
  end;
  // URL
  LineNr := FindLine('class="link10" target=_blank>', Page, LineNr);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    BeginPos := pos('class="link10" target=_blank>', Line) + 29;
    EndPos := pos('</A></TD></TR>', Line);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    SetField(fieldURL, Value);
  end;
  DisplayResults;
end;

procedure AddMoviesTitles(var Line: string);
var
  MovieTitle, MovieAddress: string;
  StartPos, EndPos: Integer;
begin
  repeat
    StartPos := pos('<LI><A HREF="/film/fichefilm', Line);
    if StartPos > 0 then
    begin
      Delete(Line, 1, StartPos + 12);
      MovieAddress := copy(Line, 1, pos('"><FONT color=#003399>', Line) - 1);
      StartPos := pos('#003399>', Line) + 8;
      MovieTitle := copy(Line, StartPos, pos('</TD>', Line) - StartPos);
      HTMLRemoveTags(MovieTitle);
      PickTreeAdd(MovieTitle, 'http://www.allocine.fr' + MovieAddress);
    end;
  until (StartPos < 1) or ((pos('<LI><A HREF="/film/fichefilm', Line) > pos('<FONT class=size2 color=#AA0000>', Line)) and (pos('<FONT class=size2 color=#AA0000>', Line) > 0));
  if (pos('Plus...',Line) > 0) and (pos('Plus...',Line) < pos('<FONT class=size4 color=#003399><B>',Line)) and (pos('Plus...',Line) < pos('<FONT class=size2 color=#AA0000><B>',Line)) then
  begin
    StartPos := pos('rubrique.html', Line);
    EndPos := pos('Plus...',Line) - 16;
    MovieAddress := copy(Line, StartPos, EndPos - StartPos);
    PickTreeAdd('Plus... ', 'http://www.allocine.fr/recherche/' + MovieAddress);
  end;
end;

begin
  if CheckVersion(3,4,1) then
  begin
    MovieName := GetField(fieldTranslatedTitle);
    if MovieName = '' then
      MovieName := GetField(fieldOriginalTitle);
    if Input('DVDFR.com Import', 'Entrez le titre du film :', MovieName) then
    begin
      AnalyzePage('http://www.dvdfr.com/search/search.php4?multiname='+UrlEncode(MovieName));
      if Pos('allocine.com', MovieName) > 0 then
        AnalyzePage2(MovieName)
      else
        AnalyzePage2('http://www.allocine.fr/recherche/default.html?motcle='+UrlEncode(MovieName));
//      AnalyzePage('http://www.allocine.fr/recherche/rubrique.html?typerecherche=3&motcle='+UrlEncode(MovieName));
    end;
  end else
    ShowMessage('Ce script requiert la version 3.4.1 ou supérieure de Ant Movie Catalog.');
end.
PS : Antoine je te l'envoi.

Posted: 2003-01-07 19:02:49
by antp
J'ai bien reçu le mail, merci ;)