Skip to content

Commit

Permalink
Merge pull request #59 from xxxserxxx/ticket_58_initiate_scan
Browse files Browse the repository at this point in the history
Adds ticket #58, ability to trigger a server library scan
  • Loading branch information
spezifisch authored Oct 11, 2024
2 parents 3afa955 + f8a964e commit b45b937
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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

Expand Down
5 changes: 5 additions & 0 deletions gui_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions help_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
20 changes: 20 additions & 0 deletions subsonic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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"`
Expand Down Expand Up @@ -257,6 +262,7 @@ type SubsonicResponse struct {
Artist Artist `json:"artist"`
Album Album `json:"album"`
SearchResults SubsonicResults `json:"searchResult3"`
ScanStatus ScanStatus `json:"scanStatus"`
}

type responseWrapper struct {
Expand Down Expand Up @@ -579,3 +585,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
}

0 comments on commit b45b937

Please sign in to comment.