Files
go-m3u8/epg.go
Matheus Sampaio Queiroga 4a45b482ab Update parse
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-07-19 01:52:55 -03:00

85 lines
1.9 KiB
Go

package gom3u8
import (
"compress/gzip"
"encoding/xml"
"path"
"strings"
"sirherobrine23.com.br/go-bds/request/v2"
)
var EPGSources = []string{
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/epg.xml",
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/vivoplay.xml",
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/band.xml",
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/claro.xml",
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/globo-internacional.xml",
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/globo.xml",
"https://github.com/limaalef/BrazilTVEPG/raw/refs/heads/main/maissbt.xml",
}
var EPGIDs = map[string]string{}
func LoadEPG() error {
for _, epgUrl := range EPGSources {
res, err := request.Request(epgUrl, nil)
if err != nil {
continue
}
defer res.Body.Close()
EPG := new(TV)
var epgXML *xml.Decoder
switch strings.ToLower(path.Ext(epgUrl)) {
case ".gz":
gz, err := gzip.NewReader(res.Body)
if err != nil {
return err
}
defer gz.Close()
epgXML = xml.NewDecoder(gz)
default:
epgXML = xml.NewDecoder(res.Body)
}
if err = epgXML.Decode(EPG); err != nil {
return err
}
for _, channel := range EPG.Channels {
for _, name := range channel.DisplayNames {
EPGIDs[name.Text] = channel.ID
}
}
break
}
return nil
}
type TV struct {
XMLName xml.Name `xml:"tv"`
Channels []EPGChannel `xml:"channel,omitempty"`
}
type EPGChannel struct {
XMLName xml.Name `xml:"channel"`
ID string `xml:"id,attr"`
DisplayNames []DisplayName `xml:"display-name"`
URLs []URL `xml:"url,omitempty"`
}
type DisplayName struct {
XMLName xml.Name `xml:"display-name"`
Lang *string `xml:"lang,attr,omitempty"`
Text string `xml:",chardata"`
}
type URL struct {
XMLName xml.Name `xml:"url"`
System *string `xml:"system,attr,omitempty"`
Text string `xml:",chardata"`
}