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