-
Notifications
You must be signed in to change notification settings - Fork 16
/
m3u8cache.go
67 lines (60 loc) · 1.45 KB
/
m3u8cache.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
66
67
package service
import (
"log"
"github.com/snowie2000/livetv/model"
"github.com/snowie2000/livetv/global"
)
var updateConcurrent = make(chan bool, 2) // allow up to 2 urls to be updated simultaneously
func LoadChannelCache() {
channels, err := GetAllChannel()
if err != nil {
log.Println(err)
return
}
for _, v := range channels {
UpdateURLCacheSingle(v.URL, v.ProxyUrl, v.Parser, true)
}
}
func UpdateURLCacheSingle(Url string, proxyUrl string, Parser string, bUpdateStatus bool) (*model.LiveInfo, error) {
updateConcurrent <- true
defer func() {
<-updateConcurrent
}()
log.Println("caching", Url)
liveInfo, err := RealLiveM3U8(Url, proxyUrl, Parser)
if err != nil {
global.URLCache.Delete(Url)
UpdateStatus(Url, Error, err.Error())
log.Println("[LiveTV]", err)
} else {
global.URLCache.Store(Url, liveInfo)
if bUpdateStatus {
UpdateStatus(Url, Ok, "Live!")
}
log.Println(Url, "cached")
}
return liveInfo, err
}
func UpdateURLCache() {
channels, err := GetAllChannel()
if err != nil {
log.Println(err)
return
}
urlcache := make(map[string]bool)
for _, v := range channels {
urlcache[v.URL] = true
}
// delete urlcaches that we do not serve anymore
global.URLCache.Range(func(k string, info *model.LiveInfo) bool {
if _, ok := urlcache[k]; !ok {
global.URLCache.Delete(k)
DeleteStatus(k)
return true
}
return true
})
for _, v := range channels {
UpdateURLCacheSingle(v.URL, v.ProxyUrl, v.Parser, true)
}
}