summaryrefslogtreecommitdiffstats
path: root/schema/schema.go
blob: e0712a349be4c6d2731162e6f6a0c9b0d6cade6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: ISC
// Copyright © 2022 siddharth <s@ricketyspace.net>

package schema

import (
	"encoding/xml"
	"strings"
	"time"
)

// Generic entry.
type Entry struct {
	Id      string
	Title   string
	PubTime time.Time
	Link    string
}

// Represents a NPR media link.
type NPRLink struct {
	XMLName xml.Name `xml:"link"`
	Url     string   `xml:",chardata"`
}

// Represents an entry in the NPR feed.
type NPREntry struct {
	XMLName xml.Name `xml:"item"`
	Id      string   `xml:"guid"`
	Title   string   `xml:"title"`
	Pub     string   `xml:"pubDate"` // RFC1123Z
	PubTime time.Time
	Link    NPRLink `xml:"link"`
}

// Represents a NPR Feed.
type NPRFeed struct {
	XMLName xml.Name   `xml:"rss"`
	Entries []NPREntry `xml:"channel>item"`
}

// Represents the link a YouTube video.
type YouTubeLink struct {
	XMLName xml.Name `xml:"content"`
	Url     string   `xml:"url,attr"`
}

// Represents an entry in the YouTube feed.
type YouTubeEntry struct {
	XMLName xml.Name `xml:"entry"`
	Id      string   `xml:"id"`
	Title   string   `xml:"group>title"`
	Pub     string   `xml:"published"` // RFC3339
	PubTime time.Time
	Link    YouTubeLink `xml:"group>content"`
}

// Represents a YouTube feed.
type YouTubeFeed struct {
	XMLName xml.Name       `xml:"feed"`
	Entries []YouTubeEntry `xml:"entry"`
}

// Represents a direct link to a Podcast.
type PodcastLink struct {
	XMLName xml.Name `xml:"enclosure"`
	Url     string   `xml:"url,attr"`
}

// Represents an entry in the Podcast feed.
type PodcastEntry struct {
	XMLName xml.Name `xml:"item"`
	Id      string   `xml:"guid"`
	Title   string   `xml:"title"`
	Pub     string   `xml:"pubDate"`
	PubTime time.Time
	Link    PodcastLink `xml:"enclosure"`
}

// Represents a iTunes Podcast feed.
type PodcastFeed struct {
	XMLName xml.Name       `xml:"rss"`
	Entries []PodcastEntry `xml:"channel>item"`
}

func (e Entry) TitleContains(contains string) bool {
	return strings.Contains(strings.ToLower(e.Title), strings.ToLower(contains))
}