Below v1.0 of gamespot.com import script. No images support. Comments are welcome. Going to sleep. Bye.
t.
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=(c) 2005 tomba
Title=GameSpot
Description=Game information import script for GameSpot
Site=http://www.gamespot.com
Language=EN
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 GameSpot;
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;
procedure cleanSpaces(var Str: string);
var one: char;
theEnd: integer;
begin
theEnd := 1;
while(theEnd > 0) do begin
one := StrGet(Str,1);
if(Pos(#13,one)>0) then CutAfter(Str,#13)
else if(Pos(#10,one)>0) then CutAfter(Str,#10)
else if(one = ' ') then CutAfter(Str,' ')
else theEnd := 0;
end
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;
Value: string;
Title: string;
Review: string;
Tmp: string;
Tmp2: string;
Comments: string;
ReviewLink: string;
TechLink: string;
ReqText: string;
Summary: string;
Score: string;
Scores: string;
ReviewHead: string;
ReviewAll: string;
isBreak: integer;
isFirst: integer;
begin
Page := GetPage(Address);
isBreak := 1;
isFirst := 1;
Tmp := TextBetween(Address, PageRoot, 'index.html');
Tmp := PageRoot + Tmp + 'index.html';
SetField(fieldURL, Tmp);
CutBefore(Page,'<ul id="tabs">');
CutBefore(Page,'<li class="tab">');
ReviewLink := GetStringFromHTML(Page, '<a', 'href="', '">Reviews</a>',0);
ReviewLink := PageRoot+ReviewLink;
TechLink := TextBetween(Address, PageRoot, 'index.html');
TechLink := PageRoot+TechLink+'tech_info.html';
CutBefore(Page,'<div class="f12 dots pb5 mb5">');
Summary := GetStringFromHTML(Page,'<div class="f12 dots pb5 mb5">', '<div class="f12 dots pb5 mb5">', '<br',1);
Summary := StringReplaceAll(Summary, #09, '');
cleanSpaces(Summary);
// Get technical information
Page := GetPage(TechLink);
CutBefore(Page,'<div class="module_wrap">');
CutBefore(Page,'Publisher:');
tmp := TextBetween(Page,'">','</a>');
SetField(fieldProducer, tmp);
CutBefore(Page,'Developer:');
tmp := TextBetween(Page,'">','</a>');
SetField(fieldDirector, tmp);
CutBefore(Page,'Genre:');
tmp := TextBetween(Page,'">','</a>');
SetField(fieldCategory, tmp);
CutBefore(Page,'ESRB:');
tmp := TextBetween(Page,'">','</a>');
SetField(fieldCountry, tmp);
// Requirements
CutBefore(Page,'Minimum System Requirements');
ReqText := #13#10+'Requirements:'+#13#10#13#10;
while Length(tmp) > 0 do begin
tmp := GetStringFromHTML(Page,'<b>','','</div>',1);
CutAfter(Page,'</div>');
ReqText := ReqText + tmp;
end;
ReqText := StringReplaceAll(ReqText, #09, '');
Summary := ReqText + #13#10#13#10 + 'Summary:' + #13#10#13#10 + Summary;
SetField(fieldDescription, Summary);
// Get the Review
while(isBreak>0) do begin
Page := GetPage(ReviewLink);
tmp := GetStringFromHTML(Page,'span class="next"','<a href="','"',0);
if(Length(tmp)>0) then begin
ReviewLink := PageRoot+tmp;
end
else isBreak := 0;
if(isFirst>0) then begin
// General Score
Score := 'GameSpot Score'+#09+': ';
CutAfter(Page,'<!--GS Review Score-->');
tmp := GetStringFromHTML(Page,'<div class','','</div>',1);
SetField(fieldRating, tmp);
Score := Score + tmp + ' (';
CutAfter(Page,'</div>')
tmp := GetStringFromHTML(Page,'<div class','','</div>',1);
Score := Score + tmp + ')';
CutAfter(Page,'</div>');
// Gameplay Score
tmp := GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</td>');
tmp := tmp + #09 + ': ';
tmp := tmp + GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</tr>');
Scores := #13#10 + tmp;
// Graphics Score
tmp := GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</td>');
tmp := tmp + #09 + ': ';
tmp := tmp + GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</tr>');
Scores := Scores + #13#10 + tmp;
// Sound Score
tmp := GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</td>');
tmp := tmp + #09 + ': ';
tmp := tmp + GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</tr>');
Scores := Scores + #13#10 + tmp;
// Value Score
tmp := GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</td>');
tmp := tmp + #09 + ': ';
tmp := tmp + GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</tr>');
Scores := Scores + #13#10 + tmp;
// Tilt Score
tmp := GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</td>');
tmp := tmp + #09 + ': ';
tmp := tmp + GetStringFromHTML(Page,'<td class','','</td>',1);
CutAfter(Page,'</tr>');
Scores := Scores + #13#10 + tmp;
SetField(fieldActors, Scores);
tmp := 'Difficulty'+#09#09+': ';
CutAfter(Page,'Difficulty: ');
tmp := tmp + TextBetween(Page,'<strong>','</strong>');
tmp := tmp + #13#10 + 'Curve'+#09#09+': ';
CutAfter(Page,'Curve: ');
tmp := tmp + TextBetween(Page,'<strong>','</strong>');
tmp := tmp + #13#10 + 'Stability'+#09#09+': ';
CutAfter(Page,'Stability: ');
tmp := tmp + TextBetween(Page,'<strong>','</strong>');
tmp := #13#10 + Score + #13#10 + tmp;
ReviewHead := tmp + #13#10#13#10#13#10;
end
isFirst := 0;
tmp := ' ';
while(Length(tmp)>0) do begin
tmp := TextBetween(Page,'<p>','</p>');
HTMLRemoveTags(tmp);
CutAfter(Page,'</p>');
ReviewAll := ReviewAll + tmp + #13#10#13#10;
end;
if(isBreak = 0) then begin
ReviewAll := StringReplaceAll(ReviewAll, #13#10#13#10#13#10#13#10, #13#10#13#10);
ReviewAll := StringReplaceAll(ReviewAll, #13#10#13#10#13#10, #13#10#13#10);
ReviewAll := StringReplaceAll(ReviewAll, '&', '&');
CutAfter(Page,'<div class="w432 pb10 fl cb">');
tmp := TextBetween(Page,'<strong>','</strong>');
CutAfter(Page,'</strong>');
ReviewAll := ReviewAll + 'Review by ' + tmp;
tmp := TextBetween(Page,'Posted ','<');
CutAfter(Page,'<');
ReviewAll := ReviewAll + '. Posted ' + tmp;
end
end;
ReviewAll := ReviewHead + ReviewAll;
SetField(fieldComments, ReviewAll);
end;
procedure AddGamesTitles(ResultsPage: TStringList);
var
Page: string;
GameTitle, GameAddress: string;
begin
Page := ResultsPage.Text;
while Pos('Game: ', Page) > 0 do
begin
CutBefore(Page, 'Game: ');
GameAddress := GetStringFromHTML(Page, '<a ', 'href="', '">', 0);
GameTitle := GetStringFromHTML(Page, 'a href', '">', '</a>', 0);
// ShowMessage('GA='+GameAddress+#10#13+'GT='+GameTitle);
CutAfter(Page, '</div>');
GameAddress := PageRoot+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<>'ą') and
(c<>'Ą') and (c<>'ę') and
(c<>'Ę') and (c<>'ć') and
(c<>'Ć') and (c<>'ś') and
(c<>'Ś') and (c<>'ż') and
(c<>'Ż') and (c<>'ź') and
(c<>'Ź') and (c<>'ó') and
(c<>'Ó') and (c<>'ł') and
(c<>'Ł') and (c<>'ń') and
(c<>'Ń') then
else
s := s + Copy(Str, i, 1);
end;
Str := s;
end;
begin
if CheckVersion(3,5,0) then begin
PageRoot := 'http://www.gamespot.com';
GameName := GetField(fieldOriginalTitle);
if GameName = '' then GameName := GetField(fieldTranslatedTitle);
RemovePronoun(GameName);
if Input('GameSpot.com Import', 'Enter game title:', GameName) then
AnalyzePage(PageRoot+'/pages/search/index.php?type=11&stype=all&qs=' + URLEncode(GameName) + '&sub=g');
end else ShowMessage('AMC version required: 3.5.0');
end.