-
Notifications
You must be signed in to change notification settings - Fork 1
/
nextsongs.go
65 lines (46 loc) · 1.26 KB
/
nextsongs.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
64
65
package main
import (
"fmt"
"regexp"
"strconv"
)
// UpcomingSongs details
type UpcomingSongs struct {
Title string `json:"song"`
Artist string `json:"artist"`
Image string `json:"image"`
Length float64 `json:"length"`
Share string `json:"share"`
}
func fetchUpcomingSongsFromDb(list []string) []UpcomingSongs {
var r []UpcomingSongs
for _, v := range list {
var u UpcomingSongs
re := regexp.MustCompile(`artist="(.*?)",`)
u.Artist = re.FindStringSubmatch(v)[1]
re = regexp.MustCompile(`title="(.*?)",`)
u.Title = re.FindStringSubmatch(v)[1]
re = regexp.MustCompile(`share="(.*?)"`)
u.Share = re.FindStringSubmatch(v)[1]
re = regexp.MustCompile(`length="(.*?)",`)
u.Length, _ = strconv.ParseFloat(re.FindStringSubmatch(v)[1], 10)
re = regexp.MustCompile(`image="(.*?)",`)
u.Image = re.FindStringSubmatch(v)[1]
if u.Image == "" {
u.Image = "default.png"
}
u.Image = fmt.Sprintf("https://img.xtradio.org/tracks/%s", u.Image)
r = append(r, u)
}
return r
}
func upcomingSongs() ([]UpcomingSongs, error) {
var dbParsedData []UpcomingSongs
command := "playlist(dot)txt.next"
data, err := telnet(command)
if err != nil {
return dbParsedData, err
}
dbParsedData = fetchUpcomingSongsFromDb(data)
return dbParsedData, nil
}