podcasts: github.com/jbub/podcasts Index | Files

package podcasts

import "github.com/jbub/podcasts"

Package podcasts implements a podcast generator.

// initialize the podcast
p := &podcasts.Podcast{
    Title:       "My podcast",
    Description: "This is my very simple podcast.",
    Language:    "EN",
    Link:        "http://www.example-podcast.com/my-podcast",
    Copyright:   "2015 My podcast copyright",
}

// add first podcast item
p.AddItem(&podcasts.Item{
    Title:   "Episode 1",
    GUID:    "http://www.example-podcast.com/my-podcast/1/episode-one",
    PubDate: podcasts.NewPubDate(time.Now()),
    Duration: podcasts.NewDuration(time.Second * 320),
    Enclosure: &podcasts.Enclosure{
        URL:    "http://www.example-podcast.com/my-podcast/1/episode.mp3",
        Length: "12312",
        Type:   "MP3",
    },
})

// add second podcast item
p.AddItem(&podcasts.Item{
    Title:   "Episode 2",
    GUID:    "http://www.example-podcast.com/my-podcast/2/episode-two",
    PubDate: podcasts.NewPubDate(time.Now()),
    Duration: podcasts.NewDuration(time.Second * 210),
    Enclosure: &podcasts.Enclosure{
        URL:    "http://www.example-podcast.com/my-podcast/2/episode.mp3",
        Length: "46732",
        Type:   "MP3",
    },
})

// get podcast feed, you can pass options to customize it
feed, err := p.Feed(
    podcasts.Author("Author Name"),
    podcasts.Block,
    podcasts.Explicit,
    podcasts.Complete,
    podcasts.NewFeedURL("http://www.example-podcast.com/new-feed-url"),
    podcasts.Subtitle("This is my very simple podcast subtitle."),
    podcasts.Summary("This is my very simple podcast summary."),
    podcasts.Owner("Podcast Owner", "owner@example-podcast.com"),
    podcasts.Image("http://www.example-podcast.com/my-podcast.jpg"),
)

// handle error
if err != nil {
    log.Fatal(err)
}

// finally write the xml to any io.Writer
feed.Write(os.Stdout)

Index

Package Files

doc.go feed.go options.go podcast.go

Constants

const (
    // ValueYes represents positive value used in XML feed.
    ValueYes = "yes"
)

Variables

var (
    // ErrInvalidURL represents a error returned for invalid url.
    ErrInvalidURL = errors.New("podcasts: invalid url")

    // ErrInvalidImage represents a error returned for invalid image.
    ErrInvalidImage = errors.New("podcasts: invalid image")
)

func Author Uses

func Author(author string) func(f *Feed) error

Author sets itunes:author of given feed.

func Block Uses

func Block(f *Feed) error

Block enables itunes:block of given feed.

func Complete Uses

func Complete(f *Feed) error

Complete enables itunes:complete of given feed.

func Explicit Uses

func Explicit(f *Feed) error

Explicit enables itunes:explicit of given feed.

func Image Uses

func Image(href string) func(f *Feed) error

Image sets itunes:image of given feed.

func NewFeedURL Uses

func NewFeedURL(newURL string) func(f *Feed) error

NewFeedURL sets itunes:new-feed-url of given feed.

func Owner Uses

func Owner(name string, email string) func(f *Feed) error

Owner sets itunes:owner of given feed.

func Subtitle Uses

func Subtitle(subtitle string) func(f *Feed) error

Subtitle sets itunes:subtitle of given feed.

func Summary Uses

func Summary(summary string) func(f *Feed) error

Summary sets itunes:summary of given feed.

type Channel Uses

type Channel struct {
    XMLName     xml.Name       `xml:"channel"`
    Title       string         `xml:"title"`
    Link        string         `xml:"link"`
    Copyright   string         `xml:"copyright"`
    Language    string         `xml:"language"`
    Description string         `xml:"description"`
    Author      string         `xml:"itunes:author,omitempty"`
    Block       string         `xml:"itunes:block,omitempty"`
    Explicit    string         `xml:"itunes:explicit,omitempty"`
    Complete    string         `xml:"itunes:complete,omitempty"`
    NewFeedURL  string         `xml:"itunes:new-feed-url,omitempty"`
    Subtitle    string         `xml:"itunes:subtitle,omitempty"`
    Summary     *ItunesSummary `xml:"itunes:summary,omitempty"`
    Owner       *ItunesOwner
    Image       *ItunesImage
    Items       []*Item
    Categories  []*ItunesCategory
}

Channel represents a RSS channel for given podcast.

type Duration Uses

type Duration struct {
    time.Duration
}

Duration represents itunes:duration attribute of given podcast item.

func NewDuration Uses

func NewDuration(d time.Duration) *Duration

NewDuration returns a new Duration.

func (Duration) MarshalXML Uses

func (d Duration) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshalls duration using HH:MM:SS, H:MM:SS, MM:SS, M:SS formats.

type Enclosure Uses

type Enclosure struct {
    XMLName xml.Name `xml:"enclosure"`
    URL     string   `xml:"url,attr"`
    Length  string   `xml:"length,attr,omitempty"`
    Type    string   `xml:"type,attr"`
}

Enclosure represents audio or video file of given item.

type Feed Uses

type Feed struct {
    XMLName xml.Name `xml:"rss"`
    Xmlns   string   `xml:"xmlns:itunes,attr"`
    Version string   `xml:"version,attr"`
    Channel *Channel
}

Feed wraps the given RSS channel.

func (*Feed) SetOptions Uses

func (f *Feed) SetOptions(options ...func(f *Feed) error) error

SetOptions sets options of given feed.

func (*Feed) Write Uses

func (f *Feed) Write(w io.Writer) error

Write writes marshalled XML to the given writer.

func (*Feed) XML Uses

func (f *Feed) XML() (string, error)

XML marshalls feed to XML string.

type Item Uses

type Item struct {
    XMLName         xml.Name       `xml:"item"`
    Title           string         `xml:"title"`
    GUID            string         `xml:"guid"`
    PubDate         *PubDate       `xml:"pubDate"`
    Author          string         `xml:"itunes:author,omitempty"`
    Block           string         `xml:"itunes:block,omitempty"`
    Duration        *Duration      `xml:"itunes:duration,omitempty"`
    Explicit        string         `xml:"itunes:explicit,omitempty"`
    ClosedCaptioned string         `xml:"itunes:isClosedCaptioned,omitempty"`
    Order           int            `xml:"itunes:order,omitempty"`
    Subtitle        string         `xml:"itunes:subtitle,omitempty"`
    Summary         *ItunesSummary `xml:"itunes:summary,omitempty"`
    Enclosure       *Enclosure
    Image           *ItunesImage
}

Item represents item of given channel.

type ItunesCategory Uses

type ItunesCategory struct {
    XMLName    xml.Name `xml:"itunes:category"`
    Text       string   `xml:"text,attr"`
    Categories []*ItunesCategory
}

ItunesCategory represents itunes:category of given channel.

type ItunesImage Uses

type ItunesImage struct {
    XMLName xml.Name `xml:"itunes:image"`
    Href    string   `xml:"href,attr"`
}

ItunesImage represents the itunes:image of given item or channel.

type ItunesOwner Uses

type ItunesOwner struct {
    XMLName xml.Name `xml:"itunes:owner"`
    Name    string   `xml:"itunes:name"`
    Email   string   `xml:"itunes:email"`
}

ItunesOwner represents the itunes:owner of given channel.

type ItunesSummary Uses

type ItunesSummary struct {
    Value string `xml:",cdata"`
}

ItunesSummary represents a summary of a Channel or Item that may contain embedded HTML such as <a href="...">...</a> links.

type Podcast Uses

type Podcast struct {
    Title       string
    Description string
    Link        string
    Language    string
    Copyright   string
    // contains filtered or unexported fields
}

Podcast represents a web podcast.

func (*Podcast) AddItem Uses

func (p *Podcast) AddItem(item *Item)

AddItem adds an item to the podcast.

func (*Podcast) Feed Uses

func (p *Podcast) Feed(options ...func(f *Feed) error) (*Feed, error)

Feed creates a new feed for current podcast.

type PubDate Uses

type PubDate struct {
    time.Time
}

PubDate represents pubDate attribute of given podcast item.

func NewPubDate Uses

func NewPubDate(d time.Time) *PubDate

NewPubDate returns a new PubDate.

func (PubDate) MarshalXML Uses

func (p PubDate) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshalls pubdate using the rfc2822 time format.

Package podcasts imports 8 packages (graph) and is imported by 3 packages. Updated 2020-07-07. Refresh now. Tools for package owners.