Skip to content

Commit

Permalink
season/episode fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjurtf committed Mar 20, 2021
1 parent 72328c5 commit a1ea2a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
8 changes: 4 additions & 4 deletions xmltv/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type Response struct {
}

type Channel struct {
XMLName xml.Name `xml:"channel"`
Id string `xml:"id,attr"`
Name string `xml:"display-name"`
BaseUrl string `xml:"base-url"`
XMLName xml.Name `xml:"channel"`
Id string `xml:"id,attr"`
Name CommonElement `xml:"display-name"`
BaseUrl string `xml:"base-url"`
}

type Programme struct {
Expand Down
66 changes: 50 additions & 16 deletions xmltv/xmltv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
XmltvDateFormat = "20060102150400 -0700"
XmltvEpisodeStd = "xmtv_ns"
GeneratorName = "xmltv.sjurtf.net"
DocHeader = `<?xml version="1.0" encoding="utf-8"?><!DOCTYPE tv SYSTEM "xmltv.dtd">`
DocHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE tv SYSTEM \"xmltv.dtd\">\n"
defaultGeneratorUrl = "https://xmltv.sjurtf.net/"
)

Expand Down Expand Up @@ -56,9 +56,15 @@ func GetChannelList() ([]byte, error) {
var channels []Channel
var programs []Programme
for _, c := range channelCache {

name := CommonElement{
Lang: "en",
Value: c.Name,
}

channel := Channel{
Id: xmlChannelIdMap[c.Id],
Name: c.Name,
Name: name,
BaseUrl: generatorUrl,
}
channels = append(channels, channel)
Expand All @@ -78,24 +84,48 @@ func getProgramsForChannel(channelId string, date time.Time) []Programme {

var programs []Programme
for _, p := range guide {
cat := "series"
if p.IsMovie {
cat = "movie"
}

titles := CommonElement{
Lang: "nb",
Value: p.Title,
category := CommonElement{
Lang: "en",
Value: cat,
}

subtitle := CommonElement{
titles := CommonElement{
Lang: "nb",
Value: p.Title,
}

episode := EpisodeNum{
System: XmltvEpisodeStd,
EpisodeNum: formatEpisode(p.Season, p.Episode, p.EpisodeTotal),
var subtitles []CommonElement
var episodeNums []EpisodeNum
if p.Season != 0 || p.Episode != 0 {
episode := EpisodeNum{
System: XmltvEpisodeStd,
EpisodeNum: formatEpisode(p.Season, p.Episode, p.EpisodeTotal),
}
if !p.IsMovie {
episodeNums = []EpisodeNum{episode}
subtitles = []CommonElement{{
Lang: "nb",
Value: formatEpisodeHuman(p.Season, p.Episode),
},
}
}

} else {
episodeNums = nil
subtitles = nil
}

desc := p.EpisodeSynopsis
if desc == "" {
var desc string
if p.EpisodeSynopsis == "" && p.SeriesSynopsis == "" {
desc = "Beskrivelse ikke tilgjengelig"
} else if p.EpisodeSynopsis != "" {
desc = p.EpisodeSynopsis
} else {
desc = p.SeriesSynopsis
}

Expand All @@ -109,9 +139,10 @@ func getProgramsForChannel(channelId string, date time.Time) []Programme {
Start: formatTime(p.Start),
Stop: formatTime(p.Stop),
Titles: []CommonElement{titles},
SubTitles: []CommonElement{subtitle},
Categories: []CommonElement{category},
Descriptions: []CommonElement{description},
EpisodeNums: []EpisodeNum{episode},
SubTitles: subtitles,
EpisodeNums: episodeNums,
}
programs = append(programs, programme)
}
Expand All @@ -128,11 +159,10 @@ func marshall(channels []Channel, programs []Programme) ([]byte, error) {
ProgrammeList: programs,
}

bytes, err := xml.Marshal(resp)
bytes, err := xml.MarshalIndent(resp, "", " ")
if err != nil {
log.Fatalln("unable to marshal")
}

return append([]byte(DocHeader), bytes...), nil
}

Expand All @@ -147,7 +177,11 @@ so Season 7, Episode 5, Part 1 of 2 would appear as:
<episode-num system="xmltv_ns">6.4.0/2</episode-num>
*/
func formatEpisode(s, e, t int) string {
return fmt.Sprintf("%d.%d/%d", s-1, e-1, t)
return fmt.Sprintf("%d.%d.0/1", s-1, e-1)
}

func formatEpisodeHuman(s, e int) string {
return fmt.Sprintf("S%dE%d", s, e)
}

func formatTime(date time.Time) string {
Expand Down

0 comments on commit a1ea2a3

Please sign in to comment.