(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Fabian Filipczyk, Bad Joker, VisualMAx, U. Pollaehne, gerol
Title=OFDb - IMDb - mod
Description=Combined OFDb / IMDb (DE)|German Title, Picture and Description from OFDb|All other from IMDb (DE)
Site=www.ofdb.de
Language=DE,EN
Version=1.6.2
Requires=3.5.0
Comments=Import from Online-Filmdatenbank (OFDb) http://www.ofdb.de|and Internet Movie Database (IMDb) http://us.imdb.com
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]
ActorsLayout=0|0|0=Separate actors by comma (default)|1=Separate actors by slash|2=Separate actors by linebreak
DirectorsLayout=0|0|0=Separate directors by comma (default)|1=Separate directors by slash
ProducersLayout=0|0|0=Separate producers by comma (default)|1=Separate producers by slash
CountryLayout=0|0|0=Separate countries by comma (default)|1=Separate countries by slash
CategoryLayout=0|0|0=Separate categories by comma (default)|1=Separate categories by slash
AudioFormatLayout=0|0|0=Separate Audio-Format by comma (default)|1=Separate Audio-Format by slash
AspectRatio=0|0|0=don't import Aspect Ratio (default)|1=Import Aspect Ratio to resolution field|2=Import Aspect Ratio to video format field
Audio=0|0|0=don't import Sound Mix (Tonverfahren) (default)|1=Import Sound Mix (Tonverfahren) to audio format field
FSK=1|0|0=don't import certification (Altersfreigabe) (default)|1=Add certification (Altersfreigabe) to description field|2=Import certification (Altersfreigabe) to comments field
***************************************************)
(***************************************************
* *
* (c) 2002 Fabian Filipczyk FFJaro@gmx.de *
* *
* @2003 *
* Overworked by Bad Joker badjoker@gmx.de *
* *
* @16.10.2004 *
* Modified by VisualMAx (at)gmail.com *
* *
* @19.12.2004 *
* Modified by u.pollaehne (at)web.de *
* *
* @08.01.2006 *
* Modified by Bad Joker badjoker@gmx.de *
* *
* @2008 *
* Modified by bad4u and gerol *
* *
* @2009, 2010 *
* Modified by gerol *
* *
***************************************************)
var
MovieName, IMDbURL, GerIMDbDURL: string;
ActorsSeparator, DirectorsSeparator, ProducersSeparator, CountriesSeparator, CategoriesSeparator, AudioFormatSeparator: string;
procedure SetSeparators;
begin
case GetOption('ActorsLayout') of
0: ActorsSeparator := ', ';
1: ActorsSeparator := ' / ';
end;
case GetOption('DirectorsLayout') of
0: DirectorsSeparator := ', ';
1: DirectorsSeparator := ' / ';
end;
case GetOption('ProducersLayout') of
0: ProducersSeparator := ', ';
1: ProducersSeparator := ' / ';
end;
case GetOption('CountryLayout') of
0: CountriesSeparator := ', ';
1: CountriesSeparator := ' / ';
end;
case GetOption('CategoryLayout') of
0: CategoriesSeparator := ', ';
1: CategoriesSeparator := ' / ';
end;
case GetOption('AudioFormatLayout') of
0: AudioFormatSeparator := ', ';
1: AudioFormatSeparator := ' / ';
end;
end;
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 AnalysePage(Address: string);
var
Page: TStringList;
LineNr: Integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if pos('OFDb - Suchergebnis', Page.Text) = 0 then
begin
AnalyseOFDBPage(Page)
AnalyseIMDBDPage(Page)
AnalyseIMDBPage(Page)
end else
begin
if FindLine('Titel:
Keine Ergebnisse', Page, 0) > 0 then
begin
ShowMessage('Die Suche nach "' + MovieName +'" ergab kein Ergebniss, bitte den Titel ändern.');
if Input('OFDb IMDb (DE)', 'Bitte einen anderen Titel eingeben :', MovieName) then
begin
AnalysePage('http://www.ofdb.de/view.php?page=suchergebnis&SText='+UrlEncode(UTF8Encode(MovieName))+'&Kat=All');
end;
end else
begin
PickTreeClear;
LineNr := FindLine('Titel:', Page, 0);
if LineNr > 0 then
begin
PickTreeAdd('Suche nach "' + MovieName + '" ergab:', '');
Address := AddMoviesTitles(Page, LineNr);
if Address = '' then
begin
if PickTreeExec(Address) then
AnalysePage(Address);
end else
AnalysePage(Address);
end;
end;
end;
Page.Free;
end;
function AddMoviesTitles(Page: TStringList; var LineNr: Integer) : string;
var
Line: string;
Headline, MovieTitle, MovieAddress: string;
StartPos, HeadlinePos, EndPos, NumTitles: Integer;
Multi: boolean;
begin
Multi := true;
result := '';
Headline := '';
Line := Page.GetString(LineNr);
NumTitles := 0;
repeat
StartPos := pos(' 0 then
begin
HeadlinePos := pos('
', Line);
if (HeadlinePos > 0) and (HeadlinePos < StartPos) then
begin
Headline := copy(Line, HeadlinePos + 7, Pos('
', Line) - HeadlinePos - 7);
Headline := UTF8Decode(Headline);
HTMLDecode(Headline);
PickTreeAdd(Headline, '');
end;
Delete(Line, 1, StartPos + 8);
MovieAddress := copy(Line, 1, pos('''>', Line) - 1);
if Multi = false then
MovieAddress := copy(Line, 1, pos('" onmouseover=', Line) - 1);
StartPos := pos('''>', Line) + 2;
if Multi = false then
StartPos := pos('">', Line) + 2;
MovieTitle := copy(Line, StartPos, pos('', Line) - StartPos);
MovieTitle := UTF8Decode(MovieTitle);
HTMLRemoveTags(MovieTitle);
NumTitles := NumTitles + 1;
PickTreeAdd(MovieTitle, 'http://www.ofdb.de/' + MovieAddress);
end;
until (StartPos < 1);
if NumTitles = 1 then
result := 'http://www.ofdb.de/' + MovieAddress;
end;
procedure AnalyseOFDBPage(Page: TStringList);
var
Line, Temp, Value, NewURL: string;
LineNr, BeginPos, EndPos: Integer;
begin
// Get IMDb URL + Set german IMDb URL
begin
LineNr :=Findline('http://www.imdb.com/Title?', Page, 0);
Line := Page.GetString(LineNr);
BeginPos := pos('Title?', Line)+6;
EndPos := pos('" target', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
NewURL := ('http://www.imdb.de/title/tt' + Value);
SetField(fieldURL, NewURL);
BeginPos := pos('Title?', Line)+6;
EndPos := pos('" target', Line);
Temp := copy(Line, BeginPos, EndPos - BeginPos);
Value := ('http://www.imdb.de/title/tt' + Temp + '/fullcredits#cast');
GerIMDbDURL := Value;
Value := ('http://us.imdb.com/title/tt' + Temp + '/');
IMDbURL := Value;
end;
// Original & Translated Title
LineNr := FindLine('Originaltitel:', Page, 0);
if LineNr > -1 then
begin
LineNr:= LineNr+2;
Line := Page.GetString(LineNr);
BeginPos := pos('class="Daten">', Line) + 17;
EndPos := pos('', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldOriginalTitle, Value);
LineNr := Findline('sans-serif" size="3">', Page, 0);
if LineNr > -1 then
begin
Line:= Page.GetString(LineNr);
BeginPos := pos('sans-serif" size="3">',Line) +24;
Endpos := pos('',Line);
Value := copy(Line,BeginPos, Endpos-Beginpos);
Value := UTF8Decode(Value);
SetField(fieldTranslatedTitle,Value);
end;
end;
// Picture
LineNr := FindLine('
10 then
begin
EndPos := pos(' alt=', Line)-1;
Value := copy(Line, BeginPos, EndPos - BeginPos);
GetPicture(Value);
end;
end;
// Description
LineNr := Findline('Inhalt:', Page, 0);
if LineNr > -1 then
begin
LineNr := Findline('[mehr]', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLRemoveTags(Value);
Value := UTF8Decode(Value);
GetDescriptions(Value);
end;
end;
procedure GetDescriptions(Address: string);
var
Line, Temp, Value: string;
LineNr, BeginPos, EndPos: Integer;
Page: TStringList;
begin
Temp:= '';
Page := TStringList.Create;
Page.Text := GetPage('http://www.ofdb.de/' + Address);
LineNr := FindLine('Eine Inhaltsangabe von', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('
', Line)+16;
while (pos('
', Line) >0) do
begin
EndPos := pos('
', Line);
Temp := Temp + copy(Line, BeginPos, EndPos - BeginPos);
LineNr:=LineNr+1;
Line:=Page.GetString(LineNr);
BeginPos:=1;
end;
EndPos := pos('
', Line);
Temp:= Temp + copy(Line, BeginPos, EndPos - BeginPos);
Value:= Temp;
Value := UTF8Decode(Value);
SetField(fieldDescription, Value);
end;
Page.Free;
end;
procedure AnalyseIMDBDPage(Page: TStringList);
var
Line, Value, Value2, FullValue, GerTitle, Ger, Temp: string;
BeginPos, EndPos, LineNr, TempPos: Integer;
begin
Page.Text := GetPage(GerIMDbDURL);
// Producers
LineNr := FindLine(' name="producers"', Page, 0);
if LineNr > -1 then
begin
Value := '';
EndPos := 0;
Line := Page.GetString(LineNr);
BeginPos := Pos('>Produktion<', Line);
EndPos := Pos(' name="music_original"', Line);
if EndPos = 0 then
begin
EndPos := Pos(' name="cinematographers"', Line);
end;
Line := copy(Line, BeginPos, EndPos - BeginPos);
BeginPos := pos('/">', Line) + 2;
Delete(Line, 1, BeginPos);
EndPos := pos('', Line);
Value := copy(Line, 1, EndPos - 1);
repeat
Delete(Line, 1, EndPos);
BeginPos := pos('/">', Line) + 3;
if BeginPos > 3 then
begin
EndPos := pos('', Line);
Value := Value + ProducersSeparator + copy(Line, BeginPos, EndPos - BeginPos);
end;
until (Line = '') or (BeginPos = 3);
Value := UTF8Decode(Value);
HTMLDecode(Value);
SetField(fieldProducer, Value);
end;
end;
procedure AnalyseIMDBPage(Page: TStringList);
var
Line, Value, Value2, FullValue: string;
BeginPos, EndPos, LineNr: Integer;
begin
// Original Title & Year
Page.Text := GetPage(IMDbURL);
LineNr := FindLine('', Page, 0);
Line := Page.GetString(LineNr);
if LineNr > -1 then
begin
BeginPos := pos('', 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);
Value := UTF8Decode(Value);
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;
// IMDb Rating
LineNr := FindLine('/10', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('', Line) + 3;
EndPos := BeginPos + 3;
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldRating, Value);
end;
// Directors
LineNr := FindLine('director-info', Page, 0);
if LineNr > -1 then
begin
LineNr := LineNr + 3;
FullValue := '';
repeat
LineNr := LineNr + 4;
Line := Page.GetString(LineNr);
BeginPos := pos('">', Line) + 2;
EndPos := pos('', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
if (Value <> 'more') and (Value <> '') then
begin
if FullValue <> '' then
FullValue := FullValue + DirectorsSeparator;
FullValue := FullValue + Value;
end;
until Value = '';
FullValue := UTF8Decode(FullValue);
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('Credited cast', Page, 0);
if LineNr = -1 then
LineNr := FindLine('Complete credited cast', Page, 0);
if LineNr > -1 then
begin
FullValue := '';
Line := Page.GetString(LineNr);
repeat
BeginPos := Pos('', Line);
if BeginPos > 0 then
begin
Delete(Line, 1, BeginPos);
Line := copy(Line, 26, Length(Line));
BeginPos := pos('">', Line) + 2;
EndPos := pos('', Line);
if EndPos = 0 then
EndPos := Pos(' | ', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
if (Value <> '(more)') and (Value <> '') then
begin
BeginPos := pos('', Line);
if BeginPos > 0 then
begin
BeginPos := BeginPos + 17;
Value2 := copy(Line, BeginPos, 7);
EndPos := pos(' | ', Line);
Value2 := copy(Line, BeginPos, EndPos - BeginPos);
if Value2 <> '' then
Value := Value + ' (als ' + Value2 + ')';
end;
if FullValue <> '' then
if GetOption('ActorsLayout') < 2 then
FullValue := FullValue + ActorsSeparator
else
FullValue := FullValue + #13#10;
FullValue := FullValue + Value;
end;
EndPos := Pos('', Line);
Delete(Line, 1, EndPos);
end else
begin
Line := '';
end;
until Line = '';
FullValue := UTF8Decode(FullValue);
HTMLRemoveTags(FullValue);
HTMLDecode(FullValue);
SetField(fieldActors, FullValue);
end;
// Comments
begin
LineNr := FindLine('Summary:', Page, 0);
if LineNr > -1 then
begin
Value := '';
repeat
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndPos := Pos('', Line);
if EndPos = 0 then
EndPos := Length(Line)
else
EndPos := EndPos - 1;
Value := Value + Copy(Line, 1, EndPos) + ' ';
until Pos('', Line) > 0;
HTMLDecode(Value);
Value := StringReplace(Value, '
', #13#10);
Value := StringReplace(Value, #13#10+' ', #13#10);
Value := UTF8Decode(Value);
SetField(fieldComments, Value);
end;
end;
// Length
LineNr := FindLine('Runtime:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('Runtime:', Line);
Line := copy(Line, BeginPos, Length(Line));
BeginPos := pos('info-content">', Line);
EndPos := pos(' min', Line);
Line := copy(Line, BeginPos, EndPos - BeginPos);
if Pos(':', Line) > 0 then
BeginPos := Pos(':', Line) + 1
else
BeginPos := 15;
Value := copy(Line, BeginPos, Length(Line));
SetField(fieldLength, Value);
end;
// Language
LineNr := FindLine('Language:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('/Sections/Languages', Line);
Line := copy(Line, BeginPos, Length(Line));
BeginPos := pos('/">', Line) + 3;
EndPos := pos('', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
Value := UTF8Decode(Value);
SetField(fieldLanguages, Value);
end;
// Countries
LineNr := FindLine('Country:', Page, 0);
if LineNr > -1 then
begin
Value := '';
Line := Page.GetString(LineNr);
repeat
BeginPos := pos('/Sections/Countries', Line);
Line := copy(Line, BeginPos, Length(Line));
BeginPos := pos('/">', Line) + 3;
EndPos := pos('', Line);
If Value <> '' then
Value := Value + CountriesSeparator;
Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
Line := copy(Line, BeginPos, Length(Line));
until pos('/Sections/Countries', Line) = 0;
Value := UTF8Decode(Value);
HTMLDecode(Value);
SetField(fieldCountry, Value);
end;
// Categories
LineNr := FindLine('Genre:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr + 2);
BeginPos := pos('/">', Line) + 3;
EndPos := pos('', Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
repeat
Delete(Line, 1, EndPos);
BeginPos := pos('/">', Line) + 3;
if BeginPos > 3 then
begin
EndPos := pos('', Line);
Value := Value + CategoriesSeparator + copy(Line, BeginPos, EndPos - BeginPos);
end;
until (Line = '') or (BeginPos = 3);
Value := UTF8Decode(Value);
HTMLDecode(Value);
SetField(fieldCategory, Value);
end;
//AspectRatio
if GetOption('AspectRatio') > 0 then
begin
LineNr := FindLine('Aspect Ratio:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr + 2);
EndPos := pos(' 0 then
begin
LineNr := FindLine('Sound Mix:', Page, 0);
if LineNr > -1 then
begin
LineNr := LineNr + 4;
Line := Page.GetString(LineNr);
EndPos := pos('', Line);
Value := copy(Line, 1, EndPos - 1);
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
if pos('', Line) = 0 then
begin
repeat
EndPos := pos('', Line);
Value := Value + AudioFormatSeparator + copy(Line, 1, EndPos - 1);
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
until pos('', Line) > 0
end;
if CanSetField(fieldAudioFormat) then
SetField(fieldAudioFormat, Value);
end;
end;
//FSK
if GetOption('FSK') > 0 then
begin
LineNr := FindLine('Certification:', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('Certification:', Line);
Line := copy(Line, BeginPos, Length(Line));
BeginPos := pos('Germany:', Line) + 8;
if BeginPos = 8 then
begin
BeginPos := pos('West Germany:', Line) + 13;
if BeginPos = 13 then
BeginPos := 0;
end;
if BeginPos > 0 then
begin
Line := copy(Line, BeginPos, Length(Line));
EndPos := pos('', Line) - 1;
Value := copy(Line, 1, EndPos);
If Value = 'o.Al.' then
Value := 'Ohne Altersbeschränkung';
if (CanSetField(fieldDescription)) and (GetOption('FSK') = 1) then
begin
Value := 'FSK: ' + (Value + #13#10 + GetField(fieldDescription));
SetField(fieldDescription, Value);
end;
if (CanSetField(fieldComments)) and (GetOption('FSK') = 2) then
begin
Value := 'FSK: ' + Value;
SetField(fieldComments, Value);
end;
end;
end;
end;
end;
begin
if CheckVersion(3,5,0) then
begin
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
Input('OFDb', 'Bitte Titel eingeben :', MovieName);
SetSeparators;
AnalysePage('http://www.ofdb.de/view.php?page=suchergebnis&Kat=Titel&SText='+StringReplace(UrlEncode(UTF8Encode(MovieName)),'&%','%26%'));
end
else
ShowMessage('Dieses Script benötigt eine neuere Version von Ant Movie Catalog (mindestens Version 3.5.0)');
end.