2023-01-13 06:19:43 +00:00
|
|
|
package tui
|
|
|
|
|
|
|
|
import (
|
2023-10-20 17:52:55 +00:00
|
|
|
"github.com/zmb3/spotify/v2"
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2023-10-20 17:52:55 +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)
|
2023-01-15 04:59:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 22:08:25 +00:00
|
|
|
func HandleVolume(ctx *gctx.Context, commands *commands.Commands, up bool) {
|
2023-01-15 04:59:52 +00:00
|
|
|
vol := 10
|
|
|
|
if !up {
|
|
|
|
vol = -10
|
|
|
|
}
|
2023-02-17 22:08:25 +00:00
|
|
|
err := commands.ChangeVolume(ctx, vol)
|
2023-01-15 04:59:52 +00:00
|
|
|
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-04-16 17:58:50 +00:00
|
|
|
err = commands.Next(ctx, 1, false)
|
2023-01-14 20:20:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-16 17:58:50 +00:00
|
|
|
func HandleNextInQueue(ctx *gctx.Context, commands *commands.Commands, amt int) {
|
|
|
|
err := commands.Next(ctx, amt, true)
|
2023-04-16 07:05:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-16 17:47:26 +00:00
|
|
|
func HandleQueueItem(ctx *gctx.Context, commands *commands.Commands, item spotify.ID) {
|
|
|
|
err := commands.QueueSong(ctx, item)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-16 18:30:37 +00:00
|
|
|
func HandleDeleteTrackFromPlaylist(ctx *gctx.Context, commands *commands.Commands, item, playlist spotify.ID) {
|
|
|
|
err := commands.DeleteTracksFromPlaylist(ctx, []spotify.ID{item}, playlist)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|