-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_list.go
42 lines (35 loc) · 1.13 KB
/
channel_list.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
package main
import (
"fmt"
"sort"
"text/template"
"github.com/gin-gonic/gin"
)
var channelItemTemplate = template.Must(template.New("channel-item").Parse(`
#EXTINF:-1 tvg-id="channel-{{ .Item.ContentID }}" tvg-name="{{ .Item.ID }}" group-title="{{ .Item.Section }}" tvg-chno="{{ .Item.ContentID }}" tvg-logo="{{ .Item.Image }}" radio="{{ .Item.IsRadio }}" catchup-source="https://www.vidio.com/videos/{catchup-id}/common_tokenized_playlist.m3u8", {{ .Item.ContentTitle }}
http://{{ .Host }}/stream/{{ .Item.ContentID }}
`))
func handleList(c *gin.Context) {
channels, err := getChannelList()
if err != nil {
c.Error(err)
return
}
orderedChannels := make([]*tvChannel, len(channels))
i := 0
for _, ch := range channels {
orderedChannels[i] = ch
i++
}
sort.SliceStable(orderedChannels, func(i, j int) bool {
return orderedChannels[i].ContentID < orderedChannels[j].ContentID
})
fmt.Fprintf(c.Writer, "#EXTM3U x-tvg-url=\"http://%s/guide.xml\"\n", c.Request.Host)
for _, ch := range orderedChannels {
data := map[string]interface{}{
"Host": c.Request.Host,
"Item": ch,
}
channelItemTemplate.Execute(c.Writer, data)
}
}