78 lines
1.3 KiB
Go
78 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/eduncan911/podcast"
|
|
)
|
|
|
|
func generateRSS() error {
|
|
rssLock.Lock()
|
|
defer rssLock.Unlock()
|
|
|
|
episodes, err := scanEpisodes()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
timeNow := time.Now()
|
|
|
|
p := podcast.New(
|
|
podTitle,
|
|
baseURL,
|
|
podDesc,
|
|
&timeNow, &timeNow,
|
|
)
|
|
|
|
// 2. Aggiungi metadati globali
|
|
p.IAuthor = podAuthor
|
|
p.AddImage(podLogo)
|
|
|
|
for _, ep := range episodes {
|
|
|
|
epBaseUrl := baseURL + "/audio/" + filepath.Base(ep.File)
|
|
|
|
strip, found := strings.CutSuffix(filepath.Base(ep.File), ".mp3")
|
|
if !found {
|
|
log.Println("Seems the file is not mp3??????")
|
|
}
|
|
epBaseImg := baseURL + "/covers/" + strip + ".jpg"
|
|
|
|
item := podcast.Item{
|
|
Title: ep.Title,
|
|
Description: ep.Description,
|
|
PubDate: &timeNow,
|
|
Enclosure: &podcast.Enclosure{
|
|
URL: epBaseUrl,
|
|
Type: podcast.MP3,
|
|
Length: ep.Size,
|
|
},
|
|
// Metadati specifici iTunes
|
|
IAuthor: ep.Artist,
|
|
IImage: &podcast.IImage{
|
|
HREF: epBaseImg, // Campo corretto
|
|
},
|
|
IExplicit: "no",
|
|
}
|
|
|
|
if _, err := p.AddItem(item); err != nil {
|
|
log.Fatal("Errore nell'aggiunta dell'episodio: ", err)
|
|
}
|
|
|
|
}
|
|
|
|
if err := p.Encode(os.Stdout); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Opzionale: salva su file
|
|
file, _ := os.Create("feed.xml")
|
|
defer file.Close()
|
|
return p.Encode(file)
|
|
|
|
}
|