Skip to content

Commit

Permalink
add subsonic scrobble endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
spezifisch committed Oct 23, 2023
1 parent 3182c8d commit d678e04
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SubsonicConnection struct {
Password string
Host string
PlaintextAuth bool
Scrobble bool
Logger Logger
directoryCache map[string]SubsonicResponse
}
Expand Down Expand Up @@ -214,6 +215,22 @@ func (connection *SubsonicConnection) GetRandomSongs() (*SubsonicResponse, error
return resp, nil
}

func (connection *SubsonicConnection) ScrobbleSubmission(id string, isSubmission bool) (*SubsonicResponse, error) {
query := defaultQuery(connection)
query.Set("id", id)

// optional field, false for "now playing", true for "submission"
query.Set("submission", strconv.FormatBool(isSubmission))

requestUrl := connection.Host + "/rest/scrobble" + "?" + query.Encode()
resp, err := connection.getResponse("ScrobbleSubmission", requestUrl)
if err != nil {
connection.Logger.Printf("ScrobbleSubmission error: %v", err)
return resp, err
}
return resp, nil
}

func (connection *SubsonicConnection) GetStarred() (*SubsonicResponse, error) {
query := defaultQuery(connection)
requestUrl := connection.Host + "/rest/getStarred" + "?" + query.Encode()
Expand Down
7 changes: 7 additions & 0 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,13 @@ func (ui *Ui) handleMpvEvents() {
ui.player.ReplaceInProgress = false
ui.startStopStatus.SetText("[::b]stmp: [green]playing " + ui.player.Queue[0].Title)
updateQueueList(ui.player, ui.queueList, ui.starIdList)

if ui.connection.Scrobble {
// scrobble "now playing" event
ui.connection.ScrobbleSubmission(ui.player.Queue[0].Id, false)
// scrobble "submission" event
ui.connection.ScrobbleSubmission(ui.player.Queue[0].Id, true)
}
} else if e.Event_Id == mpv.EVENT_IDLE || e.Event_Id == mpv.EVENT_NONE {
continue
}
Expand Down
1 change: 1 addition & 0 deletions stmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {
Password: viper.GetString("auth.password"),
Host: viper.GetString("server.host"),
PlaintextAuth: viper.GetBool("auth.plaintext"),
Scrobble: viper.GetBool("server.scrobble"),
Logger: logger,
directoryCache: make(map[string]SubsonicResponse),
}
Expand Down

0 comments on commit d678e04

Please sign in to comment.