64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/gorilla/feeds"
|
|
)
|
|
|
|
func generateRSS() error {
|
|
rssLock.Lock()
|
|
defer rssLock.Unlock()
|
|
|
|
episodes, err := scanEpisodes()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// rss := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
|
|
// <rss version="2.0"
|
|
// xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
|
|
// xmlns:podcast="https://podcastindex.org/namespace/1.0"
|
|
// xmlns:atom="http://www.w3.org/2005/Atom"
|
|
// xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
|
// <channel>
|
|
// <description>%s</description>
|
|
// <title>%s</title>
|
|
// <link>%s</link>`, podTitle, podTitle, baseURL)
|
|
|
|
feed := &feeds.Feed{
|
|
Title: podTitle,
|
|
Link: &feeds.Link{Href: baseURL},
|
|
Description: podDesc,
|
|
Author: &feeds.Author{Name: podAuthor},
|
|
Created: time.Now(),
|
|
Copyright: podRights,
|
|
}
|
|
|
|
for _, ep := range episodes {
|
|
|
|
epBaseUrl := baseURL + "/audio/" + filepath.Base(ep.File)
|
|
|
|
feed.Add(&feeds.Item{
|
|
Title: ep.Title,
|
|
Link: &feeds.Link{Href: epBaseUrl},
|
|
Description: ep.Description,
|
|
Enclosure: &feeds.Enclosure{
|
|
Url: epBaseUrl,
|
|
Length: fmt.Sprintf("%d", ep.Size),
|
|
Type: "audio/mpeg",
|
|
},
|
|
Created: time.Now(),
|
|
})
|
|
|
|
}
|
|
|
|
// Genera RSS
|
|
rss, _ := feed.ToRss()
|
|
return os.WriteFile("feed.xml", []byte(rss), 0644)
|
|
|
|
}
|