-
Notifications
You must be signed in to change notification settings - Fork 20
/
m3u.go
39 lines (36 loc) · 892 Bytes
/
m3u.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
package service
import (
"fmt"
"log"
"strconv"
"strings"
"github.com/snowie2000/livetv/global"
)
func M3UGenerate() (string, error) {
baseUrl, err := global.GetConfig("base_url")
if err != nil {
log.Println(err)
return "", err
}
channels, err := GetAllChannel()
if err != nil {
log.Println(err)
return "", err
}
var m3u strings.Builder
m3u.WriteString("#EXTM3U\n")
for _, v := range channels {
logo := ""
category := "LiveTV"
if v.Category != "" {
category = v.Category
}
if info, ok := global.URLCache.Load(v.URL); ok {
logo = info.Logo
}
liveData := fmt.Sprintf("#EXTINF:-1, tvg-name=%s tvg-logo=%s group-title=%s, %s\n", strconv.Quote(v.Name), strconv.Quote(logo), strconv.Quote(category), v.Name)
m3u.WriteString(liveData)
m3u.WriteString(fmt.Sprintf("%s/live.m3u8?token=%s&c=%d\n", baseUrl, v.Token, v.ID))
}
return m3u.String(), nil
}