Update: Culturalia+IMDB (ES) v1.9

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

Update: Culturalia+IMDB (ES) v1.9

Post by folgui »

Hi!

Here's an update for the subject script.

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.9 (12/08/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|1|0=Imports Length from Culturalia (no info)|1=Imports Length from IMDB
ImportRatingIMDB=1|1|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
HideAkaTitles=1|1|0=Show Aka Titles (IMDB)|1=Hide Aka Titles (IMDB)

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

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 movie found for this search.');
          Exit;
        end;
      if GetOption('BatchMode') = 0 then
        begin
          PickTreeClear;
          repeat
            Value := TextBefore(PageText, '</b> (Displaying', '<p><b>');
            if Value <> '' then
            begin
              HTMLRemoveTags(Value);
              HTMLDecode(Value);
              PickTreeAdd(Value, '');
            end;
            Value := TextBetween(PageText, '<table><tr>', '</table>');
            PageText := RemainingText;
          until not AddMovieTitles(Value);
          Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
          if Value <> '' then
            PickTreeMoreLink('http://us.imdb.com' + Value);
          if PickTreeExec(Address) then
            AnalyzePageIMDB(Address);
        end
      else
        begin
          Value := TextBetween(PageText, '.</td><td valign="top">', '</a>');
          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, '<b>User Rating:</b>', '<br/>');
    Value := TextBetween(Value, '<b>', '/');
    if Value <> '' then
      SetField(fieldRating, Value);
  end;

  // Length
  if (GetOption('ImportLengthIMDB') = 1) then
  begin
    Value := TextBetween(PageText, '<h5>Runtime:</h5>' + #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;
  if GetOption('HideAkaTitles') = 1 then
    Value := TextBetween(List, '.</td><td valign="top">', ')<')
  else
    begin
      Value := TextBetween(List, '.</td><td valign="top">', '</td>');
      Value := StringReplace(Value, 'aka', ' | aka');
    end;
  List := RemainingText;
  while Value <> '' do
  begin
    Address := TextBetween(Value, '<a href="/title/tt', '/');
    if (GetOption('AllActors') = 1) or (GetOption('Producer') = 1) then
      Address := Address + '/combined'
    else
      Address := Address + '/';
    HTMLRemoveTags(Value);
    HTMLDecode(Value);
    if GetOption('HideAkaTitles') = 1 then
      Value := Value + ')';
    PickTreeAdd(Value, 'http://us.imdb.com/title/tt' + Address);
    Result := True;
    if GetOption('HideAkaTitles') = 1 then
      Value := TextBetween(List, '.</td><td valign="top">', ')<')
    else
      begin
        Value := TextBetween(List, '.</td><td valign="top">', '</td>');
        Value := StringReplace(Value, 'aka', ' | aka');
      end;
    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://us.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.
Regards, folgui
Last edited by folgui on 2007-08-12 10:48:03, edited 4 times in total.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

You must change one more line in the code :

Code: Select all

Value := TextBetween(TextBetween(PageText, '<ol>', '</ol>'), '<li>', '</li>');
must be

Code: Select all

Value := TextBetween(PageText, '.</td><td valign="top">', '</a>');
It is only important if you want to use 'BatchMode' option.
I just did not see it yesterday when I fixed the IMDB script. Sorry.
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

Thanks bad4u :grinking:

Just did it ;)

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

Post by folgui »

Update to version 1.8.

It fixes a PickTree problem with imdb in some films, related to imdb's url that i was using in previous version.

Regards, folgui.
Ronin
Posts: 4
Joined: 2007-07-19 19:09:01

Post by Ronin »

Hola.

Copio y pego el código nuevo sobre el script antiguo, y no me sale en la lista de scripts disponibles, eliga el idioma que eliga.

Te suena de que puede ser? Tengo la version 3.5.0.2

Incluso he editado con el notepad el .ifs eliminando todo y poniendo el código que pones más arriba, con los mismos resultados, no me sale en la lista de scripts al darle al F6.

Saludos.
patalete
Posts: 1
Joined: 2007-07-29 15:39:34

Post by patalete »

Yo tambien estoy teniendo el mismo problema, el script de culturalia no me aparece en la lista de scripts, bajo ningun idioma. Solo consigo verlo entrando desde la opcion Herramientas-scripting y me aparece en gris claro y me da errores al ejecutarlo.

Que puede ser?
legrad
Posts: 109
Joined: 2006-02-11 09:46:06
Location: Lerida-Spain

sobre culturalia

Post by legrad »

RONIN, prueba a ver:al entrar en la ventana de scripts elije la opcion en filtro de idioma "Marcar Todos" si no le ves, es posible que hayas copiado mal script, asegurate que los asteriscos de la primera linea del script encabezan el mismo, osea que no haya por delante de los asteriscos una linea en blanco, si no es eso no se me ocurre nada mas, a mi me funciona.

PATALETE
Asegurate de que en el directorio de los scripts, tienes un archivo llamado "StringUtils1.pas" ya que si no esta en dicho directorio este script no funciona ya que hace una llamada a dicho archivo, para ejecutar algunos strings, parece probable que es lo que te esta pasando es eso
Ronin
Posts: 4
Joined: 2007-07-19 19:09:01

Post by Ronin »

El filtro del idioma "marcar todos" ya lo puse y no salía nada. Esta tarde cuando llegue a casa probaré lo de la linea en blanco que dices, a ver que tal.

Saludos y gracias.
Ronin
Posts: 4
Joined: 2007-07-19 19:09:01

Post by Ronin »

legrad, premio para ti. Era una linea en blanco al principio del fichero. He mirado a ver si se ejecutaba como decía patalete y si, a mi se me ejecutaba sin problemas, y luego repasando el script, he visto lo de la linea.

1000 gracias ;)

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

Post by folgui »

¡Hola!

Entiendo entonces que se ha solucionado? Estoy de vacaciones y no puedo comprobarlo. He visto que tenía un privado de Ronin y por eso me he pasado por aquí.

De todas formas, la versión 1.8 es descargable con el script que actualiza los scripts (valga la redundancia) y funciona ok, creo recordar.

Saludos, folgui.
Ronin
Posts: 4
Joined: 2007-07-19 19:09:01

Post by Ronin »

Yo eliminando la linea en blanco ya me funciona OK.

De todas maneras, use el script ese autoupdate, pero me da a mi que no actualizo tu script, porque tenía puesta la version 1.6, y la dejo tal cual.

Si eso, cuando vuelvas de vacaciones, le pegas un ojo, de momento a disfrutarlas ;)

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

Post by folgui »

Hello!

1.9 changes:

EN: In v1.8 the imdb import was not the default, now it is.
ES: En v1.8 la importación de imdb no estaba por defecto, y ahora sí.

EN: The first blank line is made by the CODE tag, don't copy it with the script because it won't appear in script list. The first line of the .ifs file of the script should not be a blank line.
ES: la primera línea en blanco la crea el propio "CODE" pero no se debe copiar porque si no, no aparece el script en la lista. La primera línea del archivo .ifs del script no debe ser una línea en blanco.

EN: For me, UPDATE_SCRIPTS.ifs works ok and has updated this script to 1.8 without problems..
ES: A mi, UPDATE_SCRIPTS.ifs me funciona bien y actualiza a la versión 1.8 que también va ok, salvo porque no importaba la calificación y la duración de imdb por defecto (modificado en 1.9).

Regards, folgui.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks, I updated the script on my server.
There was a mistake in the previous file (provided with AMC, and maybe on the server too): an empty line at the top of the script, before the comment properties block, which cause the script to not appear in some cases.
I suppose that this error occurred when I copy/pasted the script.
Post Reply