Skip to content

SolarFactories/gopodcast

 
 

Repository files navigation

webbgeorge/gopodcast

gopodcast is a Go package for both parsing and generating podcast feeds. It has a simple interface using regular go structs, it supports common podcast standards, and it uses a large number of popular podcast feeds in it's test suite to give a high level of coverage.

This package also has 0 dependencies.

Other similar libraries exist, however most of them either a) aren't maintained, b) support parsing or generating, not both or c) are for RSS more broadly without podcast specific features.

Install

go get github.com/webbgeorge/gopodcast

Parsing

Parsing from URL

package main

import (
  "context"
  "fmt"
  "log"

  "github.com/webbgeorge/gopodcast"
)

func main() {
  parser := gopodcast.NewParser()

  // optionally provide http.Client
  parser.HTTPClient = myClient

  // optionally provide basic auth credentials for authenticated podcast feeds
  parser.AuthCredentials = &AuthCredentials{Username: "abc", Password: "123"}

  podcast, err := parser.ParseFeedFromURL(context.TODO(), "https://www.hellointernet.fm/podcast?format=rss")
  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(podcast.Title)
}

Parsing from io.Reader

func main() {
  myReader := ...

  parser := gopodcast.NewParser()
  podcast, err := parser.ParseFeed(myReader)
  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(podcast.Title)
}

Generating

func main() {
  podcast := &gopodcast.Podcast{
    Title: "My podcast",
  }

  myWriter := ...
  podcast.WriteFeedXML(myWriter)
}

Contributing

Contributions are welcome.

Testing

To run the tests, simply:

go test ./...

Top podcasts test suite

The parser is tested against a large number of podcast feeds from the Apple charts. These files are stored in testdata/top-podcasts. These files are updated using a script:

./fetch_test_data.sh

Code generation

This package uses code generation to work around known issues with XML namespaces in Go's encoding/xml package. The generated code is in the file gopodcast_xml_fix.go and is generated by generate/main.go. To re-generate this code, run:

go generate

About

A Go package for both parsing and generating podcast feeds

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 96.1%
  • Shell 3.9%