It is currently July 16th, 2019, 5:04 am

Help with webparser

Help with creating, editing & fixing problems with skins
Dhp84
Posts: 17
Joined: June 7th, 2017, 4:29 am

Help with webparser

Dhp84 » January 29th, 2019, 2:53 pm

Hi I'm a noob, so im just starting out, but I really want to be able to scrape info from thegamedb.net. As I'm just starting, I realize that this is probably out of my depth but I wanna give it a go anyway, so any points in the right direction or tips would be massively appreciated.
User avatar
balala
Rainmeter Sage
Posts: 8364
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser

balala » January 29th, 2019, 3:25 pm

Dhp84 wrote: ↑
January 29th, 2019, 2:53 pm
Hi I'm a noob, so im just starting out, but I really want to be able to scrape info from thegamedb.net. As I'm just starting, I realize that this is probably out of my depth but I wanna give it a go anyway, so any points in the right direction or tips would be massively appreciated.
First you have to create a new skin and start building its code.
So, let's start. To create a new skin follow the steps described here: https://docs.rainmeter.net/manual/user-interface/manage/new-skin/
When you succeeded creating it, open it in your text editor and start to build its code. For first it will be a very simple code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureParent]
Measure=WebParser
UpdateRate=900
Url=ADD HERE THE ADDRESS YOU WANT TO PARSE
RegExp=(?siU) WE'LL ADD HERE THE REGEXP WHICH WILL RETURN THE APPROPRIATE INFORMATION

[MeasureInfo1]
Measure=WebParser
Url=[MeasureParent]
StringIndex=1
In the URL option of the [MeasureParent] measure you have to add the appropriate address. I tried to open the thegamedb.net address into a browser, but had no success. Please check the posted address and modify it if needed.
You can add up to 99 child WebParser measures (the only one such measure added above is [MeasureInfo1]), with succesive StringIndex values, to get the needed information one by one. Which these information will be is up to you (and to the used site).
Later we'll need one or more String or Image meters, to show up the information got by the previously added child WebParser measures. We'll add them a bit later.
First please check the posted address and see why it doesn't work for me.
Dhp84
Posts: 17
Joined: June 7th, 2017, 4:29 am

Re: Help with webparser

Dhp84 » January 30th, 2019, 5:18 am

Thanks for your help its really appreciated. I missed out the "s" its https://thegamesdb.net/ Do I need a @Resources folder?
User avatar
balala
Rainmeter Sage
Posts: 8364
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser

balala » January 30th, 2019, 2:51 pm

Dhp84 wrote: ↑
January 30th, 2019, 5:18 am
I missed out the "s" its https://thegamesdb.net/
Ok, this URL does work indeed. Now what information would you like to get from that site?
Dhp84 wrote: ↑
January 30th, 2019, 5:18 am
Do I need a @Resources folder?
At this moment not yet, however later it might be useful. You can create it, especially that this doesn't hurt. So, create a folder named @Resources into the root of your config (into the first folder contained into the Skins folder, which contains the .ini file).
Dhp84
Posts: 17
Joined: June 7th, 2017, 4:29 am

Re: Help with webparser

Dhp84 » January 30th, 2019, 3:19 pm

What I'd really like to do is have something where you put in your steam id or whatever and it then scrapes the poster and a brief synopsis of the game, so really it doesn't necessarily have to be thegamesdb.net but it could be any site that I can get that info from.
User avatar
balala
Rainmeter Sage
Posts: 8364
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser

balala » January 30th, 2019, 4:23 pm

Dhp84 wrote: ↑
January 30th, 2019, 3:19 pm
What I'd really like to do is have something where you put in your steam id or whatever and it then scrapes the poster and a brief synopsis of the game, so really it doesn't necessarily have to be thegamesdb.net but it could be any site that I can get that info from.
Not sure I understand. Can you be a bit more specific? First please decide what site would you like to use. Is it https://thegamesdb.net/ or another?
Secondly: if it is the https://thegamesdb.net/, what exactly would you like to get?
Dhp84
Posts: 17
Joined: June 7th, 2017, 4:29 am

Re: Help with webparser

Dhp84 » January 30th, 2019, 7:47 pm

Ok! Sorry I've gone to far a head 😁 Ok so what the aim is, to scrape game info and image from thegamesdb.net for the games that I have. So for instance Assassin's creed Odyssey I need to scrape from https://thegamesdb.net/game.php?id=60203 and for Scum it would be https://thegamesdb.net/game.php?id=61458
User avatar
balala
Rainmeter Sage
Posts: 8364
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser

balala » January 30th, 2019, 9:08 pm

Dhp84 wrote: ↑
January 30th, 2019, 7:47 pm
Ok so what the aim is, to scrape game info and image from thegamesdb.net for the games that I have.
Ok, here is the first attempt. The following code returns the title, the image and the description of one game. The game can be chosen, giving the appropriate URL in the URL option of the [MeasureParent] measure. Later probably we'll need to rewrite the code, to have a list of games and open the information of a game you click on - but this is a later project.
I added a few features, like:
Both the image and the description get changing their background when you're hovering the mouse over the skin.
There is a ToolTip, useful in those cases when the description is too long and doesn't fit the limited surface. In the [Variables] section you can set the value of ToolTip variable either to 0 (the ToolTip is hidden), or to 1 (the ToolTip is shown).

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
BackgroundMode=2
SolidColor=0,0,0,80

[Variables]
ToolTip=0

[StringStyle]
W=230
ClipString=1
FontColor=220,220,220
FontEffectColor=0,0,0,180
StringEffect=Shadow
SolidColor=0,0,0,1
FontFace=Segoe UI
StringStyle=BOLD
AntiAlias=1
Text=%1

[MeasureParent]
Measure=WebParser
UpdateRate=900
Url=https://thegamesdb.net/game.php?id=60203
;Url=https://thegamesdb.net/game.php?id=61458
RegExp=(?siU)<body>.*<img alt="front cover" class="card-img-top" src="(.*)"/>.*<h1>(.*)</h1>.*<p>(.*)</p>.*</body>
FinishAction=[!EnableMeasure "MeasureDownloadImage"][!CommandMeasure "MeasureDownloadImage" "Update"]

[MeasureImage]
Measure=WebParser
Url=[MeasureParent]
StringIndex=1

[MeasureTitle]
Measure=WebParser
Url=[MeasureParent]
StringIndex=2

[MeasureDescription]
Measure=WebParser
Url=[MeasureParent]
StringIndex=3

[MeasureDownloadImage]
Measure=WebParser
URL=[&MeasureImage]
Download=1
DynamicVariables=1
Disabled=1

[MeterImage]
Meter=Image
MeasureName=MeasureDownloadImage
X=0
Y=0
W=240
H=180
PreserveAspectRatio=1
SolidColor=0,0,0,80
ImageAlpha=180
MouseOverAction=[!SetOption MeterTitle SolidColor "0,0,0,120"][!SetOption MeterGame SolidColor "0,0,0,120"][!SetOption MeterImage ImageAlpha "80"][!UpdateMeter "MeterTitle"][!UpdateMeter "MeterGame"][!UpdateMeter "MeterImage"][!Redraw]
MouseLeaveAction=[!SetOption MeterTitle SolidColor "0,0,0,1"][!SetOption MeterGame SolidColor "0,0,0,1"][!SetOption MeterImage ImageAlpha "180"][!UpdateMeter "MeterTitle"][!UpdateMeter "MeterGame"][!UpdateMeter "MeterImage"][!Redraw]
ToolTipText=[MeasureTitle]#CRLF##CRLF#[MeasureDescription]
ToolTipHidden=(1-#ToolTip#)

[MeterTitle]
Meter=STRING
MeasureName=MeasureTitle
MeterStyle=StringStyle
X=120r
Y=0r
H=20
FontSize=12
StringAlign=CENTER

[MeterGame]
Meter=STRING
MeasureName=MeasureDescription
MeterStyle=StringStyle
X=-115r
Y=0R
H=160
FontSize=8
StringAlign=LEFT
Please test this code and let me know if this is what you've thought to.
Dhp84
Posts: 17
Joined: June 7th, 2017, 4:29 am

Re: Help with webparser

Dhp84 » January 31st, 2019, 8:11 am

Awesome! that works, one thing tho I use rainmeter on my living room 4k tv and any words are in poor quality, how would I fix that? Its to do with optimization I think? As far as layout, I'm looking for something like the image I'm showing here, obviously I no It cant be as polished as this but the idea is to have the game poster with the synopsis beside it like the image and being able to scroll along to each game and the poster and synopsis changes .
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 8364
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help with webparser

balala » January 31st, 2019, 5:30 pm

Dhp84 wrote: ↑
January 31st, 2019, 8:11 am
that works, one thing tho I use rainmeter on my living room 4k tv and any words are in poor quality, how would I fix that?
Increase the size of image and the size of letters as well. Modify the following options:

Code: Select all

[MeterImage]
...
W=480
H=360
...

[MeterTitle]
...
X=240r
Y=0r
H=32
FontSize=16
...

[MeterGame]
...
X=-235r
Y=0R
H=328
FontSize=12
...
You probably will have to experiment, to find the best values for all those options, but the basic idea is to modify the options one related to the other. For example half of the width of image ([MeterImage]) must be used into the X option of the following meter ([MeterTitle]) and 5 pixels less into the X option of the next meter ([MeterGame]). The height of the meters was modified according to the height of the Image meter ([MeterImage]) and so on.
This is for now. Later I'll be back trying to solve the second ask, as well.