-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (51 loc) · 1.36 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
package main
import (
"errors"
"fmt"
"github.com/fatih/color"
"github.com/joho/godotenv"
"log"
"os"
)
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
func main() {
if len(os.Args) == 1 {
err := errors.New("missing \"user\" parameter\n")
fmt.Print(err)
return
}
user := "MysteryMS"
fmt.Printf("Looking up for %v\n", user)
data := getRecent(user)
fmt.Printf("Found %v\n", color.CyanString(data.RecentTracks.Attr.User))
firstTrack := data.RecentTracks.Tracks[0]
if data.RecentTracks.Tracks[0].Attr.NowPlaying == "" {
fmt.Printf(":: Last listened track 🡒 %v (by %v on %v)\n",
color.BlueString(firstTrack.Name),
color.MagentaString(firstTrack.Artist.Name),
color.MagentaString(firstTrack.Album.Name),
)
} else {
fmt.Printf("%v 🡒 %v by %v on %v\n",
color.GreenString(":: Now Playing"),
color.YellowString(firstTrack.Name),
color.MagentaString(firstTrack.Artist.Name),
color.MagentaString(firstTrack.Album.Name),
)
}
color.Blue(":: Top 5 tracks ::")
topTrackData := getTop(user)
for pos := 0; pos < 5; pos++ {
fmt.Printf("#%v - %v by %v (played %v times)\n",
pos+1,
color.BlueString(topTrackData.TopTracks.Tracks[pos].Name),
color.MagentaString(topTrackData.TopTracks.Tracks[pos].Artist.Name),
color.RedString(topTrackData.TopTracks.Tracks[pos].PlayCount),
)
}
}