Round recording duration to the nearest second in RSS feed items (#8)
Some checks failed
Docker / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
golangci-lint / lint (push) Has been cancelled

This commit is contained in:
2025-04-13 23:31:51 +03:00
committed by GitHub
parent f9d0347ed4
commit 06b19c7cb4

View File

@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"log/slog" "log/slog"
"math"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "sort"
@@ -89,11 +90,14 @@ func (g *Generator) createFeedItems(recordings []RecordingInfo) []*feeds.Item {
for _, rec := range recordings { for _, rec := range recordings {
fileURL := fmt.Sprintf("%s/recordings/%s", baseURL, rec.Filename) fileURL := fmt.Sprintf("%s/recordings/%s", baseURL, rec.Filename)
// Round duration to the nearest second
roundedDuration := time.Duration(math.Round(float64(rec.Duration)/float64(time.Second))) * time.Second
item := &feeds.Item{ item := &feeds.Item{
Title: fmt.Sprintf("Recording %s", rec.RecordedAt.Format("2006-01-02 15:04")), Title: fmt.Sprintf("Recording %s", rec.RecordedAt.Format("2006-01-02 15:04")),
Link: &feeds.Link{Href: fileURL}, Link: &feeds.Link{Href: fileURL},
Description: fmt.Sprintf("Icecast stream recording from %s. Duration: %s", Description: fmt.Sprintf("Icecast stream recording from %s. Duration: %s",
rec.RecordedAt.Format(time.RFC1123), rec.Duration.String()), rec.RecordedAt.Format(time.RFC1123), roundedDuration.String()),
Created: rec.RecordedAt, Created: rec.RecordedAt,
Id: rec.Hash, Id: rec.Hash,
Enclosure: &feeds.Enclosure{ Enclosure: &feeds.Enclosure{