-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (57 loc) · 1.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"github.com/fatih/color"
"math/rand"
"strconv"
"time"
)
var TidalService *Service
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
color.Red("Tesla Tidal Shuffle")
TidalService = NewService()
playlists, err := TidalService.GetUserPlaylists(TidalService.UserID)
if err != nil {
panic(err)
} else {
color.Cyan("Playlists to Shuffle: ")
for x, playlist := range playlists.Items {
color.Magenta(strconv.Itoa(x) + " - " + playlist.Title)
}
color.Cyan("Choice: ")
var choice string
fmt.Scanln(&choice)
choicei, err := strconv.Atoi(choice)
if err != nil {
panic(err)
}
toShuffle := playlists.Items[choicei]
playlistTracks, err := TidalService.GetPlaylistTracks(toShuffle.UUID)
if err != nil {
panic(err)
}
songsToShuffle := playlistTracks.Items
color.Green(strconv.Itoa(len(songsToShuffle)) + " Tracks Loaded!")
color.Cyan("Shuffled Playlist Name: ")
shuffledName := ""
fmt.Scanln(&shuffledName)
shuffledPlaylist, err := TidalService.CreatePlaylist(shuffledName, toShuffle.Description)
if err != nil {
panic(err)
}
rand.Shuffle(len(songsToShuffle), func(i, j int) { songsToShuffle[i], songsToShuffle[j] = songsToShuffle[j], songsToShuffle[i] })
for _, song := range songsToShuffle {
color.Yellow("Adding Song: " + song.Title)
err := TidalService.AddTrackToPlaylist(shuffledPlaylist.UUID, song.ID)
if err != nil {
panic(err)
}
color.Green("Added Song: " + song.Title)
}
}
color.Green("All Done :)")
fmt.Scanln()
}