[grilo-plugins] Add grl-steam-store plugin
- From: Victor Toso <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] Add grl-steam-store plugin
- Date: Fri, 8 Feb 2019 09:37:31 +0000 (UTC)
commit 6ffe48330ff652a347cd98c4926d04b43e191e86
Author: Tony Crisci <tony dubstepdish com>
Date: Sun Sep 30 13:57:10 2018 -0400
Add grl-steam-store plugin
The Steam Store API plugin fetches Steam metadata from a Steam app id.
From discussion in grilo-plugins!33
> In gnome-games, we get the ids from the file system. Steam has
> registry files at ~/.steam/registry.vdf and
> ~/.local/share/Steam/steamapps/*.acf which contain the application ids
> of the installed games.
Fixes #29
src/lua-factory/sources/grl-steam-store.lua | 152 ++++++++++++++++++++++++++++
src/lua-factory/sources/meson.build | 1 +
2 files changed, 153 insertions(+)
---
diff --git a/src/lua-factory/sources/grl-steam-store.lua b/src/lua-factory/sources/grl-steam-store.lua
new file mode 100644
index 0000000..2bab40f
--- /dev/null
+++ b/src/lua-factory/sources/grl-steam-store.lua
@@ -0,0 +1,152 @@
+--[[
+* Copyright (C) 2018 Grilo Project
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+--]]
+
+---------------------------
+-- Source initialization --
+---------------------------
+
+source = {
+ id = "grl-steam-store",
+ name = "Steam Store",
+ description = "a source for game information from the Steam store api",
+ supported_keys = { "title", "description", "thumbnail", "external-url", "rating", "publication-date",
"genre", "developer", "publisher"},
+ resolve_keys = {
+ ["type"] = "none",
+ required = { "id" },
+ },
+ tags = { 'games', 'net:internet' },
+}
+
+netopts = {
+ user_agent = "Grilo Source SteamStore/0.3.0",
+}
+
+------------------
+-- Source utils --
+------------------
+
+BASE_API_URL = "https://store.steampowered.com/api/appdetails?appids="
+
+---------------------------------
+-- Handlers of Grilo functions --
+---------------------------------
+
+function grl_source_resolve()
+ local url, req
+
+ req = grl.get_media_keys()
+ if not req or not req.id
+ or #req.id == 0 then
+ grl.callback()
+ return
+ end
+
+ url = BASE_API_URL .. req.id
+ grl.debug('Fetching URL ' .. url .. ' for appid ' .. req.id)
+ grl.fetch(url, netopts, fetch_game_cb, req.id)
+end
+
+---------------
+-- Utilities --
+---------------
+
+function format_date(date)
+ local month_map = {
+ Jan = 1,
+ Feb = 2,
+ Mar = 3,
+ Apr = 4,
+ May = 5,
+ Jun = 6,
+ Jul = 7,
+ Aug = 8,
+ Sep = 9,
+ Oct = 10,
+ Nov = 11,
+ Dec = 12,
+ }
+ month, day, year = string.match(date, '^(%w+) (%d+), (%d+)')
+ day = tonumber(day)
+ year = tonumber(year)
+
+ if not month or not month_map[month] or not day or not year then
+ grl.warning('could not parse date: ' .. date)
+ return nil
+ end
+
+ return string.format("%d-%d-%d", year, month_map[month], day)
+end
+
+function fetch_game_cb(results, appid)
+ local results_table, data, media
+
+ results_table = grl.lua.json.string_to_table(results)
+
+ if not results_table[appid] or not results_table[appid].data then
+ grl.warning('Got a result without data')
+ grl.callback()
+ return
+ end
+
+ data = results_table[appid].data
+
+ media = {}
+
+ -- simple properties
+ local propmap = {
+ title = 'name',
+ description = 'about_the_game',
+ thumbnail = 'header_image',
+ external_url = 'website',
+ developer = 'developers',
+ publisher = 'publishers',
+ }
+
+ for media_key, data_key in pairs(propmap) do
+ if data[data_key] then
+ media[media_key] = data[data_key]
+ end
+ end
+
+ -- genre
+ if data.genres and #data.genres > 0 then
+ media.genre = {}
+ for i, genre_info in ipairs(data.genres) do
+ if genre_info.description then
+ table.insert(media.genre, genre_info.description)
+ end
+ end
+ end
+
+ -- rating
+ if type(data.metacritic) == 'table' and data.metacritic.score then
+ media.rating = data.metacritic.score
+ end
+
+ -- publication-date
+ if type(data.release_date) == 'table' and data.release_date.date then
+ local date = format_date(data.release_date.date)
+ if date then
+ media.publication_date = date
+ end
+ end
+
+ grl.callback(media, 0)
+end
diff --git a/src/lua-factory/sources/meson.build b/src/lua-factory/sources/meson.build
index adddf0f..37aba5a 100644
--- a/src/lua-factory/sources/meson.build
+++ b/src/lua-factory/sources/meson.build
@@ -15,6 +15,7 @@ sources = [
'grl-musicbrainz',
'grl-radiofrance',
'grl-spotify-cover',
+ 'grl-steam-store',
'grl-theaudiodb-cover',
'grl-thegamesdb',
'grl-video-title-parsing',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]