mirror of https://github.com/miniflux/v2.git
feat: use podcast duration tag as reading time
This commit is contained in:
parent
168a870c02
commit
fb8737e330
|
@ -3,7 +3,12 @@
|
||||||
|
|
||||||
package rss // import "miniflux.app/v2/internal/reader/rss"
|
package rss // import "miniflux.app/v2/internal/reader/rss"
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// PodcastFeedElement represents iTunes and GooglePlay feed XML elements.
|
// PodcastFeedElement represents iTunes and GooglePlay feed XML elements.
|
||||||
// Specs:
|
// Specs:
|
||||||
|
@ -21,6 +26,7 @@ type PodcastFeedElement struct {
|
||||||
type PodcastEntryElement struct {
|
type PodcastEntryElement struct {
|
||||||
Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
|
Subtitle string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd subtitle"`
|
||||||
Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
|
Summary string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd summary"`
|
||||||
|
Duration string `xml:"http://www.itunes.com/dtds/podcast-1.0.dtd duration"`
|
||||||
GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
|
GooglePlayDescription string `xml:"http://www.google.com/schemas/play-podcasts/1.0 description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,3 +73,26 @@ func (e *PodcastEntryElement) PodcastDescription() string {
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(description)
|
return strings.TrimSpace(description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var invalidDurationFormatErr = fmt.Errorf("rss: invalid duration format")
|
||||||
|
|
||||||
|
// normalizeDuration returns the duration tag value as a number of minutes
|
||||||
|
func normalizeDuration(rawDuration string) (int, error) {
|
||||||
|
var sumSeconds int
|
||||||
|
|
||||||
|
durationParts := strings.Split(rawDuration, ":")
|
||||||
|
if len(durationParts) > 3 {
|
||||||
|
return 0, invalidDurationFormatErr
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, durationPart := range durationParts {
|
||||||
|
durationPartValue, err := strconv.Atoi(durationPart)
|
||||||
|
if err != nil {
|
||||||
|
return 0, invalidDurationFormatErr
|
||||||
|
}
|
||||||
|
|
||||||
|
sumSeconds += int(math.Pow(60, float64(len(durationParts)-i-1))) * durationPartValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return sumSeconds / 60, nil
|
||||||
|
}
|
||||||
|
|
|
@ -199,6 +199,9 @@ func (r *rssItem) Transform() *model.Entry {
|
||||||
entry.Title = r.entryTitle()
|
entry.Title = r.entryTitle()
|
||||||
entry.Enclosures = r.entryEnclosures()
|
entry.Enclosures = r.entryEnclosures()
|
||||||
entry.Tags = r.entryCategories()
|
entry.Tags = r.entryCategories()
|
||||||
|
if duration, err := normalizeDuration(r.Duration); err == nil {
|
||||||
|
entry.ReadingTime = duration
|
||||||
|
}
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue