podcasts

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 8 Imported by: 4 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

podcasts

GoDoc Build Status Go Report Card

Podcast generator written in Go.

Install

go get github.com/jbub/podcasts

Docs

https://godoc.org/github.com/jbub/podcasts

Example usage

package main

import (
	"log"
	"os"
	"time"

	"github.com/jbub/podcasts"
)

func main() {
	// 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 * 230),
		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 * 320),
		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)
}

Which gives us this XML output:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>My podcast</title>
    <link>http://www.example-podcast.com/my-podcast</link>
    <copyright>2015 My podcast copyright</copyright>
    <language>EN</language>
    <description>This is my very simple podcast.</description>
    <itunes:author>Author Name</itunes:author>
    <itunes:block>yes</itunes:block>
    <itunes:explicit>yes</itunes:explicit>
    <itunes:complete>yes</itunes:complete>
    <itunes:new-feed-url>http://www.example-podcast.com/new-feed-url</itunes:new-feed-url>
    <itunes:subtitle>This is my very simple podcast subtitle.</itunes:subtitle>
    <itunes:summary><![CDATA[This is my very simple podcast summary.]]></itunes:summary>
    <itunes:owner>
      <itunes:name>Podcast Owner</itunes:name>
      <itunes:email>owner@example-podcast.com</itunes:email>
    </itunes:owner>
    <itunes:image href="http://www.example-podcast.com/my-podcast.jpg"></itunes:image>
    <item>
      <title>Episode 1</title>
      <guid>http://www.example-podcast.com/my-podcast/1/episode-one</guid>
      <pubDate>Tue, 10 Nov 2009 23:00:00 +0000</pubDate>
      <itunes:duration>3:50</itunes:duration>
      <enclosure url="http://www.example-podcast.com/my-podcast/1/episode.mp3" length="12312" type="MP3"></enclosure>
    </item>
    <item>
      <title>Episode 2</title>
      <guid>http://www.example-podcast.com/my-podcast/2/episode-two</guid>
      <pubDate>Tue, 10 Nov 2009 23:00:00 +0000</pubDate>
      <itunes:duration>5:20</itunes:duration>
      <enclosure url="http://www.example-podcast.com/my-podcast/2/episode.mp3" length="46732" type="MP3"></enclosure>
    </item>
  </channel>
</rss>

Documentation

Overview

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

Constants

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

Variables

View Source
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")
)

Functions

func Author

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

Author sets itunes:author of given feed.

func Block

func Block(f *Feed) error

Block enables itunes:block of given feed.

func Complete

func Complete(f *Feed) error

Complete enables itunes:complete of given feed.

func Explicit

func Explicit(f *Feed) error

Explicit enables itunes:explicit of given feed.

func Image

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

Image sets itunes:image of given feed.

func NewFeedURL

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

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

func Owner

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

Owner sets itunes:owner of given feed.

func Subtitle

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

Subtitle sets itunes:subtitle of given feed.

func Summary

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

Summary sets itunes:summary of given feed.

Types

type Channel

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

type Duration struct {
	time.Duration
}

Duration represents itunes:duration attribute of given podcast item.

func NewDuration

func NewDuration(d time.Duration) *Duration

NewDuration returns a new Duration.

func (Duration) MarshalXML

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

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

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

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

SetOptions sets options of given feed.

func (*Feed) Write

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

Write writes marshalled XML to the given writer.

func (*Feed) XML

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

XML marshalls feed to XML string.

type Item

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

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

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

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

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

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

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

AddItem adds an item to the podcast.

func (*Podcast) Feed

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

Feed creates a new feed for current podcast.

type PubDate

type PubDate struct {
	time.Time
}

PubDate represents pubDate attribute of given podcast item.

func NewPubDate

func NewPubDate(d time.Time) *PubDate

NewPubDate returns a new PubDate.

func (PubDate) MarshalXML

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

MarshalXML marshalls pubdate using the rfc2822 time format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址