Scrip for IGN

New scripts, templates and translation files that allows to use Ant Movie Catalog to manage other things than movies
Post Reply
cluis_henrique
Posts: 21
Joined: 2010-01-21 00:54:05

Scrip for IGN

Post by cluis_henrique »

Following the recommendation of ANTP put script ign.com in Mods section. please comment on it.

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.
cluis_henrique
Posts: 21
Joined: 2010-01-21 00:54:05

Script IGN for Sisimizi Game Catalog

Post by cluis_henrique »

Code: Select all

(***************************************************

Sisimizi Game Catalog importation script
http://www.sisimizi.org

[Infos]
Authors=Luis Henrique Carneiro
Title=IGN (multilanguage)
Description=Find and import information about games from ign.com
Site=www.IGN.COM
Language=EN,DE,FR, BR
Version=2.0.0
Requires=1.0.0
Comments=This script is configurable to source your details from any localised version of Amazon and does so over their E-Commerce web services interface. Thus it's not screen scraping and won't be broken by every change that Amazon make.
License="PLEASE KEEP IN MIND THAT SOME OF THE CONTENT THAT WE MAKE AVAILABLE TO YOU THROUGH THIS APPLICATION COMES FROM AMAZON WEB SERVICES. ALL SUCH CONTENT IS PROVIDED TO YOU "AS IS." THIS CONTENT AND YOUR USE OF IT ARE SUBJECT TO CHANGE AND/OR REMOVAL AT ANY TIME."||If you want to support this software and make a donation with no extra costs, you can simply do so by buying something from amazon while using the specific amazon URL, that will be saved on every item - thank you :-)|
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(fieldDeveloper, 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(fieldCustom1, 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(fieldclassification, tmp2);
   end;

 tmp := TextBetween(Page,'Publisher:</span>','<br/>');
 If (tmp = '') Then tmp := TextBetween(Page,'Published by:','</strong>');
 tmp := TextBetween(tmp, '">', '</a>');
 SetField(fieldPublisher, tmp);
 
 tmp := TextBetween(Page,'"nav-platform"','/span');
 tmp := TextBetween(tmp, '>', '<');
 SetField(fieldPlatform, 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 := TextBetween(Page,'<strong><a href="http://cheats.ign.com','#');
 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(fieldCheats,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(1,0,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('This script requires a newer version of Sisimizi Game Catalog (at least version 1.0.0)');
end.
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

Heya, a sisimizi version ! Thanks ! :)

I've uploaded it to sisimizi's scripts server, so that it is available to other users from website and when using the [Update Scripts] script.
Post Reply