gospt/src/tui/handlers.go

101 lines
2.2 KiB
Go
Raw Normal View History

2023-01-13 06:19:43 +00:00
package tui
import (
2023-03-10 07:48:02 +00:00
"git.asdf.cafe/abs3nt/gospt/src/commands"
"git.asdf.cafe/abs3nt/gospt/src/gctx"
2023-01-13 06:19:43 +00:00
"github.com/zmb3/spotify/v2"
)
2023-02-17 22:08:25 +00:00
func HandlePlayWithContext(ctx *gctx.Context, commands *commands.Commands, uri *spotify.URI, pos int) {
2023-04-07 01:11:06 +00:00
err := commands.PlaySongInPlaylist(ctx, uri, pos)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleRadio(ctx *gctx.Context, commands *commands.Commands, song spotify.SimpleTrack) {
err := commands.RadioGivenSong(ctx, song, 0)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleAlbumRadio(ctx *gctx.Context, commands *commands.Commands, album spotify.SimpleAlbum) {
err := commands.RadioFromAlbum(ctx, album)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleSeek(ctx *gctx.Context, commands *commands.Commands, fwd bool) {
err := commands.Seek(ctx, fwd)
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleVolume(ctx *gctx.Context, commands *commands.Commands, up bool) {
vol := 10
if !up {
vol = -10
}
2023-02-17 22:08:25 +00:00
err := commands.ChangeVolume(ctx, vol)
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleArtistRadio(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) {
err := commands.RadioGivenArtist(ctx, artist)
2023-01-14 20:20:41 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleAlbumArtist(ctx *gctx.Context, commands *commands.Commands, artist spotify.SimpleArtist) {
err := commands.RadioGivenArtist(ctx, artist)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandlePlaylistRadio(ctx *gctx.Context, commands *commands.Commands, playlist spotify.SimplePlaylist) {
err := commands.RadioFromPlaylist(ctx, playlist)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleLibraryRadio(ctx *gctx.Context, commands *commands.Commands) {
err := commands.RadioFromSavedTracks(ctx)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandlePlayLikedSong(ctx *gctx.Context, commands *commands.Commands, position int) {
err := commands.PlayLikedSongs(ctx, position)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandlePlayTrack(ctx *gctx.Context, commands *commands.Commands, track spotify.ID) {
err := commands.QueueSong(ctx, track)
2023-01-14 20:20:41 +00:00
if err != nil {
return
}
2023-02-17 22:08:25 +00:00
err = commands.Next(ctx, 1)
2023-01-14 20:20:41 +00:00
if err != nil {
return
}
}
2023-02-17 22:08:25 +00:00
func HandleSetDevice(ctx *gctx.Context, commands *commands.Commands, player spotify.PlayerDevice) {
2023-04-07 01:11:06 +00:00
err := commands.SetDevice(ctx, player)
2023-01-13 06:19:43 +00:00
if err != nil {
return
}
}