Pel', Page, 0);
if(LineNr > -1)then
begin
Line := Page.GetString(LineNr);
Line := MiTextBetween_2(Line,'
');
if not ModoBatch then
begin
PickTreeClear;
PickTreeAdd('ALPACINE: Resultados de la búsqueda:', '');
end
repeat
Item := MiTextBetween_2(Line,'
','');
if Item = '' then
begin
Item := MiTextBetween_2(Line,'
','');
PickTreeAdd('Más resultados', '');
PickTreeAdd(' >> MOSTRAR TODOS LOS RESULTADOS >>', Address + '&todo=1&tipo=2');
Line := MiTextAfter(Line,'');
end else
begin
MovieAddr := BaseURLAlpacine_Caratula + MiTextBetween_2(Line,'/pelicula/','/') + '/';
Year := MiTextAfter(Item,'');
Year := MiTextBetween_2(Year,'(',')');
HTMLRemoveTags(Item);
Item := Caracter(Item);
if not ModoBatch then
begin
if FiltradoAnyo = 0 then PickTreeAdd(Item, MovieAddr);
if FiltradoAnyo = 1 then
begin
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) - 1 then PickTreeAdd(Item, MovieAddr);
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) then PickTreeAdd(Item, MovieAddr);
if StrtoInt(Year,0) = StrtoInt(getfield(fieldYear),0) + 1 then PickTreeAdd(Item, MovieAddr);
end
if FiltradoAnyo = 2 then
if Year = getfield(fieldYear) then PickTreeAdd(Item, MovieAddr);
Line := MiTextAfter(Line,'');
end else
begin
if Year = getfield(fieldYear) then
begin
AnalyzeMoviePage_Alpacine(MovieAddr);
Line := '';
end else Line := MiTextAfter(Line,'');
end
end
Until Pos('
0 then
begin
AnalyzePage_Alpacine(Address);
end else AnalyzeMoviePage_Alpacine(Address);
end
end else if not ModoBatch then ShowError('ALPACINE: No se ha encontrado ninguna coincidencia para "'+ MovieName +'"');
Page.Free;
end;
procedure AnalyzeMoviePage_Alpacine(Address: string);
var
Page: TStringList;
LineNr: Integer;
Line: string;
Item: string;
Busca: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Caratula
LineNr := FindLine('src="http://img.alpacine.com/carteles/', Page, 0);
if LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
Busca := FindLine('id="ampliar">', Page, 0);
if Busca <> -1 then
begin
Item := TextBetween (Line, 'src="', '.jpg');
Item := StringReplace(Item , '-150', '');
GetPicture (Item+'.jpg');
end
else
begin
Item := TextBetween (Line, 'src="', '" alt');
GetPicture (Item);
end
end;
end;
procedure CINEOL_BuscarInformacion;
var url: String;
Articles: array of string;
Index: integer;
begin
SetArrayLength(Articles,11);
Articles[0]:='Lo ';
Articles[1]:='La ';
Articles[2]:='Le ';
Articles[3]:='Uno ';
Articles[4]:='Una ';
Articles[5]:='Un ';
Articles[6]:='El ';
Articles[7]:='Los ';
Articles[8]:='Las ';
Articles[9]:='Unos ';
Articles[10]:='Unas ';
// Eliminate spanish article if exists
for Index := 0 to 10 do
begin
if Pos(Articles[Index], MovieName) = 1 then
MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
end;
MovieName := StringReplace(MovieName,'.',' ');
MovieName := StringReplace(MovieName,' - ',' ');
MovieName := SansAccents(MovieName);
url := CINEOL_ListaBusqueda(BaseURLCineol, URLEncode('apiKey=cfdvkFD&search=' + MovieName));
if url <> '' then
CINEOL_RecuperarInformacionPelicula(url + '&apiKey=cfdvkFD');
end;
function CINEOL_ListaBusqueda(Address, params: String): string;
var
Titulo, url, texto, resultados: string;
cont: integer;
encontradoParaBatch: boolean;
begin
resultados := GetPage(Address + '?' + params);
resultados := Caracter(resultados);
resultados := MiTextBetween_2(resultados,'','');
if Pos('', resultados) > 0 then
begin
PickTreeClear;
PickTreeAdd('CINEOL: Resultados de la búsqueda:', '');
encontradoParaBatch := true;
cont := 0;
while Pos('', resultados) > 0 do
begin
texto := MiTextBetween_2(resultados,'','');
Titulo := MiTextBetween_2(texto,'','');
Titulo := Titulo + ' | (' + MiTextBetween_2(texto,'','') + ')';
url:= MiTextBetween_2(texto,'','');
if ModoBatch and (AnsiLowerCase(Titulo) = AnsiLowerCase(MovieName)) then
begin
encontradoParaBatch := true;
Break;
end
PickTreeAdd(Titulo, url);
resultados := MiTextAfter(resultados,'');
cont := cont + 1;
end
if ModoBatch then
begin
if encontradoParaBatch or (cont = 1) then
result := url;
end
else
begin
if PickTreeExec(Address) then result := Address
else result := '';
end
end else
if not ModoBatch then
ShowError('CINEOL: No se ha encontrado ninguna coincidencia para "'+ MovieName +'"');
end;
procedure CINEOL_RecuperarInformacionPelicula(Address: String);
var
resultados, s_aux, item, comentarios: string;
begin
resultados := GetPage(Address);
resultados := Caracter(resultados);
SetField(fieldURL, MiTextBetween_2(resultados,'',''));
SetField(fieldTranslatedTitle, MiTextBetween_2(resultados,'',''));
SetField(fieldOriginalTitle, MiTextBetween_2(resultados,'',''));
SetField(fieldCategory, MiTextBetween_2(resultados,'',''));
SetField(fieldCountry, MiTextBetween_2(resultados,'',''));
SetField(fieldLength, MiTextBetween_2(resultados,'',''));
SetField(fieldYear, MiTextBetween_2(resultados,'',''));
SetField(fieldRating, MiTextBetween_2(resultados,'',''));
// Director
s_aux := MiTextBetween_2(resultados,'','');
item := MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
while Pos('', s_aux) > 0 do
begin
item := item + ', ' + MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
end
SetField(fieldDirector, item);
// Productor
s_aux := MiTextBetween_2(resultados,'','');
item := MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
while Pos('', s_aux) > 0 do
begin
item := item + ', ' + MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
end
SetField(fieldProducer, item);
//Interpretes
s_aux := MiTextBetween_2(resultados,'','');
//v 2.0beta3 - JXO: Para volver al listado separado por comas, cambiar la linea comentada por la actual.
item := MiTextBetween_2(s_aux,'','') + ' (' + MiTextBetween_2(s_aux,'','') + ')' +#13#10;
//item := MiTextBetween_2(s_aux,'','') + ' (' + MiTextBetween_2(s_aux,'','') + ')';
s_aux := MiTextAfter(s_aux,'');
while Pos('', s_aux) > 0 do
begin
//v 2.0beta3 - JXO: Para volver al listado separado por comas, cambiar la linea comentada por la actual.
item := item + MiTextBetween_2(s_aux,'','') + ' (' + MiTextBetween_2(s_aux,'','') + ')' +#13#10;
//item := item + ', ' + MiTextBetween_2(s_aux,'','') + ' (' + MiTextBetween_2(s_aux,'','') + ')';
s_aux := MiTextAfter(s_aux,'');
end
SetField(fieldActors, item);
// Sinopsis
item := MiTextBetween_2(resultados,'','');
item := StringReplace(item, '
', #13#10);
item := StringReplace(item, #13#10#13#10#13#10, #13#10);
item := StringReplace(item, #13#10#13#10#13#10, #13#10);
item := StringReplace(item, '“','"');
item := StringReplace(item, '”','"');
item := StringReplace(item, '‘','''');
item := StringReplace(item, '’','''');
item := StringReplace(item, '–','-');
item := StringReplace(item, '—','-');
item := StringReplace(item, '[i]','');
item := StringReplace(item, '[/i]','');
HTMLDecode(item);
HTMLRemoveTags(item);
SetField(fieldDescription, item);
// Comentarios
comentarios := '';
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
begin
item := MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
while Pos('', s_aux) > 0 do
begin
item := item + ', ' + MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
end
comentarios := comentarios + 'Guión: ' + #9#9 + item + #13#10;
end
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
begin
item := MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
while Pos('', s_aux) > 0 do
begin
item := item + ', ' + MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
end
comentarios := comentarios + 'Música: ' + #9#9 + item + #13#10;
end
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
begin
item := MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
while Pos('', s_aux) > 0 do
begin
item := item + ', ' + MiTextBetween_2(s_aux,'','');
s_aux := MiTextAfter(s_aux,'');
end
comentarios := comentarios + 'Fotografía: ' + #9 + item + #13#10;
end
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
if s_aux <> '0' then comentarios := comentarios + 'Recaudación Esp.: ' +#9+ s_aux + ' euros' + #13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
if s_aux <> '0' then comentarios := comentarios + 'Recaudación USA: ' +#9+ s_aux + ' dolares' + #13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then comentarios := comentarios + 'Estreno España: ' + #9 + s_aux + #13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then comentarios := comentarios + 'Estreno Mundial: ' + #9 + s_aux + #13#10;
comentarios := comentarios + ' _________________________________________________'#13#10#13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then comentarios := comentarios + 'Erorramas: ' + #9 + s_aux + #13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then comentarios := comentarios + 'Frases: ' + #9#9 + s_aux + #13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then comentarios := comentarios + 'Cameos: ' + #9#9 + s_aux + #13#10;
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
//v 2.0beta3 - JXO: Para insertar unicamente la URL, cambiar la linea comentada por la otra.
comentarios := comentarios + CINEOL_RecuperarCuriosidades(s_aux);
//comentarios := comentarios + 'Curiosidades: ' + #9 + s_aux + #13#10;
//v 2.0beta3 + JXO
setField(fieldComments, comentarios);
//Carátula
if ModoBusquedaCaratula = 1 then
begin
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
begin
GetPicture(s_aux);
end else GetPicture(MiTextBetween_2(resultados,'',''));
end;
if ModoBusquedaCaratula = 0 then
begin
s_aux := MiTextBetween_2(resultados,'','');
if s_aux <> '' then
begin
GetPicture(s_aux);
end else
begin
GetPicture(MiTextBetween_2(resultados,'',''));
ModoBusquedaCaratula := 3;
end
end;
end;
//v 2.0beta3 - JXO
function CINEOL_RecuperarCuriosidades(Address: String) :string;
var
resultados, s_aux, comentarios, s_aux2: string;
begin
resultados := GetPage(Address);
resultados := Caracter(resultados);
// Curiosidades
s_aux := MiTextBetween_2(resultados,'','
');
//JXO: Limpio simbolos y formatos
s_aux := StringReplace(s_aux, #13#10 , '');
s_aux := StringReplace(s_aux, '
','');
s_aux := StringReplace(s_aux, '','');
s_aux2 := MiTextBetween_2(s_aux,'
');
while (s_aux2 <> '') do
BEGIN
s_aux := StringReplace(s_aux, s_aux2,'');
s_aux := StringReplace(s_aux, '','');
s_aux2 := MiTextBetween_2(s_aux,'');
END;
s_aux := StringReplace(s_aux, '','');
s_aux := StringReplace(s_aux, '','');
//JXO: Organizo y separo los resultados
s_aux := StringReplace(s_aux, '
' , '');
s_aux := StringReplace(s_aux, '
' , '');
s_aux := StringReplace(s_aux, ' ' , '');
s_aux := StringReplace(s_aux, '' , #13#10 +'----------------------------------------'+#13#10);
s_aux := StringReplace(s_aux, '
' , #13#10 +'----------------------------------------'+#13#10);
s_aux := StringReplace(s_aux, '
' , ' ');
comentarios := ' _________________________________________________'#13#10;
comentarios := comentarios + #13#10 +'CURIOSIDADES: ' + #13#10 + s_aux;
result := comentarios;
end;
//v 2.0beta3 + JXO
function buscaCampo2(patronInicial, patronFinal: String; offset: integer; ini, fin: string): String;
var
LineNr: Integer;
Line: string;
Item: string;
s: string;
hayMasDeUno: Boolean;
finalLinea: Integer;
begin
Result := '';
LineNr := FindLine(patronInicial, Page, 0);
if LineNr > 0 then
begin
LineNr := LineNr + offset;
Line := Page.GetString(LineNr);
if offset = 0 then
Line := copy(Line, pos(patronInicial ,Line)+length(patronInicial), length(Line));
if patronFinal <> '' then
Line := copy(Line, 1, pos(patronFinal ,Line));
Item := MiTextBetween (Line, ini, fin);
hayMasDeUno := false;
While trim(Item) <> '' do
begin
if hayMasDeUno then s := s + ' / ';
hayMasDeUno := true;
s := s + Item;
Line := copy(Line, pos(Item ,Line)+length(Item), length(Line));
Item := MiTextBetween (Line, ini, fin);
end;
HTMLDecode(s);
result := Trim(s);
end;
end;
function buscaCampo(patron: String; offset: integer; ini, fin: string): String;
begin
result := buscaCampo2(patron, '', offset, ini, fin);
end;
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
begin
ModoBusquedaCaratula := getOption('ModoBusquedaCaratula');
FiltradoAnyo := getOption('FiltradoAnyo');
ModoBatch := getOption('ModoBatch') = 1; //OJO: SI EL TITULO DE
//LA PELICULA NO COINCIDE NO MOSTRARA INFORMACIÓN, POR QUE LOS
//RESULTADOS DE LA BUSQUEDA NO LOS ORDENA POR ORDEN DE SEMEJANZA
{ Un modo mas cómodo de asignar las variables es marcando el check de la caratula y
del titulo traducido, en los "campos modificables". Si me desmarca la imagen no la buscaré
y si me marca el titulo traducido(por ejemplo) serà un proceso batch.:
BuscarCaratula := CanSetPicture();
ModoBatch := not CanSetField(fieldTranslatedTitle);
}
if CheckVersion(3,5,1) then
begin
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if (MovieName = '') or not (ModoBatch) then
if not Input('Importar de CINeol + Culturalia y/o Alpacine', 'Introduzca el titulo de la pelicula:', MovieName) then
Exit;
if (MovieName <> '') then
begin
CINEOL_BuscarInformacion; // El titulo a buscar siempre está en MovieName
if ModoBusquedaCaratula = 2 then BuscarCaratulaCulturalia;
if ModoBusquedaCaratula = 3 then
begin
MovieName := SansAccents(MovieName);
MovieName := StringReplace(MovieName, ' ', '+');
AnalyzePage_Alpacine(BaseURLAlpacine + UrlEncode(MovieName));
end
end;
end
else
ShowMessage('Este script requiere una version mas reciente de Ant Movie Catalog (por lo menos la version 3.5.1)');
end.