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.
go get github.com/webbgeorge/gopodcast
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)
}
func main() {
myReader := ...
parser := gopodcast.NewParser()
podcast, err := parser.ParseFeed(myReader)
if err != nil {
log.Fatal(err)
}
fmt.Println(podcast.Title)
}
func main() {
podcast := &gopodcast.Podcast{
Title: "My podcast",
}
myWriter := ...
podcast.WriteFeedXML(myWriter)
}
Contributions are welcome.
To run the tests, simply:
go test ./...
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
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