Skip to content

Commit

Permalink
Merge pull request #293 from mishako/try-catch-duration
Browse files Browse the repository at this point in the history
Catch itunes duration parsing exceptions
  • Loading branch information
PatrickGotthard authored Jun 11, 2016
2 parents 3c681bd + 943c0db commit 961a640
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ public com.rometools.rome.feed.module.Module parse(final Element element, final
final Element duration = element.getChild("duration", ns);

if (duration != null && duration.getValue() != null) {
final Duration dur = new Duration(duration.getValue().trim());
entryInfo.setDuration(dur);
try {
final Duration dur = new Duration(duration.getValue().trim());
entryInfo.setDuration(dur);
} catch (Exception e) {
LOG.warn("Failed to parse duration: {}", duration.getValue());
}
}

final Element closedCaptioned = element.getChild("isClosedCaptioned", ns);
Expand Down Expand Up @@ -216,7 +220,7 @@ public com.rometools.rome.feed.module.Module parse(final Element element, final
final URL imageURL = new URL(image.getAttributeValue("href").trim());
module.setImage(imageURL);
} catch (final MalformedURLException e) {
LOG.debug("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href"));
LOG.warn("Malformed URL Exception reading itunes:image tag: {}", image.getAttributeValue("href"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.rometools.modules.itunes.EntryInformationImpl;
import com.rometools.modules.itunes.FeedInformationImpl;
import com.rometools.modules.itunes.io.ITunesGenerator;
import com.rometools.modules.itunes.types.Duration;
import com.rometools.rome.feed.module.Module;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
Expand Down Expand Up @@ -133,4 +134,28 @@ public void testParseItem() throws Exception {
assertEquals(Integer.valueOf(2), entryInfo.getOrder());
assertEquals("http://example.org/image.png", entryInfo.getImage().toString());
}

public void testDuration() throws Exception {
SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource("duration.xml")));
SyndEntry entry = feed.getEntries().get(0);
EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

assertEquals(1000, module.getDuration().getMilliseconds());
}

public void testDurationEmpty() throws Exception {
SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource("duration-empty.xml")));
SyndEntry entry = feed.getEntries().get(0);
EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

assertNull(module.getDuration());
}

public void testDurationBad() throws Exception {
SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource("duration-bad.xml")));
SyndEntry entry = feed.getEntries().get(0);
EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

assertNull(module.getDuration());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<item>
<itunes:duration>00:00:00:01</itunes:duration>
</item>
</channel>
</rss>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<item>
<itunes:duration/>
</item>
</channel>
</rss>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<item>
<itunes:duration>00:00:01</itunes:duration>
</item>
</channel>
</rss>

0 comments on commit 961a640

Please sign in to comment.