Here are almost the final results.
Code: Select all
(***************************************************
Sisimizi Game Catalog importation script
http://www.sisimizi.org
[Infos]
Authors=Bianca Manglie
Title=GamesMeter.nl
Description=GamesMeter.nl import script
Site=www.gamesmeter.nl
Language=NL
Version=0.1.0
Requires=0.9.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]
AllCountries=0|0|0=Take only first country|1=Take all countries (separated by "/")
ImportComments=0|0|0=Do not import users' comments|1=Import users' comments
***************************************************)
program GamesMeter;
uses
StringUtils1;
var
GameName: string;
procedure AnalyzeGamePage(Address: string);
var
PageText, Line, Temp, Value: string;
begin
PageText := GetPage(Address);
// URL
SetField(fieldURL, Address);
// title & year
Line := TextBetween(PageText, '<h1>', '</h1>');
Value := TextBetween(Line, '(', ')');
SetField(fieldYear, Value);
Value := Trim(TextBefore(Line, '(', ''));
HTMLDecode(Value);
SetField(fieldOriginalTitle, Value);
// translated title
Line := TextBetween(PageText, 'Alternatieve titel', ' </p>');
if Line <> '' then
begin
Line := TextAfter(Line, ': ');
if Line <> '' then
begin
HTMLDecode(Line);
SetField(fieldTranslatedTitle, Line);
end;
end;
// platform
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
if Pos('>meer..', Value) > 0 then
begin
Value := TextBetween(PageText, 'id="platforms_all">', '</span>');
Line := RemainingText;
end;
if Pos('/', Value) > 0 then
begin
Temp := Value;
PickListClear;
while Pos('/', Temp) > 0 do
begin
PickListAdd(TextBefore(Temp, ' / ', ''));
Temp := RemainingText;
end;
PickListAdd(Temp);
PickListExec('Beschikbare platforms voor deze game : ' + Value + #13#10 + #13#10 + 'Kies het platform', Value);
end;
setField(fieldPlatform, Value);
// Category
Value := TextBefore(Line, '<br />', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldCategory, Value);
// player
Value := TextBefore(Line, '<br />', '');
Line := RemainingText;
HTMLDecode(Value);
if Pos('single', Value) > 0 then
SetField(fieldLocalPlayers, '1');
if Pos('multi', Value) > 0 then
SetField(fieldLocalPlayers, '2');
if Pos('online', Value) > 0 then
SetField(fieldNetworkPlayers, '2');
// Developer
Value := TextBetween(line, '>Ontwikkeld door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := StringReplace(Value, ' en ', ', ');
SetField(fieldDeveloper, Value);
// publisher
Value := TextBetween(line, 'Uitgegeven door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
Value := StringReplace(Value, ' en ', ', ');
SetField(fieldPublisher, Value);
// Description
Value := TextBetween(Line, '<br />', '</div>');
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDescription, Value);
// Picture
Value := TextBetween(PageText, '<img class="poster" src="', '" ');
if Value <> '' then
begin
GetPicture(Value);
end;
// Rating
Value := TextBetween(PageText, '</span>gemiddelde <b>', '<');
Value := StringReplace(FloatToStr(StrToFloat(StringReplace(Value, ',', '.')) * 2), ',', '.');
SetField(fieldRating, Value);
// Comments
if GetOption('ImportComments') = 1 then
begin
Value := TextBetween(PageText, '<div class="forum_message_user">', '<div class="to_page entitypages" id="pages_bottom"></div>');
Value := StringReplace(Value, ' uur', ' uur : ' + #13#10);
// Value := StringReplace(Value, '<div class="forum_message_message">', #13#10);
Value := StringReplace(Value, '</div><div class="form_horizontal_divider" ', '-------------------------------------------------------------' + #13#10 + #13#10 + '<');
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldComments, Value);
end;
end;
procedure AnalyzeResultsPage(Address: string);
var
Page: TStringList;
Line: string;
GameAddress: string;
GameTitle: string;
aantal : integer;
begin
// get results page
aantal := 0;
Page := TStringList.Create;
Page.Text := GetPage(Address);
// get redirect javascript
Line := Page.GetString(Page.Count-2);
// more than 1 game found
if Pos('location.replace("http://www.gamesmeter.nl/game/searchresults#results");', Line) <> 0 then
begin
PickTreeClear;
PickTreeAdd('Zoekresultaten voor ' + GameName, '');
// get results page
Page.Text := GetPage('http://www.gamesmeter.nl/game/searchresults#results');
if Pos('Populaire zoekresultaten in games:', Page.Text) > 0 then
Line := TextBetween(Page.Text, 'Populaire zoekresultaten in games:</p>', '<form action="http://www.gamesmeter.nl/game/search/"');
if Pos('Alle zoekresultaten in games:', Page.Text) > 0 then
Line := TextBetween(Page.Text, 'Alle zoekresultaten in games:</p>', '<form action="http://www.gamesmeter.nl/game/search/"');
if Pos('Zoekresultaten in games:', Page.Text) > 0 then
Line := TextBetween(Page.Text, 'Zoekresultaten in games:</p>', '<form action="http://www.gamesmeter.nl/game/search/"');
Line := TextBetween(Line, '</p></div>', '<p><br /></p>');
while Pos('gameresults_row', Line) > 0 do
begin
GameAddress := TextBetween(Line, 'href="', '" >');
GameTitle := TextBefore(Line, '</p></div>', '');
Line := RemainingText;
HTMLRemoveTags(GameTitle);
HTMLDecode(GameTitle);
PickTreeAdd(Trim(GameTitle), GameAddress);
aantal := aantal + 1;
end;
if aantal = 0 then
begin
ShowMessage('Geen resultaten gevonden...');
Page.Free;
exit;
end;
// if user picks a game from the results list, import game details
if PickTreeExec(Address) then
AnalyzeGamePage(Address);
end
else
begin
GameAddress := TextBetween(Line, '("', '");');
if GameAddress <> 'http://www.gamesmeter.nl/game/' then
// if only 1 game found --> redirect to game page
AnalyzeGamePage(GameAddress)
else
// no games found
ShowMessage('Geen zoekresultaat voor "'+GameName+'".');
end;
Page.Free;
end;
begin
if CheckVersion(0,9,7) then
begin
if StringUtils1_Version >= 2 then
begin
GameName := GetField(fieldOriginalTitle);
if GameName = '' then
GameName := GetField(fieldTranslatedTitle);
if Input('GamesMeter.nl Import', 'Geef de titel van de game:', GameName) then
begin
AnalyzeResultsPage('http://www.gamesmeter.nl/game/search/'+UrlEncode(GameName));
end;
end
else
ShowMessage('Het bestand "StringUtils1.pas" is verouderd, zoek een nieuwere versie (op zijn minst versie 2)');
end
else
ShowMessage('Dit script vereist een nieuwere versie van Sisimizi Catlog (minstens versie 0.9.0)');
exit;
end.