package models import ( "encoding/json" "encoding/xml" "os" ) // Target Show XML structure: // // // #{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:"-"` Resolution string `json:"resolution" xml:"-"` Height int32 `json:"height" xml:"-"` Width int32 `json:"width" 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 }