summaryrefslogtreecommitdiff
path: root/steam.lisp
blob: 35a77f9667467c2c3f06ef2057628ce54ad579f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(defvar steam-host "api.steampowered.com")

(defun set-steam-key (key)
  (setf (steam-key *config*) key))

(defun set-steam-id (id)
  (setf (steam-user-id *config*) id))

(defun steam-games-uri ()
  (quri:render-uri
   (quri:make-uri-http
    :host steam-host
    :path "IPlayerService/GetOwnedGames/v0001/"
    :query (quri:url-encode-params `(("key" . ,(steam-key *config*))
				     ("steamid" . ,(steam-user-id *config*))
				     ("include_appinfo" . "true"))))))

(defun steam-games ()
  (cadadr
   (json:parse
   (flexi-streams:octets-to-string
    (drakma:http-request (steam-games-uri))))))

;; (:|rtime_last_played| 1674604954
;;  :|playtime_linux_forever| 15
;;  :|playtime_mac_forever| 0
;;  :|playtime_windows_forever| 0
;;  :|has_community_visible_stats| T
;;  :|img_icon_url| "560d02f1edb9bf8a40060ff1c8cf818332cc2c9a"
;;  :|playtime_forever| 15
;;  :|name| "Amazing Cultivation Simulator"
;;  :|appid| 955900)

(defun make-steam-game (json)
  (with-plist ((id :|appid|) (playtime :|playtime_forever|) (name :|name|)
	       (icon-url :|img_icon_url|) (last-played :|rtime_last_played|))
      json
    (let ((game (make-instance 'steam-game :name name :appid id)))
      (setf (playtime game) playtime
	    (icon-url game) icon-url
	    (last-played game) last-played)
      game)))