diff --git a/Providers/PodcastProvider/Classes/PodcastProvider.cs b/Providers/PodcastProvider/Classes/PodcastProvider.cs index da556ae4..8a41d48c 100644 --- a/Providers/PodcastProvider/Classes/PodcastProvider.cs +++ b/Providers/PodcastProvider/Classes/PodcastProvider.cs @@ -185,22 +185,7 @@ public override AvailableEpisodes GetAvailableEpisodes(string progExtId, Program continue; } - if (itemNode.SelectSingleNode("./title[text()]") == null) - { - continue; - } - - var urlAttrib = itemNode.SelectSingleNode("./enclosure/@url") as XmlAttribute; - - if (urlAttrib == null) - { - continue; - } - - Uri uri; - Uri.TryCreate(urlAttrib.Value, UriKind.Absolute, out uri); - - if (uri == null) + if (this.FilterItemNode(itemNode)) { continue; } @@ -507,6 +492,11 @@ private XmlNode ItemNodeFromEpisodeID(XmlDocument rss, string episodeExtId) foreach (XmlNode itemNode in itemNodes) { + if (this.FilterItemNode(itemNode)) + { + continue; + } + string itemId = this.ItemNodeToEpisodeID(itemNode); if (itemId == episodeExtId) @@ -518,6 +508,28 @@ private XmlNode ItemNodeFromEpisodeID(XmlDocument rss, string episodeExtId) return null; } + private bool FilterItemNode(XmlNode itemNode) + { + if (itemNode.SelectSingleNode("./title[text()]") == null) + { + return true; + } + + if (!(itemNode.SelectSingleNode("./enclosure/@url") is XmlAttribute urlAttrib)) + { + return true; + } + + Uri.TryCreate(urlAttrib.Value, UriKind.Absolute, out Uri uri); + + if (uri == null) + { + return true; + } + + return false; + } + private CompressedImage FetchImage(XmlNode parent, string xpath, XmlNamespaceManager namespaceMgr) { var urlNode = parent.SelectSingleNode(xpath, namespaceMgr); diff --git a/Test/Providers/PodcastProvider/Classes/TestGetInfo.cs b/Test/Providers/PodcastProvider/Classes/TestGetInfo.cs index a7fc9610..3af8f055 100644 --- a/Test/Providers/PodcastProvider/Classes/TestGetInfo.cs +++ b/Test/Providers/PodcastProvider/Classes/TestGetInfo.cs @@ -119,5 +119,21 @@ public void EpisodeFiltering() Assert.Contains("nofilter-valid", available); Assert.Contains("nofilter-enclosure-encoded-url", available); } + + /// + /// Test that correct podcast information can be retrieved for episodes + /// with the same id as a previous filtered episode. + /// + [Fact] + public void EpisodeSameIdAsFilteredInfo() + { + var instance = TestCommon.CreateInstance(); + string extId = "http://example.com/EpisodeFiltering.xml"; + + var programme = instance.GetProgrammeInfo(extId); + var episode = instance.GetEpisodeInfo(extId, programme, "filter-nofilter-sameid"); + + Assert.Equal("NOT FILTERED", episode.Name); + } } } diff --git a/Test/Providers/PodcastProvider/TestData/EpisodeFiltering.xml b/Test/Providers/PodcastProvider/TestData/EpisodeFiltering.xml index 3a171b35..3cef062d 100644 --- a/Test/Providers/PodcastProvider/TestData/EpisodeFiltering.xml +++ b/Test/Providers/PodcastProvider/TestData/EpisodeFiltering.xml @@ -39,5 +39,34 @@ nofilter-enclosure-encoded-url + + + filter-nofilter-sameid + + + + + filter-nofilter-sameid + + + + FILTERED + filter-nofilter-sameid + + + FILTERED + filter-nofilter-sameid + + + + FILTERED + filter-enclosure-invalid-url + + + + NOT FILTERED + filter-nofilter-sameid + +