fancy next
This commit is contained in:
parent
617e343039
commit
a26234b38a
@ -1,6 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gospt/src/commands"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -13,9 +15,18 @@ func init() {
|
||||
var nextCmd = &cobra.Command{
|
||||
Use: "next",
|
||||
Aliases: []string{"n"},
|
||||
Args: cobra.MatchAll(cobra.RangeArgs(0, 1)),
|
||||
Short: "Skip to next song",
|
||||
Long: `Skip to next song`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
commands.Next(ctx, client)
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
skipAmt := 1
|
||||
if len(args) >= 1 {
|
||||
var err error
|
||||
skipAmt, err = strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return commands.Next(ctx, client, skipAmt)
|
||||
},
|
||||
}
|
||||
|
@ -544,11 +544,52 @@ func Unlike(ctx *gctx.Context, client *spotify.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Next(ctx *gctx.Context, client *spotify.Client) error {
|
||||
err := client.Next(ctx)
|
||||
func Next(ctx *gctx.Context, client *spotify.Client, amt int) error {
|
||||
if amt == 1 {
|
||||
err := client.Next(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// found := false
|
||||
// playingIndex := 0
|
||||
current, err := client.PlayerCurrentlyPlaying(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
playbackContext := current.PlaybackContext.Type
|
||||
switch playbackContext {
|
||||
case "playlist":
|
||||
found := false
|
||||
currentTrackIndex := 0
|
||||
for !found {
|
||||
page := 1
|
||||
playlist, err := client.GetPlaylistItems(ctx, spotify.ID(strings.Split(string(current.PlaybackContext.URI), ":")[2]), spotify.Limit(50), spotify.Offset((page-1)*50))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for idx, track := range playlist.Items {
|
||||
if track.Track.Track.ID == current.Item.ID {
|
||||
currentTrackIndex = idx + (50 * (page - 1))
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
page++
|
||||
}
|
||||
fmt.Println(currentTrackIndex)
|
||||
client.PlayOpt(ctx, &spotify.PlayOptions{
|
||||
PlaybackContext: ¤t.PlaybackContext.URI,
|
||||
PlaybackOffset: &spotify.PlaybackOffset{
|
||||
Position: currentTrackIndex + amt,
|
||||
},
|
||||
})
|
||||
default:
|
||||
for i := 0; i <= amt; i++ {
|
||||
client.Next(ctx)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func HandlePlayTrack(ctx *gctx.Context, client *spotify.Client, track spotify.ID
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
err = commands.Next(ctx, client)
|
||||
err = commands.Next(ctx, client, 1)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user