From f8a964e5056de6c31f72e3b56467eb1e3631fe66 Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Fri, 11 Oct 2024 11:18:44 -0500 Subject: [PATCH] Adds ticket #58, ability to trigger a server library scan --- README.md | 1 + gui_handlers.go | 5 +++++ help_text.go | 1 + subsonic/api.go | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/README.md b/README.md index bab3d28..612d7ed 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ These controls are accessible from any view: - `-`/`=`: Volume down/volume up - `,`/`.`: Seek -10/+10 seconds - `r`: Add 50 random songs to the queue +- `s`: Start a server library scan ### Browser Controls diff --git a/gui_handlers.go b/gui_handlers.go index 0690c9d..d465569 100644 --- a/gui_handlers.go +++ b/gui_handlers.go @@ -99,6 +99,11 @@ func (ui *Ui) handlePageInput(event *tcell.EventKey) *tcell.EventKey { } ui.queuePage.UpdateQueue() + case 's': + if err := ui.connection.StartScan(); err != nil { + ui.logger.PrintError("startScan:", err) + } + default: return event } diff --git a/help_text.go b/help_text.go index 667110a..32f79e6 100644 --- a/help_text.go +++ b/help_text.go @@ -10,6 +10,7 @@ P stop -/=(+) volume down/volume up ,/. seek -10/+10 seconds r add 50 random songs to queue +s start server library scan ` const helpPageBrowser = ` diff --git a/subsonic/api.go b/subsonic/api.go index db8691d..1b204e7 100644 --- a/subsonic/api.go +++ b/subsonic/api.go @@ -111,6 +111,11 @@ type SubsonicResults struct { Song SubsonicEntities `json:"song"` } +type ScanStatus struct { + Scanning bool `json:"scanning"` + Count int `json:"count"` +} + type Artist struct { Id string `json:"id"` Name string `json:"name"` @@ -244,6 +249,7 @@ type SubsonicResponse struct { Artist Artist `json:"artist"` Album Album `json:"album"` SearchResults SubsonicResults `json:"searchResult3"` + ScanStatus ScanStatus `json:"scanStatus"` } type responseWrapper struct { @@ -540,3 +546,17 @@ func (connection *SubsonicConnection) Search(searchTerm string, artistOffset, al res, err := connection.getResponse("Search", requestUrl) return res, err } + +// StartScan tells the Subsonic server to initiate a media library scan. Whether +// this is a deep or surface scan is dependent on the server implementation. +// https://subsonic.org/pages/api.jsp#startScan +func (connection *SubsonicConnection) StartScan() error { + query := defaultQuery(connection) + requestUrl := fmt.Sprintf("%s/rest/startScan?%s", connection.Host, query.Encode()) + if res, err := connection.getResponse("StartScan", requestUrl); err != nil { + return err + } else if !res.ScanStatus.Scanning { + return fmt.Errorf("server returned false for scan status on scan attempt") + } + return nil +}