-
Notifications
You must be signed in to change notification settings - Fork 1
/
tunein.go
52 lines (43 loc) · 1.26 KB
/
tunein.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
package main
import (
"log"
"net/http"
"net/url"
"github.com/prometheus/client_golang/prometheus"
)
func constructTuneinURL(endpoint string, artist string, title string) string {
partnerid := getEnv("TUNEIN_PARTNER_ID")
partnerkey := getEnv("TUNEIN_PARTNER_KEY")
stationid := getEnv("TUNEIN_STATION_ID")
if partnerid == "" || partnerkey == "" || stationid == "" {
return ""
}
var URL *url.URL
URL, _ = url.Parse(endpoint)
parameters := url.Values{}
parameters.Add("partnerId", partnerid)
parameters.Add("partnerKey", partnerkey)
parameters.Add("id", stationid)
parameters.Add("artist", artist)
parameters.Add("title", title)
URL.RawQuery = parameters.Encode()
return URL.String()
}
func tuneinAPI(artist string, title string) {
tuneinEndpoint := "http://air.radiotime.com/Playing.ashx"
callURL := constructTuneinURL(tuneinEndpoint, artist, title)
if callURL == "" {
log.Println("No tunein creds, skipping")
return
}
res, err := http.Get(callURL)
if err != nil {
log.Println(err)
}
if res.StatusCode == 200 {
tuneinSubmission.With(prometheus.Labels{"artist": artist, "title": title}).Inc()
log.Printf("Successfull TuneIn submission: %s - %s", artist, title)
} else {
log.Println("Tunein submission failed, error code: ", res.StatusCode)
}
}