Merge pull request #293 from mishako/try-catch-duration

Catch itunes duration parsing exceptions
This commit is contained in:
Patrick Gotthard 2016-06-11 07:47:38 +02:00 committed by GitHub
commit 961a6407e1
5 changed files with 56 additions and 3 deletions

View file

@ -147,8 +147,12 @@ public class ITunesParser implements ModuleParser {
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);
@ -216,7 +220,7 @@ public class ITunesParser implements ModuleParser {
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"));
}
}
}

View file

@ -34,6 +34,7 @@ import com.rometools.modules.itunes.AbstractITunesObject;
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;
@ -133,4 +134,28 @@ public class ITunesParserTest extends AbstractTestCase {
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());
}
}

View file

@ -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>

View file

@ -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>

View file

@ -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>