[ES] Script for www.labutaca.net

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
micmic
Posts: 24
Joined: 2004-03-21 13:36:45
Location: Mi casa
Contact:

[ES] Script for www.labutaca.net

Post by micmic »

Here it is, the first version

It use Google to find the film, I hope you like it. The picture in the next version :/

Edit: 12.Oct.2004 : picture, year, comments, producer, length ;)
Edit: 17.Dic.2004 : various, picture directory, little errors

Code: Select all

// GETINFO SCRIPTING
// labutaca.net+Google v1.5 by micmic

(***************************************************
 *  Author    : micmic   (micmic@dieznet.com)      *
 *  BetaTester: Macoco   (gracias)                 *
 *                                                 *
 *  Script for the importation of pictures from    *
 *  www.labutaca.net                               *
 *                                                 *
 *  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 labutacaImport;
var
  MovieName: string;
const
  Dominio = 'www.labutaca.net';
  BaseURL1 = 'http://www.google.com/custom?hl=es&ie=ISO-8859-1&cof=&domains=';
  BaseURL2 = '&q=';
  BaseURL3 = '&btnG=B%FAsqueda+en+Google&sitesearch=';

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 EliminaInicio(S: string; CR: string): string;
begin
  result := S;
  while Pos(CR, result) = 1 do
  begin
    Delete(result, 1, Length(CR));
  end;
end;

function SustitucionReiterada(S: string; Buscado: string; Sustituto: string): string;
var
  InicioPos: Integer;
  Longitud: Integer;
  TextoAntes: string;
  TextoDespues : string;
begin
  result := S;
  Longitud := Length(Buscado);
  InicioPos := Pos(Buscado, result);
  while InicioPos > 0 do
  begin
    TextoAntes := copy(result, 1, InicioPos);
    TextoDespues := copy(result, (InicioPos + Longitud), Length(result));
    result := TextoAntes + TextoDespues;
    InicioPos := Pos(Buscado, result);
  end;
end;

function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
var
  InicioPos: Integer;
  S_Aux: string;
begin
  S_Aux := S;

  InicioPos := Pos(StartTag, S_Aux);
  Delete(S_Aux, 1, InicioPos + Length(StartTag) - 1);
  InicioPos := Pos(EndTag, S_Aux);
  result := copy(S_Aux, 1, InicioPos - 1);
  Delete(S_Aux, 1, InicioPos + 1);
end;

procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr: Integer;
  PosIni, PosFin: Integer;
  Line, SubLine: string;
  Title, DirURL: string;
  txtTemp: string;
begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if Pos('No se encontró ninguna página', Page.Text) > 0 then
  begin
    ShowMessage('No se ha encontrado ningún artículo por título.');
  end else
  begin
    PickTreeClear;
    PickTreeAdd('Resultados de la búsqueda para "' + MovieName + '" (' + Dominio + ') por Google:', '');
   
    Page.Text := StringReplace(Page.Text, '<br>', #13#10);
    Page.Text := StringReplace(Page.Text, '<p class=g>', #13#10 + '<p class=g>');

    // buscamos los resultados
    LineNr := 0;

    while LineNr < Page.Count do
    begin
      SubLine := Page.GetString(LineNr);
      txtTemp := '<p class=g><a href=';
      PosIni := pos(txtTemp, SubLine);
      if PosIni > 0 then
      begin
        SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
        txtTemp := '>';
        PosFin := pos(txtTemp, SubLine);
        DirURL := Copy(SubLine, 1, PosFin - 1);
        DirURL := StringReplace(DirURL, '"', '');
       
        SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
        txtTemp := '</a>';
        PosFin := pos(txtTemp, SubLine);
        Title := Copy(SubLine, 1, PosFin - 1);
        HTMLRemoveTags(Title);

        //ShowMessage(Title + '-->' + DirURL);
        PickTreeAdd(Title, DirURL);
      end;
      LineNr := LineNr + 1;
    end;

    Page.Free;
    if PickTreeExec(Address) then
      AnalyzeMoviePage(Address);
  end;
end;

procedure AnalyzeMoviePage(Address: string);
var
  MoviePage: TStringList;
  LineNr: Integer;
  posIni: Integer;
  LineImg: string;
  Line: string;
  valor: string;
  txttemp: string;
begin

  Line := '';
  LineImg := '';

  SetField(fieldURL, Address);
  
  MoviePage := TStringList.Create;
  MoviePage.Text := GetPage(Address);
 
  LineNr := FindLine('<title>', MoviePage, 0);
  Line := MoviePage.GetString(LineNr);
  Line := CadenaEntre(Line, '<title>LA BUTACA - ', '</title>');
  SetField(fieldTranslatedTitle, Line);

  // eliminamos caracteres de saltos de línea y tabulaciones
  // luego eliminamos blancos consecutivos
  MoviePage.Text := StringReplace(MoviePage.Text, #13#10, ' ');
  MoviePage.Text := StringReplace(MoviePage.Text, #9, ' ');
  MoviePage.Text := SustitucionReiterada(MoviePage.Text, '  ', ' ');
  
  Line := MoviePage.Text;
  
  txttemp := 'Ampliar cartel';
  if pos(txttemp, Line) <= 0 then
  begin
    txttemp := 'Dirección';
  end
  if pos(txttemp, Line) > 0 then
  begin
    LineImg := CadenaEntre(Line, '<body>', txttemp);
    Line := CadenaEntre(Line, txttemp, '</body>');
  end
  
  txttemp := 'Dirección:';
  if pos(txttemp, Line) <= 0 then
  begin
    txttemp := 'Dirección y guión:';
  end
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, '<br>');
    HTMLRemoveTags(valor);
    SetField(fieldDirector, Trim(valor));
  end
  
  txttemp := 'País:';
  if pos(txttemp, Line) <= 0 then
  begin
    txttemp := 'Países:';
  end
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, '<br>');
    HTMLRemoveTags(valor);
    SetField(fieldCountry, Trim(valor));
  end

  txttemp := 'Año:';
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, '<br>');
    HTMLRemoveTags(valor);
    SetField(fieldYear, Trim(StringReplace(valor, '.', '')));
  end
  
  txttemp := 'Duración:';
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, ' min');
    HTMLRemoveTags(valor);
    SetField(fieldLength, Trim(valor));
  end

  txttemp := 'Interpretación:';
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, '<br>');
    HTMLRemoveTags(valor);
    SetField(fieldActors, Trim(valor));
  end
  
  txttemp := 'Producción:';
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, '<br>');
    HTMLRemoveTags(valor);
    SetField(fieldProducer, Trim(valor));
  end

  txttemp := 'Música:';
  if pos(txttemp, Line) > 0 then
  begin
    valor := txttemp + CadenaEntre(Line, txttemp, '<strong>SINOPSIS');
    valor := StringReplace(valor, '<br>', #13#10);
    HTMLRemoveTags(valor);
    SetField(fieldComments, Trim(valor));
  end
  
  txttemp := 'SINOPSIS';
  if pos(txttemp, Line) > 0 then
  begin
    valor := CadenaEntre(Line, txttemp, '<hr');
    HTMLRemoveTags(valor);
    SetField(fieldDescription, Trim(valor));
  end
  
  //lo ultimo la imagen
  txttemp := '../../crt/';
  posIni := pos(txttemp, LineImg);
  if posIni <= 0 then
  begin
    txttemp := '../../fotos/';
    posIni := pos(txttemp, LineImg);
  end
  if posIni > 0 then
  begin
    LineImg := copy(LineImg, posIni, Length(LineImg));
    txttemp := 'jpg';
    posIni := pos(txttemp, LineImg);
    LineImg := copy(LineImg, 1, posIni + 2);
    LineImg := EliminaInicio(Lineimg, '../..');
    if LineImg <> '' then LineImg := 'http://' + Dominio + LineImg;
    GetPicture(LineImg, False);
  end
  
  MoviePage.Free;
  DisplayResults;
end;

// bmicmic: Bucle Principal
begin
  if CheckVersion(3,4,0) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);

    Input('Importar de ' + Dominio + ' (por Google)', 'Introduce el Titulo de la Pelicula:', MovieName);
    AnalyzePage(BaseURL1 + Dominio + BaseURL2 + UrlEncode(MovieName) + BaseURL3 + Dominio);

  end else
       ShowMessage('Este script necesita una versión superior de Ant Movie Catalog (al menos la version 3.4.0)');
end.
Last edited by micmic on 2004-12-17 19:28:37, edited 2 times in total.
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

thanks ;)
micmic
Posts: 24
Joined: 2004-03-21 13:36:45
Location: Mi casa
Contact:

Post by micmic »

thanks for you and this great program :grinking:
micmic
Posts: 24
Joined: 2004-03-21 13:36:45
Location: Mi casa
Contact:

Post by micmic »

Version 1.5 is out, code in the first post
Post Reply