Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=(c) 2010 Luis Henrique Carneiro
Title=IGN
Description=Game information import script for IGN
Site=http://www.IGN.com
Language=EN,BR
Version=1.0
Requires=3.5.0
Comments=First public version
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]
***************************************************)
program IGN;
uses
StringUtils1;
var
GameName: string;
PageRoot: string;
ImageFrom: Integer;
// simple string procedures
function StringReplaceAll(S, Old, New: string): string;
begin
while Pos(Old, S) > 0 do
S := StringReplace(S, Old, New);
Result := S;
end;
procedure CutAfter(var Str: string; Pattern: string);
begin
Str := Copy(str, Pos(Pattern, Str) + Length(Pattern), Length(Str));
end;
procedure CutBefore(var Str: string; Pattern: string);
begin
Str := Copy(Str, Pos(Pattern, Str), Length(Str));
end;
// Loads and analyses page from internet
procedure AnalyzePage(Address: string);
var
Page: TStringList;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if Pos('NO RESULTS RETURNED FOR', Page.Text) > 0 then
begin
ShowMessage('Nothing found.');
Exit;
end
else
begin
PickTreeClear;
PickTreeAdd('Search results:', '');
AddGamesTitles(Page);
if PickTreeExec(Address) then
AnalyzeGamePage(Address);
end
end;
procedure AnalyzeGamePage(Address: string);
var
Page: string;
PageT: string;
Value: string;
Title: string;
RealTitle: string;
Review: string;
Tmp: string;
Tmp2: string;
Cover: string;
Comments: string;
ReviewLink: string;
TechLink: string;
ReqText: string;
Summary: string;
Score: string;
Scores: string;
ReviewHead: string;
ReviewAll: string;
Year: integer;
isBreak: integer;
isFirst: integer;
begin
Page := GetPage(Address);
tmp := TextBetween(Page,'score-ign-number','</div>');
tmp := TextBetween(tmp,'html">','<');
SetField(fieldRating, tmp);
tmp := TextBetween(Page,'<div class="column-about-boxart">','<div id="column-about"');
SetField(fieldDescription, tmp);
tmp:=TextBetween(Page,'<span class="txt-lbl">Genre:','br/>');
If (tmp = '') Then tmp := TextBetween(Page,'</span><strong>Genre:','br');
If (tmp = '') Then tmp := TextBetween(Page,' <strong>Genre: </strong><a','br');
tmp2 := TextBetween(tmp, '>', '<');
If (Length(tmp2) < 4) Then tmp2 := TextBetween(tmp, '">', '<');
SetField(fieldCategory, tmp2);
tmp:=TextBetween(Page,'>Developer:</span>','br/>');
If (tmp = '') Then tmp := TextBetween(Page,'>Developed by: <a','/a></');
tmp := TextBetween(tmp, '>', '<');
SetField(fieldDirector, tmp);
tmp:=TextBetween(Page,'"game-title"','span ');
If (tmp = '') Then tmp := TextBetween(Page,'<title>IGN','/title');
tmp2 := TextBetween(tmp, '>', '<');
If (tmp2 = '') Then tmp2 := TextBetween(tmp, ':', '<');
RealTitle := tmp2;
SetField(fieldOriginalTitle, RealTitle);
SetField(fieldTranslatedTitle, RealTitle);
tmp := TextBetween(Page,'<img id="gameDetailsBoxShotImg"','<br/>');
If (tmp = '') Then tmp := TextBetween(Page,'<div class="img-thumb"><a href="','</div>');
cover := TextBetween(tmp, 'src="', '"');
if cover = '/img/nogame_large.gif' then cover := '';
if (cover <> '') and CanSetPicture then GetPicture(cover);
tmp:=TextBetween(Page,'<strong>MSRP: </','br/>');
tmp := TextBetween(tmp, '>', '<');
SetField(fieldResolution, tmp);
//*** ESRB rating
tmp :=TextBetween(Page,'ESRB Rating:','/a>');
tmp := TextBetween(tmp, '">', '<');
if tmp <> '' then
begin
case tmp of
'EC': tmp2 := 'Early Childhood';
'E': tmp2 := 'Everyone';
'E10': tmp2 := '10+';
'T': tmp2 := '13+';
'M': tmp2 := '17+';
'AO': tmp2 := '18+';
'RP': tmp2 := 'Rating Pending';
else tmp2 := tmp;
end;
SetField(fieldCountry, tmp2);
end;
tmp := TextBetween(Page,'Publisher:</span>','<br/>');
If (tmp = '') Then tmp := TextBetween(Page,'Published by:','</strong>');
tmp := TextBetween(tmp, '">', '</a>');
SetField(fieldProducer, tmp);
tmp := TextBetween(Page,'"nav-platform"','/span');
tmp := TextBetween(tmp, '>', '<');
SetField(fieldMediatype, tmp);
tmp := TextBetween(Page,'<strong>Release Date:</strong>','br/>');
tmp := TextBetween(tmp,', ','<');
SetField(fieldYear, trim(copy(tmp, 0, 4)));
SetField(fieldUrl, Address);
tmp := TextBetween(Page,'<div class="nav-lnk"><a href="','" class="nav-content-lnk">');
If (tmp = '') Then tmp := TextBetween(Page,'<div class="objectNavBtn"><a href="http://cheats.ign.com','">CHEATS<');
if (tmp <> '') Then tmp := 'http://cheats.ign.com' + tmp;
Page := GetPage(tmp);
tmp := TextBetween(Page,'<h2 class="hdr-section">Cheats & Codes</h2>','<h2 class="hdr-tbl-discuss">');
HTMLRemoveTags(tmp);
HTMLDecode(tmp);
value:=FullTrim(tmp);
SetField(fieldComments,tmp);
end;
procedure AddGamesTitles(ResultsPage: TStringList);
var
Page: string;
GameTitle, GameAddress , Plat: string;
begin
Page := ResultsPage.Text;
while Pos('"searchResultTitle"', Page) > 0 do
begin
CutBefore(Page, '"searchResultTitle"');
GameAddress := GetStringFromHTML(Page, '<a ', 'href="', '">', 0);
Plat:= TextBetween(GameAddress,'http://','.');
GameTitle := GetStringFromHTML(Page, 'a href', '">', '</a>', 0) + ' (' + Plat + ')';
//ShowMessage('GA='+GameAddress+#10#13+'GT='+GameTitle);
CutAfter(Page, '</div>');
GameAddress := GameAddress;
PickTreeAdd(GameTitle, GameAddress);
end;
end;
function GetStringFromHTML(Page, StartTag, CutTag, EndTag: string; RemoveTags: Integer): string;
begin
Result := '';
// recognition tag - if present, extract detail from page, otherwise assume detail is not present
if Pos(StartTag, Page) > 0 then begin
CutBefore(Page, StartTag);
// optional cut tag helps finding right string in html page
if Length(CutTag) > 0 then
CutAfter(Page, CutTag);
// movie detail copied with html tags up to end string
Result := Copy(Page, 0, Pos(EndTag, Page) - 1);
// remove html tags (if needed) and decode html string
if RemoveTags > 0 then
begin
HTMLRemoveTags(Result);
end;
HTMLDecode(Result);
//ShowMessage('DEBUG: GetStringFromHTML - StartTag "'+StartTag+'", CutTag "'+CutTag+'", EndTag "'+EndTag+'", Result "'+Result+'" ___ '+Page);
end;
end;
procedure RemovePronoun(var Str: string);
var
i: Integer;
s: string;
c: char;
begin
// remove pronouns
if (Copy(Str, 0, 2) = 'L ') or (Copy(Str, 0, 2) = 'A ') then
Str := Copy(Str, 3, Length(Str) - 2)
else if (Copy(Str, 0, 3) = 'Le ') or (Copy(Str, 0, 3) = 'La ') or (Copy(Str, 0, 3) = 'Un ') then
Str := Copy(Str, 4, Length(Str) - 3)
else if (Copy(Str, 0, 4) = 'Les ') or (Copy(Str, 0, 4) = 'Une ') or (Copy(Str, 0, 4) = 'The ') then
Str := Copy(Str, 5, Length(Str) - 4);
Str := StringReplaceAll(Str, '_', ' ');
// remove non-letters, non-digits and non-spaces
// polish diacritics chars are allowed
s := '';
for i := 1 to Length(Str) do begin
c := StrGet(Str, i);
if ((c<'a') or (c>'z')) and
((c<'A') or (c>'Z')) and
((c<'0') or (c>'9')) and
(c<>' ') and (c<>'a') and
(c<>'A') and (c<>'e') and
(c<>'E') and (c<>'c') and
(c<>'C') and (c<>'s') and
(c<>'S') and (c<>'z') and
(c<>'Z') and (c<>'z') and
(c<>'Z') and (c<>'ó') and
(c<>'Ó') and (c<>'l') and
(c<>'L') and (c<>'n') and
(c<>'N') then
else
s := s + Copy(Str, i, 1);
end;
Str := s;
end;
begin
if CheckVersion(3,5,0) then begin
PageRoot := 'http://www.IGN.com';
GameName := GetField(fieldOriginalTitle);
if GameName = '' then GameName := GetField(fieldTranslatedTitle);
RemovePronoun(GameName);
if Input('IGN.com Import', 'Enter game title:', GameName) then
Gamename := StringReplaceAll(Gamename, ' ', '%20');
AnalyzePage('http://search.ign.com/products?query=' + GameName) ;
end else ShowMessage('AMC version required: 3.5.0');
end.