if no songs are playing
This commit is contained in:
parent
2214ec9616
commit
b7133bfd5f
1
go.mod
1
go.mod
@ -8,7 +8,6 @@ require (
|
|||||||
github.com/charmbracelet/lipgloss v0.6.0
|
github.com/charmbracelet/lipgloss v0.6.0
|
||||||
github.com/cristalhq/aconfig v0.18.3
|
github.com/cristalhq/aconfig v0.18.3
|
||||||
github.com/cristalhq/aconfig/aconfigyaml v0.17.1
|
github.com/cristalhq/aconfig/aconfigyaml v0.17.1
|
||||||
github.com/zmb3/spotify v1.3.0
|
|
||||||
github.com/zmb3/spotify/v2 v2.3.1
|
github.com/zmb3/spotify/v2 v2.3.1
|
||||||
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5
|
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -171,8 +171,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/zmb3/spotify v1.3.0 h1:6Z2F1IMx0Hviq/dpf8nFwvKPppFEMXn8yfReSBVi16k=
|
|
||||||
github.com/zmb3/spotify v1.3.0/go.mod h1:GD7AAEMUJVYc2Z7p2a2S0E3/5f/KxM/vOnErNr4j+Tw=
|
|
||||||
github.com/zmb3/spotify/v2 v2.3.1 h1:aEyIPotROM3JJjHMCImFROgnPIUpzVo8wymYSaPSd9w=
|
github.com/zmb3/spotify/v2 v2.3.1 h1:aEyIPotROM3JJjHMCImFROgnPIUpzVo8wymYSaPSd9w=
|
||||||
github.com/zmb3/spotify/v2 v2.3.1/go.mod h1:+LVh9CafHu7SedyqYmEf12Rd01dIVlEL845yNhksW0E=
|
github.com/zmb3/spotify/v2 v2.3.1/go.mod h1:+LVh9CafHu7SedyqYmEf12Rd01dIVlEL845yNhksW0E=
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
|
@ -79,21 +79,23 @@ func QueueSong(ctx *gctx.Context, client *spotify.Client, id spotify.ID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Radio(ctx *gctx.Context, client *spotify.Client) error {
|
func Radio(ctx *gctx.Context, client *spotify.Client) error {
|
||||||
err := ClearRadio(ctx, client)
|
rand.Seed(time.Now().Unix())
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
radioPlaylist, err := GetRadioPlaylist(ctx, client)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
current_song, err := client.PlayerCurrentlyPlaying(ctx)
|
current_song, err := client.PlayerCurrentlyPlaying(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
seed := spotify.Seeds{
|
seed_song := current_song.Item.SimpleTrack
|
||||||
Tracks: []spotify.ID{current_song.Item.ID},
|
if !current_song.Playing {
|
||||||
|
tracks, err := client.CurrentUsersTracks(ctx, spotify.Limit(10))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
seed_song = tracks.Tracks[rand.Intn(len(tracks.Tracks))].SimpleTrack
|
||||||
}
|
}
|
||||||
|
seed := spotify.Seeds{
|
||||||
|
Tracks: []spotify.ID{seed_song.ID},
|
||||||
|
}
|
||||||
|
fmt.Println("GETTING RECOMENDATIONS FOR", seed_song.Name)
|
||||||
recomendations, err := client.GetRecommendations(ctx, seed, &spotify.TrackAttributes{}, spotify.Limit(100))
|
recomendations, err := client.GetRecommendations(ctx, seed, &spotify.TrackAttributes{}, spotify.Limit(100))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -102,6 +104,14 @@ func Radio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
for _, song := range recomendations.Tracks {
|
for _, song := range recomendations.Tracks {
|
||||||
recomendationIds = append(recomendationIds, song.ID)
|
recomendationIds = append(recomendationIds, song.ID)
|
||||||
}
|
}
|
||||||
|
err = ClearRadio(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
radioPlaylist, err := GetRadioPlaylist(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
_, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, recomendationIds...)
|
_, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, recomendationIds...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -116,7 +126,7 @@ func Radio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rand.Seed(time.Now().Unix())
|
fmt.Println("RADIO STARTED")
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
id := rand.Intn(len(recomendationIds)-2) + 1
|
id := rand.Intn(len(recomendationIds)-2) + 1
|
||||||
seed := spotify.Seeds{
|
seed := spotify.Seeds{
|
||||||
@ -126,17 +136,16 @@ func Radio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(len(additional_recs.Tracks))
|
|
||||||
additionalRecsIds := []spotify.ID{}
|
additionalRecsIds := []spotify.ID{}
|
||||||
for _, song := range additional_recs.Tracks {
|
for _, song := range additional_recs.Tracks {
|
||||||
additionalRecsIds = append(additionalRecsIds, song.ID)
|
additionalRecsIds = append(additionalRecsIds, song.ID)
|
||||||
}
|
}
|
||||||
fmt.Println(len(additionalRecsIds))
|
|
||||||
_, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, additionalRecsIds...)
|
_, err = client.AddTracksToPlaylist(ctx, radioPlaylist.ID, additionalRecsIds...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println("500 TRACKS QUEUED")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +154,6 @@ func RefillRadio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("PLAYING", status.PlaybackContext.URI)
|
|
||||||
to_remove := []spotify.ID{}
|
to_remove := []spotify.ID{}
|
||||||
radioPlaylist, err := GetRadioPlaylist(ctx, client)
|
radioPlaylist, err := GetRadioPlaylist(ctx, client)
|
||||||
found := false
|
found := false
|
||||||
@ -156,7 +164,6 @@ func RefillRadio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, track := range tracks.Items {
|
for _, track := range tracks.Items {
|
||||||
fmt.Println("CHECKING", track.Track.Track.Name)
|
|
||||||
if track.Track.Track.ID == status.Item.ID {
|
if track.Track.Track.ID == status.Item.ID {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@ -194,7 +201,7 @@ func RefillRadio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println("RADIO REPLENISHED")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user