mirror of
https://github.com/kemko/icecast-ripper.git
synced 2026-01-01 15:55:42 +03:00
Round recording duration to the nearest second in RSS feed items (#8)
This commit is contained in:
@@ -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{
|
||||||
|
|||||||
Reference in New Issue
Block a user