This is my first script, not full, but really worked on it
Originally script is from Andrea Cristaudo, and comes with AMC pack.
Spanish database pages are a bit different from italian one, so i need not only to change strings, also work on checks, ...
Sure, some bugs, but i tried it with several movies and no problems. If any, tell me. Also, optimizations i can do for it are welcome.
Sorry if my english isn't 100% ok
Here's the script, i named file as: Yahoo Cinema (ES).ifs
Code: Select all
// GETINFO SCRIPTING
// Yahoo!Cinema (Spanish) v1.1
(**************************************************
* Movie importation script for: *
* Yahoo!Cinema (ES), http://es.movies.yahoo.com *
* *
* (c) 2003 Andrea Cristaudo achris@tiscalinet.it *
* *
* Updated for Spanish Database support and more *
* info importing by folgui (folgui@bigfoot.com) *
* *
* For use with Ant Movie Catalog 3.4.3 *
* www.antp.be/software/moviecatalog *
* *
* 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. *
***************************************************)
program YahooCinema;
const
LargePic = True; // Import Large Picture
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, False);
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;
strTemp: string;
Line: string;
ImageURL: 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 Not LargePic 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, False);
end
end
// Import Large Picture
else
begin
if pos('Agrandar la imagen</a>', Line) <> 0 then
begin
ImageURL := TextBetween(Line, '<a href="', '">Agrandar la imagen</a>');
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);
Delete(Line, 1, 9);
SetField(fieldLength, copy(Line, 1, 3));
If GetField(fieldLength) = '' then
SetField(fieldLength, copy(Line, 1, 2));
end
//Rating
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 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
SetField(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,4,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.4.0)');
end.