From 19ecfcd0bc34b5727c21de9b920357f32457022f Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Tue, 22 Jun 2021 14:29:40 +0200 Subject: [PATCH] ParseRSS: accept any file with audio/ media type as podcast There are some podcasts that use audio/opus files (mostly as an alternative, but still), which makes the audio attachment not being displayed. Instead of increasing the list of allowed formats (because audio/mp3 would be quite useful on the list too), I guess it'd be better to give any audio/ media type to the user-agent and let him worry about it. :^) --- src/parser/rss.go | 2 +- src/parser/rss_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/parser/rss.go b/src/parser/rss.go index 0ce8a4b..9eedfc1 100644 --- a/src/parser/rss.go +++ b/src/parser/rss.go @@ -71,7 +71,7 @@ func ParseRSS(r io.Reader) (*Feed, error) { for _, srcitem := range srcfeed.Items { podcastURL := "" for _, e := range srcitem.Enclosures { - if e.Type == "audio/mpeg" || e.Type == "audio/x-m4a" { + if strings.HasPrefix(e.Type, "audio/") { podcastURL = e.URL if srcitem.OrigEnclosureLink != "" && strings.Contains(podcastURL, path.Base(srcitem.OrigEnclosureLink)) { diff --git a/src/parser/rss_test.go b/src/parser/rss_test.go index 58e9c5d..65d0b41 100644 --- a/src/parser/rss_test.go +++ b/src/parser/rss_test.go @@ -136,6 +136,26 @@ func TestRSSPodcast(t *testing.T) { } } +func TestRSSOpusPodcast(t *testing.T) { + feed, _ := Parse(strings.NewReader(` + + + + + + + + + `)) + have := feed.Items[0].AudioURL + want := "http://example.com/audio.ext" + if want != have { + t.Logf("want: %#v", want) + t.Logf("have: %#v", have) + t.FailNow() + } +} + // found in: https://podcast.cscript.site/podcast.xml func TestRSSPodcastDuplicated(t *testing.T) { feed, _ := Parse(strings.NewReader(`