Culturalia (Single Movie) Script, Latest Version

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

Culturalia (Single Movie) Script, Latest Version

Post by folgui »

Hello!

I've created this topic to help antp to know where he can find the latest version of the Culturalia script, single movie version.

All fixes/updates made to it would be updated here. If you have some suggestion you can reply here o in another topic, but always would be updated here with latest version that works ok.

This is neccesary to not mix and go crazy with other versions that people are working on them like "imdb+culturalia (batch)" or perhaps a "imdb+culturalia (single)".

THE LATEST SCRIPT:

Code: Select all

// GETINFO SCRIPTING
// Culturalia  (Con Portada) 

(***************************************************
 *  Movie importation script for:                  *
 *    Culturalia, http://www.culturalianet.com     *
 *                                                 *
 *  Original version made by David Arenillas       *
 *  New version made by Antoine Potten             *
 *  Contributors:                                  *
 *    Jose Miguel Folgueira                        *
 *    RedDwarf                                     *
 *    Hades666                                     *
 *    KaBeCi                                       *
 *    PolloPolea                                   *
 *                                                 *
 *  Sort Results Made by Moises Déniz 13/04/2004   *
 *                                                 *
 *  TransformTitle function from IMDB (US) Script  *
 *  (c) 2002-2004 Antoine Potten                   *
 *                          software@antp.be       *
 *  Contributors :                                 *
 *    Danny Falkov                                 *
 *    Kai Blankenhorn                              *
 *    lboregard                                    *
 *    Ork <ork@everydayangels.net>                 *
 *    Trekkie <Asimov@hotmail.com>                 *
 *                                                 *
 *  Thanks to Culturalia's webmaster for his help  *
 *  and for providing more direct access to his    *
 *  database                                       *
 *                                                 *
 *  For use with Ant Movie Catalog 3.4.x           *
 *  www.antp.be/software/moviecatalog              *
 *                                                 *
 *  This program is free software; you can         *
 *  redistribute it and/or modify it under the     *
 *  terms of the GNU General Public License as     *
 *  published by the Free Software Foundation;     *
 *  either version 2 of the License, or (at your   *
 *  option) any later version.                     *
 ***************************************************)

program Culturalia;
const
  BaseURL = 'http://www.culturalianet.com/bus/catalogo.php';

  TitleMixedCase = False; // If true, each letter of each word of title begins with Uppercase. If false, the script transforms the titles in lowercase except first word
  ExternalPictures = False;
     { True: Pictures will be stored as external files in the folder of the catalog
       False: Pictures will be stored inside the catalog (only for .amc files) }
  // Donde vamos a buscar en el caso de no haber introducido ni el título original ni el traducido en los campos correspondientes, sino en la ventana que 
  // se abre y nos lo solicita.
  // 1-Titulo traducido, 2-Titulo original, 3-General
  // What type of search in case we don't write the original title nor traslated one in the corresponding fields, we do it in the input box.
  // 1-Translated title, 2-Original Title, 3-General
  defdonde='1';

var
  MovieName: string;
  tmp: string;
  donde: string;  
  Articles: array of string;
  Index: Integer;

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;

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, ': ', ' - ');

  If TitleMixedCase then
     Result := AnsiMixedCase(Result, ' ')
  else
    begin
     Result := AnsiLowerCase(Result);
     Result := AnsiUpFirstLetter(Result);
    end;

  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;

function Valoracion(Resultado: string; Titulo :TStringList) : Integer;
var i,j,val: integer;
begin
    val := 0;
    for i := 0 to Titulo.Count-1 do
      begin
        if (Pos(Titulo.GetString(i),Resultado) > 0) then
          val := val + 5;
      end;
    Valoracion := val;
end;

procedure SortStrings(var List : TStringList; Nombre : string);
var i,j,ValI,ValJ: integer;
    NombreArray: TStringList;
    palabra : string;
begin
    Nombre := LowerCase(Nombre);
    NombreArray := TStringList.Create;
    while ((pos(' ',Nombre) > 0) and (Length(Nombre)> 0)) do
    begin
      palabra := copy(Nombre,0,pos(' ',Nombre)-1);
      Nombre  := copy(Nombre,pos(' ',Nombre)+1,Length(Nombre));
      NombreArray.Add(palabra);
    end
    NombreArray.Add(Nombre);
    for i := 0 to List.Count-1 do
    begin
      for j := 0 to List.Count-1 do
      begin
         ValI := Valoracion(LowerCase(List.GetString(i)),NombreArray);
         ValJ := Valoracion(LowerCase(List.GetString(j)),NombreArray);
         if (ValI > ValJ) then
          begin
          List.Exchange(i,j);
          end;
         if (ValI = ValJ) and (List.GetString(i) < List.GetString(j)) then
          List.Exchange(i,j);
      end;
    end;
    NombreArray.Free;
end;

procedure AnalyzePage(Address,Nombre: string);
var
  Page,TempTit: TStringList;
  LineNr,i: Integer;
  Code, Title, TitleOrig, Year,Texto,Url: string;
begin
  Page := TStringList.Create;
  TempTit := TStringList.Create;
  Page.Text := GetPage(Address);
  if Pos('No se ha encontrado ningún artículo por título', Page.Text) > 0 then
  begin
    ShowMessage('No se ha encontrado ninguna coincidencia por título');
  end else
  begin
    PickTreeClear;
    LineNr := 1;
    Page.Text := StringReplace(Page.Text, '<br>', #13#10);
    while LineNr + 3 < Page.Count do
    begin
      Code := GetValueAfter(Page.GetString(LineNr), 'Codigo = ');
      Title := GetValueAfter(Page.GetString(LineNr+1), 'Titulo = ');
      TitleOrig := GetValueAfter(Page.GetString(LineNr+2), 'Titulo original = ');
      Year := GetValueAfter(Page.GetString(LineNr+3), 'Año = ');
      TempTit.Add(Title + ' (' + TitleOrig + '), ' + Year+';'+BaseURL + '?catalogo=1&codigo=' + Code);
      LineNr := LineNr + 5;
    end;
    SortStrings(TempTit,Nombre);
    PickTreeAdd('Resultados más probables de buscar: "'+Nombre+'"', '');
    for i := 0 to TempTit.Count-1 do
        begin
         Texto := copy(TempTit.GetString(i),0,Pos(';',TempTit.GetString(i))-1);
         Url := copy(TempTit.GetString(i),Pos(';',TempTit.GetString(i)),Length(TempTit.GetString(i)));
         PickTreeAdd(Texto,Url);
         if (i = 0) then PickTreeAdd('Resto de resultados de buscar: "'+Nombre+'"', '');
        end;
    Page.Free;
    TempTit.Free;
    if PickTreeExec(Address) then
      AnalyzeMoviePage(Address);
  end;
end;

procedure AnalyzeMoviePage(Address: string);
var
  Page: TStringList;
  Comments: string;
  strTitle: string;
  strSinopsis: string;
  Line: string;
  LineNr: Integer;
  tmp: string;


begin
  Page := TStringList.Create;
  Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10);
  Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  strTitle := GetValueAfter(Page.GetString(1), 'Titulo = ');
  if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then
  begin
    tmp := Copy(strTitle, 1, Length(strTitle) -1);
  end else
  begin
    tmp := strTitle;
  end;
  SetField(fieldTranslatedTitle, TransformTitle(tmp));
  tmp := GetValueAfter(Page.GetString(2), 'Titulo original = ');
  SetField(fieldOriginalTitle, TransformTitle(tmp));
  SetField(fieldYear, GetValueAfter(Page.GetString(3), 'Año = '));
  SetField(fieldCategory, GetValueAfter(Page.GetString(4), 'Genero = '));
  SetField(fieldCountry, GetValueAfter(Page.GetString(5), 'Nacion = '));
  SetField(fieldDirector, GetValueAfter(Page.GetString(6), 'Director = '));
  SetField(fieldActors, GetValueAfter(Page.GetString(7), 'Actores = '));
  SetField(fieldProducer, GetValueAfter(Page.GetString(8), 'Productor = '));
  Comments := 'Guión: ' + GetValueAfter(Page.GetString(9), 'Guion = ');
  Comments := Comments + #13#10 + 'Fotografía: ' + GetValueAfter(Page.GetString(10), 'Fotografia = ');
  Comments := Comments + #13#10 + 'Música: ' + GetValueAfter(Page.GetString(11), 'Musica = ');
  SetField(fieldComments, Comments);
  LineNr := FindLine('Sinopsis = ', Page, 0);
  Line := Page.GetString(LineNr);
  strSinopsis := GetValueAfter(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, GetValueAfter(Page.GetString(LineNr), 'URL = '));
  LineNr := FindLine('Imagen = ', Page, 0);
  if LineNr <> -1 then
    GetPicture(GetValueAfter(Page.GetString(LineNr), 'Imagen = '), ExternalPictures);
  Page.Free;
  DisplayResults;
end;

function GetValueAfter(Line, Identifier: string): string;
begin
  if Pos(Identifier, Line) = 1 then
    Result := Copy(Line, Length(Identifier)+1, Length(Line))
  else
    Result := '';
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,4,0) then
   begin
     MovieName := GetField(fieldOriginalTitle);
     donde := '&donde=2'; 
     if MovieName = '' then
      begin
       MovieName := GetField (fieldTranslatedTitle);
       donde := '&donde=1'; 
      end
     if MovieName = '' then
      begin
       Input('Importar de Culturalia', 'Introduce el Titulo de la Pelicula:', MovieName);
       donde := '&donde=' + defdonde;
      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
         tmp := MovieName;
         if Copy(tmp, Length(tmp), Length(tmp)) = '.' then
            MovieName := Copy(tmp, 1, Length(tmp) -1);
         AnalyzePage(BaseURL + '?catalogo=1&texto=' + UrlEncode(MovieName) + donde, MovieName);
       end;
   end else
     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.
Regards, folgui :)
Last edited by folgui on 2004-10-01 00:23:08, edited 8 times in total.
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Good idea, thanks :)
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

Script updated with the next fixes/updates:

- If there's a point at final of movie title before search, Culturalia doesn't find it. Fixed!. Sample: "Sunset Bvld.". Thanks KaBeCi.
- By default, culturalia's import of TranslatedTitle (spanish) has the articles at the final, after ', '. But then if you do a search of that, it doesn't find it. So changed to import article at beginning of title. Used same function as IDMB (US) script, works perfectly. Now after an import, if you do a new search, it works Ok. Thanks KaBeCi.
- If exists MovieName at 'fieldOriginalTitle' or "fieldTranslatedTitle' then it doesn't offer the window (input) to introduce movie name, otherwise, the window appears.
- Searchs now first for "OriginalTitle" rather than "TranslatedTitle", seems better for non-spanish users. Thanks KaBeCi.
- Some code has been cleaned, not neccesary or superfluous.

That's all ATM.

Enjoy!

Regards, folgui.
RedDwarf

Post by RedDwarf »

Hey, wow!! Good work.
About the second point seems that now culturalia finds the movie, not because the article is at beginning, but because it search for the original title.
If I search por "Los Últimos Dias Del Edén" or "Últimos Dias Del Edén, Los" there isn't any result.
The only option I see is to eliminate articles from searches, but is strange that any of the two gives results :(
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

Script modified.

Added an option to obtain different case of titles. This option is a "const" at beginning of script: TitleMixedCase

By default is "False", that means all letters lowercase except first one. With "True" we obtain a mixed case, with first letter of each word in Uppercase.

Another fix is that this script didn't eliminate the spanish articles in search, like the "batch" one, so i've added the code. This caused a problem searching for "Los Ultimos dias del eden" for example.

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

Post by folgui »

Script updated, now the image import from culturalia uses the new const "ExternalPictures" to import it as a external file or internal to AMC
file.

By default, the script saved/saves the images as internal. To save as external, set the const "ExternalPictures" (at the beginning of script) to "True".

Thanks to KaBeCi.

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

Post by folgui »

Script updated with some code optimization/changes, nothing enhanced.

The code at first message of this thread is the latest updated/working version of the script. So copy/paste/save it.

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

Post by antp »

Hmmm you update it few hours after I made the setup for next update and sent it to Simtel for mirror servers :D
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

No problem, the next time ;) I've been busy and couldn't do it before.

By the way, people can get them from here, and the scripts difference are minimal. This one is 99% identical and the other two culturalia+imdb only adds the support to configure the Picture saving like external/internal with a constant, and deleted some variables that weren't neccesary with your imdb changes.

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

Post by folgui »

Hello!

The first message of this thread has been updated with the latest script.

Updates:

* Added Pollopolea code of this thread: viewtopic.php?t=906 , but i've modified it since the search with "donde=0" doesn't work at all, it works with "donde=3" for a general search based on original title of the movie, but with translated titles it doesn't find the correct movies in a lot of cases. I've added a const at the beginning of the script, to let us define what type of search to do in case we introduce the title in the input box and not in the corresponding fields. By default, it searches by "translated title".

Hope no mismatches or new bugs, if you find any, tell me.

Regards, folgui.
pollopolea
Posts: 23
Joined: 2004-10-02 09:53:47
Location: Granada (Spain)

Post by pollopolea »

Hi. I wrote this new script because culturalia has changed its search web page, and the older script doesn´t work very well now.

Now we get all avaliable data in culturalia web page (except awards) including rating, "clasificacion moral", and length.

All functions has been rewritten except findline & transformTitle.

We can choose the type of search in case we don't write the original title nor traslated one in the corresponding fields, we do it in the input box writing the following values in 'defdonde' :
0-General 1-Translated title, 2-Original Title,
The default value is 0, and its work fine.

probably I´ll merge these new funtions in the others script based in culturalia
(or perhaps folgui will do it before ;) )


enjoy.

(and sorry for my english!!! :ha:)
homeroarg

Post by homeroarg »

What has to be changed to choose always the first name of the list of results !?!?!
Post Reply