songs play in context
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
jjohnstondev 2023-01-09 18:03:31 -08:00
parent a6f06a753e
commit 0ff00ef79b
3 changed files with 49 additions and 13 deletions

View File

@ -88,6 +88,53 @@ func QueueSong(ctx *gctx.Context, client *spotify.Client, id spotify.ID) error {
return nil
}
func PlaySongInPlaylist(ctx *gctx.Context, client *spotify.Client, context *spotify.URI, offset int) error {
err := client.PlayOpt(ctx, &spotify.PlayOptions{
PlaybackOffset: &spotify.PlaybackOffset{Position: offset},
PlaybackContext: context,
})
return err
}
func PlayLikedSongs(ctx *gctx.Context, client *spotify.Client, position int) error {
err := ClearRadio(ctx, client)
if err != nil {
return err
}
playlist, err := GetRadioPlaylist(ctx, client)
if err != nil {
return err
}
songs, err := client.CurrentUsersTracks(ctx, spotify.Limit(50), spotify.Offset(position))
if err != nil {
return err
}
to_add := []spotify.ID{}
for _, song := range songs.Tracks {
to_add = append(to_add, song.ID)
}
client.AddTracksToPlaylist(ctx, playlist.ID, to_add...)
client.PlayOpt(ctx, &spotify.PlayOptions{
PlaybackContext: &playlist.URI,
PlaybackOffset: &spotify.PlaybackOffset{
Position: 0,
},
})
for page := 2; page <= 5; page++ {
songs, err := client.CurrentUsersTracks(ctx, spotify.Limit(50), spotify.Offset((50*(page-1))+position))
if err != nil {
return err
}
to_add := []spotify.ID{}
for _, song := range songs.Tracks {
to_add = append(to_add, song.ID)
}
client.AddTracksToPlaylist(ctx, playlist.ID, to_add...)
}
return err
}
func RadioGivenSong(ctx *gctx.Context, client *spotify.Client, song_id spotify.ID, pos int) error {
start := time.Now().UnixMilli()
seed := spotify.Seeds{
@ -491,7 +538,6 @@ func GetRadioPlaylist(ctx *gctx.Context, client *spotify.Client) (*spotify.FullP
// private flag doesnt work
playlist, err := client.CreatePlaylistForUser(ctx, ctx.UserId, "autoradio", "Automanaged radio playlist", false, false)
if err != nil {
fmt.Println("AHHHHHHHHHHHHh", ctx.UserId)
return nil, err
}
out, err := json.MarshalIndent(playlist, "", " ")

View File

@ -88,13 +88,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
if msg.String() == "enter" {
track := m.list.SelectedItem()
var err error
err = commands.QueueSong(m.ctx, m.client, track.(item).ID)
if err != nil {
m.ctx.Printf(err.Error())
}
err = commands.Skip(m.ctx, m.client)
err = commands.PlayLikedSongs(m.ctx, m.client, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
if err != nil {
m.ctx.Printf(err.Error())
}

View File

@ -87,13 +87,8 @@ func (m playlistTracksModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
if msg.String() == "enter" {
track := m.list.SelectedItem()
var err error
err = commands.QueueSong(m.ctx, m.client, track.(item).ID)
if err != nil {
m.ctx.Printf(err.Error())
}
err = commands.Skip(m.ctx, m.client)
err = commands.PlaySongInPlaylist(m.ctx, m.client, &m.playlist.URI, m.list.Cursor()+(m.list.Paginator.Page*m.list.Paginator.PerPage))
if err != nil {
m.ctx.Printf(err.Error())
}