FilmAffinity (ES): New version 'reviewed'
Posted: 2010-02-27 14:10:56
Hola a todos,
He revisado la última versión del script para corregir un par de cosas:
- Ahora funciona correctamente el modo DontAsk (proceso batch -o por lotes- de las películas) [gracias Kreti]
- Ahora carga correctamente las imágenes aunque no tengan un poster grande [gracias Kreti]
- Ahora la sección 'Premios' de la página se incluye en los comentarios [gracias Félix A. del Blanco]
- Reordenación del código para optimizar la carga de información.
Espero vuestros comentarios.
Que os guste!
--------------------------------------------
Hi all,
I have reviewed the latest version of the script to fix some bugs and add new features:
- 'DontAsk' mode works again! (batch process of the films) [thanks Kreti]
- Now thie script also loads images that haven't enlarge version (posters) [thanks Kreti]
- Now the 'Awards' section (changed in the website) is loaded into the Comments field [thanks Félix A. del Blanco]
- Some code optimizations to process faster the pages
I'm on hold for your comments
Enjoy it!
He revisado la última versión del script para corregir un par de cosas:
- Ahora funciona correctamente el modo DontAsk (proceso batch -o por lotes- de las películas) [gracias Kreti]
- Ahora carga correctamente las imágenes aunque no tengan un poster grande [gracias Kreti]
- Ahora la sección 'Premios' de la página se incluye en los comentarios [gracias Félix A. del Blanco]
- Reordenación del código para optimizar la carga de información.
Espero vuestros comentarios.
Que os guste!
--------------------------------------------
Hi all,
I have reviewed the latest version of the script to fix some bugs and add new features:
- 'DontAsk' mode works again! (batch process of the films) [thanks Kreti]
- Now thie script also loads images that haven't enlarge version (posters) [thanks Kreti]
- Now the 'Awards' section (changed in the website) is loaded into the Comments field [thanks Félix A. del Blanco]
- Some code optimizations to process faster the pages
I'm on hold for your comments
Enjoy it!
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
Title=FilmAffinity (ES)
Description=Movie importation script for FilmAffinity Spain
Site=http://www.filmaffinity.com
Language=ES
Version=2.48
Requires=3.5.0
Comments=Updated: Script option for batch running (default disabled), and now it gets the category.
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
[Options]
DontAsk=1|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
***************************************************)
program FilmAffinity;
const
BaseURL1 = '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(var S: string; StartTag: string; EndTag: string): string;
var
InitialPos: Integer;
begin
InitialPos := Pos(StartTag, S);
if InitialPos = 0 then
result := ''
else
begin
Delete(S, 1, InitialPos + Length(StartTag) - 1);
InitialPos := Pos(EndTag, S);
if InitialPos = 0 then
result := S
else
begin
result := Copy(S, 1, InitialPos - 1);
Delete(S, 1, InitialPos + 1);
end;
end;
end;
//------------------------------------------------------------------------------------
function DeleteTags(var S: string): string;
var
n, len, tag: Integer;
c: char;
t: String;
begin
tag := 0;
t := '';
len := length(s);
for n :=1 to len do
begin
c := Copy(s,n,1);
// quitamos los tabuladores
if c = #9 then c := ' ';
if tag = 1 then
begin
if c = '>' then tag := 0;
continue;
end
else
begin
if c = '<' then
begin
tag := 1;
continue;
end;
t := t + c;
end;
end
s := t;
result := t;
end;
//------------------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line,Line2: string;
Count: Integer;
MovieTitle, MovieAddress: string;
begin
Count := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
PickTreeClear;
// Veamos si solo hay un solo resultado
LineNr := FindLine('<b>1 resultados.</b>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 7);
Line2 := Line;
MovieAddress := TextBetween(Line, '<b><a href="', '">');
MovieTitle := TextBetween(Line2, '.html">', '</td>');
HTMLDecode(MovieTitle);
DeleteTags(MovieTitle);
if (MovieAddress <> '') AND (MovieTitle <> '') then
begin
MovieAddress := BaseURL1 + MovieAddress;
PickTreeAdd(MovieTitle, MovieAddress);
if GetOption('DontAsk') = 0 then
if PickTreeExec(MovieAddress) then
AnalyzeMoviePage(MovieAddress);
if GetOption('DontAsk') = 1 then
AnalyzeMoviePage(MovieAddress);
end
Page.Free;
exit;
end;
// Veamos cuantos resultados se han encontrado
LineNr := FindLine('resultados.</b></td></tr>', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Count := StrToInt(TextBetween(Line, '<b>', ' resultados.</b>'), 0);
end;
// Si no hemos encontrado ningún resultado, abandonamos
if Count = 0 then
begin
ShowMessage('No se ha encontrado ningún registro');
Page.Free;
exit;
end;
LineNr := 0;
while TRUE do
begin
LineNr := FindLine('<b><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);
Address := TextBetween(Line, '<a href="', '">');
Page.Text := GetPage(Address);
LineNr := 0;
continue;
end;
Line := Page.GetString(LineNr);
Line2 := Line;
MovieAddress := TextBetween(Line, '<b><a href="', '">');
MovieTitle := TextBetween(Line2, '.html">', '</td>');
HTMLDecode(MovieTitle);
DeleteTags(MovieTitle);
if (MovieAddress <> '') AND (MovieTitle <> '') then
PickTreeAdd(MovieTitle, BaseURL1 + MovieAddress);
end;
if PickTreeExec(Address) then
AnalyzeMoviePage(Address);
Page.Free;
end;
//------------------------------------------------------------------------------------
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Item: string;
Comments: string;
Actors: string;
Directors: string;
begin
Comments := '';
Actors := '';
// URL
SetField(fieldURL, Address);
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Translated Title
LineNr := FindLine('<div style="margin-bottom: 4; padding:1; text-align: left; border-bottom: 1px solid #990000;"><span style="color:#990000; font-size:16; font-weight: bold;">', Page, 0);
Line := Page.GetString(LineNr);
Item := TextBetween(Line, ' border="0"> ', '</span>');
HTMLDecode(Item);
SetField(fieldTranslatedTitle, Trim(Item));
// Original Title
LineNr := FindLine('<b>TÍTULO ORIGINAL</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<td ><b>', '</b></td>');
HTMLDecode(Item);
SetField(fieldOriginalTitle, Trim(Item));
end;
// Year
LineNr := FindLine('<b>AÑO</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 3);
Item := TextBetween(Line, '<td >', '</td>');
HTMLDecode(Item);
SetField(fieldYear, Trim(Item));
end;
// Length
LineNr := FindLine('<b>DURACIÓN</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 3);
Item := TextBetween(Line, '<td>', ' min.</td>');
HTMLDecode(Item);
SetField(fieldLength, Trim(Item));
end;
// Country
LineNr := FindLine('<b>PAÍS</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 3);
Item := TextBetween(Line, 'title="', '" border');
HTMLDecode(Item);
SetField(fieldCountry, Trim(Item));
end;
// Director
LineNr := FindLine('<b>DIRECTOR</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Directors := '';
while Pos('stype=director', Line) > 0 do
begin
Item := TextBetween(Line, '">', '</a>');
HTMLDecode(Item);
if Directors = '' then
Directors := Item
else
Directors := Directors + ', ' + Item;
end;
SetField(fieldDirector, Trim(Directors));
end;
// Script writer
LineNr := FindLine('<b>GUIÓN</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<td >', '</td>');
Comments := Comments + 'Guión: ' + Item + #13#10 + #13#10;
end;
// Composer
LineNr := FindLine('<b>MÚSICA</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<td >', '</td>');
Comments := Comments + 'Música: ' + Item + #13#10 + #13#10;
end;
// Photography
LineNr := FindLine('<b>FOTOGRAFÍA</b', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<td >', '</td>');
Comments := Comments + 'Fotografía: ' + Item + #13#10 + #13#10;
end;
// Actors
LineNr := FindLine('<b>REPARTO</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := '';
while TRUE do
begin
LineNR := LineNR + 1;
Line := Line + Page.GetString(LineNr);
if Pos('</td>', Line) > 0 then
break;
end;
Actors := TextBetween(Line, '">', '</a>') + #13#10;
while Pos('stype=cast', Line) > 0 do
Actors := Actors + TextBetween(Line, '"> ', '</a>') + #13#10;
HTMLDecode(Actors);
SetField(fieldActors, Actors);
end;
// Productor
LineNr := FindLine('<b>PRODUCTORA</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<td >', '</td>');
HTMLDecode(Item);
SetField(fieldProducer, Trim(Item));
end;
// Official Webpage
LineNr := FindLine('<b>WEB OFICIAL</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Comments := Comments + 'Web oficial: ' + TextBetween(Line, '<a href="', '" target="_blank">') + #13#10 + #13#10;
end;
// Awards
LineNr := FindLine('<b>PREMIOS</b>', Page, LineNr);
if LineNr <> -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Comments := Comments + 'Premios: ' + #13#10;
while Pos('<a href="/es/awards.php', Line) > 0 do
begin
Item := DeleteTags(Line);
Comments := Comments + ' - ' + Trim(Item) + #13#10;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
end;
Comments := Comments + #13#10;
end;
// Category
LineNr := FindLine('<b>GÉNERO</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 2);
Item := DeleteTags(Line);
HTMLDecode(Item);
SetField(fieldCategory, Trim(Item));
end;
// Synopsis
LineNr := FindLine('<b>SINOPSIS</b>', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr + 1);
Item := TextBetween(Line, '<td>', '</td>');
HTMLDecode(Item);
SetField(fieldDescription, Trim(Item));
end;
// Critic
LineNr := FindLine('<b>CRÍTICAS</b>', Page, LineNr);
if LineNr <> -1 then
begin
Item := Page.GetString(LineNr + 3);
while Pos('<br>', Item) <> 0 do
Item := StringReplace(Item, '<br>', #13#10);
while Pos('</br>', Item) <> 0 do
Item := StringReplace(Item, '</br>', #13#10);
while Pos(' ', Item) <> 0 do
Item := StringReplace(Item, ' ', ' ');
Comments := Comments + 'Críticas: ' + #13#10 + DeleteTags(Item) + #13#10;
end;
// 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="', '"');
if Length(Item) = 0 then
Item := TextBetween(Line, '<img src="', '"');
GetPicture(Item);
end;
// Rating
LineNr := FindLine('<td align="center" style="color:#990000; font-size:22px; font-weight: bold;">', Page, LineNr);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Item := TextBetween(Line, '<td align="center" style="color:#990000; font-size:22px; font-weight: bold;">', '</td>');
HTMLDecode(Item);
SetField(fieldRating, Item);
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 MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if GetOption('DontAsk') = 0 then
Input('FilmAffinity', 'Pelicula:', MovieName);
if Pos('filmaffinity.com', MovieName) > 0 then
AnalyzeMoviePage(MovieName)
else
AnalyzePage(BaseURL1 +'/es/search.php?stext=' + UrlEncode(MovieName) + '&stype=Title');
end.