FilmAffinity (ES): version 2.82.Compatible con Ant Movie 4.2
-
- Posts: 21
- Joined: 2014-06-08 09:08:31
Muy buen trabajo | Good Work!!
Muchas gracias, Arturo, por esta nueva mejora del script: era lo que le faltaba, poder añadir los extras!!
Se añade la posibilidad de limitar el número de extras capturados. Hay paginas que tienen muchos y a alguien puede parecerle excesivos el número de items en el registro (por ejemplo Casablanca tiene 94 imágenes).
Esto se hace editando los parametros (Script parameters), estos parametros son:
- ExtraCriticsLimit : Limita el número de enlaces a páginas de críticas.
- ExtraImagesLimit: Limita el númer0 de imagenes capturadas.
- ExtraTrailersLimit: Limita el número de enlaces a trailers.
Debereis pues, cuando abrais el script, ajustar estos valores. Poniendo, por ejemplo 99 seguramente los capturará todos, poniendo 0, entoces no capturará ninguno-
Esto se hace editando los parametros (Script parameters), estos parametros son:
- ExtraCriticsLimit : Limita el número de enlaces a páginas de críticas.
- ExtraImagesLimit: Limita el númer0 de imagenes capturadas.
- ExtraTrailersLimit: Limita el número de enlaces a trailers.
Debereis pues, cuando abrais el script, ajustar estos valores. Poniendo, por ejemplo 99 seguramente los capturará todos, poniendo 0, entoces no capturará ninguno-
-
- Posts: 21
- Joined: 2014-06-08 09:08:31
Muchas gracias por esta nueva mejora. En algunos casos se generaban muchos extras, la más de las veces, no necesarios.
He modificado la incorporación de imágenes extras para que la categoría no sea siempre "imagen", sino que dependa del tipo que indica FilmAffinity: póster, fotogramas, etc., que es justo lo que introduces en el campo título.
------------------------------------------------------------------------------------
Thank you very much for this new improvement. In some cases many extras, most of the time, not needed were generated.
I modified the incorporation of extra pictures for the category is not always "image", but that depends on the type indicated FilmAffinity. Posters, frames, etc., which is just what you enter in the title field.
He modificado la incorporación de imágenes extras para que la categoría no sea siempre "imagen", sino que dependa del tipo que indica FilmAffinity: póster, fotogramas, etc., que es justo lo que introduces en el campo título.
------------------------------------------------------------------------------------
Thank you very much for this new improvement. In some cases many extras, most of the time, not needed were generated.
I modified the incorporation of extra pictures for the category is not always "image", but that depends on the type indicated FilmAffinity. Posters, frames, etc., which is just what you enter in the title field.
-
- Posts: 26
- Joined: 2013-04-11 07:13:02
-
- Posts: 100
- Joined: 2010-02-22 23:15:05
-
- Posts: 26
- Joined: 2013-04-11 07:13:02
Por si te sirve de ayuda Arturo, he visto que el otro script que hay de Filmaffinity (+Caratula DVD) que está actualizado hace unos días, incluye unas líneas de código en determinadas sentencias, donde utiliza la orden 'UTF8Decode' delante de 'GetPage', que por lo visto es para que obtenga correctamente la codificación de las páginas.
Yo he intentado modificar tu script Arturo, pero mi nivel no da la talla para ello, se ve que algo se me escapa y no funciona el script, pero creo que te puede servir de referencia, y si eres tan amable como siempre seguramente lo puedas resolver...
Gracias de nuevo de antemano y un cordial saludo.
Yo he intentado modificar tu script Arturo, pero mi nivel no da la talla para ello, se ve que algo se me escapa y no funciona el script, pero creo que te puede servir de referencia, y si eres tan amable como siempre seguramente lo puedas resolver...
Gracias de nuevo de antemano y un cordial saludo.
-
- Posts: 100
- Joined: 2010-02-22 23:15:05
-
- Posts: 26
- Joined: 2013-04-11 07:13:02
-
- Posts: 100
- Joined: 2010-02-22 23:15:05
-
- Posts: 21
- Joined: 2014-06-08 09:08:31
Se van resolviendo los problemas. Este scripts funciona haciendo unos pequeños cambios. A ver si los termino y os lo paso.
El truco está en el cambio de codificación que ha hecho Filmaffinity, y su paso a UTF8.... ¡¡ y que el gran Ant Movie Catalog no soporta esta codificación !!!.
Por ejemplo, para el título original este script busca en la página web el literal "<dt>Título original</dt>". Hasta ahora iba bien pero al llevar un carácter "especial" (la 'í' acentuada), ahora no la encuentra.
¿Cómo se puede resolver?
Pues traduciendo dicho literal a UTF8 antes de buscarlo. Quedaría algo así para el título original:
Este cambio se debe de hacer en todos los apartados de búsqueda ("críticas", "guión", etc.) donde el literal a buscar contenga caracteres no "generales".
Hay que seguir puliendo detalles pero parece que se puede arreglar...
¡¡ Menos mal !!!
=============================================
They will resolve problems. This script works by making small changes. See if the term and I will pass.
The trick is to change coding has Filmaffinity, and advancing to UTF8 .... and the great Ant Movie Catalog does not support this encoding!.
For example, the original title for this script searches the website the literal "<dt> Original title </ dt>". So far going well but to take a "special" character (the 't' pronounced), now it is not.
How can you solve?
For such literally translating to UTF8 before searching. Remain so for the original title:
This change should be done in all sections search ("reviews", "script", etc..) Where to find literal containing no "general" characters.
We must continue to refine details but it seems you can fix ...
El truco está en el cambio de codificación que ha hecho Filmaffinity, y su paso a UTF8.... ¡¡ y que el gran Ant Movie Catalog no soporta esta codificación !!!.
Por ejemplo, para el título original este script busca en la página web el literal "<dt>Título original</dt>". Hasta ahora iba bien pero al llevar un carácter "especial" (la 'í' acentuada), ahora no la encuentra.
¿Cómo se puede resolver?
Pues traduciendo dicho literal a UTF8 antes de buscarlo. Quedaría algo así para el título original:
Code: Select all
BuscarCadena: string;
// Original Title
BuscarCadena:= '<dt>Título original</dt>';
BuscarCadena:= UTF8Encode(BuscarCadena);
//LineNr := FindLine('<dt>Título original</dt>', Page, LineNr);
LineNr := FindLine(BuscarCadena, Page, LineNr);
Hay que seguir puliendo detalles pero parece que se puede arreglar...
¡¡ Menos mal !!!
=============================================
They will resolve problems. This script works by making small changes. See if the term and I will pass.
The trick is to change coding has Filmaffinity, and advancing to UTF8 .... and the great Ant Movie Catalog does not support this encoding!.
For example, the original title for this script searches the website the literal "<dt> Original title </ dt>". So far going well but to take a "special" character (the 't' pronounced), now it is not.
How can you solve?
For such literally translating to UTF8 before searching. Remain so for the original title:
Code: Select all
BuscarCadena: string;
// Original Title
BuscarCadena:= '<dt>Título original</dt>';
BuscarCadena:= UTF8Encode(BuscarCadena);
//LineNr := FindLine('<dt>Título original</dt>', Page, LineNr);
LineNr := FindLine(BuscarCadena, Page, LineNr);
This change should be done in all sections search ("reviews", "script", etc..) Where to find literal containing no "general" characters.
We must continue to refine details but it seems you can fix ...
Hola, me estreno en el foro, aparte de buscar, falta poner bien el formato en las descripciones, ya que sino aparecen caracteres extraños.
Por ejemplo en la parte de sinopsis se ha de hacer así:
LineNr := FindLine('<dt>Sinopsis</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(Line);
Item:= UTF8Decode(Item);
SetField(fieldDescription, Item);
end;
La línea añadida es Item:= UTF8Decode(Item);
Saludos
Por ejemplo en la parte de sinopsis se ha de hacer así:
LineNr := FindLine('<dt>Sinopsis</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(Line);
Item:= UTF8Decode(Item);
SetField(fieldDescription, Item);
end;
La línea añadida es Item:= UTF8Decode(Item);
Saludos
aquí está el scrip que me funciona. como es la primera vez que escribo no se a quien pasar el scrip para que lo suban, pero bueno, aquí está.
Un saludo y gracias a todo el mundo por el curro destinado a esta herramienta cojonuda.
program FilmAffinity;
const
BaseURL = 'http://www.filmaffinity.com';
var
MovieName: string;
MovieURL: string;
//------------------------------------------------------------------------------------
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, UTF8Decode(List.GetString(i))) <> 0 then
begin
Result := i;
Break;
end;
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 := UTF8Decode(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
HTMLDecode(S);
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;
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Count: Integer;
MovieTitle, MovieAddress: string;
begin
Count := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
PickTreeClear;
// Get how much search results have been found
LineNr := FindLine('</strong> resultados</div>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Count := StrToInt(TextBetween(Line, '<div style="text-align:right;"><strong>', '</strong> resultados</div>'), 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 href="', Page, LineNr + 1);
if LineNr = -1 then
begin
LineNr := FindLine('siguientes >>', Page, 0);
if LineNr = -1 then
break;
Line := Page.GetString(LineNr);
Page.Text := GetPage('http://www.filmaffinity.com/es/search.php' + TextBetween(Line, '<a href="search.php', '"><div class="'));
LineNr := 0;
continue;
end;
Line := Page.GetString(LineNr);
MovieAddress := TextBetween(Line, '<div class="mc-title"><a href="', '.html">') + '.html';
MovieTitle := DeleteTags(TextBetween(Line, '.html">', '<img src="'));
if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then
PickTreeAdd(MovieTitle, BaseURL + MovieAddress);
end;
if ((Count = 1) and (GetOption('DontAsk') = 1)) then
AnalyzeMoviePage(BaseURL + MovieAddress)
else
begin
PickTreeExec(Address);
AnalyzeMoviePage(Address)
end
end;
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr, LineInc: Integer;
Line: string;
Item: string;
Comments: string;
CharStar: string;
BuscarCadena: 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);
Item := DeleteTags(TextBetween(Line, '<h1 id="main-title">', '</h1>'));
SetField(fieldTranslatedTitle, Item);
// Picture
LineNr := FindLine('http://pics.filmaffinity.com/', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Item := TextBetween(Line, '<a class="lightbox" href="', '" title="');
if Length(Item) = 0 then
Item := TextBetween(Line, '" src="', '"></a>');
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 := UTF8Decode(Item);
SetField(fieldRating, StringReplace(Item, ',', '.'));
end;
// Original Title
//LineNr := FindLine('<dt>Título original</dt>', Page, LineNr);
BuscarCadena:= '<dt>Título original</dt>';
//BuscarCadena:= UTF8Encode(BuscarCadena);
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
//Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item := UTF8Decode(Item);
SetField(fieldOriginalTitle, Item);
end;
// Year
BuscarCadena:= '<dt>Año</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item := UTF8Decode(Item);
SetField(fieldYear, Item);
end;
// Length
BuscarCadena:= '<dt>Duración</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', 'min.</dd>'));
Item := UTF8Decode(Item);
SetField(fieldLength, Item);
end;
// Country
BuscarCadena:= '<dt>País</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, 'title="', '"></span>'));
Item:= UTF8Decode(Item);
SetField(fieldCountry, Item);
end;
// Director
BuscarCadena:= '<dt>Director</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
//Item := UTF8Decode(Item);
SetField(fieldDirector, Item);
end;
// Script writer
BuscarCadena:= '<dt>Guión</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Item:= UTF8Decode(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
BuscarCadena:= 'Música';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Item:= UTF8Decode(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
BuscarCadena:= '<dt>Fotografía</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Item:= UTF8Decode(Item);
Comments := Comments + 'Fotografía: ' + Item + #13#10 + #13#10;
end;
// Actors
LineNr := FindLine('<dt>Reparto</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
if Length(TextBetween(Line, '<dd>', '</dd>')) = 0 then
Item := DeleteTags(Line)
else Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item:= UTF8Decode(Item);
if GetOption('ActorsInALine') = 0 then Item := StringReplace(Item, ', ', #13#10);
SetField(fieldActors, Item);
end;
// Productor
LineNr := FindLine('<dt>Productora</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item:= UTF8Decode(Item);
SetField(fieldProducer, Item);
end;
// Category
BuscarCadena:= '<dt>Género</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags(Line);
Item := StringReplace(Item, ' | ', ', ');
Item := StringReplace(Item, '. ', ', ');
Item:= UTF8Decode(Item);
SetField(fieldCategory, Item);
end;
// Official Webpage
LineNr := FindLine('<dt>Web oficial</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, ' href="', '">'));
Item:= UTF8Decode(Item);
Comments := Comments + 'Web oficial: ' + Item + #13#10 + #13#10;
end;
// Synopsis
LineNr := FindLine('<dt>Sinopsis</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(Line);
Item:= UTF8Decode(Item);
SetField(fieldDescription, Item);
end;
// Awards
LineNr := FindLine('<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:= UTF8Decode(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
BuscarCadena:= '<dt>Críticas</dt>';
LineNr := FindLine(BuscarCadena, 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 ('<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);
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(Line);
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);
Comments := UTF8Decode(Comments);
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: Integer;
Line: string;
TrailersAddress: string;
ImagesAddress: string;
ImageTitle: string;
ExtraIndex: Integer;
ExtraString: string;
ExtraURL: string;
ExtraTagBase: string;
begin
ExtraTagBase := 'FA'+TextBetween(Address, '/film', '.html');
ClearExtrasOfScript;
// Enlaces a Criticas
LineNr := FindLine('<dt>Críticas</dt>', Page, LineNr);
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 ('<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);
end;
end;
// Imágenes y Trailers
NumTrailers := 0;
NumImages := 0;
LineNr := FindLine('>Trailers <em>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
NumTrailers := StrToInt(TextBetween(Line, '<em>[', ']</em>'),0);
TrailersAddress := 'http://www.filmaffinity.com'+TextBetween(Line, 'href="', '"');
end
LineNr := FindLine('>Imágenes <em>', Page, LineNr+1);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
NumImages := StrToInt(TextBetween(Line, '<em>[', ']</em>'),0);
ImagesAddress := 'http://www.filmaffinity.com'+TextBetween(Line, 'href="', '"');
end
// Imágenes
if NumImages >0 then
begin
Page.Text := GetPage(ImagesAddress);
LineNr := FindLine('<span>Posters</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();
SetExtraField(ExtraIndex, extraFieldCategory, 'Imágenes');
SetExtraField(ExtraIndex, extraFieldTitle, ImageTitle);
SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'I'+IntToStr(ExtraIndex));
GetExtraPicture(ExtraIndex, ExtraString);
end;
end;
end;
end;
if NumTrailers > 0 then
begin
Page.Text := GetPage(TrailersAddress);
LineNr := FindLine('>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('Mostrar video', Page,LineNr + 1);
end;
end;
end;
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;
if (CheckVersion(4,2,0) = false) then
SetOption('DontWantExtras', 1);
MovieName := GetField(fieldOriginalTitle);
if Length(MovieName) = 0 then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('DontAsk') = 0 then
Input('FilmAffinity', 'Pelicula:', MovieName);
MovieName := UTF8Encode(MovieName);
if Pos('filmaffinity.com', MovieName) > 0 then
AnalyzeMoviePage(MovieName)
else
AnalyzePage(BaseURL +'/es/search.php?stext=' + UrlEncode(MovieName) + '&stype=Title');
end.
Un saludo y gracias a todo el mundo por el curro destinado a esta herramienta cojonuda.
program FilmAffinity;
const
BaseURL = 'http://www.filmaffinity.com';
var
MovieName: string;
MovieURL: string;
//------------------------------------------------------------------------------------
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, UTF8Decode(List.GetString(i))) <> 0 then
begin
Result := i;
Break;
end;
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 := UTF8Decode(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
HTMLDecode(S);
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;
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Count: Integer;
MovieTitle, MovieAddress: string;
begin
Count := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
PickTreeClear;
// Get how much search results have been found
LineNr := FindLine('</strong> resultados</div>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Count := StrToInt(TextBetween(Line, '<div style="text-align:right;"><strong>', '</strong> resultados</div>'), 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 href="', Page, LineNr + 1);
if LineNr = -1 then
begin
LineNr := FindLine('siguientes >>', Page, 0);
if LineNr = -1 then
break;
Line := Page.GetString(LineNr);
Page.Text := GetPage('http://www.filmaffinity.com/es/search.php' + TextBetween(Line, '<a href="search.php', '"><div class="'));
LineNr := 0;
continue;
end;
Line := Page.GetString(LineNr);
MovieAddress := TextBetween(Line, '<div class="mc-title"><a href="', '.html">') + '.html';
MovieTitle := DeleteTags(TextBetween(Line, '.html">', '<img src="'));
if (Length(MovieAddress) <> 0) and (Length(MovieTitle) <> 0) then
PickTreeAdd(MovieTitle, BaseURL + MovieAddress);
end;
if ((Count = 1) and (GetOption('DontAsk') = 1)) then
AnalyzeMoviePage(BaseURL + MovieAddress)
else
begin
PickTreeExec(Address);
AnalyzeMoviePage(Address)
end
end;
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr, LineInc: Integer;
Line: string;
Item: string;
Comments: string;
CharStar: string;
BuscarCadena: 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);
Item := DeleteTags(TextBetween(Line, '<h1 id="main-title">', '</h1>'));
SetField(fieldTranslatedTitle, Item);
// Picture
LineNr := FindLine('http://pics.filmaffinity.com/', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Item := TextBetween(Line, '<a class="lightbox" href="', '" title="');
if Length(Item) = 0 then
Item := TextBetween(Line, '" src="', '"></a>');
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 := UTF8Decode(Item);
SetField(fieldRating, StringReplace(Item, ',', '.'));
end;
// Original Title
//LineNr := FindLine('<dt>Título original</dt>', Page, LineNr);
BuscarCadena:= '<dt>Título original</dt>';
//BuscarCadena:= UTF8Encode(BuscarCadena);
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
//Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item := UTF8Decode(Item);
SetField(fieldOriginalTitle, Item);
end;
// Year
BuscarCadena:= '<dt>Año</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item := UTF8Decode(Item);
SetField(fieldYear, Item);
end;
// Length
BuscarCadena:= '<dt>Duración</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', 'min.</dd>'));
Item := UTF8Decode(Item);
SetField(fieldLength, Item);
end;
// Country
BuscarCadena:= '<dt>País</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, 'title="', '"></span>'));
Item:= UTF8Decode(Item);
SetField(fieldCountry, Item);
end;
// Director
BuscarCadena:= '<dt>Director</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
//Item := UTF8Decode(Item);
SetField(fieldDirector, Item);
end;
// Script writer
BuscarCadena:= '<dt>Guión</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Item:= UTF8Decode(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
BuscarCadena:= 'Música';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Item:= UTF8Decode(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
BuscarCadena:= '<dt>Fotografía</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Item:= UTF8Decode(Item);
Comments := Comments + 'Fotografía: ' + Item + #13#10 + #13#10;
end;
// Actors
LineNr := FindLine('<dt>Reparto</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
if Length(TextBetween(Line, '<dd>', '</dd>')) = 0 then
Item := DeleteTags(Line)
else Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item:= UTF8Decode(Item);
if GetOption('ActorsInALine') = 0 then Item := StringReplace(Item, ', ', #13#10);
SetField(fieldActors, Item);
end;
// Productor
LineNr := FindLine('<dt>Productora</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
Item:= UTF8Decode(Item);
SetField(fieldProducer, Item);
end;
// Category
BuscarCadena:= '<dt>Género</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags(Line);
Item := StringReplace(Item, ' | ', ', ');
Item := StringReplace(Item, '. ', ', ');
Item:= UTF8Decode(Item);
SetField(fieldCategory, Item);
end;
// Official Webpage
LineNr := FindLine('<dt>Web oficial</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, ' href="', '">'));
Item:= UTF8Decode(Item);
Comments := Comments + 'Web oficial: ' + Item + #13#10 + #13#10;
end;
// Synopsis
LineNr := FindLine('<dt>Sinopsis</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(Line);
Item:= UTF8Decode(Item);
SetField(fieldDescription, Item);
end;
// Awards
LineNr := FindLine('<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:= UTF8Decode(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
BuscarCadena:= '<dt>Críticas</dt>';
LineNr := FindLine(BuscarCadena, 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 ('<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);
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(Line);
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);
Comments := UTF8Decode(Comments);
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: Integer;
Line: string;
TrailersAddress: string;
ImagesAddress: string;
ImageTitle: string;
ExtraIndex: Integer;
ExtraString: string;
ExtraURL: string;
ExtraTagBase: string;
begin
ExtraTagBase := 'FA'+TextBetween(Address, '/film', '.html');
ClearExtrasOfScript;
// Enlaces a Criticas
LineNr := FindLine('<dt>Críticas</dt>', Page, LineNr);
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 ('<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);
end;
end;
// Imágenes y Trailers
NumTrailers := 0;
NumImages := 0;
LineNr := FindLine('>Trailers <em>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
NumTrailers := StrToInt(TextBetween(Line, '<em>[', ']</em>'),0);
TrailersAddress := 'http://www.filmaffinity.com'+TextBetween(Line, 'href="', '"');
end
LineNr := FindLine('>Imágenes <em>', Page, LineNr+1);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
NumImages := StrToInt(TextBetween(Line, '<em>[', ']</em>'),0);
ImagesAddress := 'http://www.filmaffinity.com'+TextBetween(Line, 'href="', '"');
end
// Imágenes
if NumImages >0 then
begin
Page.Text := GetPage(ImagesAddress);
LineNr := FindLine('<span>Posters</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();
SetExtraField(ExtraIndex, extraFieldCategory, 'Imágenes');
SetExtraField(ExtraIndex, extraFieldTitle, ImageTitle);
SetExtraField(ExtraIndex, extraFieldTag, ExtraTagBase+'I'+IntToStr(ExtraIndex));
GetExtraPicture(ExtraIndex, ExtraString);
end;
end;
end;
end;
if NumTrailers > 0 then
begin
Page.Text := GetPage(TrailersAddress);
LineNr := FindLine('>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('Mostrar video', Page,LineNr + 1);
end;
end;
end;
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;
if (CheckVersion(4,2,0) = false) then
SetOption('DontWantExtras', 1);
MovieName := GetField(fieldOriginalTitle);
if Length(MovieName) = 0 then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('DontAsk') = 0 then
Input('FilmAffinity', 'Pelicula:', MovieName);
MovieName := UTF8Encode(MovieName);
if Pos('filmaffinity.com', MovieName) > 0 then
AnalyzeMoviePage(MovieName)
else
AnalyzePage(BaseURL +'/es/search.php?stext=' + UrlEncode(MovieName) + '&stype=Title');
end.
a mi no me funciona. sigo con el problema que en los campos con caracteres con tilde o especiales no obtiene los datos (País, Año, Duración)
por ejemplo, esta linea no la encuentra en la pagina, el Findline no funciona
por lo que LineNr sigue con valor -1 y no lo extrae el dato
por ejemplo, esta linea no la encuentra en la pagina, el Findline no funciona
Code: Select all
BuscarCadena:= '<dt>País</dt>';
LineNr := FindLine(BuscarCadena, Page, LineNr);
if LineNr <> -1 then
Efectivamente han cambiado la codificación de la pagina de ISO a utf8.
Me ha pillado de vacaciones. Solo he tenido un ratito para modificarlo. Creo que funciona pero no he podido hacer pruebas.
Dejo pues la versión 2.77 en el primer post.
Probadlo y ya direis. y si está bien que antp lo suba.
Cuando vuelva le daré un repaso.
He añadido un nueva opción: GroupImages. Si tiene valor 1 agrupa todas las imágenes en una categoria uníca (como hasta ahora). Si está a 0 las divide en las categorias que tiene la página, tal como decia JuanRa_007
Me ha pillado de vacaciones. Solo he tenido un ratito para modificarlo. Creo que funciona pero no he podido hacer pruebas.
Dejo pues la versión 2.77 en el primer post.
Probadlo y ya direis. y si está bien que antp lo suba.
Cuando vuelva le daré un repaso.
He añadido un nueva opción: GroupImages. Si tiene valor 1 agrupa todas las imágenes en una categoria uníca (como hasta ahora). Si está a 0 las divide en las categorias que tiene la página, tal como decia JuanRa_007
Una pregunta de novato, ¿cuál es el primer post?, ¿podéis poner el link aquí?Arturo wrote:Efectivamente han cambiado la codificación de la pagina de ISO a utf8.
Me ha pillado de vacaciones. Solo he tenido un ratito para modificarlo. Creo que funciona pero no he podido hacer pruebas.
Dejo pues la versión 2.77 en el primer post.
Probadlo y ya direis. y si está bien que antp lo suba.
Cuando vuelva le daré un repaso.
He añadido un nueva opción: GroupImages. Si tiene valor 1 agrupa todas las imágenes en una categoria uníca (como hasta ahora). Si está a 0 las divide en las categorias que tiene la página, tal como decia JuanRa_007
Gracias