[REL] [UPDATE] [ES] Culturalia+IMDB v1.6

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
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

[REL] [UPDATE] [ES] Culturalia+IMDB v1.6

Post by folgui »

¡Hi!

[EN] A few days ago, IMDB made some changes on their web, so rating/length were not imported correctly in this script. Fixed!

[ES] Hace unos días, IMDB ha hecho unos cambios en su página, lo cual impedía que se importase correctamente la valoración/duración. ¡Corregido!

Regards, folgui.

Code: Select all

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

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

[Infos]
Authors=David Arenillas, Antoine Potten and J.M. Folgueira
Title=Culturalia(+IMDB)
Description=Movie importation script for Culturalia and IMDB
Site=http://www.culturalianet.com
Language=ES
Version=1.6 (04 Mar 2007)
Requires=3.5.0
Comments=Several updates made by: folgui (folgui@bigfoot.com), RedDwarf, Hades666, KaBeCi, PolloPolea, Moises Déniz.||Thanks to Culturalia's webmaster for his help and for providing more direct access to his database.||
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]
ImportLengthIMDB=1|0|0=Imports Length from Culturalia (no info)|1=Imports Length from IMDB
ImportRatingIMDB=1|0|0=Imports Rating from Culturalia (no info)|1=Imports Rating from IMDB
BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found

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

program Culturalia_IMDB;
uses
  StringUtils1;
const
  BaseURLCulturalia = 'http://www.culturalianet.com/bus/catalogo.php';
var
  MovieName, strTemp, donde: string;
  Articles: array of string;
  Index: integer;

procedure AnalyzePageIMDB(Address: string);
var
  PageText: string;
  Value: string;
begin
  PageText := GetPage(Address);
  if pos('<title>IMDb', PageText) = 0 then
  begin
    AnalyzeMoviePageIMDB(PageText)
  end else
  begin
    if Pos('<b>No Matches.</b>', PageText) > 0 then
    begin
      if GetOption('BatchMode') = 0 then
        ShowMessage('No se ha encontrado ninguna coincidencia');
      Exit;
    end;
    if GetOption('BatchMode') = 0 then
    begin
      PickTreeClear;
      repeat
        Value := TextBefore(PageText, '<ol>', '<b>');
        if Value <> '' then
        begin
          HTMLRemoveTags(Value);
          HTMLDecode(Value);
          PickTreeAdd(Value, '');
        end;
        Value := TextBetween(PageText, '<ol>', '</ol>');
        PageText := RemainingText;
      until not AddMovieTitles(Value);
      Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
      if Value <> '' then
        PickTreeMoreLink('http://former.imdb.com' + Value);
      if PickTreeExec(Address) then
        AnalyzePageIMDB(Address);
    end
    else
    begin
      Value := TextBetween(TextBetween(PageText, '<ol>', '</ol>'), '<li>', '</li>');
      if Value <> '' then
        AnalyzePageIMDB(TextBetween(Value, '<a href="', '">'));
    end;
  end;
end;

procedure AnalyzeMoviePageIMDB(PageText: string);
var
  Value: string;
begin
  // Rating
  if (GetOption('ImportRatingIMDB') = 1) then
  begin
   Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/');
   SetField(fieldRating, TextBetween(Value, '<b>', '/'));
  end;

  // Length
  if (GetOption('ImportLengthIMDB') = 1) then
  begin
    Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' ');
    if Value <> '' then
    begin
      if Pos(':', Value) > 0 then
        SetField(fieldLength, TextAfter(Value, ':'))
      else
        SetField(fieldLength, Value);
    end;
  end;
end;

function AddMovieTitles(List: string): Boolean;
var
  Value: string;
  Address: string;
begin
  Result := False;
  Value := TextBetween(List, '<li>', '</li>');
  List := RemainingText;
  while Value <> '' do
  begin
    Address := TextBetween(Value, '<a href="', '">');
    HTMLRemoveTags(Value);
    HTMLDecode(Value);
    PickTreeAdd(Value, Address);
    Result := True;
    Value := TextBetween(List, '<li>', '</li>');
    List := RemainingText;
  end;
end;

function TransformTitle(Title: string): string;
var
  BeginPos, EndPos: Integer;
  Value: string;
  Words: array of string;
  Articles: array of string;
  Replace,Original: string;
  Index, CommaCount: Integer;
Begin
  // Original Title
  Result:=Title;

  Setarraylength(Words,11);
  Words[0]:=' In ';
  Words[1]:=' On ';
  Words[2]:=' Of ';
  Words[3]:=' As ';
  Words[4]:=' The ';
  Words[5]:=' At ';
  Words[6]:=' And A ';
  Words[7]:=' And ';
  Words[8]:=' An ';
  Words[9]:=' To ';
  Words[10]:=' For ';

  SetArrayLength(Articles,35);
  Articles[0]:=' The';
  Articles[1]:=' a';
  Articles[2]:=' An';
  Articles[3]:=' Le';
  Articles[4]:=' L''';
  Articles[5]:=' Les';
  Articles[6]:=' Der';
  Articles[7]:=' Das';
  Articles[8]:=' Die';
  Articles[9]:=' Des';
  Articles[10]:=' Dem';
  Articles[11]:=' Den';
  Articles[12]:=' Ein';
  Articles[13]:=' Eine';
  Articles[14]:=' Einen';
  Articles[15]:=' Einer';
  Articles[16]:=' Eines';
  Articles[17]:=' Einem';
  Articles[18]:=' Il';
  Articles[19]:=' Lo';
  Articles[20]:=' La';
  Articles[21]:=' I';
  Articles[22]:=' Gli';
  Articles[23]:=' Le';
  Articles[24]:=' Uno';
  Articles[25]:=' Una';
  Articles[26]:=' Un''';
  Articles[27]:=' O';
  Articles[28]:=' Os';
  Articles[29]:=' As';
  Articles[30]:=' El';
  Articles[31]:=' Los';
  Articles[32]:=' Las';
  Articles[33]:=' Unos';
  Articles[34]:=' Unas';

  // Count the Comma in The Title
  CommaCount := 0;
  EndPos := 0;
  Value := Title;
  repeat
     BeginPos := Pos(',', Value);
     if BeginPos > 0 then
     begin
       Delete(Value, 1, BeginPos);
       CommaCount := CommaCount + 1;
       EndPos := EndPos + BeginPos;
     end;
  until( Pos(',',Value) = 0);

  // Compare the Article to a list of known ones
  for Index := 0 to 34 do
  begin
    if Pos(Articles[Index], Value) <> 0 then
    begin
       CommaCount := 1;
       BeginPos := EndPos;
       Break;
    end;
  end;

  if (BeginPos > 0) and (CommaCount = 1) then
  begin
    Value := Copy(Title, BeginPos + 1, Length(Title));
    Value := Trim(Value);
    Result := Value + ' ' + Copy(Title, 1, BeginPos - 1);
  end;

  BeginPos := Pos(': ', Result);
  if BeginPos > 0 then
    Result := StringReplace(Result, ': ', ' - ');

  Result := AnsiMixedCase(Result, ' ');

  for Index := 0 to 10 do
  begin
    if Pos(Words[Index],Result) <> 0 then
    begin
      Original := Words[Index];
      Replace := AnsiLowerCase(Original);
      Result := StringReplace(Result, Original, Replace);
    end;
  end;

  Result := StringReplace(Result, ' - the ', ' - The ');
  Result := Trim(Result);
end;

procedure AnalyzePageCulturalia(Address: string);
var
  Page, TempTit: TStringList;
  LineNr: Integer;
  Code, Title, TitleOrig, Year: string;
  TitleFound: Boolean;
begin
  Page := TStringList.Create;
  TempTit := TStringList.Create;
  Page.Text := GetPage(Address);
  Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  if Pos('No se ha encontrado ningún artículo por título', Page.Text) = 0 then
  begin
    if GetOption('BatchMode') = 0 then
    begin
       PickTreeClear;
       LineNr := 1;
       PickTreeAdd('Resultados más probables de la búsqueda:', '');
       while LineNr + 3 < Page.Count do
       begin
         Code := TextAfter(Page.GetString(LineNr), 'Codigo = ');
         Title := TextAfter(Page.GetString(LineNr+1), 'Titulo = ');
         TitleOrig := TextAfter(Page.GetString(LineNr+2), 'Titulo original = ');
         Year := TextAfter(Page.GetString(LineNr+3), 'Año = ');
         PickTreeAdd(Title + ' (' + TitleOrig + '), ' + Year, BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
         LineNr := LineNr + 5;
       end;
       Page.Free;
       if PickTreeExec(Address) then
         AnalyzeMoviePageCulturalia(Address);
    end else
    begin
      LineNr := 1;
      TitleFound := True;
      Code := TextAfter(Page.GetString(LineNr), 'Codigo = ');
      Address := (BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
      if TitleFound then
        AnalyzeMoviePageCulturalia(Address);
      Page.Free;
    end;
  end else
  if (GetOption('BatchMode') = 0) then
    ShowMessage('No se ha encontrado ninguna coincidencia por título');
end;

procedure AnalyzeMoviePageCulturalia(Address: string);
var
  Page: TStringList;
  Comments: string;
  strTitle: string;
  strSinopsis: string;
  Line: string;
  LineNr: Integer;
  strTemp: string;
begin
  Page := TStringList.Create;
  Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10);
  Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  strTitle := TextAfter(Page.GetString(1), 'Titulo = ');
  if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then
  begin
    strTemp := Copy(strTitle, 1, Length(strTitle) -1);
  end else
  begin
    strTemp := strTitle;
  end;
  SetField(fieldTranslatedTitle, TransformTitle(strTemp));
  strTemp := TextAfter(Page.GetString(2), 'Titulo original = ');
  SetField(fieldOriginalTitle, TransformTitle(strTemp));
  SetField(fieldYear, TextAfter(Page.GetString(3), 'Año = '));
  SetField(fieldCategory, TextAfter(Page.GetString(4), 'Genero = '));
  SetField(fieldCountry, TextAfter(Page.GetString(5), 'Nacion = '));
  SetField(fieldDirector, TextAfter(Page.GetString(6), 'Director = '));
  SetField(fieldActors, TextAfter(Page.GetString(7), 'Actores = '));
  SetField(fieldProducer, TextAfter(Page.GetString(8), 'Productor = '));
  Comments := 'Guión: ' + TextAfter(Page.GetString(9), 'Guion = ');
  Comments := Comments + #13#10 + 'Fotografía: ' + TextAfter(Page.GetString(10), 'Fotografia = ');
  Comments := Comments + #13#10 + 'Música: ' + TextAfter(Page.GetString(11), 'Musica = ');
  SetField(fieldComments, Comments);
  LineNr := FindLine('Sinopsis = ', Page, 0);
  Line := Page.GetString(LineNr);
  strSinopsis := TextAfter(Line, 'Sinopsis = ');
  LineNr := LineNr + 1;
  Line := Page.GetString(LineNr);
  while pos('URL = ', Line) = 0 do
  begin
    strSinopsis := strSinopsis + #13#10 + Line;
    LineNr := LineNr + 1;
    Line := Page.GetString(LineNr);
  end
  HTMLRemoveTags(strSinopsis);
  SetField(fieldDescription, StringReplace(StringReplace(strSinopsis, '“', '"'), '”', '"'));
  LineNr := FindLine('URL = ', Page, 0);
  if LineNr <> -1 then
    SetField(fieldURL, TextAfter(Page.GetString(LineNr), 'URL = '));
  LineNr := FindLine('Imagen = ', Page, 0);
  if LineNr <> -1 then
    GetPicture(TextAfter(Page.GetString(LineNr), 'Imagen = '));
  Page.Free;
end;

begin
  SetArrayLength(Articles,11);
  Articles[0]:='Lo ';
  Articles[1]:='La ';
  Articles[2]:='Le ';
  Articles[3]:='Uno ';
  Articles[4]:='Una ';
  Articles[5]:='Un ';
  Articles[6]:='El ';
  Articles[7]:='Los ';
  Articles[8]:='Las ';
  Articles[9]:='Unos ';
  Articles[10]:='Unas ';

if CheckVersion(3,5,0) then
   begin
    MovieName := '';
    MovieName := GetField(fieldTranslatedTitle);
     donde := '&donde=1';
     if MovieName = '' then
      begin
       MovieName := GetField (fieldOriginalTitle);
       donde := '&donde=2';
      end
     if MovieName = '' then
      begin
       Input('Importar de Culturalia', 'Introduzca el Titulo de la Pelicula:', MovieName);
       donde := '&donde=1';
      end
    If MovieName <> '' then
      begin
        // Eliminate spanish article if exists
        for Index := 0 to 10 do
        begin
         if Pos(Articles[Index], MovieName) <> 0 then
         MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
        end;

        // Eliminate point(s) at final of MovieName before search
        strTemp := MovieName;
        if Copy(strTemp, Length(strTemp), Length(strTemp)) = '.' then
          MovieName := Copy(strTemp, 1, Length(strTemp) -1);
        AnalyzePageCulturalia(BaseURLCulturalia + '?catalogo=1&texto=' + UrlEncode(MovieName) + donde);
        if (GetOption('ImportRatingIMDB')=1) or (GetOption('ImportLengthIMDB')=1) then
          AnalyzePageIMDB('http://former.imdb.com/find?tt=1;q='+UrlEncode(GetField(fieldOriginalTitle)));
      end;
   end else
     ShowMessage('Este script requiere una versión más reciente de Ant Movie Catalog (al menos la versión 3.5.0)');
end.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks
rocanrol
Posts: 4
Joined: 2006-02-11 17:12:41

Post by rocanrol »

Muchas Gracias folgui

Ahora parece que hay un problema con la importación de la sinopsis desde culturalia.

Saludos


Thxs Folgui

By now, it seems like there is some trubble during the importation of the plot from Culturalia

Greetings
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

rocanrol wrote:Ahora parece que hay un problema con la importación de la sinopsis desde culturalia.
¡Hola!

ES: ¿Puedes ponerme un ejemplo de película donde no funcione? Yo lo llevo usando desde la modificación y no he tenido ningún problema.

EN: Can you tell me with what film it doesn't work? I have been using it since modification y haven't got any problems.

Saludos, folgui.
rocanrol
Posts: 4
Joined: 2006-02-11 17:12:41

Post by rocanrol »

Para cualquier película aparece el siguiente mensaje:
In any film this message appears:

Error de Script en "CULTURALIA_IMDB": unknown identifier: FINDLINE en la línea 295
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Check that you have the file Stringutils1.pas up-to-date (you can get it from www.antp.be/temp/scripts)
But that strange since it is included with the program since long time.
rocanrol
Posts: 4
Joined: 2006-02-11 17:12:41

Post by rocanrol »

Thanks folgui and antp, overwriting the old *.pas files worked for me perfectly

Gracias a folgui y antp, sobreescribiendo los archivos antiguos *.pas se solucionó el problema
lestatou
Posts: 25
Joined: 2006-10-28 20:45:45

Post by lestatou »

Hola.

He actualizado el codigo del script culturalia para que importe la duracion y la valoracion pero no lo hace. 1º me aparece la lista de peliculas, escojo la correcta y me lo importa todo menos eso. 2º me sale un pop up de "no movie found".

Ke puede ser? gracias.

------

Hi

I've updated the script with new code, but it doesn't imports length and rating. First appears the list of movies to choose and imports almost all the info, buet at the end of importation process appears a pop with "no movie found".

What happens?

Thanks a lot.
Post Reply