its not perfect but it works if you have the link to the movie on imdb already or only the imdb id only ...only in URL field
1)bring the pic. first
3)puts the plot outline or tagline in the comments field.
if you have another link in the URL that is different than the imdb it will skip the movie and move on to the next one.
Code: Select all
// GETINFO SCRIPTING
// IMDB (US) ** Automatic ** import with small picture
(* things to work on description import:
1) Plot summary import some summary contain
links in the summary , need to check <> tags
in the summary itself and delete them
2) if there is no plot outline & no tagline to import a
user comment if available ( 10 lines top !! usaily those users write nevels there :) ).
*)
(***************************************************
* Movie importation script for: *
* IMDB (US), http://us.imdb.com *
* *
* (c) 2002 Antoine Potten antoine@buypin.com *
* Improvements made by Danny Falkov *
* *
* For use with Ant Movie Catalog 3.3.0 *
* www.ant.be.tf/moviecatalog ··· www.buypin.com *
***************************************************)
program AutoIMDb;
var
MovieName,id,IMDBid: 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;
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
// Page.Text := Page2;
if pos('<TITLE>IMDb', Page.Text) = 0 then
begin
AnalyzeMoviePage(Page)
end else
begin
PickTreeClear;
LineNr := 0;
LineNr := FindLine('<H2><A NAME="top">Most popular searches</A></H2>', Page, LineNr);
if LineNr > -1 then
begin
PickTreeAdd('Most popular searches', '');
AddMoviesTitles(Page, LineNr);
end;
LineNr := FindLine('<H2><A NAME="mov">Movies</A></H2>', Page, LineNr);
if LineNr > -1 then
begin
PickTreeAdd('Movies', '');
AddMoviesTitles(Page, LineNr);
end;
LineNr := FindLine('<H2><A NAME="tvm">TV-Movies</A></H2>', Page, LineNr);
if LineNr > -1 then
begin
PickTreeAdd('TV-Movies', '');
AddMoviesTitles(Page, LineNr);
end;
LineNr := FindLine('<H2><A NAME="vid">Made for video</A></H2>', Page, LineNr);
if LineNr > -1 then
begin
PickTreeAdd('Made for video', '');
AddMoviesTitles(Page, LineNr);
end;
if PickTreeExec(Address) then
AnalyzePage(Address);
end;
Page.Free;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Line, Value, FullValue: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
begin
// Original Title & Year
LineNr := FindLine('<TITLE>', Page, 0);
Line := Page.GetString(LineNr);
if LineNr > -1 then
begin
BeginPos := pos('<TITLE>', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 7;
EndPos := pos('(', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos - 1);
HTMLDecode(Value);
SetField(fieldOriginalTitle, Value);
BeginPos := pos('(', Line) + 1;
if BeginPos > 0 then
begin
EndPos := pos(')', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldYear, Value);
end;
end;
//URL
LineNr := FindLine('<BASE HREF="', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<BASE HREF="', Line) + 12;
EndPos := pos('">', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldURL, Value);
end;
// Picture
LineNr := FindLine('<IMG SRC="http://posters.imdb.com/', Page, 0);
if LineNr < 0 then
LineNr := FindLine('<A HREF="/ImageView?', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<IMG SRC="', Line) + 10;
EndPos := pos('ALT="cover" ', Line);
if (BeginPos > 10) and (EndPos > 0) then
begin
Value := copy(Line, BeginPos, EndPos - BeginPos - 2);
GetPicture(Value, False); // False = do not store picture externally ; store it in the catalog file
end;
end;
// Rating
LineNr := FindLine('User Rating:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<B>', Line) + 3;
Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
SetField(fieldRating, Value);
end;
// Director
LineNr := FindLine('Directed by', Page, 0);
if LineNr > -1 then
begin
FullValue := '';
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
BeginPos := pos('">', Line) + 2;
EndPos := pos('</A>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
if (Value <> '(more)') and (Value <> '') then
begin
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value;
end;
until (pos('<BR><BR>', Line) > 0) or (LineNr >= Page.Count-1) or (Line = '<BR>');
HTMLDecode(FullValue);
SetField(fieldDirector, FullValue);
end;
// Actors
LineNr := FindLine('Cast overview', Page, 0);
if LineNr = -1 then
LineNr := FindLine('cast overview', Page, 0);
if LineNr = -1 then
LineNr := FindLine('Complete credited cast', Page, 0);
if LineNr > -1 then
begin
FullValue := '';
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if pos('<TD VALIGN="TOP">', Line) > 0 then
begin
Line := copy(Line, 25, Length(Line));
BeginPos := pos('">', Line) + 2;
EndPos := pos('</A>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
if (Value <> '(more)') and (Value <> '') then
begin
if FullValue <> '' then
FullValue := FullValue + ', ';
FullValue := FullValue + Value;
end;
end else
begin
Line := '';
end;
until Line = '';
HTMLDecode(FullValue);
SetField(fieldActors, FullValue);
end;
//Country
LineNr := FindLine('Country</B>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('/">', Line) + 3;
EndPos := pos('</A>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
SetField(fieldCountry, Value);
end;
//Category
LineNr := FindLine('Genre</B>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('/">', Line) + 3;
EndPos := pos('</A>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
SetField(fieldCategory, Value);
end;
//Description
LineNr := FindLine('Plot Summary:', Page, 0);
if LineNr < 1 then
LineNr := FindLine('Plot Outline:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('</B>', Line) + 4;
EndPos := pos('<A HREF', Line);
if EndPos < 1 then
Line := Line + Page.GetString(LineNr+1);
EndPos := pos('<A HREF', Line);
PickListClear;
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
// put the plot outline in the comments field , to disable it delete the line below
SetField(fieldComments, Value);
BeginPos := pos('/Plot?', Line);
EndPos := pos('"> (more)', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
GetDescriptions(Value);
//Value := '';
//if PickListExec('Select a description for "' + MovieName + '"', Value) then
end;
//Length
LineNr :=FindLine('Runtime</B>:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('</B>', Line) + 7;
EndPos := pos(' /', Line);
if EndPos = 0 then
EndPos := pos('</TD>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldLength, Value);
end;
// Language
LineNr := FindLine('Language</B>:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('/">', Line) + 3;
EndPos := pos('</A>', Line);
if EndPos = 0 then
EndPos := pos('</TD>', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldLanguages, Value);
end;
DisplayResults;
end;
procedure GetDescriptions(Address: string);
var
Line, Value: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
Page: TStringList;
begin
Page := TStringList.Create;
Page.Text := GetPage('http://us.imdb.com' + Address);
LineNr := FindLine('<P CLASS="plotpar">', Page, 0);
if LineNr > -1 then
begin
Value := '';
repeat
Line := Page.GetString(LineNr);
BeginPos := pos('"plotpar">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 10
else
BeginPos := 1;
EndPos := pos('</P>', Line);
if EndPos < 1 then
EndPos := Length(Line) + 1;
if Value <> '' then
Value := Value + ' ';
Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
LineNr := LineNr + 1;
until (pos('</P>', Line) > 0);
SetField(fieldDescription, Value);
LineNr := FindLine('<P CLASS="plotpar">', Page, LineNr);
end;
Page.Free;
end;
procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
Line: string;
MovieTitle, MovieAddress: string;
StartPos: Integer;
begin
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
StartPos := pos('="', Line);
if StartPos > 0 then
begin
Startpos := Startpos + 2;
MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos);
StartPos := pos('">', Line) + 2;
MovieTitle := copy(Line, StartPos, pos('</A>', Line) - StartPos);
HTMLDecode(Movietitle);
PickTreeAdd(MovieTitle, 'http://us.imdb.com' + MovieAddress);
end;
until pos('</OL>', Line) > 0;
end;
// add zeros to imdb id to be a 7 chars id
procedure GetIMDBid ();
var
URLfield : string;
i: Integer;
begin
URLfield := '' ;
// if the imdb id is in another field then add\change this field here
URLfield:=GetField(fieldURL);
if (length(URLfield) = 7) then IMDBid := URLfield
else if (length(URLfield) < 7) then
begin
i := Length(URLfield);
for i := 1 to 7 - Length(URLfield) do
IMDBid := IMDBid + '0';
IMDBid := IMDBid + URLfield;
end else
// if the URL has already a link to IMDB then get the id
//else if ( (length(URLfield) - pos('?' , URLfield)) > 7 ) then
IMDBid := copy(URLfield , pos('?' , URLfield)+1 , Length(URLfield)+1);
end;
// main script
begin
IMDBid := '';
GetIMDBid();
if (length(IMDBid) > 2) then
AnalyzePage('http://us.imdb.com/Title?' + IMDBid );
end.