@@ -2,13 +2,14 @@ package client
22
33import (
44 "fmt"
5+ "log/slog"
56 "strings"
67 "time"
7- "log/slog"
88
99 "crypto/md5"
1010 "crypto/rand"
1111 "encoding/base64"
12+ "encoding/json"
1213 "net/url"
1314
1415 "explo/src/config"
@@ -61,6 +62,24 @@ type Playlist struct {
6162 CoverArt string `json:"coverArt"`
6263}
6364
65+ type ScanState struct {
66+ SubsonicResponse struct {
67+ Status string `json:"status"`
68+ Version string `json:"version"`
69+ Type string `json:"type"`
70+ ServerVersion string `json:"serverVersion"`
71+ OpenSubsonic bool `json:"openSubsonic"`
72+ ScanStatus struct {
73+ Scanning bool `json:"scanning"`
74+ Count int `json:"count"`
75+ FolderCount int `json:"folderCount"`
76+ LastScan time.Time `json:"lastScan"`
77+ ScanType string `json:"scanType"`
78+ ElapsedTime int `json:"elapsedTime"`
79+ } `json:"scanStatus"`
80+ } `json:"subsonic-response"`
81+ }
82+
6483type Subsonic struct {
6584 Token string
6685 Salt string
@@ -181,7 +200,25 @@ func (c *Subsonic) startScan() error {
181200}
182201
183202func (c * Subsonic ) CheckRefreshState () bool {
184- return false
203+ var state ScanState
204+ reqParam := "getScanStatus?f=json"
205+
206+ for {
207+ body , err := c .subsonicRequest (reqParam )
208+ if err != nil {
209+ slog .Warn ("could not check scan status" , "err" , err .Error ())
210+ return false
211+ }
212+ if err = json .Unmarshal (body , & state ); err != nil {
213+ slog .Warn ("failed to unmarshal scan status response" , "err" , err .Error ())
214+ return false
215+ }
216+ if ! state .SubsonicResponse .ScanStatus .Scanning {
217+ return true
218+ }
219+ slog .Debug ("Library scan still ongoing" )
220+ time .Sleep (30 * time .Second )
221+ }
185222}
186223
187224func (c * Subsonic ) CreatePlaylist (tracks []* models.Track ) error {
0 commit comments