Con tu permiso Arturo, he modificado el script un poco, ya que había un par de líneas diferentes al script anterior, en el que tú dejabas como estaba hace tiempo el caracter "-" para separar los comentarios, en vez de "_" que es el que había en el último script, es una chorrada pero más que nada para que todos los que ya teníamos las críticas con ese formato siga igual.
También lo he dejado con las mismas tabulaciones que habían en el código antiguo, además de incluír también el código que puso Albher para que se importasen las calificaciones, y ya funciona todo correctamente o eso creo al menos...
Os he citado al principio del script a tí y a Albher como mods del script, pues entre todos ha sido posible dejar el script funcionando de p.m., y yo también me he puesto entre los mods, pues también he puesto mi granito de arena, jeje...
Pongo el código del script entero y así quien quiera que lo pruebe y si dáis el visto bueno, quizás si antp lo considera oportuno que lo suba al servidor para que se pueda actualizar automáticamente desde el script "[ UPDATE SCRIPTS ]".
Yo lo he probado con bastantes películas y me funciona perfectamente, pero bueno si alguien detecta algún problema que lo comente, aunque creo que va todo bien ya, y si va todo bien que lo suba admin antp al servidor si lo considera oportuno.
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
Title=FilmAffinity (ES)
Description=Movie importation script for FilmAffinity Spain
Site=http://www.filmaffinity.com
Language=ES
Version=2.67
Requires=3.5.0
Comments=Updated to 2013/08/04 version of the web-page. Added an option to choose Actor list format (ActorsInALine).
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
[Parameters]
***************************************************)
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, List.GetString(i)) <> 0 then
begin
Result := i;
Break;
end;
end;
//------------------------------------------------------------------------------------
function TextBetween(S: string; StartTag: string; EndTag: string): string;
var
ini, fin: Integer;
begin
Result := '';
ini := Pos(StartTag, S);
if ini <> 0 then
begin
ini := ini + Length(StartTag);
fin := Pos(EndTag, S);
if (fin <> 0) and (fin > ini) then
begin
Result := Copy(S, ini, fin - ini);
end;
end;
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)) or PickTreeExec(Address) then
AnalyzeMoviePage(Address);
end;
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr, LineInc: Integer;
Line: string;
Item: string;
Comments: 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);
SetField(fieldRating, StringReplace(Item, ',', '.'));
end;
// Original Title
LineNr := FindLine('<dt>Título original</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
SetField(fieldOriginalTitle, Item);
end;
// Year
LineNr := FindLine('<dt>Año</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
SetField(fieldYear, Item);
end;
// Length
LineNr := FindLine('<dt>Duración</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', 'min.</dd>'));
SetField(fieldLength, Item);
end;
// Country
LineNr := FindLine('<dt>País</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, 'title="', '" border'));
SetField(fieldCountry, Item);
end;
// Director
LineNr := FindLine('<dt>Director</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
SetField(fieldDirector, Item);
end;
// Script writer
LineNr := FindLine('<dt>Guión</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Comments := Comments + 'Guión: ' + Item + #13#10 + #13#10;
end;
// Composer
LineNr := FindLine('<dt>Música</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
Comments := Comments + 'Música: ' + Item + #13#10 + #13#10;
end;
// Photography
LineNr := FindLine('<dt>Fotografía</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<dd>', '</dd>');
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);
Item := DeleteTags(TextBetween(Line, '<dd>', '</dd>'));
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>'));
SetField(fieldProducer, Item);
end;
// Category
LineNr := FindLine('<dt>Género</dt>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags(Line);
Item := StringReplace(Item, ' | ', ', ');
Item := StringReplace(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="', '">'));
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);
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);
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('<dt>Críticas</dt>', Page, LineNr);
if LineNr <> -1 then
begin
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);
LineInc := 2;
if Pos ('<a title="Leer crítica completa" href=', Line) <> 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
LineInc := 3;
end;
Line:= StringReplace(Line, '★', '*');
Item := DeleteTags(Line);
if (Length(Item) <> 0) then
begin
Comments := Comments + Item + #13#10;
LineNr := LineNr + LineInc;
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);
end;
end;
HTMLDecode(Comments);
SetField(fieldComments, Comments);
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(fieldOriginalTitle);
if Length(MovieName) = 0 then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('DontAsk') = 0 then
Input('FilmAffinity', 'Pelicula:', MovieName);
if Pos('filmaffinity.com', MovieName) > 0 then
AnalyzeMoviePage(MovieName)
else
AnalyzePage(BaseURL +'/es/search.php?stext=' + UrlEncode(MovieName) + '&stype=Title');
end.
Saludos a todos.
P.D.: ojo con lo que comentó Arturo unos posts atrás, que en la línea 345 del script aquí se visualiza como:
Line:= StringReplace(Line, '★', '*');
, pero en realidad el archivo contiene lo siguiente:
, lo que pasa es que no sé por qué aquí en el foro se visualiza la estrellita en vez del código correcto, debe ser por la codificación del archivo de texto, que lo debemos guardar como ANSI al editarlo con el Bloc de Notas, pero se ve que la web utiliza otra codificación o algo así...
Para evitar confusiones lo subo a MEGA para el que lo quiera probar y tal...
Code: Select all
https://mega.co.nz/#!lsNSXYgA!O8IqU3yFfzBRsbB5nVpJrQREtLs98lvEaoXlZ6tdJDQ