No dudéis en avisarme si encontráis algún problema con el script.
Disfrutadla!
Edit: De ahora en adelante actualizaré el código del script siempre en esta entrada. De esta forma espero que sea más claro para todos.
----
The new version of the FilmAffinity (ES) script, complaining with recent web changes, is attached below.
Please, let me know if you found any unexpected issue using the script.
Enjoy!
Edit: Now on, I will update the script code always in this post entry. I hope it will be clearest for everybody.
_____________________________________________
Script Versión : v2.65 (2013-04-25)
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
Title=FilmAffinity (ES)
Description=Movie importation script for FilmAffinity Spain
Site=http://www.filmaffinity.com
Language=ES
Version=2.65
Requires=3.5.0
Comments=Updated to 2013/04/16 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('<b>siguientes >></b>', Page, 0);
if LineNr = -1 then
break;
Line := Page.GetString(LineNr);
Page.Text := GetPage(TextBetween(Line, '<a href="', '">'));
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">', 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;
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.
[Added] Se ha añadido una opción (ActorsInALine) en el script para elegir el formato de la lista de actores: en una línea separados por comas; o bien cada uno en una línea independiente (formato columna). Gracias a granguash y jacqlittle por hacerme ver "otras posibilidades".
[Updated] En ocasiones no se obtiene correctamente la duración de la película.
[Fixed] En ocasiones no se obtiene correctamente la sinopsis de la película. Gracias a J.M.Talegón por detectar el fallo.
[Changed] Se ha optimizado el proceso de adquisición de resultados. Gracias a Arturo por hacerme ver ese fragmento de código tan obsoleto.
[Updated] En la página de FilmAffinity han vuelto a modificar el código de la duración de la película. He actualizado el script para adaptarse a los nuevos cambios.
[Fixed] Se ha corregido el caso en el que hay más de 10 críticas y éstas quedan ocultas en la página de FilmAffinity (antes no se importaban). Gracias a m2s por percatarse de ello.
[Changed] He modificado el formato del campo 'Género' para que tenga el formato "Genero1, Genero2, ..., GeneroN"... en vez del que tiene la página. Con esto se mejora la búsqueda por Género en la aplicación. Gracias fotja por la recomendación.
[Updated] He actualizado el script a los últimos cambios de la página. Vuelve a adquirirse correctamente los campos "Género", "Premios", "WebOficial" y "Crítica".
[Fixed] juliojs ha actualizado el script para adaptarlos a los nuevos cambios en la web de FilmAffinity. Gracias juliojs!
----
Change log from release v2.60:
[Added] Added a script option (ActorsInALine) to choose the Actor's list format: all of them in the same line separated by commas; or each one of them in a different line (column format). Thanks to granguash and jacqlittle to let me know other "points of view".
[Updated] Sometimes 'Length' field was empty.
[Fixed] Sometimes 'Synopsis' field was empty. Thanks to J.M.Talegón for debbuging.
[Changed] Web-search result code was optimized. Thanks to Arturo to let me see that obsolete part of code.
[Updated] FilmAffinity website team updated again the web-code, making the script unable to load the 'Length' field. I have updated it to complain the web changes.
[Fixed] When a film has more than 10 critics, the script was unable to load the following critics (hidden in the web-page by default). Thanks to m2s to report this bug.
[Changed] I have changed the format of the 'Category' field to "Cat1, Cat2, ..., CatN"... instead of the original format from the web-page. Now, it's easier to seach by Category in the app. Thanks to fotja to report this issue.
[Updated] Another script update to complain with website changes. It fixes the acquisition of the folowing fields: "Catefory", "Awards", "OfficialWebsite" and "Critic".
[Fixed] juliojs has updated the script to comply with recent changes made in the FilmAffinity web page. Thanks juliojs!