parent
51217baeed
commit
82ae6a76e6
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -186,33 +185,5 @@ func (c *Commander) RadioGivenList(songs []spotify.ID, name string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < 4; i++ {
|
|
||||||
id := rand.Intn(len(songs)-2) + 1
|
|
||||||
seed := spotify.Seeds{
|
|
||||||
Tracks: []spotify.ID{songs[id]},
|
|
||||||
}
|
|
||||||
additionalRecs, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
additionalRecsIds := []spotify.ID{}
|
|
||||||
for _, song := range additionalRecs.Tracks {
|
|
||||||
exists, err := c.SongExists(c.db, song.ID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
_, err = c.db.QueryContext(c.Context, fmt.Sprintf("INSERT INTO radio (id) VALUES('%s')", string(song.ID)))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
additionalRecsIds = append(additionalRecsIds, song.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_, err = c.Client().AddTracksToPlaylist(c.Context, radioPlaylist.ID, additionalRecsIds...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user