-
Notifications
You must be signed in to change notification settings - Fork 0
/
esc.go
41 lines (34 loc) · 953 Bytes
/
esc.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
package main
import (
"fmt"
"regexp"
"strings"
)
func trimEscValue(value string) string {
res := strings.ReplaceAll(value, "CDATA[ ", "")
return strings.ReplaceAll(res, " ]", "")
}
func addLatestEscRadioSongs(playlistID, sToken string) {
const url = "https://www.escradio.com/_playlist/playlist.xml"
data, err := doGetRequest(url, "")
if err != nil {
panic(err)
}
tracks := make([]*Track, 0)
regex := regexp.MustCompile(`CDATA\[(.*?)\]`)
matches := regex.FindAllString(string(data), -1)
for i := 0; i < len(matches); i += 2 {
artist := trimEscValue(matches[i])
title := trimEscValue(matches[i+1])
cutIndex := strings.Index(title, "(")
if cutIndex > 0 {
title = title[:cutIndex]
}
tracks = append(tracks, &Track{Artist: artist, Title: title})
fmt.Println(artist, title)
}
if err = addSongsFromRadioToPlaylist(tracks, playlistID, sToken); err != nil {
panic(err)
}
fmt.Println("All done! Happy Eurovision!")
}