Compare commits

..

3 Commits

Author SHA1 Message Date
Renovate Bot
805b8a9911 fix(deps): update golang.org/x/exp digest to 778ce7b
All checks were successful
builder / build (push) Successful in 45s
2024-08-22 11:48:54 -07:00
1b52748db0
refill
All checks were successful
builder / build (push) Successful in 37s
2024-08-22 00:35:50 -07:00
57c97cddb4
Refill
All checks were successful
builder / build (push) Successful in 47s
2024-08-22 00:17:10 -07:00
3 changed files with 11 additions and 19 deletions

2
go.mod
View File

@ -13,7 +13,7 @@ require (
github.com/urfave/cli/v3 v3.0.0-alpha9
github.com/zmb3/spotify/v2 v2.4.2
go.uber.org/fx v1.22.1
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/exp v0.0.0-20240822175202-778ce7bba035
golang.org/x/net v0.27.0
golang.org/x/oauth2 v0.21.0
golang.org/x/sync v0.8.0

4
go.sum
View File

@ -309,8 +309,8 @@ golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkq
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/exp v0.0.0-20240822175202-778ce7bba035 h1:VkSUcpKXdGwUpn/JsiWXwSNnIJVXRfMA4ThL5vwljWg=
golang.org/x/exp v0.0.0-20240822175202-778ce7bba035/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

View File

@ -35,20 +35,11 @@ func (c *Commander) Radio() error {
}
func (c *Commander) RadioFromPlaylist(playlist spotify.SimplePlaylist) error {
total := playlist.Tracks.Total
if total == 0 {
return fmt.Errorf("this playlist is empty")
}
pages := int(math.Ceil(float64(total) / 50))
randomPage := 1
if pages > 1 {
randomPage = rand.Intn(pages-1) + 1
}
playlistPage, err := c.Client().GetPlaylistItems(
c.Context,
playlist.ID,
spotify.Limit(50),
spotify.Offset((randomPage-1)*50),
spotify.Offset(0),
)
if err != nil {
return err
@ -365,8 +356,9 @@ func (c *Commander) RefillRadio() error {
if err != nil {
return err
}
paused := false
if !status.Playing {
return nil
paused = true
}
toRemove := []spotify.ID{}
radioPlaylist, db, err := c.GetRadioPlaylist("")
@ -374,15 +366,15 @@ func (c *Commander) RefillRadio() error {
return err
}
if status.PlaybackContext.URI != radioPlaylist.URI {
return nil
}
playlistItems, err := c.Client().GetPlaylistItems(c.Context, radioPlaylist.ID)
if err != nil {
return fmt.Errorf("orig playlist items: %w", err)
}
if status.PlaybackContext.URI != radioPlaylist.URI || paused {
return c.RadioFromPlaylist(radioPlaylist.SimplePlaylist)
}
page := 0
for {
tracks, err := c.Client().GetPlaylistItems(c.Context, radioPlaylist.ID, spotify.Limit(50), spotify.Offset(page*50))
@ -403,7 +395,7 @@ func (c *Commander) RefillRadio() error {
if len(toRemove) > 0 {
var trackGroups []spotify.ID
for idx, item := range toRemove {
if idx%100 == 0 {
if idx%100 == 0 && idx != 0 {
_, err = c.Client().RemoveTracksFromPlaylist(c.Context, radioPlaylist.ID, trackGroups...)
trackGroups = []spotify.ID{}
}