Update to Culturalia to retrieve length

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
RedDwarf

Update to Culturalia to retrieve length

Post by RedDwarf »

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             *
*  Modified by Jose Miguel Folgueira
*  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.0           *
*  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               *
***************************************************)

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

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;
  Code, Title, TitleOri, Year: string;
begin
  Page := 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 ningún artículo por título');
  end else
  begin
    PickTreeClear;
    LineNr := 1;
    Page.Text := StringReplace(Page.Text, '<br>', #13#10);
    PickTreeAdd('Search results:', '');
    while LineNr + 3 < Page.Count do
    begin
      Code := GetValueAfter(Page.GetString(LineNr), 'Codigo = ');
      Title := GetValueAfter(Page.GetString(LineNr+1), 'Titulo = ');
      TitleOri := GetValueAfter(Page.GetString(LineNr+2), 'Titulo original = ');
      Year := GetValueAfter(Page.GetString(LineNr+3), 'Año = ');
      PickTreeAdd(Title + ' (' + TitleOri + '), ' + Year, BaseURL + '?catalogo=1&codigo=' + Code);
      LineNr := LineNr + 5;
    end;
    Page.Free;
    if PickTreeExec(Address) then
      AnalyzeMoviePage(Address, Code);
  end;
end;

procedure AnalyzeMoviePage(Address: string; Code: string);
var
  Page: TStringList;
  Comments: string;
  strTitle: string;
  strSinopsis: string;
  strLength: string;
  Line: string;
  LineNr: Integer;
  BeginPos, EndPos: Integer;
  EndSinopsis: Integer;
begin
  Page := TStringList.Create;
  Page.Text := StringReplace(GetPage(Address), '<br>', #13#10);
  strTitle := GetValueAfter(Page.GetString(1), 'Titulo = ');
  if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then
  begin
    SetField(fieldTranslatedTitle, copy(strTitle, 1, Length(strTitle) -1 ));
  end else
  begin
    SetField(fieldTranslatedTitle, strTitle);
  end;
  SetField(fieldOriginalTitle, GetValueAfter(Page.GetString(2), 'Titulo original = '));
  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
  SetField(fieldDescription, 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 = '), False);
  Page.Free;
  Page := TStringList.Create;
  Page.Text := StringReplace(GetPage('http://www.culturalianet.com/art/ver.php?art=' + Code), '<br>', #13#10);
  LineNr := FindLine('>Duración:</font> ', Page, 0);
  strLength := Page.GetString(LineNr);
  EndPos := pos(' minutos.', strLength);
  BeginPos := pos('Duración:</font> ', strLength) + 17;
  strLength := copy(strLength, BeginPos, EndPos - BeginPos);
  SetField(fieldLength, strLength);
  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
  if CheckVersion(3,4,0) then
  begin
     MovieName := GetField(fieldTranslatedTitle);
   if MovieName = '' then
      MovieName := GetField (fieldOriginalTitle);
     if Input('Importar de Culturalia', 'Introduce el Titulo de la Pelicula:', MovieName) then
           AnalyzePage(BaseURL + '?catalogo=1&texto=' + UrlEncode(MovieName) + '&donde=3');
  end else
     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.

"Thanks to Culturalia's webmaster for his help and for providing more direct access to his database."

This direct access to database has no the length information, but it is on normal webpage. Now Retrieves everything from the "direct access to database", and after the length from the normal webpage.
There is still more information than can be retrieved from the normal webpage, but I'm not really interested in it. (Premios, Calificacion Moral, Puntuacion...)
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

It would be better to ask the webmaster to add these info to the "direct" page ;)
RedDwarf

Post by RedDwarf »

I'm still waiting for an answer :(
PT

RE: Update of Culturalia

Post by PT »

Thanks for this cool update. It works fine. Buy I have found one problem that occurs in both the original and your update. The problem is that sometimes the query gets back a page with a double <br> before picture and URL data and sometimes only one. Try with the information for the film "El informe pelicano", for example: (http://www.culturalianet.com/bus/catalo ... odigo=1697)

I have solved the problem replacing the line:

Page.Text := StringReplace(GetPage(Address), '<br>', #13#10);

with this:

Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10);
Page.Text := StringReplace(Page.Text, '<br>', #13#10);

There is another problem with the characters ", ' and <b> </b> of the description field, that appears bad. I have solved replacing the line of SetField(fieldDescription... with this:

SetField(fieldDescription, StringReplace(StringReplace(StringReplace(StringReplace(strSinopsis, '“', '"'), '”', '"'),'<b>', ''), '</b>', ''));

It isn't very elegant but it works.

Thanks again for your work.
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

To remove the HTML tags (b and /b) you can also use the HTMLRemoveTags procedure :

Code: Select all

  HTMLRemoveTags(strSinopsis);
  SetField(fieldDescription, StringReplace(StringReplace(strSinopsis, '“', '"'), '”', '"'));
Guest

Post by Guest »

The double <br> only makes that to the description field to have a extra empty line, correct? Or there is another problem with this I have not saw?
Anyway, you correction should eliminate any problem with this.

The problem with “ and ” is that the program uses a font that don't have these characters, but next version will show them.

There is any option to support bold, italic and "subrayado" (put a line under the text :p) in the next version, antp?
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

Hi PT !

I don't have that problem with "El Informe Pelicano" in the culturalia script that i modified in this thread viewtopic.php?t=743

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

Post by antp »

Anonymous wrote:
There is any option to support bold, italic and "subrayado" (put a line under the text :p) in the next version, antp?
"underline" :)

No, it will still be a text only thing.
But I'll add a "view as webpage" base on templates (a little like what extreme movie manager does), so if you put HTML in your fields, in this mode you will see these text formatting.
folgui
Posts: 113
Joined: 2003-02-04 19:15:03
Location: Madrid, Spain

Post by folgui »

Good work RedDwarf :grinking:

It works perfectly for me.

Perhaps it would be interesting to obtain ratings (puntuacion). A lot of people use them. Tell me if you're going to work on it, otherwise i'll do it.

Regards, folgui ;)
RedDwarf

Post by RedDwarf »

I rate the movies when I saw them (is a good way to mark them like "viewed" :) ). Anyway I could put them in the script but antp sayed in your post that Culturalia webmaster only wants that the scripts read the "special" webs. Then I will not add anything more from the "normal" web until webmaster says anything else.

I have not still received any response from the webmaster (I wrote him 8 days ago), I have not hope to receive anything now. Who contacted with him the first time? If he can try to contact with the webmaster again...
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Maybe he is on holydays ;)
It is him that contacted me actually, for this special import page.
Maybe I should try to contact him again ?
RedDwarf

Post by RedDwarf »

How many time a web like Culturalia can be up without a webmaster? :)
If I receive an answer I will say here. But perhaps you have more luck...yes, if you can try to contact with him would be of help.

....Or we can wait until enough people starts using this script and the webmaster contacts you again XD
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

RedDwarf wrote: ....Or we can wait until enough people starts using this script and the webmaster contacts you again XD
That's maybe not the best solution :D
I'll wait 1 more week, then I'll contact him
Post Reply