dont restart song on radio start
This commit is contained in:
parent
f5f176b801
commit
16c0ba104e
@ -25,6 +25,13 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
func GetClient(ctx *gctx.Context) (*spotify.Client, error) {
|
||||||
|
if config.Values.ClientId == "" || config.Values.ClientSecret == "" {
|
||||||
|
configDir, _ := os.UserConfigDir()
|
||||||
|
fmt.Println("PLEASE WRITE YOUR CONFIG FILE IN", filepath.Join(configDir, "gospt/client.yml"))
|
||||||
|
fmt.Println("GO HERE TO AND MAKE AN APPLICATION: https://developer.spotify.com/dashboard/applications")
|
||||||
|
fmt.Println("\nclient_id: \"idgoesherelikethis\"\nclient_secret: \"secretgoesherelikethis\"")
|
||||||
|
return nil, fmt.Errorf("\nINVALID CONFIG")
|
||||||
|
}
|
||||||
auth = spotifyauth.New(
|
auth = spotifyauth.New(
|
||||||
spotifyauth.WithClientID(config.Values.ClientId),
|
spotifyauth.WithClientID(config.Values.ClientId),
|
||||||
spotifyauth.WithClientSecret(config.Values.ClientSecret),
|
spotifyauth.WithClientSecret(config.Values.ClientSecret),
|
||||||
|
@ -91,7 +91,8 @@ func QueueSong(ctx *gctx.Context, client *spotify.Client, id spotify.ID) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RadioGivenSong(ctx *gctx.Context, client *spotify.Client, song_id spotify.ID) error {
|
func RadioGivenSong(ctx *gctx.Context, client *spotify.Client, song_id spotify.ID, pos int) error {
|
||||||
|
start := time.Now().UnixMilli()
|
||||||
seed := spotify.Seeds{
|
seed := spotify.Seeds{
|
||||||
Tracks: []spotify.ID{song_id},
|
Tracks: []spotify.ID{song_id},
|
||||||
}
|
}
|
||||||
@ -117,11 +118,16 @@ func RadioGivenSong(ctx *gctx.Context, client *spotify.Client, song_id spotify.I
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
delay := time.Now().UnixMilli() - start
|
||||||
|
if pos != 0 {
|
||||||
|
pos = pos + int(delay)
|
||||||
|
}
|
||||||
client.PlayOpt(ctx, &spotify.PlayOptions{
|
client.PlayOpt(ctx, &spotify.PlayOptions{
|
||||||
PlaybackContext: &radioPlaylist.URI,
|
PlaybackContext: &radioPlaylist.URI,
|
||||||
PlaybackOffset: &spotify.PlaybackOffset{
|
PlaybackOffset: &spotify.PlaybackOffset{
|
||||||
Position: 0,
|
Position: 0,
|
||||||
},
|
},
|
||||||
|
PositionMs: pos,
|
||||||
})
|
})
|
||||||
err = client.Repeat(ctx, "context")
|
err = client.Repeat(ctx, "context")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -178,7 +184,7 @@ func Radio(ctx *gctx.Context, client *spotify.Client) error {
|
|||||||
seed_song = tracks.Tracks[rand.Intn(len(tracks.Tracks))].SimpleTrack
|
seed_song = tracks.Tracks[rand.Intn(len(tracks.Tracks))].SimpleTrack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RadioGivenSong(ctx, client, seed_song.ID)
|
return RadioGivenSong(ctx, client, seed_song.ID, current_song.Progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefillRadio(ctx *gctx.Context, client *spotify.Client) error {
|
func RefillRadio(ctx *gctx.Context, client *spotify.Client) error {
|
||||||
|
@ -10,9 +10,6 @@ import (
|
|||||||
var Values struct {
|
var Values struct {
|
||||||
ClientId string `yaml:"client_id"`
|
ClientId string `yaml:"client_id"`
|
||||||
ClientSecret string `yaml:"client_secret"`
|
ClientSecret string `yaml:"client_secret"`
|
||||||
DeviceId string `yaml:"device_id"`
|
|
||||||
Port int `yaml:"port"`
|
|
||||||
DeviceName string `yaml:"device_name"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(configDir string) {
|
func LoadConfig(configDir string) {
|
||||||
|
@ -75,7 +75,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
if msg.String() == "ctrl+r" {
|
if msg.String() == "ctrl+r" {
|
||||||
track := m.list.SelectedItem()
|
track := m.list.SelectedItem()
|
||||||
err := commands.RadioGivenSong(m.ctx, m.client, track.(item).ID)
|
err := commands.RadioGivenSong(m.ctx, m.client, track.(item).ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (m playlistTracksModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
if msg.String() == "ctrl+r" {
|
if msg.String() == "ctrl+r" {
|
||||||
track := m.list.SelectedItem()
|
track := m.list.SelectedItem()
|
||||||
err := commands.RadioGivenSong(m.ctx, m.client, track.(item).ID)
|
err := commands.RadioGivenSong(m.ctx, m.client, track.(item).ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
|
7
main.go
7
main.go
@ -14,8 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
homeDir, _ := os.UserHomeDir()
|
configPath, _ := os.UserConfigDir()
|
||||||
configDir := filepath.Join(homeDir, ".config/gospt/")
|
configDir := filepath.Join(configPath, "gospt")
|
||||||
config.LoadConfig(configDir)
|
config.LoadConfig(configDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,8 @@ func main() {
|
|||||||
ctx := gctx.NewContext(context.Background())
|
ctx := gctx.NewContext(context.Background())
|
||||||
client, err := auth.GetClient(ctx)
|
client, err := auth.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
currentUser, err := client.CurrentUser(ctx)
|
currentUser, err := client.CurrentUser(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user