He hecho unos cambios menores al script de Yahoo Cinema ES. Con esta versión:
· Se obtiene la imagen, que se había perdido por un cambio menor en la página
· Se puede especificar con una opción que el script NO descargue la duración de la película (que ya lo consigue Mediainfo)
· No busca por la "crítica", ya que Yahoo ha quitado la crítica mediante estrellas de los usuarios.
El código modificado, más abajo, debajo del post en inglés. Espero que guste,
enriquevagu
Hi all,
This is a minor update to the Yahoo Cinema ES script. The changes are:
· Picture retrieval is restored.
· New option added to specify if the length should be retrieved or not.
· It does not search for the "stars" rating, removed from the page.
Best regards,
enriquevagu
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Andrea Cristaudo (achris@tiscalinet.it) & folgui (folgui@bigfoot.com)
Title=Yahoo!Cinema Spain
Description=Movie importation script for Yahoo!Cinema Spain
Site=http://es.movies.yahoo.com
Language=ES
Version=1.3 (23 Sep 2005)
Requires=3.5.0
Comments=Updated by folgui for Spanish Database Support and more info importing. Reported/fixed bug by enriquevagu, thanks!|
License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
GetInfo=1
[Options]
LargePic=1|1|0=Importa la imagen pequeña|1=Importa una imagen mayor
ImportarDuracion=0|0|0=No importa la duración de la película|1=Importa la duración de la película
***************************************************)
program YahooCinema;
var
MovieName: string;
TheMovieAddress: 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);
Delete(S, 1, InitialPos + Length(StartTag) - 1);
InitialPos := Pos(EndTag, S);
result := copy(S, 1, InitialPos - 1);
Delete(S, 1, InitialPos + 1);
end;
procedure AnalyseLargePicPage(Address: string);
var
Page: TStringList;
LineNr: integer;
Line: string;
ImageURL: string;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<img src="http://eur.news1.yimg.com/eur.yimg.com/', Page, 0);
If LineNr <> -1 then
begin
Line := Page.GetString(LineNr);
ImageURL := TextBetween (Line, '<img src="', '"');
GetPicture (ImageURL);
end
Page.Free;
end;
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: integer;
BeginPos: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<font face=arial,helvetica size=+1><b>Resultados de búsqueda</b></font>', Page, 0);
if LineNr = -1 then
begin
SetField(fieldURL, Address);
AnalyzeMoviePage(Page);
end
else
begin
PickTreeClear;
AddMoviesTitles(Page);
if TheMovieAddress='' then
begin
if PickTreeExec(Address) then
begin
SetField(fieldURL, Address);
Page.Text := GetPage(Address);
AnalyzeMoviePage(Page);
end;
end
else
begin
SetField(fieldURL, TheMovieAddress);
Page.Text := GetPage(TheMovieAddress);
AnalyzeMoviePage(Page);
end;
end;
Page.Free;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Fine: Integer;
EndActors: Integer;
EndProducers: Integer;
EndMusics: Integer;
EndDirectors: Integer;
EndPhotographers: Integer;
EndWriters: Integer;
EndRating: Integer;
strActors: string;
strComments: string;
strProducers: string;
strMusics: string;
strDirectors: string;
strPhotographers: string;
strWriters: string;
Line: string;
ImageURL: string;
strTemp: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
Field: integer;
irate: integer;
begin
Page.Text := StringReplace(Page.Text, ' ', '');
Fine := 0;
LineNr := FindLine('<FONT color=white face="arial, helvetica"><b>', Page, 0);
if LineNr > -1 then
begin
//Translated Title
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
Line := StringReplace(Line,'"','');
SetField(fieldTranslatedTitle,Line);
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
//GetPicture of Movie
if GetOption('LargePic') = 0 then
// Import Small Picture
begin
if pos('html"><img src="http:', Line) <> 0 then
begin
Delete(Line, 1, pos('<img ', Line) + 9);
Delete(Line, pos('" border=', Line), pos('</a>', Line) + 1);
GetPicture(Line);
end
end
// Import Large Picture
else
begin
if pos('border=0 alt="Poster de ', Line) <> 0 then
begin
ImageURL := TextBetween(Line, '<a href="', '"><img src="');
AnalyseLargePicPage('http://es.movies.yahoo.com' + ImageURL);
end
end
//Original Title
if pos('<b>Título original:</b>', Line) <> 0 then
begin
HTMLRemoveTags(Line);
Delete(Line, 1, 16);
Line := StringReplace(Line,'"','');
SetField(fieldOriginalTitle, Line);
end
//Country and Year
else if pos('<b>País y año:</b>',Line) <> 0 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
SetField(fieldCountry, Line);
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
SetField(fieldYear, copy(Line, 2, 4));
end
//Category and Length
else if pos('<b>Género:</b>', Line) <> 0 then
begin
HTMLRemoveTags(Line);
Delete(Line, 1, 7);
SetField(fieldCategory, Line);
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
if GetOption('ImportarDuracion') = 1 then
begin
Delete(Line, 1, 9);
SetField(fieldLength, copy(Line, 1, 3));
If GetField(fieldLength) = '' then
SetField(fieldLength, copy(Line, 1, 2));
end
end
//Rating
//Yahoo cinema has removed the stars
// else if pos('<b>Crítica:</b>', Line) <> 0 then
// begin
// irate := 0;
// LineNr := LineNr + 1;
// Line := Page.GetString(LineNr);
// EndRating := pos('<img src="http://eur.i1.yimg.com/eur.yimg.com/i/de/mo/1sg.gif" width=10 height=9>', Line);
// while (EndRating = 0) and (irate < 5) do
// begin
// irate := irate + 1;
// LineNr := LineNr + 1;
// Line := Page.GetString(LineNr);
// EndRating := pos('<img src="http://eur.i1.yimg.com/eur.yimg.com/i/de/mo/1sg.gif" width=10 height=9>', Line);
// end
// SetField(fieldRating, IntToStr(irate*2));
// end
//Description
else if pos('<b>Sinopsis:</b>', Line) <> 0 then
begin
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
HtmlRemoveTags(Line);
SetField(fieldDescription, Line);
end
//List of Actors
else if pos('<b>Actor / Actriz:</b>', Line) <> 0 then
begin
strActors := '';
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
EndActors := pos('</font></td></tr>', Line);
while EndActors = 0 do
begin
HtmlRemoveTags(Line);
if strActors = '' then
strActors := Line
else
strActors := strActors + ' ' + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndActors := pos('</font></td></tr>', Line);
end
If GetField(fieldActors) = '' then
SetField(fieldActors, strActors)
else
SetField(fieldActors, GetField(fieldActors) + ', ' + strActors);
end
else if pos('Montador:</b>', Line) <> 0 Then
begin
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
HtmlRemoveTags(Line);
strComments := 'Montaje: ' + Line + #13#10;
end
// Music for Comments
else if pos('<b>Musica:</b>', Line) <> 0 then
begin
strMusics := '';
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
EndMusics := pos('</font></td></tr>', Line);
while EndMusics = 0 do
begin
HtmlRemoveTags(Line);
if strMusics = '' then
strMusics := Line
else
strMusics := strMusics + ' ' + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndMusics := pos('</font></td></tr>', Line);
end
strComments := strComments + 'Música: ' + strMusics + #13#10;
end
// Aditional Music Author for Comments
else if pos('<b>Compositor (música adicional):</b>', Line) <> 0 then
begin
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
HtmlRemoveTags(Line);
strComments := strComments + 'Compositor: ' + Line + #13#10;
end
//Director
else if pos('<b>Director:</b>', Line) <> 0 then
begin
strDirectors := '';
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
EndDirectors := pos('</font></td></tr>', Line);
while EndDirectors = 0 do
begin
HtmlRemoveTags(Line);
if strDirectors = '' then
strDirectors := Line
else
strDirectors := strDirectors + ' ' + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndDirectors := pos('</font></td></tr>', Line);
end
SetField(fieldDirector, strDirectors);
end
//Photography for Comments
else if pos('<b>Fotografía:</b>', Line) <> 0 then
begin
strPhotographers := '';
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
EndPhotographers := pos('</font></td></tr>', Line);
while EndPhotographers = 0 do
begin
HtmlRemoveTags(Line);
if strPhotographers = '' then
strPhotographers := Line
else
strPhotographers := strPhotographers + ' ' + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndPhotographers := pos('</font></td></tr>', Line);
end
strComments := strComments + 'Fotografía: ' + strPhotographers + #13#10;
end
//Screenplay Writer for Comments
else if (pos('<b>Guionista:</b>', Line) <> 0) Or (pos('<b>Guión', Line) <> 0) then
begin
strWriters := '';
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
EndWriters := pos('</font></td></tr>', Line);
while EndWriters = 0 do
begin
HtmlRemoveTags(Line);
if strWriters = '' then
strWriters := Line
else
strWriters := strWriters + ' ' + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndWriters := pos('</font></td></tr>', Line);
end
strComments := strComments + 'Guionista: ' + strWriters + #13#10;
end
//Producer
else if (pos('<b>Producción:</b>', Line) <> 0) Or (pos('<b>Productor', Line) <> 0) then
begin
strProducers := '';
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
EndProducers := pos('</font></td></tr>', Line);
while EndProducers = 0 do
begin
HtmlRemoveTags(Line);
if strProducers = '' then
strProducers := Line
else
strProducers := strProducers + ' ' + Line;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndProducers := pos('</font></td></tr>', Line);
end
SetField(fieldProducer, strProducers);
end
// More Comments
else if pos('<b>Notas de Producción</b>', Line) <> 0 then
begin
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
strTemp := TextBetween(Line, '<FONT face=arial size=-1>', '<a href="');
HtmlDecode(strTemp);
strComments := strComments + '------------------------------';
strComments := strComments + #13#10 + strTemp;
end
// More Comments
else if pos('<b>Crítica</b>', Line) <> 0 then
begin
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
strTemp := TextBetween(Line, '<FONT face=arial size=-1>', '<a href="');
HtmlDecode(strTemp);
strComments := strComments + '------------------------------';
strComments := strComments + #13#10 + strTemp;
end
else if Line = '</html>' then
Fine := 1;
until Fine = 1;
SetField(fieldComments, strComments);
end;
//DisplayResults;
end;
procedure AddMoviesTitles(Page: TStringList);
var
LineNr: Integer;
NewLineNr: Integer;
Line: string;
MovieTitle, MovieAddress: string;
BeginPos, EndPos: Integer;
begin
TheMovieAddress := '*';
LineNr := 0;
LineNr := FindLine('<font face=arial,helvetica><b>Resultado de películas</b>',Page,LineNr);
LineNr := LineNr + 3;
PickTreeAdd('Resultados encontrados:','');
while LineNr > 2 do
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<li><a href="',Line)+13;
EndPos := pos('">',Line);
MovieAddress := copy(Line,BeginPos,EndPos-BeginPos);
Delete(Line,1,EndPos + 1);
BeginPos := 1;
EndPos := -1;
MovieTitle := Line;
HTMLRemoveTags(MovieTitle);
HTMLDecode(Movietitle);
PickTreeAdd(MovieTitle, MovieAddress);
NewLineNr := FindLine('<li><a href="',Page,LineNr+1);
if NewLineNr <> (LineNr + 1) then
LineNr := 2
else
LineNr := NewLineNr;
if TheMovieAddress='*' then
TheMovieAddress := MovieAddress
else
TheMovieAddress := '';
end;
if TheMovieAddress='*' then TheMovieAddress := '';
end;
begin
if CheckVersion(3,5,0) then
begin
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if Input('Yahoo!Cinema España', 'Introduce el título de la película (enter movie title):', MovieName) then
begin
AnalyzePage('http://es.search.movies.yahoo.com/search/movies_db_es?mt='+UrlEncode(MovieName));
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.