package models import ( "encoding/json" "encoding/xml" "fmt" "os" "time" ) // Target Episode XML structure: // // // // #{safe(metadata["title"])} // #{safe(metadata["uploader"])} // #{safe(metadata["id"])} // #{safe(metadata["description"])} // #{safe(upload_date)} // #{safe(season)} // #{episode} // YouTube // type Episode struct { XMLName xml.Name `xml:"episodedetails"` Title string `json:"title" xml:"title"` ShowTitle string `json:"channel" xml:"showtitle"` Id string `json:"id" xml:"-"` UniqueId UniqueId `json:"-" xml:"uniqueid"` Plot string `json:"description" xml:"plot"` UploadDate string `json:"upload_date" xml:"-"` Aired string `json:"-" xml:"aired"` Season string `json:"-" xml:"season"` Episode string `json:"-" xml:"episode"` Genre string `json:"-" xml:"genre"` InfoPath string `json:"-" xml:"-"` } func LoadEpisode(info_path string) Episode { info, err := os.ReadFile(info_path) if err != nil { panic(err) } episode := Episode{} err = json.Unmarshal(info, &episode) if err != nil { panic(err) } parsed, err := time.Parse("20060102", episode.UploadDate) if err != nil { panic(err) } episode.Aired = parsed.String() episode.Season = fmt.Sprintf("s%d", parsed.Year()) episode.Episode = fmt.Sprintf("e%02d%02d", parsed.Month(), parsed.Day()) // these fields cannot be inferred episode.Genre = "YouTube" episode.UniqueId = UniqueId{ Default: "true", Type: "youtube", Text: episode.Id, } episode.InfoPath = info_path return episode }