Update Animerate(ES) v.1.1

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
legrad
Posts: 109
Joined: 2006-02-11 09:46:06
Location: Lerida-Spain

Update Animerate(ES) v.1.1

Post by legrad »

Problem when copy into the forum.
The post change the characters.
in previous post change the string on line 57
change this &#39 for is '
then the script not run

Solucionado


Code: Select all

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

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

[Infos]
Authors=Legrad
Title=Animerate(ES)
Description=cine
Site=www.animerate.net
Language=es
Version=1.1
Requires=3.5.0
Comments=
License=
GetInfo=1

[Options]

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

 program Animerate;

var
  MovieName: string;
  MovieURL: string;
  //---------------------------------------
function UpFirstLetterWord(texto:string):string;
var espaco:integer;
sst:string;
begin
texto:=AnsiUpFirstLetter(AnsiLowerCase(texto));
repeat
    espaco:=Pos(' ',texto);
    sst:=AnsiUpperCase(Copy(texto,espaco+1,1));

texto:=Copy(texto,1,espaco-1)+'/|\'+sst+Copy(texto,espaco+2,length(texto));
until Pos(' ',texto)=0;
texto := StringReplace(texto, '/|\', ' ');
if Copy(texto,1,1)=' ' then
  texto:=Copy(texto,2,length(texto));
result:=texto;
end;
//------------------------------------------------------------------------------------
function BorraComillas(var S: string): string;
var
   n,len, tag: Integer;
   c: char;
   t: String;
begin
   tag := 0;
   t := '';
   len := length(s);
   for n :=1 to len do
   begin
     c := Copy(s,n,1);
     // quitamos las comillas
     if c = '''' then
        c := ' ';
        t := t + c;
   end
   s := t;
   result := t;
end;
//---------------------------------------------------------------------
function Acentos(str1: string) :string;
begin
          str1 := StringReplace(str1, 'Ö' , 'Ö');
          str1 := StringReplace(str1, 'ö' , 'ö');
          str1 := StringReplace(str1, 'Ã￾' , 'À');
          str1 := StringReplace(str1, 'É' , 'É');
          str1 := StringReplace(str1, 'é' , 'é');
          str1 := StringReplace(str1, 'Ã￾', 'Í');
          str1 := StringReplace(str1, 'Ó' , 'Ó');
          str1 := StringReplace(str1, 'Ñ' , 'Ñ');
          str1 := StringReplace(str1, 'á' , 'à');
          Str1 := StringReplace(Str1, ''', '');
          Str1 := StringReplace(Str1, 'Ñ©', 'é');
          Str1 := StringReplace(Str1, '&', '&');
          Str1 := StringReplace(Str1, 'ó', 'ó');
          Str1 := StringReplace(Str1, 'Ú', 'ú');
          Str1 := StringReplace(Str1, 'ë', 'ë');
          Str1 := StringReplace(Str1, '-', ' ');
          Str1 := StringReplace(Str1, '()', '');
          Str1 :=UpFirstLetterWord(Str1);
result := str1;
end;

//------------------------------------------------------------------
                              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 TextBetween(var S: string; StartTag: string; EndTag: string): string;
var
  InitialPos: Integer;
begin
  InitialPos := Pos(StartTag, S);
  if InitialPos = 0 then
    result := ''
  else
  begin
    Delete(S, 1, InitialPos + Length(StartTag) - 1);
    InitialPos := Pos(EndTag, S);
    if InitialPos = 0 then
      result := S
    else
    begin
      result := copy(S, 1, InitialPos - 1);
      Delete(S, 1, InitialPos + 1);
    end;
  end;
end;

//------------------------------------------------------------------------------------
                               function DeleteTags(var S: string): string;
var
   n,len, tag: Integer;
   c: char;
   t: String;
begin

   tag := 0;
   t := '';
   len := length(s);

   for n :=1 to len do
   begin
      c := Copy(s,n,1);


      if c = #9 then
         c := ' ';

      if(tag=1) then
      begin
         if(c='>') then tag := 0;
         continue;
      end
      else
      begin
         if(c='<') then
         begin
            tag := 1;
            continue;
         end;
         t := t + c;
      end;
   end
   s := t;
   result := t;
end;


//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
  strPage, MovieAddr, MovieTitle, MovieDate, MovieID, Movie: string;
  BeginPos, EndPos: Integer;
  BeginPoss, EndPoss: Integer;
begin
  strPage := GetPage(Address);
  BeginPos := Pos('rowheader', strPage);
  if(BeginPos > -1)then
    begin
      PickTreeClear;
      Delete(strPage, 1, BeginPos);
      BeginPos := Pos('align="absmiddle"> <a href=', strPage);
      EndPos := 1;
      while ((BeginPos > 0) and (EndPos > 0)) do

        begin
          Delete(strPage, 1, BeginPos);
          EndPos := Pos('><b>', strPage);
          MovieId := Copy(strPage,+27, EndPos-27);
          MovieId := BorraComillas(MovieId);
          MovieAddr := 'http://www.animerate.net/' + MovieId;
          MovieAddr := StringReplace (MovieAddr,' ','');
          BeginPoss := Pos('href=',strPage);
          EndPoss := Pos('</td>', strPage);
          MovieTitle := Copy(strPage,BeginPoss, EndPoss);
          DeleteTags(MovieTitle);
          MovieTitle := TextBetween (MovieTitle, '>', '</a>');
          MovieTitle := Acentos(MovieTitle);
          PickTreeAdd(MovieTitle,  MovieAddr);
          BeginPos := Pos('align="absmiddle"> <a href=', strPage);
          if(Pos('</body>', strPage) < BeginPos) then
           BeginPos := -1;
        end;

    end;
    PickTreeExec(Address)
    AnalyzeMoviePage(Address);
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
  Page: TStringList;
  LineNr: Integer;
  Line: string;
  Item: string;
  Comments: string;
  Actors: string;
  Directors: string;
  Description: string;


begin
  Comments := '';
  Description := '';

  // URL
  SetField(fieldURL, Address);

  Page := TStringList.Create;
  Page.Text := GetPage(Address);

  // Traducido
  LineNr := FindLine('<strong> Anime: ', Page, 0);
  Line := Page.GetString(LineNr);
  Item := TextBetween (Line, '<strong> Anime: ', '</strong>');
  Item :=UpFirstLetterWord(Item);
  HTMLDecode(Item);
  SetField(fieldTranslatedTitle, Trim (Item));

  // Original
  //LineNr := FindLine('<td class="animeinfos" width="80%"  valign="top">', Page, 0);
  //if LineNr <> -1 then
  //begin
    //Line := Page.GetString(LineNr);
    //Item := TextBetween (Line, '<td class="animeinfos" width="80%"  valign="top">', '<tr>');
    //DeleteTags (Item);
    //HTMLDecode(Item);
    //Item :=UpFirstLetterWord(Item);
    //SetField(fieldOriginalTitle, Trim (Item));
  //end;
  // Género
  LineNr := FindLine('<b>Géneros:</b></td>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Géneros:</b></td>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'valign="top">', '</td>');
    Item := StringReplace(Item , #13#10, '');
    Item  := StringReplace(Item , '   ', '');
    DeleteTags (Item);
    Item   := AnsiUpFirstLetter(Item );
    Item  := Trim(Item );
    SetField(fieldCategory, Trim (Item));
  end;
  // Autor
  LineNr := FindLine('<b>Autor:</b></td>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Autor:</b></td>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'valign="top">', '<tr>');
    Item := StringReplace(Item , #13#10, '');
    Item  := StringReplace(Item , '   ', '');
    DeleteTags (Item);
    Item   := AnsiUpFirstLetter(Item );
    Item  := Trim(Item );
    SetField(fieldDirector, Trim (Item));
  end;
  // Productor
  LineNr := FindLine('<b>Estudio:</b></td>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Estudio:</b></td>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'valign="top">', '</td>');
    Item := StringReplace(Item , #13#10, '');
    Item  := StringReplace(Item , '   ', '');
    DeleteTags (Item);
    Item   := AnsiUpFirstLetter(Item );
    Item  := Trim(Item );
    SetField(fieldProducer, Trim (Item));
  end;
  // Año
  LineNr := FindLine('<b>Año:</b>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Año:</b>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'valign="top">', '</td>');
    Item := StringReplace(Item , #13#10, '');
    Item  := StringReplace(Item , '   ', '');
    DeleteTags (Item);
    Item  := Trim(Item );
    SetField(fieldYear, Trim (Item));
  end;
  // Sinopsis
  LineNr := FindLine('<b>Sinopsis:</b>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Sinopsis:</b>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, '<br>', '</div>');
    Item := StringReplace(Item , #13#10, '');
    Item  := StringReplace(Item , '   ', '');
    DeleteTags (Item);
    Item  := Trim(Item );
    SetField(fieldDescription, Trim (Item));
  end;
  // Sinopsis2
  LineNr := FindLine('aportar_sinopsis.php', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('aportar_sinopsis.php',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'value="   ', '   ">');
    Item := StringReplace(Item , #13#10, '');
    Item  := StringReplace(Item , '   ', '');
    Item  := StringReplace(Item , 'Aporta una sinopsis en Español', 'No hay sinopsis en la pagina,lo sentimos.');
    DeleteTags (Item);
    Item  := Trim(Item );
    SetField(fieldDescription, Trim (Item));
  end;
    // Comentario1
  LineNr := FindLine('<b>Titulos Alternos:', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Titulos Alternos:',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'valign="top">', '</td>');
    DeleteTags (Item);
    Item  := Trim(Item );
    Item  := StringReplace(Item , ';&#', '');
    Item  := StringReplace(Item , '0', '');
    Item  := StringReplace(Item , '1', '');
    Item  := StringReplace(Item , '2', '');
    Item  := StringReplace(Item , '3', '');
    Item  := StringReplace(Item , '4', '');
    Item  := StringReplace(Item , '5', '');
    Item  := StringReplace(Item , '6', '');
    Item  := StringReplace(Item , '7', '');
    Item  := StringReplace(Item , '8', '');
    Item  := StringReplace(Item , '9', '');
    Item  := StringReplace(Item , '#', '');
    Item  := StringReplace(Item , ';Z', '');
    Item  := StringReplace(Item , ';', '');
    Item  := StringReplace(Item , '&', '');
    Item  := StringReplace(Item , '  , ', '');
    Comments := Comments + 'Título alternativo: ' + Item + #13#10;
  end;
  // Comentario2
  LineNr := FindLine('<b>Formato:</b>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Formato:</b>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'valign="top">', '</td>');
    DeleteTags (Item);
    Item  := Trim(Item );
    HTMLDecode(Item);
    Comments := Comments + 'Formato: ' + Item + #13#10;
  end;

  // Comentario3
  LineNr := FindLine('<b>Episodios:</b>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>Episodios:</b>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, ' valign="top">', '</td>');
    DeleteTags (Item);
    Item  := Trim(Item );
    HTMLDecode(Item);
    Comments := Comments + 'Episodios: ' + Item + #13#10;
  end;
  // Comentario4
  LineNr := FindLine('<b>URL:</b></td>', Page, 0);
  if LineNr > 0 then
  begin
    Item := copy(Page.Text, pos('<b>URL:</b></td>',Page.Text), length(Page.Text));
    Item := TextBetween (Item, 'class=base>', '</a></td>');
    DeleteTags (Item);
    Item  := Trim(Item );
    HTMLDecode(Item);
    Comments := Comments + 'URL: ' + Item + #13#10;
  end;
  // Comentario5
  LineNr := FindLine('<br><div class=base align=center>', Page, 0);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr);
    Item := TextBetween (Line, '<br><div class=base align=center>', '</div>');
    DeleteTags (Item);
    HTMLDecode(Item);
    Comments := Comments + 'Descargas: ' + Item + #13#10;
  end;
    SetField(fieldComments, Comments);

// Picture
  LineNr := FindLine('src="http://www.animerate.net/fotos/anime/', Page, 0);
  if LineNr <> -1 then
  begin
     Line := Page.GetString(LineNr);
     Item := TextBetween (Line, 'src="http://www.animerate.net/fotos/anime/', '" alt');
     GetPicture ('http://www.animerate.net/fotos/anime/'+Item);
  end;
end;
 //-------------------------------------------------------------------------
begin
       if (CheckVersion(3,5,0)=FALSe) then
   begin
      ShowMessage('Se requiere Ant Movie Catalog versión 3.5 o superior');
      exit;
   end;

   MovieName := GetField(fieldTranslatedTitle);
   if MovieName = '' then
            MovieName := GetField(fieldOriginalTitle);
Input('Animerate', 'Buscar:', MovieName);

     if(GetOption('Sin resultado') = 0) then  Input('Animerate', 'Buscar', MovieName);

   AnalyzePage('http://www.animerate.net/buscar.php?words=' + UrlEncode(MovieName));
end.
NeoQueen
Posts: 7
Joined: 2007-02-21 19:10:17
Location: Argentina

Post by NeoQueen »

Funciona perfecto :grinking:

Gracias!!!
Post Reply