SteamLUG / steamlug.org

SteamLUG
https://steamlug.org
8 stars 11 forks source link

Write a steamcmd script to return icon hash #169

Open johndrinkwater opened 9 years ago

johndrinkwater commented 9 years ago

It would be nice to, on demand, fetch Steam app icons. This data is not query‐able from the WebAPI, but it is however fetchable via steamcmd with app_info_print %appid which returns ‘kindof json’ like:

"292030"
{
    …
    "common"
    {
        "name"          "The Witcher 3: Wild Hunt"
        "type"          "Game"
        "oslist"        "windows"
        "logo"          "2f22c2e5528b78662988dfcb0fc9aad372f01686"
        "logo_small"    "2f22c2e5528b78662988dfcb0fc9aad372f01686_thumb"
        "icon"          "778d9d0159630fb4e61d875a62e4fe9657d0abdb"
        "clienticon"    "23bc32ca8f5d01b23e74a3120470d34f82a760c6"
        "clienttga"     "f48bd0b21a584f24f43c54f74e65d3e794709c72"
        …
    }
}

Which we can use to build an icon url: http://cdn.akamai.steamstatic.com/steamcommunity/public/images/apps/%appid%/%icon%.jpg

Leaving this open as a task for someone else!

johndrinkwater commented 9 years ago
AppID : 440, change number : 1027099/1027099, token 0, last change : Mon May  4 22:47:08 2015 
"440"
{
    "common"
    {
        "icon"      "e3f595a92552da3d664ad00277fad2107345f743"
        "logo"      "07385eb55b5ba974aebbe74d3c99626bda7920b8"
        "logo_small"        "07385eb55b5ba974aebbe74d3c99626bda7920b8_thumb"
        "metacritic_url"        "pc/teamfortress2"
        "name"      "Team Fortress 2"
        "clienticon"        "033bdd91842b6aca0633ee1e5f3e6b82f2e8962f"
        "clienttga"     "689dd46bd63e3e460cdd86d936d5de409a291633"
        "languages"
        {
            "english"       "1"
            …
        }
        "clienticns"        "b0780e91df4308b1ad57cc93d6032b4f0e2930cc"
        "linuxclienticon"       "b2659c540592221fcd7675d76a0171f4b3782c1c"
        "oslist"        "windows,macos,linux"
        "workshop_visible"      "1"
        "type"      "game"
        "metacritic_name"       "Team Fortress 2"
        "controller_support"        "partial"
        "metacritic_score"      "92"
        "metacritic_fullurl"        "http://www.metacritic.com/game/pc/team-fortress-2"
        "community_visible_stats"       "1"
        "GameID"        "440"
    }
    "extended"
    {
        "developer"     "Valve"
        "developer_url"     "http://www.valvesoftware.com/"
        "gamedir"       "tf"
        "gamemanualurl"     "http://store.steampowered.com/manual/440/"
        "homepage"      "http://www.teamfortress.com/"
        "icon"      "steam/games/icon_tf2"
        "icon2"     "steam/games/icon_tf2"
        "isfreeapp"     "1"
        "languages"     "english,german,french,spanish,russian"
        "loadallbeforelaunch"       "1"
        "minclientversion"      "1393366296"
        "noservers"     "0"
        "primarycache"      "452"
        "primarycache_linux"        "452"
        "requiressse"       "1"
        "serverbrowsername"     "Team Fortress 2"
        "sourcegame"        "1"
        "state"     "eStateAvailable"
        "vacmacmodulecache"     "160"
        "vacmodulecache"        "202"
        "vacmodulefilename"     "sourceinit.dat"
        "validoslist"       "windows,macos,linux"
        "listofdlc"     "456,457,458,459,217221,217222"
        "publisher"     "Valve"
    }

Got to be careful if we do grepping rather than json parsing because ↑

Tele42 commented 9 years ago

if you do get steamcmd to behave, you want something like

icon=$(./steamcmd +stuff | grep -EB 100 -m 1 "^\s+\"extended\"$" | grep -EA 100 "^\s+\"common\"$" | grep -E "^\s+\"icon\"\s+" | awk '{print $2}' | sed -e 's/^"//' -e 's/"$//')

Which reads as run steamcmd, return 100 lines before extended (one match), return everything after common, return icon line, return only the second value of the icon line, remove start and end quote, and store in icon variable.

EDIT: remove the need for head

johndrinkwater commented 9 years ago

Might need some magic here :< doing it twice because first just says it is fetching and bombs out… and that just returns poop data

./steamcmd.sh +login anonymous +app_info_print 120 +app_info_print 120 <<< quit
Redirecting stderr to '/home/steam/Steam/logs/stderr.txt'
[  0%] Checking for available updates...
[----] Verifying installation...
Steam Console Client (c) Valve Corporation
-- type 'quit' to exit --
Loading Steam API...OK.

Connecting anonymously to Steam Public...Logged in OK
Waiting for license info...OK
No app info for AppID 120 found, requesting...
AppID : 120, change number : 0/0, token 0, last change : Thu Jan  1 01:00:00 1970 
"120"
{
}

Steam>
johndrinkwater commented 9 years ago

./steamcmd.sh +login anonymous +app_info_print 120 +force_install_dir ./4 +app_update 4 +app_info_print 120 <<< quit so this ‘install’ of a non‐app kinda makes it work. Test more.

johndrinkwater commented 9 years ago

Look into appids 362300 + 294420 to make the parsing more robust

Tele42 commented 9 years ago

We may be able to use | grep -EB 100 -m 1 $'^\t}$' instead of | grep -EB 100 -m 1 "^\s+\"extended\"$" to limit to the first section instead of everything before extended.

johndrinkwater commented 9 years ago

If we went with awk, https://gist.github.com/johndrinkwater/869fdb879aeafcb8e1eb

steam@joran:~/steamcmd$ ./steamcmd.sh +login anonymous +app_info_print 440 +force_install_dir ./4 +app_update 4 +app_info_print 440 <<< quit | awk -f icon.awk 
"e3f595a92552da3d664ad00277fad2107345f743"
steam@joran:~/steamcmd$ ./steamcmd.sh +login anonymous +app_info_print 294420 +force_install_dir ./4 +app_update 4 +app_info_print 294420 <<< quit | awk -f icon.awk 
"35ffe403ab7b4cd649359f5399c59326810d466d"
steam@joran:~/steamcmd$ ./steamcmd.sh +login anonymous +app_info_print 362300 +force_install_dir ./4 +app_update 4 +app_info_print 362300 <<< quit | awk -f icon.awk 
"71fcbf4c9853bae150d485ea94f6cc14ab90f8d9"
JasonRivers commented 7 years ago

Why not leave the data as JSON and parse back to PHP using json_decode within the PHP itself? This would be safer than using grep or awk. alternatively there's this project: https://stedolan.github.io/jq/

johndrinkwater commented 7 years ago

It’s not JSON.

meklu commented 7 years ago

That VDF doesn't look too difficult to parse…