This commit is contained in:
parent
0b21f3df9d
commit
3180c156b2
30
src/cmd/linkcontext.go
Normal file
30
src/cmd/linkcontext.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"gospt/src/commands"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// linkCmd represents the link command
|
||||||
|
var linkContextCmd = &cobra.Command{
|
||||||
|
Use: "linkcontext",
|
||||||
|
Aliases: []string{"lc"},
|
||||||
|
Short: "Get url to current context(album, playlist)",
|
||||||
|
Long: `Get url to current context(album, playlist)`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
link, err := commands.LinkContext(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Print(link)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(linkContextCmd)
|
||||||
|
}
|
@ -797,6 +797,14 @@ func Link(ctx *gctx.Context, client *spotify.Client) (string, error) {
|
|||||||
return state.Item.ExternalURLs["spotify"], nil
|
return state.Item.ExternalURLs["spotify"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LinkContext(ctx *gctx.Context, client *spotify.Client) (string, error) {
|
||||||
|
state, err := client.PlayerState(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(state.PlaybackContext.ExternalURLs["spotify"]), nil
|
||||||
|
}
|
||||||
|
|
||||||
func NowPlaying(ctx *gctx.Context, client *spotify.Client) error {
|
func NowPlaying(ctx *gctx.Context, client *spotify.Client) error {
|
||||||
current, err := client.PlayerCurrentlyPlaying(ctx)
|
current, err := client.PlayerCurrentlyPlaying(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"gospt/src/gctx"
|
"gospt/src/gctx"
|
||||||
|
|
||||||
|
"github.com/atotto/clipboard"
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/list"
|
"github.com/charmbracelet/bubbles/list"
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
@ -192,6 +193,38 @@ func (m *mainModel) GoBack() (tea.Cmd, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SpotifyUrl struct {
|
||||||
|
ExternalURLs map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mainModel) CopyToClipboard() error {
|
||||||
|
item := m.list.SelectedItem().(mainItem).SpotifyItem
|
||||||
|
m.list.NewStatusMessage("Copying link to " + item.(mainItem).Title())
|
||||||
|
switch item.(type) {
|
||||||
|
case spotify.SimplePlaylist:
|
||||||
|
clipboard.WriteAll(item.(spotify.SimplePlaylist).ExternalURLs["spotify"])
|
||||||
|
case *spotify.FullPlaylist:
|
||||||
|
clipboard.WriteAll(item.(*spotify.FullPlaylist).ExternalURLs["spotify"])
|
||||||
|
case spotify.SimpleAlbum:
|
||||||
|
clipboard.WriteAll(item.(spotify.SimpleAlbum).ExternalURLs["spotify"])
|
||||||
|
case *spotify.FullAlbum:
|
||||||
|
clipboard.WriteAll(item.(*spotify.FullAlbum).ExternalURLs["spotify"])
|
||||||
|
case spotify.SimpleArtist:
|
||||||
|
clipboard.WriteAll(item.(spotify.SimpleArtist).ExternalURLs["spotify"])
|
||||||
|
case *spotify.FullArtist:
|
||||||
|
clipboard.WriteAll(item.(*spotify.FullArtist).ExternalURLs["spotify"])
|
||||||
|
case spotify.SimpleTrack:
|
||||||
|
clipboard.WriteAll(item.(spotify.SimpleTrack).ExternalURLs["spotify"])
|
||||||
|
case spotify.PlaylistTrack:
|
||||||
|
clipboard.WriteAll(item.(spotify.PlaylistTrack).Track.ExternalURLs["spotify"])
|
||||||
|
case spotify.SavedTrack:
|
||||||
|
clipboard.WriteAll(item.(spotify.SavedTrack).ExternalURLs["spotify"])
|
||||||
|
case spotify.FullTrack:
|
||||||
|
clipboard.WriteAll(item.(spotify.FullTrack).ExternalURLs["spotify"])
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mainModel) SelectItem() error {
|
func (m *mainModel) SelectItem() error {
|
||||||
switch m.mode {
|
switch m.mode {
|
||||||
case Search:
|
case Search:
|
||||||
@ -457,6 +490,12 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
if msg.String() == "ctrl+c" {
|
if msg.String() == "ctrl+c" {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
if msg.String() == "c" {
|
||||||
|
err := m.CopyToClipboard()
|
||||||
|
if err != nil {
|
||||||
|
return m, tea.Quit
|
||||||
|
}
|
||||||
|
}
|
||||||
if msg.String() == ">" {
|
if msg.String() == ">" {
|
||||||
go HandleSeek(m.ctx, m.client, true)
|
go HandleSeek(m.ctx, m.client, true)
|
||||||
}
|
}
|
||||||
@ -579,6 +618,7 @@ func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model,
|
|||||||
key.NewBinding(key.WithKeys("s"), key.WithHelp("s", "search")),
|
key.NewBinding(key.WithKeys("s"), key.WithHelp("s", "search")),
|
||||||
key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("ctrl+c", "quit")),
|
key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("ctrl+c", "quit")),
|
||||||
key.NewBinding(key.WithKeys("ctrl"+"r"), key.WithHelp("ctrl+r", "start radio")),
|
key.NewBinding(key.WithKeys("ctrl"+"r"), key.WithHelp("ctrl+r", "start radio")),
|
||||||
|
key.NewBinding(key.WithKeys("ctrl"+"shift"+"c"), key.WithHelp("ctrl+shift+c", "copy url")),
|
||||||
key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "select device")),
|
key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "select device")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,6 +632,7 @@ func InitMain(ctx *gctx.Context, client *spotify.Client, mode Mode) (tea.Model,
|
|||||||
key.NewBinding(key.WithKeys("-"), key.WithHelp("-", "volume down")),
|
key.NewBinding(key.WithKeys("-"), key.WithHelp("-", "volume down")),
|
||||||
key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("ctrl+c", "quit")),
|
key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("ctrl+c", "quit")),
|
||||||
key.NewBinding(key.WithKeys("ctrl"+"r"), key.WithHelp("ctrl+r", "start radio")),
|
key.NewBinding(key.WithKeys("ctrl"+"r"), key.WithHelp("ctrl+r", "start radio")),
|
||||||
|
key.NewBinding(key.WithKeys("ctrl"+"shift"+"c"), key.WithHelp("ctrl+shift+c", "copy url")),
|
||||||
key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "select device")),
|
key.NewBinding(key.WithKeys("d"), key.WithHelp("d", "select device")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,12 @@ func PlaylistView(ctx *gctx.Context, client *spotify.Client, playlist spotify.Si
|
|||||||
}
|
}
|
||||||
for _, track := range tracks.Tracks {
|
for _, track := range tracks.Tracks {
|
||||||
items = append(items, mainItem{
|
items = append(items, mainItem{
|
||||||
Name: track.Track.Name,
|
Name: track.Track.Name,
|
||||||
Artist: track.Track.Artists[0],
|
Artist: track.Track.Artists[0],
|
||||||
Duration: track.Track.TimeDuration().Round(time.Second).String(),
|
Duration: track.Track.TimeDuration().Round(time.Second).String(),
|
||||||
ID: track.Track.ID,
|
ID: track.Track.ID,
|
||||||
Desc: track.Track.Artists[0].Name + " - " + track.Track.TimeDuration().Round(time.Second).String(),
|
Desc: track.Track.Artists[0].Name + " - " + track.Track.TimeDuration().Round(time.Second).String(),
|
||||||
|
SpotifyItem: track,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return items, nil
|
return items, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user