Page 1 of 1

FilmAffinity (ES) 3.0.4 + Ecartelera (ES) 1.2

Posted: 2015-09-04 17:44:22
by carlosmg2
Hola,

Tras el cierre de cartelespeliculas me he migrado a E-Cartelera como sustituto para conseguir posters de calidad. He unido estos 2 scripts haciendo un poco de Franquestein porque me gustan las caratulas de "Ecartelera".
Todos los creditos van para sus creadores.

Espero que a alguien le resulte util.
Un saludo

-------------------------------------------

Hello,

I've done a little merge of these 2 scripts with the permission of their Authors. All credits to them. And thanks to Raoul_Volfoni for helping me doing Ecartelera script

Code: Select all

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

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

[Infos]
Authors=aviloria (aviloria@yahoo.com) modded by: rodpedja (rodpedja@gmail.com), kreti (bisoft@hotmail.com), MrK, gilistico, juliojs, Albher, Arturo, jacqlittle, carlosmg2
Title=FilmAffinity (ES) + Ecartelera (ES)
Description=Movie importation script for FilmAffinity Spain + Poster from eCartelera
Site=http://www.filmaffinity.com + http://www.ecartelera.com
Language=ES
Version=3.0.4 + 1.2
Requires=4.2.2
Comments=adaptation for compatibility with 4.2.1 https version. Added Extras capture. Changed Charset ISO-> utf8
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
RequiresMovies=1

[Options]
DontAsk=0|0|1=Método rápido: No te pregunta el titulo al principio, ni te pide confirmar si sólo hay un resultado|0=Método lento: Confirmas la información manualmente
ActorsInALine=0|0|1=Actores separados por comas|0=Actores en lineas independientes
Force350=0|0|1=force the behavior of 3.5.0 version|0=Version auto
DontWantExtras=1|1|1=No se recopilan extras|0=Se recopilan extras: enlaces, imágenes
GroupImages=1|1|1=Agrupa todas las imagenes en una misnma categoría 'Imagenes'|0=Divide las imágenes por categorias
OrdenPorAnyo=1|0|1=Ordena lista de busqueda por año|0=Ordena lista de busqueda por relevancia

[Parameters]
ExtraCriticsLimit=5|99|Límite de criticas en Extras
ExtraImagesLimit=5|99|Límite de imágenes en Extras
ExtraTrailersLimit=5|99|Límite de Trailers en Extras

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

program FilmAffinity;
const
  BaseURL = 'https://www.filmaffinity.com';
var
  MovieName    : string;
  MovieURL     : string;
  MovieYear    : string;

  YearFrom     : string;
  YearTo       : string;

  AdvQuery     : string;

//------------------------------------------------------------------------------------

function LineDecode(S: string):string;
begin
  S:= UTF8Decode(S);
  HTMLDecode(S);
  Result := S;
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;

//------------------------------------------------------------------------------------

//
//  ConvertAlphaNum: Quita todo menos letras (mayusculas y minusculas) y numeros
//

Function ConvertAlphaNum(s: string) : string;
var
  i: Integer;
  s2, ch: string;
begin
  s2 := '';
  For i := 1 To Length(s) do
  begin
    ch := copy(s, i, 1);
    if ((ch >= 'a') and (ch <= 'z')) or ((ch >= '0') and (ch <= '9')) or ((ch >= 'A') and (ch <= 'Z'))  then
    s2 := s2 + ch;
  end;
  result := s2;
end;

//------------------------------------------------------------------------------------

function TextBetween(S: string; StartTag: string; EndTag: string): string;
var
  ini, fin, lenS: Integer;
begin
  Result := '';
  lenS := Length(S);
  ini := Pos(StartTag, S);
  if ini <> 0 then
  begin
    ini := ini + Length(StartTag);
    S:= Copy(S,ini,lenS-ini+1);
    ini:=1;
    fin := Pos(EndTag, S);
    if (fin <> 0) and (fin > ini) then
    Result := Copy(S, ini, fin - ini);
  end;
end;

//------------------------------------------------------------------------------------

function TextAfter(S: string; StartTag: string): string;
var
  ini: Integer;
begin
  ini := Pos(StartTag, S);
  if ini <> 0 then
  Result := Copy(S, ini + Length(StartTag), Length(S)-ini+1)
  else
  Result := '';
end;

//------------------------------------------------------------------------------------

function DeleteTags(S: string): string;
var
  n, len, tag: Integer;
  c, p: char;
begin
  len    := Length(S);
  tag    := 0;
  p      := ' ';
  Result := '';
  for n := 1 to len do
  begin
    c := Copy(S,n,1);

      // Eliminamos los tabuladores
    if c = #9 then c := ' ';

      // Los espacios redundantes no se procesan
    if (c <> ' ') or (p <> ' ') then
    begin
         // Eliminamos los tags de HTML
      if tag = 0 then
      begin
        if c <> '<' then
        begin
          Result := Result + c;
          p := c;
        end
        else tag := 1;
      end
      else if c = '>' then tag := 0;
    end;
  end
  if p = ' ' then Result := Copy(Result, 1, Length(Result) - 1);
end;

//------------------------------------------------------------------------------------

function Occurrences(Subtext: string; Text: string): integer;
var
  offset: Integer;
begin
  result := 0;
  while true do
  begin
    offset := Pos(Subtext, Text);
    if offset = 0 then break;
    Result := Result + 1;
    Text := TextAfter(Text, Subtext);
  end;
end;


//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

// FUNCIONES DE ECARTELERA

//
// Función que suprime los acentos
//

function Sinacento(Conacento : String): String;

var
  Acento, Noacento : String;
  i : integer;
begin
  Acento := 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿ';
  Noacento := 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuy';
 for i := 1  to Length(Acento) do
    Conacento := StringReplace(Conacento,copy(Acento, i, 1),copy(Noacento, i, 1));
  result := Conacento;
end;

//
// Función para convertir a ascii
//

function Caracter(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 := 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 , '&#8220;' , '"'  );
  str1 := StringReplace(str1 , '&#8221;' , '"'  );
  str1 := StringReplace(str1 , '&#8217;' , '''' );
  str1 := StringReplace(str1 , '&#8216;' , '''' );
  str1 := StringReplace(str1 , '&'   , '&'  );
  str1 := StringReplace(str1 , '&#8211;' , '-'  );
  str1 := StringReplace(str1 , '&'  , '&'  );
  str1 := StringReplace(str1 , '&#8243;' , '"'  );
  str1 := StringReplace(str1 , '&#8230;' , '...');
  str1 := StringReplace(str1 , '&nbsp;' , '');
//Str1 := Sinacento (Str1);
  result := str1;

end;

//
// Funcion que borra signos y quita acentos
//

function PreparaTitulo(T: string): string;

var
  i: Integer;

begin
  HTMLDecode(result);
  result := AnsiLowerCase(T);
  result := StringReplace(result, chr(146), '');
  result := StringReplace(result, chr(39), '');
  result := StringReplace(result, '´', '');
  result := StringReplace(result, '`', '');
  result := StringReplace(result, '"', '');
  result := StringReplace(result, '¿', '');
  result := StringReplace(result, '?', '');
  result := StringReplace(result, '¡', '');
  result := StringReplace(result, '!', '');
  result := StringReplace(result, '.', '');
  result := StringReplace(result, ':', '');
  result := StringReplace(result, ';', '');
  //result := StringReplace(result, '-', '');
  result := StringReplace(result, '/', '');
  result := StringReplace(result, '\', '');
  result := StringReplace(result, '_', '');
  result := StringReplace(result, 'á', 'a');
  result := StringReplace(result, 'Á', 'a');
  result := StringReplace(result, 'À', 'a');
  result := StringReplace(result, 'é', 'e');
  result := StringReplace(result, 'í', 'i');
  result := StringReplace(result, 'ó', 'o');
  result := StringReplace(result, 'ú', 'u');
  result := StringReplace(result, 'ä', 'a');
  result := StringReplace(result, 'ë', 'e');
  result := StringReplace(result, 'ï', 'i');
  result := StringReplace(result, 'ö', 'o');
  result := StringReplace(result, 'ü', 'u');
  result := StringReplace(result, '–', '-'  );
  result := StringReplace(result, '…', '...');
  result := Caracter (result);
end;


// PROCEDIMIENTOS DE ECARTELERA

//
// Crea la lista de las peliculas que contengan el titulo introducido
//

procedure PaginasEcartelera (Titulo: string);

var
  CPPage : TStringList;
  Line, PageWeb, TitleWeb, Encontrado, SwFin, TitleWebSin, Any, PageWebList : string;
  LineNr, ContPagina, i, j, PosAny : Integer;

begin
    Encontrado := '0';                     						// Si encontrado = '0' es que no se encuentra la pelicula
    PickTreeClear;
																// Se crea la URL para ver todas las peliculas que contengan el texto introducido
    //PageWeb := PostPage('http://www.ecartelera.com/buscar/', 'campo=' + UrlEncode(UTF8Encode(Titulo)) + '&B1=Buscar');

    //PageWeb := PostPage('https://www.ecartelera.com/buscar/', 'ajcbus=' + URLEncode(UTF8Encode(Titulo)));
    
    PageWeb := GetPage('https://www.ecartelera.com/buscar/?q=' + URLEncode(UTF8Encode(Titulo)));
    
    CPPage := TStringList.Create;
    CPPage.Text := PageWeb;  //GetPage(PageWeb);
    CPPage.Text := Caracter (CPPage.Text);
    LineNr := 1;
    SwFin := '0';
    ContPagina := 1;

	Repeat                                                          // Para cada pelicula que contenga el texto mira a ver si coincide con el titulo
		If FindLine ('<div class="fl-item">' , CPPage , LineNr) > 0 then
        begin
            LineNr := FindLine ('<div class="fl-item">' , CPPage , LineNr);
            LineNr := FindLine('<img src="', CPPage, LineNr);
            Line  := CPPage.GetString(LineNr);

            PageWebList := 'https://www.ecartelera.com' + TextBetween (Line, '<img src="' , '"');        //caratula mini
            PageWebList := StringReplace(PageWebList,'_mini','');                                        //caratula grande
            PageWebList := StringReplace(PageWebList,'_p','');

            LineNr := FindLine('<p class="tit">', CPPage, LineNr);
            Line := CPPage.GetString(LineNr);

            TitleWeb := TextBetween (Line, '/">' , '</a></p>');          		// Extrae el titulo
            TitleWebSin := Sinacento(Titleweb);
            Titulo := UrlDecode (Titulo);
            TitleWebSin  := PreparaTitulo(TitleWebSin);

            //if Pos(AnsiLowerCase(Titulo), TitleWebSin) > 0 then                 // Verifica si el titulo de la web coincide con el texto
            //  begin
            LineNr := LineNr - 3;
            Line  := CPPage.GetString(LineNr);

    				Any := TextBetween (Line, '="year"><span>' , '</span></p>');                 //conseguir el año
    				Any := ' (' + Any + ')';

            PickTreeAdd(TitleWeb + Any, PageWebList);                   // Añade el titulo, año y direccion de la caratula
            Encontrado := '1';

        end

        else
        begin
			   SwFin := '1';
        end

    until (SwFin = '1');

    if (Encontrado = '1') then
		begin

			PickTreeSort;

			if PickTreeExec(PageWebList) then                                    // Selecciona que nos interese y va a buscar la caratula
				begin
					//AnalyzeCoverPage (PageWeb); 							// Muestra los carteles seleccionados
					Getpicture (PageWebList);
				end
		end
	else
     ShowMessage('Titulo ' + Titulo + ' no encontrado en ecartelera');

end;

//
// CARATULA
//
//Accede a la web para extraer la caratula, Primero va a una web intermedia y despues accede a la caratula
//

(*procedure AnalyzeCoverPage(PageWeb: string);

var
   Page: TStringList;
   LineNr : Integer;
   Line : string;

begin
	Page := TStringList.Create;
	PageWeb := PageWeb + 'carteles/';                                 // Accede a la Web donde están todas las caratulas
	Page.Text := getPage(PageWeb);
	RemovePicture;
	LineNr := 1;

    LineNr := FindLine('title="Cartel Espa', Page, LineNr);
    If FindLine ('title="Cartel Espa' , Page , LineNr) > 0 then
		begin
			Line  := Page.GetString(LineNr);
			PageWeb := TextBetween (Line, '<a href="' , '" title'); 		// Forma la Web donde esta la caratula

			Page.Free
			Page := TStringList.Create;                                         // Accede a la Web intermedia
			Page.Text := GetPage(PageWeb);
			LineNr := 1;
			LineNr := FindLine('class="fotoa"', Page, LineNr);
			If FindLine ('class="fotoa"' , Page , LineNr) > 0 then
				begin
					LineNr := LineNr + 1;
					Line := Page.GetString(LineNr);
					PageWeb := TextBetween (Line, 'img src="' , '" />'); 		// Forma la Web donde esta la caratula

					Getpicture (PageWeb);										// Envía la caratula al programa.
				end
		end
	else 														//si no hay caratula española asi que cogemos la primera que haya
		begin
			LineNr := FindLine('title="Cartel ', Page, LineNr);
			If FindLine ('title="Cartel ' , Page , LineNr) > 0 then
				begin
					Line  := Page.GetString(LineNr);
					PageWeb := TextBetween (Line, '<a href="' , '" title'); 		// Forma la Web donde esta la caratula
					Page.Free
					Page := TStringList.Create;                                         // Accede a la Web intermedia
					Page.Text := GetPage(PageWeb);
					LineNr := 1;
					LineNr := FindLine('class="fotoa"', Page, LineNr);
					If FindLine ('class="fotoa"' , Page , LineNr) > 0 then
						begin
							LineNr := LineNr + 1;
							Line := Page.GetString(LineNr);
							PageWeb := TextBetween (Line, 'img src="' , '" />'); 		// Forma la Web donde esta la caratula

							Getpicture (PageWeb);										// Envía la caratula al programa.
						end
					else
						ShowMessage('Titulo no encontrado en ecartelera')
				end
		end

end;
*)
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------

procedure AnalyzeAdvPage(Address: string);
var
  Page: TStringList;
  LineNr,LineNrax,NextPageNr,Pages: Integer;
  Line, PageNr: string;
  Count: Integer;
  MovieTitle, MovieAddress, MovieDirector, Title: string;
  YearAnt: string;
  PagSig:String;

begin
  Count := 0;
  Page  := TStringList.Create;
  Page.Text := GetPage(Address);
  PickTreeClear;
   // Get how much search results have been found

  LineNr := FindLine('<div class="float-right"><b>', Page, 0);
  Count := StrToInt(TextBetween(Page.GetString(LineNr),'<div class="float-right"><b>','</b>' ),0);

  if LineNr <> -1 then
   // Add the results to the PickTree
  if Count = 0 then
  ShowMessage('No se ha encontrado ningún registro')
  else
  begin
    PageNr := '';
    LineNr := 0;
    while true do
    begin
      LineNr := FindLine('<div class="mc-title"><a', Page, LineNr + 1);
      if LineNr = -1 then
      begin

        LineNr := FindLine('<span class="current">', Page, 0);
        if LineNr = -1 then
        break;
        Line := Page.GetString(LineNr);

        Pages := Occurrences('<a href="advsearch.php?page=', Line);
        PageNr := TextBetween(Line, '<span class="current">', '</span>');

        if StrToInt(PageNr, 0) = Pages then
        break;

        NextPageNr := StrToInt(PageNr, 0) + 1;
        PagSig:= 'https://www.filmaffinity.com/es/advsearch.php?page=' + IntToStr(NextPageNr) + '&stext=' + TextBetween(Line, '&stext=', '">');

        PagSig:=StringReplace(PagSig,'&','&');
        Page.Text := GetPage(PagSig);

        LineNr    := 0;
        continue;

      end;

      Line         := Page.GetString(LineNr);
      MovieAddress := TextBetween(Line, 'href="', '.html"') + '.html';
      MovieTitle   := TextBetween(Line, 'title="', '"');
      MovieTitle   := DeleteTags(MovieTitle);
      MovieTitle   := LineDecode(MovieTitle);

         //-------------------------------------

      MovieYear := TextBetween(Line, '</a> (', ') <img src="/imgs/countries/');
      if MovieYear = '' Then MovieYear := YearAnt
      else YearAnt := MovieYear;

      Line:= Page.GetString(LineNr-9);

          //------------------------------------

      LineNrax := FindLine('div class="mc-director">', Page, LineNr);
      if LineNrax <> -1 then
      begin
        Line:= Page.GetString(LineNrax+1);
        MovieDirector:= TextBetween(Line, 'title="', '"');
        MovieDirector:= DeleteTags(MovieDirector);
        MovieDirector:= LineDecode(MovieDirector);
      end;
         //------------------------------------
      if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then
      PickTreeAdd(MovieTitle+'     ('+MovieYear+')'+'        -<'+MovieDirector+'>-', BaseURL + MovieAddress);
    end;
    if ((Count = 1) and (GetOption('DontAsk') = 1)) then
    AnalyzeMoviePage(BaseURL + MovieAddress)
    else
    begin

//
//         PickTreeSort;      // Si se quiere clasificar por orden alfabetico hay que activar el PickTreeSort, quitar las 2
//                            // las 2 barras "//" que hay a la izquierda la instrucción PickTreeSort y ya esta.
//
      PickTreeExec(Address);
      AnalyzeMoviePage(Address);

      Title := GetField(fieldTranslatedTitle);
      if Title = '' then
		    Title := GetField(fieldOriginalTitle);
		    Title := PreparaTitulo(Title);
      if Input('Importar de eCartelera', 'Por favor, introduce el titulo:', Title) then
		    PaginasEcartelera(Title);

    end
  end;
  Page.Free;
end;

//------------------------------------------------------------------------------------

procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr,LineNrax: Integer;
  Line: string;
  Count: Integer;
  MovieTitle, MovieAddress, MovieDirector, MovieYear, Title: string;
  YearAnt: string;
  PagSig:String;

begin
  Count := 0;
  Page  := TStringList.Create;
  Page.Text := GetPage(Address);
  PickTreeClear;
   // Get how much search results have been found

   // No encuentra las palabras "Resultados por título"¿?, busco la
   // linea anterior, y cojo la siguiente linea, le quito los espacios
   // y me quedo con el numerode peliculas.

  LineNr := FindLine('<div class="sub-header-search">', Page, 0);
  if LineNr <> -1 then
  begin
    LineNr := LineNr + 1;
    Line   := Page.GetString(LineNr);
    Line   := DeleteTags(Line);
    Line   := ConvertAlphaNum(Line);
    Count  := StrToInt(Line, 0);
  end;
   // Add the results to the PickTree
  if Count = 0 then
  ShowMessage('No se ha encontrado ningún registro')
  else
  begin
    LineNr := 0;
    while true do
    begin
      LineNr := FindLine('<div class="mc-title"><a', Page, LineNr + 1);
      if LineNr = -1 then
      begin
        LineNr := FindLine('siguientes >>', Page, 0);
        if LineNr = -1 then
        break;
        Line      := Page.GetString(LineNr);

        PagSig:=  'https://www.filmaffinity.com/es/search.php' + TextBetween(Line, '<a href="search.php', '"><div class="' );
        PagSig:=StringReplace(PagSig,'&','&');
        Page.Text := GetPage(PagSig);

        LineNr    := 0;
        continue;
      end;

      Line         := Page.GetString(LineNr);
      MovieAddress := TextBetween(Line, 'href="', '.html"') + '.html';
      MovieTitle   := TextBetween(Line, 'title="', '"');
      MovieTitle   := DeleteTags(MovieTitle);
      MovieTitle   := LineDecode(MovieTitle);

         //-------------------------------------

      Line:= Page.GetString(LineNr-9);
      MovieYear := TextBetween(Line, 'ye-w">', '</div>');
      if MovieYear = '' Then MovieYear := YearAnt
      else YearAnt := MovieYear;

          //------------------------------------

      LineNrax := FindLine('div class="mc-director">', Page, LineNr);
      if LineNrax <> -1 then
      begin
        Line:= Page.GetString(LineNrax+1);
        MovieDirector:= TextBetween(Line, 'title="', '"');
        MovieDirector:= DeleteTags(MovieDirector);
        MovieDirector:= LineDecode(MovieDirector);
      end;
         //------------------------------------
      if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then
      PickTreeAdd(MovieTitle+'     ('+MovieYear+')'+'        -<'+MovieDirector+'>-', BaseURL + MovieAddress);
    end;
    if ((Count = 1) and (GetOption('DontAsk') = 1)) then
    AnalyzeMoviePage(BaseURL + MovieAddress)
    else
    begin

//
//         PickTreeSort;      // Si se quiere clasificar por orden alfabetico hay que activar el PickTreeSort, quitar las 2
//                            // las 2 barras "//" que hay a la izquierda la instrucción PickTreeSort y ya esta.
//
      PickTreeExec(Address);
      AnalyzeMoviePage(Address);

	  Title := GetField(fieldTranslatedTitle);
      if Title = '' then
		Title := GetField(fieldOriginalTitle);
		Title := PreparaTitulo(Title);
      if Input('Importar de eCartelera', 'Por favor, introduce el titulo:', Title) then
		PaginasEcartelera(Title);

      end
   end;
   Page.Free;
end;

//------------------------------------------------------------------------------------

procedure AnalyzeMoviePage(Address: string);
var
  Page: TStringList;
  LineNr, LineInc: Integer;
  Line: string;
  Item: string;
  Comments: string;
  CharStar: string;
  auxItem: string;
begin
  Comments := '';

   // URL
  SetField(fieldURL, Address);

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

   // Translated Title
  LineNr := FindLine('<h1 id="main-title">', Page, 0);
  Line   := Page.GetString(LineNr+1);
  Item   := DeleteTags(TextBetween(Line, '<span itemprop="name">', '</span>'));
  Item   := LineDecode(Item);
  SetField(fieldTranslatedTitle, Item);

   // Picture
  LineNr := FindLine('href="https://pics.filmaffinity.com/', Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr);
    Item := TextBetween(Line, '<a class="lightbox" style="display: block;" href="', '" title="');
    if Length(Item) = 0 then
    Item := TextBetween(Line, '" src="', '"></a>');
    Item := StringReplace(Item,'https://','http://');
    GetPicture(Item);
  end;

   // Rating
  LineNr := FindLine('<div id="movie-rat-avg" itemprop="ratingValue"', Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(Line);
    Item := LineDecode(Item);
    SetField(fieldRating, StringReplace(Item, ',', '.'));
  end;

   // Original Title
  LineNr := FindLine(UTF8Encode('<dt>Título original</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);

      // Eliminar aka
    if Pos('>aka <',Line) <>0 then
    Line:= StringReplace(Line,'>aka <','');

    Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
    Item := LineDecode(Item);
    if Length(Item) = 0 then
    begin
      Line := Page.GetString(LineNr + 2);

      // Eliminar aka
      if Pos('>aka <',Line) <>0 then
      Line:= StringReplace(Line,'>aka <','');

      Item := DeleteTags(Line);
      Item := LineDecode(Item);
    end;
    SetField(fieldOriginalTitle, Item);
  end;

   // Year
  LineNr := FindLine(UTF8Encode('<dt>Año</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(TextBetween(Line, '">', '</dd>'));
    Item := LineDecode(Item);
    SetField(fieldYear, Item);
  end;

   // Length
  LineNr := FindLine(UTF8Encode('<dt>Duración</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(TextBetween(Line, 'duration">', 'min.</dd>'));
    Item := LineDecode(Item);
    SetField(fieldLength, Item);
  end;

   // Country
  LineNr := FindLine(UTF8Encode('<dt>País</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(TextBetween(Line, 'title="', '"></span'));
    Item := LineDecode(Item);
    SetField(fieldCountry, Item);
  end;

   // Director
  LineNr := FindLine(UTF8Encode('class="directors">'), Page, LineNr);
  if LineNr <> -1 then
  begin
    LineNr := LineNr + 3;
    Line := Page.GetString(LineNr);
    Item := TextBetween(Line,'"name">','</span>');
    while Pos (',', Line) <> 0 do
    begin
      Item := Item + ', ';
      LineNr := LineNr + 3;
      Line := Page.GetString(LineNr);
      auxItem := TextBetween(Line,'"name">','</span>');
      Item := Item + auxItem;
    end;
    Item := LineDecode(Item);
    SetField(fieldDirector, Item);
  end;

   // Script writer
  LineNr := FindLine(UTF8Encode('<dt>Guion</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := TextBetween(Line, '<span>', '</span>');
    Item := LineDecode(Item);
    if ((CheckVersion(4,2,0) = true) and (GetOption('Force350') = 0)) then SetField(fieldWriter, Item)
    else   Comments := Comments + 'Guión: ' + Item + #13#10 + #13#10;
  end;

   // Composer
  LineNr := FindLine(UTF8Encode('Música'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := TextBetween(Line, '<span>', '</span>');
    Item := LineDecode(Item);
    if ((CheckVersion(4,2,0) = true) and (GetOption('Force350') = 0)) then SetField(fieldComposer, Item)
    else Comments := Comments + 'Música: ' + Item + #13#10 + #13#10;
  end;

   // Photography
  LineNr := FindLine(UTF8Encode('<dt>Fotografía</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := TextBetween(Line, '<span>', '</span>');
    Item := LineDecode(Item);
    Comments := Comments + 'Fotograf&iacute;a: ' + Item + #13#10 + #13#10;
  end;

   // Actors
  LineNr := FindLine(UTF8Encode('<dt>Reparto</dt>'), Page, LineNr);
  if LineNr <> -1  then
  begin
    Item := '';
    while true do
    begin
      LineNr := FindLine('itemprop="name">', Page, LineNr);

      if LineNr = -1 then break;
      begin
        if Item <> '' Then Item := Item + ', ';
        Line := Page.GetString(LineNr);
        Item := Item + TextBetween(Line, 'name">', '</span');
        LineNr:=LineNr+1
      end
    end;
    if GetOption('ActorsInALine') = 0 then
    Item := StringReplace(Item, ', ', #13#10);
    SetField(fieldActors, LineDecode(Item));
  end;

   // Productor
  LineNr := FindLine(UTF8Encode('<dt>Productora</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
    Item := LineDecode(Item);
    SetField(fieldProducer, Item);
  end;

   // Category
  LineNr := FindLine(UTF8Encode('<dt>Género</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 2);
    Item := DeleteTags(Line);
    Item := LineDecode(Item);
    Item := StringReplace(Item, ' | ', ', ');
    Item := StringReplace(Item, '. ', ', ');
    SetField(fieldCategory, Item);
  end;

   // Official Webpage
  LineNr := FindLine(UTF8Encode('<dt>Web oficial</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(TextBetween(Line, ' href="', '">'));
    Item := LineDecode(Item);
    Comments := Comments + 'Web oficial: ' + Item + #13#10 + #13#10;
  end;

   // Synopsis
  LineNr := FindLine(UTF8Encode('<dt>Sinopsis</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr + 1);
    Item := DeleteTags(Line);
    Item := LineDecode(Item);
    SetField(fieldDescription, Item);
  end;

   // Awards
  LineNr := FindLine(UTF8Encode('<dt>Premios</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
    LineNr   := LineNr + 1;
    Line     := Page.GetString(LineNr);
    Comments := Comments + 'Premios: ' + #13#10;
    while Pos ('</dd>', Line) = 0 do
    begin
      if Pos ('<span id="show-all-awards">', Line) = 0 then
      begin
        Item := DeleteTags(Line);
        Item := LineDecode(Item);
        if (Length(Item) <> 0) then
        begin
          Comments := Comments + '  - ' + Item + #13#10;
        end;
      end;
      LineNr := LineNr + 1;
      Line   := Page.GetString(LineNr);
    end;
    Comments := Comments + #13#10;
  end;

   // Critic
  LineNr := FindLine(UTF8Encode('<dt>Críticas</dt>'), Page, LineNr);
  if LineNr <> -1 then
  begin
      // El unico objeto de esta linea es poder presentar en el foro el listado
      // del script sin que se produzca la conversión del caracter estrella

    CharStar       := '&'+'#9733;';
    Comments := Comments + 'Críticas: ' + #13#10 + #13#10;
    LineNr := FindLine('<div class="pro-review"', Page, LineNr + 1);
    while LineNr <> -1 do
    begin
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
      if Pos (UTF8Encode('<a title="Leer crítica completa" href='), Line) <> 0 then
      begin
        LineNr := LineNr + 1;
        Line := Page.GetString(LineNr);
      end;
      Line:= StringReplace(Line, CharStar, '*');
      Item := DeleteTags(Line);
      Item := LineDecode(Item);
      if (Length(Item) <> 0) then
      begin
        Comments := Comments + Item + #13#10;
        LineNr := FindLine('div class="pro-crit-med"', Page, LineNr + 1);
        Line := Page.GetString(LineNr);
        Item := DeleteTags(TextBetween(Line, ' itemprop="author">', '<i'));
        Item := LineDecode(Item);
        if (Length(Item) <> 0) then
        begin
          Comments := Comments + Item + #13#10;
        end;
        Comments := Comments + '________________________________________' + #13#10 + #13#10;
      end;
      LineNr := FindLine('<div class="pro-review"', Page, LineNr + 1)
    end;
  end;

  HTMLDecode(Comments);
  SetField(fieldComments, Comments);
  if GetOption('DontWantExtras') = 0 then
  AnalyzeExtras(Page,Address);
end;

//------------------------------------------------------------------------------------
// Extras
procedure AnalyzeExtras(Page: TStringList; Address: string);
var
  LineNr,NumImages,NumTrailers, i,CountC: Integer;
  Line: string;
  TrailersAddress: string;
  ImagesAddress: string;
  ImageTitle: string;
  ExtraIndex: Integer;
  ExtraString: string;
  ExtraURL: string;
  ExtraTagBase: string;
  LimitImages,LimitTrailers,LimitCritics: Integer;

begin
  ExtraTagBase :=  'FA'+TextBetween(Address, '/film', '.html');
  ClearExtrasOfScript;
  LimitImages := StrtoInt (GetParam('ExtraImagesLimit'),0);
  if LimitImages < 0 then LimitImages := 0;
  LimitTrailers := StrtoInt (GetParam('ExtraTrailersLimit'),0);
  if LimitTrailers < 0 then LimitTrailers := 0;
  LimitCritics := StrtoInt (GetParam('ExtraCriticsLimit'),0);
  if LimitCritics < 0 then LimitCritics := 0;

// Enlaces a Criticas
  LineNr := FindLine(UTF8Encode('<dt>Críticas</dt>'), Page, LineNr);
  CountC := 0;
  if LineNr <> -1 then
  begin
    LineNr := FindLine('<div class="pro-review"', Page, LineNr + 1);
    while LineNr <> -1 do
    begin
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
      if Pos (UTF8Encode('<a title="Leer crítica completa" href='), Line) <> 0 then
      begin
        Line := Page.GetString(LineNr);
        ExtraURL:= TextBetween(Line, 'href="', '" ');
        if (Length(ExtraURL))>0 then
        begin
          ExtraIndex := AddExtra();
          SetExtraField(ExtraIndex, extraFieldURL, ExtraURL);
          SetExtraField(ExtraIndex, extraFieldCategory, 'Críticas');
          SetExtraField(ExtraIndex, extraFieldTitle, TextBetween(ExtraURL, '//', '/'));
          SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'C'+IntToStr(ExtraIndex));
        end;
        LineNr := LineNr + 1;
        Line := Page.GetString(LineNr);
      end;
      LineNr := FindLine('<div class="pro-review"', Page, LineNr + 1);
      CountC := CountC+1;
      if CountC = LimitCritics then
      break;
    end;
  end;

   // Imágenes  y Trailers
  NumTrailers := 0;
  NumImages := 0;

  LineNr := FindLine(UTF8Encode('>Tráilers&nbsp;<em>'), Page, 0);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr);
    NumTrailers := StrToInt(TextBetween(Line, '<em>[', ']</em>'),0);
    TrailersAddress := TextBetween(Line, 'href="', '"');
  end

  LineNr := FindLine(UTF8Encode('>Imágenes&nbsp;<em>'), Page, LineNr+1);
  if LineNr <> -1 then
  begin
    Line := Page.GetString(LineNr);
    NumImages := StrToInt(TextBetween(Line, '<em>[', ']</em>'),0);
    ImagesAddress := TextBetween(Line, 'href="', '"');
  end

   // Imágenes
  If NumImages > LimitImages then NumImages := LimitImages;
  if NumImages >0 then
  begin
    Page.Text := GetPage(ImagesAddress);
    LineNr := FindLine(UTF8Encode('<span>Posters</span>'), Page,0);
    if LineNr = -1 then
    LineNr := FindLine(UTF8Encode('<span>Movie Posters</span>'), Page,0);
    if LineNr =-1 then
    LineNr := FindLine(UTF8Encode('<span>Fotogramas</span>'), Page,0);
    if LineNr =-1 then
    LineNr := FindLine(UTF8Encode('span>Otros</span>'), Page,0);
    if LineNr <> -1 then
    begin
      Line := Page.GetString(LineNr);
      for i := 1 to NumImages do
      begin
        LineNr := FindLine('<a href="', Page, LineNr + 1);
        if LineNr <> -1 then
        begin
          Line := Page.GetString(LineNr);
          ExtraString := TextBetween(Line, 'href="', '"');
          ImageTitle := TextBetween(Line, 'Tipo: </strong>', '</div>');
          ExtraIndex := AddExtra();
          if GetOption('GroupImages') = 1 then
          begin
            SetExtraField(ExtraIndex, extraFieldCategory, 'Imágenes');
            SetExtraField(ExtraIndex, extraFieldTitle, ImageTitle);
          end
          else
          begin
            SetExtraField(ExtraIndex, extraFieldCategory, ImageTitle);
            SetExtraField(ExtraIndex, extraFieldTitle, 'Imágenes')
          end;

          SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'I'+IntToStr(ExtraIndex));
          GetExtraPicture(ExtraIndex, ExtraString);
        end;
      end;
    end;
  end;

  If NumTrailers > LimitTrailers then NumTrailers := LimitTrailers;
  if NumTrailers > 0 then
  begin
    Page.Text := GetPage(TrailersAddress);
    LineNr := FindLine(UTF8Encode('>Mostrar video<'),Page,0);
    if LineNr <> -1 then
    begin
      Line := Page.GetString(LineNr);
      for i:= 1 to NumTrailers do
      begin
        LineNr := FindLine('src="', Page,LineNr + 1);
        if LineNr <> -1 then
        begin
          Line := Page.GetString(LineNr);
          ExtraString := TextBetween(Line, 'src="', '"');
          ExtraURL := TextAfter(ExtraString, '//');
          ExtraIndex := AddExtra();
          SetExtraField(ExtraIndex, extraFieldURL, ExtraURL);
          SetExtraField(ExtraIndex, extraFieldCategory, 'Trailers');
          SetExtraField(ExtraIndex, extraFieldTitle, TextBetween(ExtraString, '//', '/'))
          SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'T'+IntToStr(ExtraIndex));
          LineNr := FindLine(UTF8Encode('Mostrar video'), Page,LineNr + 1);
        end;
      end;
    end;
  end;
end;


//------------------------------------------------------------------------------------

begin
  if (CheckVersion(4,2,2) = false) then
  begin
    if ShowWarning('This script requires a newer version of Ant Movie Catalog, at least the version 4.2.2, currently available as beta - do you wish to open the link to download it?)') = true then
    begin
      Launch('https://forum.antp.be/phpbb3/viewtopic.php?f=6&t=6862', '');
    end;
    exit;
  end;

  MovieName     := GetField(fieldOriginalTitle);
  MovieYear     := GetField(fieldYear);

  YearFrom      := MovieYear;
  YearTo        := MovieYear;

  AdvQuery      := '/es/advsearch.php';

  if Length(MovieName) = 0 then
  MovieName := GetField(fieldTranslatedTitle);

  if GetOption('DontAsk') = 0 then
  Input('FilmAffinity', 'Título: ' + GetField(fieldFilePath), MovieName);

  if Pos('filmaffinity.com', MovieName) > 0 then
  AnalyzeMoviePage(MovieName)
  else
  begin
    //MovieName := UTF8Encode(MovieName);
    AdvQuery := AdvQuery + '?stext=' + UrlEncode(MovieName);

    if GetOption('SearchByFromToYears') = 1 then
    begin
      if GetOption('DontAsk') = 0 then
      begin
        Input('FilmAffinity', 'Desde el año: ', YearFrom);
        Input('FilmAffinity', 'Hasta el año: ', YearTo);
      end;
      AdvQuery := AdvQuery + '&fromyear=' + YearFrom;
      AdvQuery := AdvQuery + '&toyear=' + YearTo;
    end;

    {
    stype[]=title         Título
    stype[]=director      Director
    stype[]=cast          Reparto
    stype[]=script        Guión
    stype[]=photo         Fotografía
    stype[]=music         Música
    stype[]=producer      Productor
    }

    if GetOption('SearchByTitle') = 1 then
    AdvQuery := AdvQuery + '&stype[]=title';

    if GetOption('SearchByDirector') = 1 then
    AdvQuery := AdvQuery + '&stype[]=director';

    if GetOption('SearchByCast') = 1 then
    AdvQuery := AdvQuery + '&stype[]=cast';

    if GetOption('SearchByScript') = 1 then
    AdvQuery := AdvQuery + '&stype[]=script';

    if GetOption('SearchByPhoto') = 1 then
    AdvQuery := AdvQuery + '&stype[]=photo';

    if GetOption('SearchByMusic') = 1 then
    AdvQuery := AdvQuery + '&stype[]=music';

    if GetOption('SearchByProducer') = 1 then
    AdvQuery := AdvQuery + '&stype[]=producer';

    if GetOption('SortByYear') = 1 then
    AdvQuery := AdvQuery + '&orderby=year';

    AnalyzeAdvPage(BaseURL + AdvQuery);
  end;
end.

Posted: 2015-09-13 12:05:28
by buitre225
Me ha servido de mucho,
Gracias

Posted: 2015-11-10 22:10:51
by carlosmg2
updated script to fix a little issue

Posted: 2016-04-26 08:51:19
by carlosmg2
updated script to fix filmaffinity 2.88

Posted: 2016-05-25 14:05:03
by carlosmg2
updated to temporarily fix filmaffinity 2.88 year issue

Posted: 2016-05-27 09:12:26
by carlosmg2
updated code with filmaffinity 2.90 fixes

Posted: 2016-06-10 11:07:37
by carlosmg2
updated code with filmaffinity 2.93 fixes

Posted: 2017-02-20 15:29:16
by carlosmg2
updated code in first post with filmaffinity 2.95 fixes

Posted: 2017-03-29 18:57:03
by magol
Muchas gracias

Posted: 2017-06-06 15:06:29
by carlosmg2
updated code in first post with Filmaffinity 3.00 fixes

Posted: 2017-06-13 19:11:10
by magol
Muchas gracias, me gustan los carteles en español.

Posted: 2017-08-07 11:30:04
by carlosmg2
updated code in first post to fix Error getting picture from Ecartelera

Posted: 2017-08-12 19:10:37
by magol
Gracias por la actualización.

Posted: 2017-09-03 11:19:54
by magol
Buenos días.

Ecartelera vuelve a fallar.

Ayuda por favor, me gustan los carteles en español.

Saludos

Re: FilmAffinity (ES) 3.00 + Ecartelera (ES) 1.1

Posted: 2018-04-24 14:02:17
by carlosmg2
updated code in first post to fix Error getting picture from Ecartelera + updating Filmaffinity to 3.0.3.
AMC 4.2.2 BETA needed

---

actualizado script en el primer post para arreglar caratula de Ecartelera + actualizar script de Filmaffinity 3.0.3.
Se necesita AMC 4.2.2 BETA

Re: FilmAffinity (ES) 3.0.3 + Ecartelera (ES) 1.2

Posted: 2018-05-11 10:52:21
by carlosmg2
updated code in first post to fix Error getting picture from Ecartelera again.
AMC 4.2.2 BETA needed

---

actualizado script en el primer post para arreglar caratula de Ecartelera otra vez.
Se necesita AMC 4.2.2 BETA

Re: FilmAffinity (ES) 3.0.3 + Ecartelera (ES) 1.2

Posted: 2018-05-15 14:05:41
by magol
Uso bastante estos scrips, menos mal que te has acordado de actualizarlos.

Muchísimas gracias carlosmg2.

Saludos

Re: FilmAffinity (ES) 3.0.4 + Ecartelera (ES) 1.2

Posted: 2018-07-05 09:36:25
by carlosmg2
updated code in first post to update Filmaffinity part to 3.0.4.

Re: FilmAffinity (ES) 3.0.4 + Ecartelera (ES) 1.2

Posted: 2018-07-13 10:30:05
by khepper
Sería interesante poder poner la url, en algunso casos salen tantos resultados que no aparece el que quieres, pero lo buscas con google y aparece sin problemas, pero no hay gforma de ponerlo
Con imdb se puede hacer
Gracias por todo