RobLoach / lutris-kodi-addon

Lutris Kodi Addon
http://lutris.net
GNU General Public License v2.0
39 stars 6 forks source link

Add game specific infoLabels to ListItems #41

Open solbero opened 5 years ago

solbero commented 5 years ago

With the new games content type in Kodi v18 it is possible to set game specific InfoLabes for the ListItems in the addon. This makes it possible to display information about a game in skins that support this feature (most of them).

Available infoLabels for the games content type are:

Info label Description
title string (Super Mario Bros.)
platform string (Atari 2600)
genres list (["Action","Strategy"])
publisher string (Nintendo)
developer string (Square)
overview string (Long Description)
year integer (1980)
gameclient string (game.libretro.fceumm

It should be possible to scrape this info from lutris.net, or perhaps it is already exposed in the Lutris client somewhere? The website uses the URL format https://lutris.net/games/[slug]/, and the game slugs are already known.

I will be able to implement the infoLabels in the code, but I have no experience scraping info from a website. I looked a little bit at Kodi's documentation and it seems to have a powerful built in scraper.

Any thoughts, @RobLoach or @arustler?

arustler commented 5 years ago

I like this idea. I’ll see what I can do about the scraping.

RobLoach commented 5 years ago

This would be pretty cool to see! Is any of this data stored locally? We should allow it to work without needing the scraper... Perhaps a toggle?

solbero commented 5 years ago

I got the idea @RobLoach, when I saw the image you uploaded to PR #40. That image for Original Sin 2 says "No information available".

We could use a toggle in the addon's settings to enable the scraper or add a context menu item. Another solution could be to check for an internet connection before scraping begins. What is being scraped is text, so the download size should not be too excessive.

Anyways, this is the information I could find that Lutris exposes locally: titleand platform. They are part of the JSON output from Lutris. The rest needs to be scraped.

As for constructing a scraper this could be done using BeautifulSoup4, which is already included in the Kodi main repo.

Scraped data should be stored locally in the addon's data directory. If you have a large number of games in your library the addon should not scrape all items every time it constructs the item list in Kodi. This would put quite a large number of requests on the website being scraped and could end with an IP blacklist.

We could use the Common Plugin Cache, but this data is not persistent. So I think a database or individual JSON files containing the scraped data could be a solution. I personally like the idea of using JSON files, these could be named after the Lutris gameID, and we only need to check if the JSON file with a matching gameID is present, then read the data from the file.

The first time the addon is run, it scrapes everything. Subsequent runs it should check the local information and only scrape new or updated items. The scraping progress should be visible to the user.

In a few days my summer break begins, and I should be able to dedicate some time to this.

RobLoach commented 5 years ago

That'd be awesome! https://lutris.net/api/games?search=divinity-original-sin-2

Could likely have Lutris.net API output more info about the games.

solbero commented 5 years ago

That's brilliant! I didn't know Lutris.net had its own API.

Here is the JSON for Original Sin 2: https://lutris.net/api/games/divinity-original-sin-2?format=json. The format for the request would just be https://lutris.net/api/games/[slug]?format=json

Edit: I noticed that developer and publisher information is missing in the JSON, but available on lutris.net.

arustler commented 5 years ago

I've finished a Lutris API Client Object in Python for this Repo. Because we might working together on this enhancement, I would propose to open a new Branch of this Repo named infoLabels. I would have done it but I don't have permission to push to this Repo

RobLoach commented 5 years ago

I would have done it but I don't have permission to push to this Repo

You're able to fork the repo and submit a pull request from your own branch.

https://help.github.com/assets/images/help/repository/fork_button.jpg

arustler commented 5 years ago

You're able to fork the repo and submit a pull request from your own branch.

Didn't know I can also request Pull Requests from my branch to yours Created PR #42

solbero commented 5 years ago

That is very nice work, @arustler. I like how you have implemented methods for the whole API.

I have rewritten the code in main.py. I have tried keep to addon “best practices“ where I could find them. I am not a programmer by trade, so "reinventing the wheel" has been a good exercise for me to understand how the addon functions. A few original addon abilities are missing, and I have removed some that didn’t work.

The new code is available in branch function_rewrite.

solbero commented 5 years ago

Is it possible to get the Lutris API to provide more data, @RobLoach? Such as developer, studio, path to screenshots and fanart, and overview? You are involved with the project, is this something that would be prioritised?

This might be a suggestion that comes a bit late, considering all the work you have done @arustler. But fetching information from thegamesdb.net API could be an alternative.

arustler commented 5 years ago

This might be a suggestion that comes a bit late, considering all the work you have done @arustler. But fetching information from thegamesdb.net API could be an alternative.

Shouldn't be a problem and no it isn't to late. I try to keep my code modular so extending it stays a breeze. I think we could check first Lutris.net for information and then gather more informations from this API