Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=dmitry501,Pavel Uher,Chetan Rao,Deadeye
Title=DVDEmpire.com
Description=Import script for DVD Empire
Site=http://www.dvdempire.com
Language=EN
Version=2.0.10
Requires=3.5.0
Comments=
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]
SearchType=1|1|0=Keyword (more results)|1=Title only (fewer results)
MediaType=0|0|0=DVD|1=Blu-ray|2=HD-DVD
PictureType=0|0|0=Large Picture|1=Small Picture
ClearCheckMark=0|0|0=No|1=Yes
***************************************************)
program DVDEmpire;
uses
StringUtils1;
var
MovieName: string;
extras: string;
// ----------------------------------------------------------------------------
function GetValues(Line : String; UseCommaDelimiter : Boolean): String;
var
Value : String;
StartPos : Integer;
EndPos : Integer;
Delimiter : String;
begin
Result := '';
Line := StringReplace(Line, '•', '');
if (UseCommaDelimiter) then
Delimiter := ','
else
Delimiter := #13 + #10;
while(true) do
begin
StartPos := Pos('">', Line) + 2;
EndPos := Pos('</a>', Line);
Value := Copy(Line, StartPos, EndPos - StartPos);
Line := Copy(Line, EndPos + 1, Length(Line) - EndPos);
if (EndPos < StartPos) then
break;
Value := Trim(Value);
HTMLDecode(Value);
HTMLRemoveTags(Value);
if (Length(Result) > 0) then
Result := Result + Delimiter;
Result := Result + Value;
end;
end;
// ----------------------------------------------------------------------------
procedure GetInfo(Page: TStringList; ItemID: String);
var Line, Value, Text, TempValue : String;
LineNR, StartPos, EndPos, LineNrEnd, i, y : Integer;
LineCR: Boolean;
begin
// Original Title
LineNr := FindLine('<td class="fontxlarge"', Page, 0);
if LineNr > -1 then
begin
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
EndPos := Pos('</strong>', Line);
StartPos := 9;
Value := Trim(Copy(Line, StartPos, EndPos - StartPos));
SetField(fieldOriginalTitle, Value);
// Media Type
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
StartPos := LastPos('"none"', Line) + 8;
EndPos := Pos('</a></b>', Line);
Value := Trim(Copy(Line, StartPos, EndPos - StartPos));
SetField(fieldMediaType, Value);
end;
// URL
SetField(fieldURL,'http://www.dvdempire.com/Exec/v4_item.asp?item_id=' + ItemID);
// Year
LineNr := FindLine('<b>Production Year:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Value := Trim(TextBetween (Line, '<b>Production Year:</b>', ' ') );
SetField(fieldYear, Value);
end;
// Length
LineNr := FindLine('<b>Length:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Value := Trim(TextBetween (Line, '<b>Length:</b>', 'mins') );
SetField(fieldLength, Value);
end;
//Number of Discs
LineNr := FindLine('<b>Number of Discs:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Value := Trim(TextBetween (Line, '<b>Number of Discs:</b>', '<br />') );
SetField(fieldDisks, Value);
end;
// Actors
LineNr := FindLine('<b>Actors:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := TextBetween(Line, '<b>Actors:</b>', '</td>');
Value := GetValues(Line, false);
SetField(fieldActors, Value);
end;
// Producers
LineNr := FindLine('<b>Producers:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := TextBetween(Line, '<b>Producers:</b>', '<b>Directors:</b>');
Value := GetValues(Line, true);
SetField(fieldProducer, Value);
end;
// Directors
LineNr := FindLine('<b>Directors:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Line := TextBetween(Line, '<b>Directors:</b>', '</td>');
Value := GetValues(Line, true);
SetField(fieldDirector, Value);
end;
// Picture
LineNr := FindLine('http://images.dvdempire.com/gen/movies/', Page, 0);
if LineNr > -1 then
if GetOption('PictureType') = 1 then
begin
Line := 'http://images.dvdempire.com/gen/movies/' + ItemID + '.jpg';
GetPicture(Line);
end
else
begin
Line := 'http://images.dvdempire.com/gen/movies/' + ItemID + 'h.jpg';
GetPicture(Line);
end;
// AudioFormat
LineNr := FindLine('<b>Audio:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
EndPos := Length(Line) + 1;
StartPos := LastPos(':', Line) + 1;
Value := Copy(Line, StartPos, EndPos - StartPos);
Value := Trim(StringReplace(Value, '[CC]', '') );
SetField(fieldAudioFormat, Value);
end;
// Languages
LineNr := FindLine('<b>Audio:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
HTMLRemoveTags(Line);
Value := TextBetween(Line, 'Audio:', ':');
Value := AnsiLowerCase(Value);
Value := AnsiUpFirstLetter(Value);
SetField(fieldLanguages, Value);
end;
//Subtitles
LineNr := FindLine('<b>Subtitles:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
HTMLDecode(Line);
HTMLRemoveTags(Line);
Value := TextAfter(Line, 'Subtitles:');
SetField(fieldSubtitles, Value);
end;
// VideoFormat / Resolution
LineNr := FindLine('<b>Video:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
HTMLDecode(Line);
HTMLRemoveTags(Line);
if Pos('Screen Resolution:', Line) > 0 then
begin
Value := Trim(TextBetween(Line, 'Video:', 'Screen Resolution:') );
SetField(fieldVideoFormat, Value);
Value := Trim(TextBetween(Line, 'Screen Resolution:', 'Audio:') );
SetField(fieldResolution, Value);
end
else
begin
Value := Trim(TextBetween(Line, 'Video:', 'Audio:') );
SetField(fieldVideoFormat, Value);
end;
end;
// Description
Value := TextBetween(Page.Text, '<td width="100%" valign="top" class="fontsmall3">', '</table>');
Value := StringReplace(Value, '>i<', '> <');
HTMLDecode(Value);
HTMLRemoveTags(Value);
Value := FullTrim(Value);
SetField(fieldDescription, Value);
// Rating
LineNr := FindLine('<b>Rating:</b>', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
Value := 'Rating: ' + Trim(TextBetween(Line, '<b>Rating:</b>', '<br />'));
SetField(fieldComments, Value);
end;
// Clear Check Mark
if GetOption('ClearCheckMark') = 1 then
SetField(fieldChecked, 'false');
end;
// ----------------------------------------------------------------------------
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr, StartPos, EndPos, L, EndPos2: Integer;
Line, TempValue: string;
ItemID, MovieAddress, MovieTitle : string;
AddItem : Boolean;
begin
PickTreeClear;
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<title>DVD Empire - Item -', Page, 0);
if LineNr > -1 then
begin
LineNr := FindLine('javascript:itemHelp(', Page, 0);
Line := Trim(Page.GetString(LineNr));
// parameters are separated by ', '
StartPos := pos(''', ''', Line) + 4; // move past the delimiter
Line := copy(Line, StartPos, length(Line) - StartPos + 1); // skip the starting quotes
ItemID := copy(Line, 0, pos(''', ''', Line) - 1);
GetInfo(Page,ItemID);
end
else
begin
LineNr := FindLine('</strong> Matches Found', Page, 0);
if LineNr >-1 then
begin
Line := Page.GetString(LineNr);
StartPos := pos('<strong>', Line) + Length('<strong>');
L := StrToInt('0'+ Copy(Line, StartPos, pos('</strong>', Line) - StartPos),1);
If L > 50 Then L := 50;
PickTreeAdd(IntToStr(L)+' Matches found', '');
If L > 0 Then
begin
// Find Films
LineNr := FindLine('<b><a href=''/Exec/v4_item.asp?item_id=', Page, LineNr + 1);
if LineNr >-1 then
begin
Line := Trim( Page.GetString(LineNr) );
repeat
// find the item id
StartPos := Pos('valign=''top''><b><a href=''/Exec/v4_item.asp?item_id=', Line) + 51;
EndPos := StartPos;
if (EndPos < 1) then
break;
repeat
TempValue := Copy(Line, EndPos, 1);
if (TempValue = '>') then
break;
EndPos := EndPos + 1;
until(EndPos < 1);
EndPos := EndPos - 1;
ItemID := Copy(Line, StartPos, EndPos - StartPos);
MovieAddress := 'http://www.dvdempire.com/Exec/v4_item.asp?item_id=' + ItemID;
// discard the stuff we've already processed
EndPos := EndPos + 2;
Line := Copy(Line, EndPos, Length(Line) - EndPos - 1);
// find the movie name
StartPos := 1;
Line := Copy(Line, StartPos, Length(Line) - StartPos);
EndPos := Pos('</a>', Line);
MovieTitle := Copy(Line, 1, EndPos - 1);
// add it to the tree
HTMLDecode(Movietitle);
HTMLRemoveTags(MovieTitle);
PickTreeAdd(MovieTitle, MovieAddress);
L := L - 1;
until (L = 0);
end;
end;
end;
Page.Free;
if PickTreeExec(Address) then
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
ItemID :=copy(Address, 51, 8);
GetInfo(Page,ItemID);
end;
end;
//DisplayResults;
end;
// ----------------------------------------------------------------------------
// Begin program
begin
if CheckVersion(3,5,0) then
begin
PickListClear;
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);
if Input('Import from www.dvdempire.com', 'Enter the title of the movie:', MovieName) then begin
MovieName := AnsiLowerCase(MovieName);
MovieName := StringReplace(MovieName, '’', '');
MovieName := StringReplace(MovieName, Chr(39), '');
MovieName := StringReplace(MovieName, ' ', '+');
// Blu-ray
if GetOption('MediaType')=1 then extras := '&site_id=69';
//HD-DVD
if GetOption('MediaType')=2 then extras := '&site_id=68';
// SearchType
if GetOption('SearchType')=1 then extras := extras + '&search_refined=32';
// &pp=3 limits results to 50
AnalyzePage('http://www.dvdempire.com/Exec/v5_search_item.asp?string='+MovieName+'&pp=3'+extras);
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.