Fixes #8 (NumberFormatException if duration is has decimals on

media:content)
This commit is contained in:
Patrick Gotthard 2014-04-18 20:52:37 +02:00
parent 8608efd489
commit 60a61b926a
3 changed files with 29 additions and 1 deletions

View file

@ -50,6 +50,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.rometools.utils.Integers; import com.rometools.utils.Integers;
import com.rometools.utils.Longs;
import com.rometools.utils.Strings; import com.rometools.utils.Strings;
import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleParser; import com.sun.syndication.io.ModuleParser;
@ -129,7 +130,7 @@ public class MediaModuleParser implements ModuleParser {
} }
try { try {
if (content.getAttributeValue("duration") != null) { if (content.getAttributeValue("duration") != null) {
mc.setDuration(Long.valueOf(content.getAttributeValue("duration"))); mc.setDuration(Longs.parseDecimal(content.getAttributeValue("duration")));
} }
} catch (final Exception ex) { } catch (final Exception ex) {
LOG.warn("Exception parsing content tag.", ex); LOG.warn("Exception parsing content tag.", ex);

View file

@ -109,6 +109,24 @@ public class MediaModuleTest extends AbstractTestCase {
} }
/**
* tests parsing a decimal duration (https://github.com/rometools/rome-modules/issues/8).
*
* @throws IOException if file not found or not accessible
* @throws FeedException when the feed can't be parsed
*
*/
public void testParseDecimalDuration() throws FeedException, IOException {
final SyndFeed feed = getSyndFeed("org/rometools/feed/module/mediarss/issue-08.xml");
final SyndEntry entry = feed.getEntries().get(0);
final MediaEntryModule module = (MediaEntryModule) entry.getModule(MediaEntryModule.URI);
final Thumbnail[] thumbnails = module.getMetadata().getThumbnail();
assertThat(thumbnails, is(notNullValue()));
}
/** /**
* tests parsing rating without scheme (https://github.com/rometools/rome-modules/issues/12). * tests parsing rating without scheme (https://github.com/rometools/rome-modules/issues/12).
* *

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<item>
<media:content url="http://someurl/somevideo.wmv" fileSize="21592869" bitrate="496024"
duration="174.42" type="video/x-ms-wmv" isDefault="false" />
</item>
</channel>
</rss>