This commit is contained in:
parent
162574aa62
commit
ba2b6f9952
@ -32,6 +32,16 @@ func Run(c *commands.Commander, s fx.Shutdowner) {
|
||||
return c.Play()
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "playurl",
|
||||
Aliases: []string{"plu"},
|
||||
Usage: "Plays a spotify url",
|
||||
Args: true,
|
||||
ArgsUsage: "url",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
return c.PlayUrl(ctx.Args().First())
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "pause",
|
||||
Aliases: []string{"pa"},
|
||||
|
@ -1,6 +1,11 @@
|
||||
package commands
|
||||
|
||||
import "github.com/zmb3/spotify/v2"
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
func (c *Commander) Play() error {
|
||||
err := c.Client.Play(c.Context)
|
||||
@ -22,3 +27,40 @@ func (c *Commander) Play() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Commander) PlayUrl(urlString string) error {
|
||||
url, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
track_id := strings.Split(url.Path, "/")[2]
|
||||
err = c.Client.QueueSong(c.Context, spotify.ID(track_id))
|
||||
if err != nil {
|
||||
if isNoActiveError(err) {
|
||||
deviceID, err := c.activateDevice(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.Client.QueueSongOpt(c.Context, spotify.ID(track_id), &spotify.PlayOptions{
|
||||
DeviceID: &deviceID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.Client.NextOpt(c.Context, &spotify.PlayOptions{
|
||||
DeviceID: &deviceID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = c.Client.Next(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user