subsyt/internal/model/show.go
Viktor Varland 6ff2d53c2d
Some checks are pending
build / build (push) Waiting to run
feat: use rss to fetch list of videos
This uses RSS to fetch a list of videos to avoid the vid being invisible
due to "restrictions", then downloads the videos one-by-one instead of
scraping and parsing the channel page using yt-dlp.

We lose metadata for the entire channel (show-level) so introducing a
hack to download just the metadata of a channel.
2025-09-08 22:30:57 +02:00

62 lines
1.4 KiB
Go

package model
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:"-"`
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
}