Some checks are pending
build / build (push) Waiting to run
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.
74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"encoding/xml"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// Target Episode XML structure:
|
|
//
|
|
// <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
// <episodedetails>
|
|
// <title>#{safe(metadata["title"])}</title>
|
|
// <showtitle>#{safe(metadata["uploader"])}</showtitle>
|
|
// <uniqueid type="youtube" default="true">#{safe(metadata["id"])}</uniqueid>
|
|
// <plot>#{safe(metadata["description"])}</plot>
|
|
// <aired>#{safe(upload_date)}</aired>
|
|
// <season>#{safe(season)}</season>
|
|
// <episode>#{episode}</episode>
|
|
// <genre>YouTube</genre>
|
|
// </episodedetails>
|
|
|
|
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
|
|
}
|