59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"encoding/xml"
|
|
"os"
|
|
)
|
|
|
|
// Target Show XML structure:
|
|
// <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
// <tvshow>
|
|
// <title>#{safe(metadata["title"]}/title>
|
|
// <plot>#{safe(metadata["description"]}</plot>
|
|
// <uniqueid type="youtube" default="true">#{safe(metadata["id"])}</uniqueid>
|
|
// <genre>YouTube</genre>
|
|
// </tvshow>
|
|
|
|
type Show struct {
|
|
XMLName xml.Name `xml:"tvshow"`
|
|
Title string `json:"channel" xml:"title"`
|
|
Id string `json:"channel_id" xml:"-"`
|
|
UniqueId UniqueId `json:"-" xml:"uniqueid"`
|
|
Plot string `json:"description" xml:"plot"`
|
|
Genre string `json:"-" xml:"genre"`
|
|
InfoPath string `json:"-" xml:"-"`
|
|
Thumbnails []Thumbnail `json:"thumbnails" xml:"-"`
|
|
}
|
|
|
|
type Thumbnail struct {
|
|
Url string `json:"url" xml:"-"`
|
|
Id string `json:"id" xml:"-"`
|
|
}
|
|
|
|
func LoadShow(info_path string) Show {
|
|
info, err := os.ReadFile(info_path)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
show := Show{}
|
|
|
|
err = json.Unmarshal(info, &show)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// these fields cannot be inferred
|
|
show.Genre = "YouTube"
|
|
show.UniqueId = UniqueId{
|
|
Default: "true",
|
|
Type: "youtube",
|
|
Text: show.Id,
|
|
}
|
|
|
|
show.InfoPath = info_path
|
|
|
|
return show
|
|
}
|