Change moviemeter to gamesmeter script
Change moviemeter to gamesmeter script
Hi,
I want to use the dutch script for moviemeter.nl for gamesmeter.nl in combination with sisimizi game catalog.
How do i change the moviemeter script?
Can anyone help me with this.
Thanks,
Bianca
I want to use the dutch script for moviemeter.nl for gamesmeter.nl in combination with sisimizi game catalog.
How do i change the moviemeter script?
Can anyone help me with this.
Thanks,
Bianca
Last edited by pele on 2009-02-28 16:07:27, edited 1 time in total.
Ok. But I cannot answer within minutes all the time, so please be patient if some answer should need some hours or a day. I never did work on a script this way before
If some steps might look "too easy" for you to mention, please keep in mind that it might help others that want to work on or fix bugs on another script.
1. Make sure that you have latest script version from http://update.antp.be/amc/scripts before you begin. Test the script on AMC to be sure it works.
2. Now copy the script to SGC's script folder. Start SGC, open scripting window and choose moviemeter script. Click on 'editor'.
You should do some kind of "pre-work" now, as the script should become a "real" game script: That means you need to change all 'movie' and 'film' inside to 'game', but be careful, especially if you should use an external editor with a replace function (e.g. if you change a variable named 'dir' to 'folder', full replacement would result in 'Directory' becoming 'Folderectory' - just to explain the problem).
3. Change
[i]Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)[/i]
to
[i]Dit script vereist een nieuwere versie van Sisimizi Game Catalog (minstens versie 0.9.0)[/i]
4. Please translate message
[i]The file "StringUtils1.pas" is outdated, please find a new version of it (at least version 2)[/i]
to dutch.
5. Now go through the script and change all (but NOT on URLs !) :
MovieMeter > GamesMeter (take care for the 's' !)
movie > game
film > game
AnalyzeMoviePage > AnalyzeGamePage
MovieName > GameName
MovieAddress > GameAddress
film_info > game_info
etc..
6. When you finished, use the search function to see if you have missed any 'movie' or 'film' on the script (except on the URLs, we will test and change them later).
7. On editor click "Properties" and change script properties to correct values (Script title, description, site address, "script version" could be set to 0.1.0, "requires at least" to 0.9.0 for SGC).
8. Save the script to a new file (Save as) with a correct file name (e.g. GamesMeter (NL) ).
That was what I call "pre-work", now try to run the script, but it probably won't do anything yet.. so please copy/paste the script here on forum within [code] [/code] tags. I'll test it and then tell you what to do next..
As I said, it is still some work to do, but it will result in a working script. Hopefully.
If some steps might look "too easy" for you to mention, please keep in mind that it might help others that want to work on or fix bugs on another script.
1. Make sure that you have latest script version from http://update.antp.be/amc/scripts before you begin. Test the script on AMC to be sure it works.
2. Now copy the script to SGC's script folder. Start SGC, open scripting window and choose moviemeter script. Click on 'editor'.
You should do some kind of "pre-work" now, as the script should become a "real" game script: That means you need to change all 'movie' and 'film' inside to 'game', but be careful, especially if you should use an external editor with a replace function (e.g. if you change a variable named 'dir' to 'folder', full replacement would result in 'Directory' becoming 'Folderectory' - just to explain the problem).
3. Change
[i]Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.5.0)[/i]
to
[i]Dit script vereist een nieuwere versie van Sisimizi Game Catalog (minstens versie 0.9.0)[/i]
4. Please translate message
[i]The file "StringUtils1.pas" is outdated, please find a new version of it (at least version 2)[/i]
to dutch.
5. Now go through the script and change all (but NOT on URLs !) :
MovieMeter > GamesMeter (take care for the 's' !)
movie > game
film > game
AnalyzeMoviePage > AnalyzeGamePage
MovieName > GameName
MovieAddress > GameAddress
film_info > game_info
etc..
6. When you finished, use the search function to see if you have missed any 'movie' or 'film' on the script (except on the URLs, we will test and change them later).
7. On editor click "Properties" and change script properties to correct values (Script title, description, site address, "script version" could be set to 0.1.0, "requires at least" to 0.9.0 for SGC).
8. Save the script to a new file (Save as) with a correct file name (e.g. GamesMeter (NL) ).
That was what I call "pre-work", now try to run the script, but it probably won't do anything yet.. so please copy/paste the script here on forum within [code] [/code] tags. I'll test it and then tell you what to do next..
As I said, it is still some work to do, but it will result in a working script. Hopefully.
Last edited by bad4u on 2009-02-21 23:07:15, edited 1 time in total.
Well i could not wait, so i give it a try.
I change everything even the url's and guess what. It runs in antmoviecatalog but not in sismizi game catalog grr...
Here is the code, can you take a look what the problem is. The sript error says :
unknown identifier: fieldcontry at line 46
SetField(fieldCountry, Value);
I change everything even the url's and guess what. It runs in antmoviecatalog but not in sismizi game catalog grr...
Here is the code, can you take a look what the problem is. The sript error says :
unknown identifier: fieldcontry at line 46
SetField(fieldCountry, Value);
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[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, 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;
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
// Country
if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0) then
Value := TextBefore(Value, ' / ', '');
HTMLDecode(Value);
SetField(fieldCountry, Value);
// Category
Value := TextBefore(Line, '<br />', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldCategory, Value);
// Length
Value := TextBefore(Line, ' minuten', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldLength, Value);
// Director
Value := TextBetween(Line, 'geregisseerd door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDirector, Value);
// Actors
Value := TextBetween(Line, 'met ', '<br />');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldActors, 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.
No, sorry, I can write in german or english only.
Well, you changed movie/film in URLs, too, but in this case it's ok, as it will work for this site. For other sites I would recommend another way to find and confirm the correct URLs.
Now you should be able to run the script and get a results list. You can test the results list when you mark a game (so that it's blue) and then click on "View page". It should open the correct game page in your browser. So you can confirm that not only the title, but the corresponding (invisible) URL is correct, too.
Time to import some game details..
Well, you changed movie/film in URLs, too, but in this case it's ok, as it will work for this site. For other sites I would recommend another way to find and confirm the correct URLs.
Now you should be able to run the script and get a results list. You can test the results list when you mark a game (so that it's blue) and then click on "View page". It should open the correct game page in your browser. So you can confirm that not only the title, but the corresponding (invisible) URL is correct, too.
Time to import some game details..
oke i have done that for the game safecracker and the page is visible. the url is http://www.gamesmeter.nl/game/6189
When you now run the script it will stop with an error message: 'Script error in "GAMESMETER": unknown identifier: FIELDCOUNTRY at line 46"
Let's have a look on line 46 (from SGC script editor):
The script tries to write a string (from variable value) to fieldCountry. Sisimizi Game Catalog does not have a field country, so the script stops.
Click on the "Help" button in script editor (on the bottom of the page). It will open SGC help file on chapter "Technical information / Script files creation". Scroll down and you will find a list of all fieldnames that SGC supports.
For the moment we will outcomment the lines that do not work, as we eventually might need the code later. So write two // in front of line 46.
Run the script again and outcomment all lines that the script doesn't like. After this had been done you will see that the script basically works. It will import some game details like picture, URL, rating and category. Compare it with the data from game's website, to see if category is imported correct (there still might be a bug if it is imported incomplete, e.g. only Action instead of Action / Adventure). It should be a first success
Next step will be to fix broken and add missing details import. But this has to wait until tomorrow, sorry
Please post current script again here on forum when you changed it so far.
Let's have a look on line 46 (from SGC script editor):
Code: Select all
SetField(fieldCountry, Value);
Click on the "Help" button in script editor (on the bottom of the page). It will open SGC help file on chapter "Technical information / Script files creation". Scroll down and you will find a list of all fieldnames that SGC supports.
For the moment we will outcomment the lines that do not work, as we eventually might need the code later. So write two // in front of line 46.
Code: Select all
// SetField(fieldCountry, Value);
Next step will be to fix broken and add missing details import. But this has to wait until tomorrow, sorry
Please post current script again here on forum when you changed it so far.
Oke i outcommented the lines that doesn't work.
Here is the next script.
Here is the next script.
Code: Select all
program GamesMeter;
uses
StringUtils1;
var
GameName: string;
procedure AnalyzeGamePage(Address: string);
var
PageText, Line, 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;
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
// Country
if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0) then
Value := TextBefore(Value, ' / ', '');
HTMLDecode(Value);
//SetField(fieldCountry, Value);
// Category
Value := TextBefore(Line, '<br />', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldCategory, Value);
// Length
Value := TextBefore(Line, ' minuten', '');
Line := RemainingText;
HTMLDecode(Value);
//SetField(fieldLength, Value);
// Director
Value := TextBetween(Line, 'geregisseerd door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
//SetField(fieldDirector, Value);
// Actors
Value := TextBetween(Line, 'met ', '<br />');
Line := RemainingText;
HTMLDecode(Value);
//SetField(fieldActors, 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.
So then, time to do some bugfixing
We'll go through the script and see what can be fixed, delete unnecessary parts, add missing details import and finally clean up the script a little bit.
Here we go.. let's see what procedure AnalyzeGamePage does :
Procedure AnalyzeGamePage starts. We use game safecracker as an example now. It get's the address of the game page as a string (for safecracker it is 'http://www.gamesmeter.nl/game/6190').
Script retrieves HTML sources for the game, using the address from above. It is written to variable PageText.
Now open the website in your browser (http://www.gamesmeter.nl/game/6190). This is what the user sees and we need this page to verify values we want to import.
Then right-click on the website and on the popup menu choose "Show website's source code" or "Open HTML source" or something similar (it differs between browsers and languages). If you use Firefox it is the second menu topic from bottom on the popup menu. This HTML code is what the script "sees", we need to find and import all values from here. On this window you should be able to open a search line or window, at least on Firefox (on the tools menu). Keep these windows open, we'll need them more than once.
Here the script writes game URL to fieldURL. No need for changes, as it works correct. If you tested the script, you will see that import of original title and year both work correct, too. So no need to change either.
For the next function "Translated title" you should check with a game that has an "Alternatieve titel", e.g. try script on "Mario Yoshi" and import game data for "Mario & Yoshi". It should import the alternative titles "Yoshi no Tamago" and "Yoshi" correctly and write them to fieldTranslatedTitle. You can check that if you open the corresponding website for that game.
We'll go through the script and see what can be fixed, delete unnecessary parts, add missing details import and finally clean up the script a little bit.
Here we go.. let's see what procedure AnalyzeGamePage does :
Code: Select all
procedure AnalyzeGamePage(Address: string);
Code: Select all
PageText := GetPage(Address);
Now open the website in your browser (http://www.gamesmeter.nl/game/6190). This is what the user sees and we need this page to verify values we want to import.
Then right-click on the website and on the popup menu choose "Show website's source code" or "Open HTML source" or something similar (it differs between browsers and languages). If you use Firefox it is the second menu topic from bottom on the popup menu. This HTML code is what the script "sees", we need to find and import all values from here. On this window you should be able to open a search line or window, at least on Firefox (on the tools menu). Keep these windows open, we'll need them more than once.
Code: Select all
// URL
SetField(fieldURL, Address);
For the next function "Translated title" you should check with a game that has an "Alternatieve titel", e.g. try script on "Mario Yoshi" and import game data for "Mario & Yoshi". It should import the alternative titles "Yoshi no Tamago" and "Yoshi" correctly and write them to fieldTranslatedTitle. You can check that if you open the corresponding website for that game.
Last edited by bad4u on 2009-02-22 13:04:58, edited 2 times in total.
Now there is this code on the script :
Here we have two variables that are set (Value, Line). On the first line Value is set to a specific string from PageText (= HTML source code of game's website). You should open the source code window now, and try to find the div id="game_info" string there (use the search function). You will see that this string is on line 121 within some other code
What the script does is, that the string between <div id="game_info" and <br /> is copied to variable Value.
So variable Value now contains
On the next line it copies the remaining string to variable Line (everything behind the <br />, starting with Adventure...
The next line then gets rid of the leading >, so that the result is
Well, now we have the platform(s) in variable Value: Macintosh / PC. What we need to do is store them on corresponding field. When you open SGC helpfile from editor you know about the list of fieldnames. There you will identify fieldPlatform as correct name for it. Now add a line of code behind previous lines that saves the platform to fieldPlatform:
That's it. Now the script imports the platform, too.
If something goes wrong, you can easily check what the script does. If you don't know about that, you should try it now, even if everything is going ok. On script editor set breakpoints for the four lines. That means you click on the left side near the line number, inside the grey frame (left beside the numbers 40, 41, 42, 43). The lines should turn red and script execution will now pause on these lines. Now right-click on the variables "Value" and "Line" and add them to the watch list ("Add watch"). The watch list should open, if it resides on the right side of your window you should drag it to the bottom of the window, so that you can see longer variables. Run the script. It should stop on line 40. Variable Value shows Safecracker. Click run, the script will execute one more line, variable Value changes correctly to Macintosh / PC. Hit run again, and the script will execute line 41, so that variable Line changes to a longer string beginning with Adventure.... Nice...
You should add a short outcommented description above these lines, so that others know what is going on:
That's it. Sounds complicated ? Not really. And if you once understood what is going on, you might be able to fix the script on your own, when it should be broken in future.
Please ask if anything isn't clear or doesn't work.
Code: Select all
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
Code: Select all
......</div></div><div id="game_info">Macintosh / PC<br />Adventure<br /> single player<br /><br />Ontwikkeld door....
So variable Value now contains
Code: Select all
>Macintosh / PC
The next line then gets rid of the leading >, so that the result is
Code: Select all
Macintosh / PC
Code: Select all
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
setField(fieldPlatform, Value);
If something goes wrong, you can easily check what the script does. If you don't know about that, you should try it now, even if everything is going ok. On script editor set breakpoints for the four lines. That means you click on the left side near the line number, inside the grey frame (left beside the numbers 40, 41, 42, 43). The lines should turn red and script execution will now pause on these lines. Now right-click on the variables "Value" and "Line" and add them to the watch list ("Add watch"). The watch list should open, if it resides on the right side of your window you should drag it to the bottom of the window, so that you can see longer variables. Run the script. It should stop on line 40. Variable Value shows Safecracker. Click run, the script will execute one more line, variable Value changes correctly to Macintosh / PC. Hit run again, and the script will execute line 41, so that variable Line changes to a longer string beginning with Adventure.... Nice...
You should add a short outcommented description above these lines, so that others know what is going on:
Code: Select all
// platform
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
setField(fieldPlatform, Value);
That's it. Sounds complicated ? Not really. And if you once understood what is going on, you might be able to fix the script on your own, when it should be broken in future.
Please ask if anything isn't clear or doesn't work.
Last edited by bad4u on 2009-02-22 13:42:29, edited 1 time in total.
Next steps.
We do not have a field country on Game Catalog, so we can delete this code block now.
Category block works correct, so leave it as it is. Length block doesn't make sense for games, so this can be deleted, too.
For the director block we will use it and change it to import game developer. If you have a look on the game's website (still safecracker) you will see that we now have correctly imported the original title (and alternative title as we know from Mario & Yoshi), the year, platform, category and picture. Next detail to import is developer.
Let's have a look on the director import block
Change comment line // Director to // Developer. Now we have to change variable Value to import developer instead of director. Have a look on game's website. You will see
Ontwikkeld door Daydream . So we need to import Daydream as developer. Open the HTML source window of game's website again. Use the search function to find the developer in the HTML source. You should find some code like
Have a look on variable Value again. It is set to a string between geregisseerd door and <br />. On our code snappet we see that developer must be between Ontwikkeld door and <br />. We do not have to care for the HTML tags <a href.. and </a> now, as we do not know what exactly is inside (it maight change from game to game). So now you should be able to change variable Value to import correct developer.
The next line copies the remaining text to variable Line again, we know that from earlier.
These lines "clean up" the variable Value, e.g. the HTML tags <a href... and </a> will be deleted from the string.
Change this line so that developer is saved to correct field on SGC. See help file again, if you need to know the correct fieldname. Test developer import. Please release the new script version now before we continue (it might help others to see the results, if they want to follow the topic for learning fixing other scripts)
PS: No need to hurry, take all the time you need.
Code: Select all
// Country
if (GetOption('AllCountries') = 0) and (Pos(' / ', Value) > 0) then
Value := TextBefore(Value, ' / ', '');
HTMLDecode(Value);
//SetField(fieldCountry, Value);
Category block works correct, so leave it as it is. Length block doesn't make sense for games, so this can be deleted, too.
For the director block we will use it and change it to import game developer. If you have a look on the game's website (still safecracker) you will see that we now have correctly imported the original title (and alternative title as we know from Mario & Yoshi), the year, platform, category and picture. Next detail to import is developer.
Let's have a look on the director import block
Code: Select all
// Director
Value := TextBetween(Line, 'geregisseerd door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
//SetField(fieldDirector, Value);
Ontwikkeld door Daydream . So we need to import Daydream as developer. Open the HTML source window of game's website again. Use the search function to find the developer in the HTML source. You should find some code like
Code: Select all
<br />Ontwikkeld door <a href="http://www.gamesmeter.nl/developer/Daydream">Daydream</a><br />Uitgegeven door ...
Code: Select all
Value := TextBetween(.................);
Code: Select all
HTMLRemoveTags(Value);
HTMLDecode(Value);
Code: Select all
//SetField(fieldCountry, Value);
PS: No need to hurry, take all the time you need.
hi there,
It's a bit late but i manage to get the script working.
the Original title and translated title is working.
the platform and developer is working.
So now what?
Grtz. Bianca
It's a bit late but i manage to get the script working.
the Original title and translated title is working.
the platform and developer is working.
So now what?
Grtz. Bianca
Code: Select all
program GamesMeter;
uses
StringUtils1;
var
GameName: string;
procedure AnalyzeGamePage(Address: string);
var
PageText, Line, 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);
// platform
Line := TextBetween(PageText, 'Alternatieve titel', ' </p>');
if Line <> '' then
begin
Line := TextAfter(Line, ': ');
if Line <> '' then
begin
HTMLDecode(Line);
SetField(fieldTranslatedTitle, Line);
end;
end;
Value := TextBetween(PageText, '<div id="game_info"', '<br />');
Line := RemainingText;
Value := TextAfter(Value, '>');
setField(fieldPlatform, Value);
// Category
Value := TextBefore(Line, '<br />', '');
Line := RemainingText;
HTMLDecode(Value);
SetField(fieldCategory, Value);
// Developer
Value := TextBetween(line, '>Ontwikkeld door ', '<br />');
Line := RemainingText;
HTMLRemoveTags(Value);
HTMLDecode(Value);
SetField(fieldDeveloper, Value);
// Actors
Value := TextBetween(Line, 'met ', '<br />');
Line := RemainingText;
HTMLDecode(Value);
//SetField(fieldActors, 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.