An open API service indexing awesome lists of open source software.

https://github.com/mutablelogic/go-rss

Yet another RSS feed parser
https://github.com/mutablelogic/go-rss

golang rss rss-parser

Last synced: about 1 month ago
JSON representation

Yet another RSS feed parser

Awesome Lists containing this project

README

          

# go-rss

A Go library for parsing RSS feeds with support for iTunes and Podcasting 2.0 namespaces.

## Installation

```bash
go get github.com/mutablelogic/go-rss
```

## Usage

### Parsing an RSS Feed

```go
package main

import (
"fmt"
"os"

"github.com/mutablelogic/go-rss"
)

func main() {
// Open the RSS file
file, err := os.Open("podcast.rss")
if err != nil {
panic(err)
}
defer file.Close()

// Parse the feed
feed, err := rss.Read(file)
if err != nil {
panic(err)
}

// Access feed information
fmt.Println("Title:", feed.Channel.Title)
fmt.Println("Description:", feed.Channel.Description)
fmt.Println("Link:", feed.Channel.Link)

// Iterate through items
for _, item := range feed.Channel.Items {
fmt.Println("Episode:", item.Title)
if item.Enclosure != nil {
fmt.Println(" Audio:", item.Enclosure.URL)
}
}
}
```

### Parsing from HTTP Response

```go
resp, err := http.Get("https://example.com/feed.rss")
if err != nil {
panic(err)
}
defer resp.Body.Close()

feed, err := rss.Read(resp.Body)
if err != nil {
panic(err)
}
```

### Working with Dates

```go
for _, item := range feed.Channel.Items {
if item.PubDate != nil {
pubTime, err := item.PubDate.Parse()
if err == nil {
fmt.Println("Published:", pubTime.Format(time.RFC3339))
}
}
}
```

### Working with Durations

```go
for _, item := range feed.Channel.Items {
if item.Duration != nil {
duration, err := item.Duration.Seconds()
if err == nil {
fmt.Println("Duration:", duration)
}
}
}
```

## Supported Namespaces

### RSS 2.0 Core Elements

- Channel: title, link, description, language, copyright, pubDate, lastBuildDate, categories, image, items, etc.
- Item: title, link, description, author, pubDate, guid, enclosure, source, comments, etc.

### iTunes Podcast Extension

Feed-level elements:

- `itunes:author`, `itunes:explicit`, `itunes:type`, `itunes:owner`, `itunes:block`, `itunes:complete`, `itunes:new-feed-url`

Item-level elements:

- `itunes:duration`, `itunes:image`, `itunes:explicit`, `itunes:episode`, `itunes:season`, `itunes:episodeType`, `itunes:block`

### Podcasting 2.0 Extension

Feed-level elements:

- `podcast:locked` - Prevents unauthorized feed imports
- `podcast:funding` - Donation/support links
- `podcast:guid` - Globally unique podcast identifier
- `podcast:medium` - Content medium type
- `podcast:license` - Content license
- `podcast:person` - Credits for hosts, producers, etc.
- `podcast:location` - Geographic location
- `podcast:value` - Cryptocurrency payment info (Value4Value)
- `podcast:images` - Multiple image sizes
- `podcast:trailer` - Preview/trailer episodes
- `podcast:txt` - Verification/metadata text records
- `podcast:liveItem` - Live streaming support

Item-level elements:

- `podcast:transcript` - Links to transcript files (SRT, VTT, JSON)
- `podcast:chapters` - Links to chapter files (JSON)
- `podcast:soundbite` - Highlight clips from episodes
- `podcast:person` - Credits for hosts, guests, editors
- `podcast:location` - Geographic location of episode
- `podcast:alternateEnclosure` - Multiple audio formats/qualities
- `podcast:value` - Payment info for specific episode
- `podcast:images` - Episode-specific images
- `podcast:license` - Episode-specific license
- `podcast:txt` - Episode metadata
- `podcast:socialInteract` - Comments via ActivityPub, etc.
- `podcast:contentLink` - Related content links

## Example: Accessing Podcasting 2.0 Elements

```go
feed, _ := rss.Read(file)
ch := feed.Channel

// Check if feed is locked
if ch.Locked != nil && ch.Locked.Value == "yes" {
fmt.Println("Feed is locked by:", ch.Locked.Owner)
}

// Get funding links
for _, funding := range ch.Funding {
fmt.Printf("Support: %s (%s)\n", funding.Value, funding.URL)
}

// Get transcripts for an episode
for _, item := range ch.Items {
for _, transcript := range item.Transcript {
fmt.Printf("Transcript (%s): %s\n", transcript.Type, transcript.URL)
}
}

// Get chapter markers
for _, item := range ch.Items {
if item.Chapters != nil {
fmt.Println("Chapters:", item.Chapters.URL)
}
}

// Get people credited
for _, person := range ch.Persons {
fmt.Printf("%s: %s\n", person.Role, person.Value)
}
```

## References

- [RSS 2.0 Specification](https://www.rssboard.org/rss-specification)
- [PSP-1 Podcast RSS Specification](https://github.com/Podcast-Standards-Project/PSP-1-Podcast-RSS-Specification)
- [Podcasting 2.0 Namespace](https://github.com/Podcastindex-org/podcast-namespace)
- [iTunes Podcast RSS](https://podcasters.apple.com/support/823-podcast-requirements)

## License

Apache 2.0 License. See [LICENSE](LICENSE) for details.