Volodymyr
Volodymyr

Reputation: 113

Can't read image URL from RSS using Rome API

My question almost the same as it is in the topic I found - Unable to read image URL from feed using Rome API except 2 conditions. So, how to read image url:

<item> 
  <title>Dementia in care homes 'more common'</title>  
  <description>Eight out of 10 residents in care homes are now thought to have dementia or severe memory problems, new data shows.</description>  
  <link>http://www.bbc.co.uk/news/health-21579394#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
  <guid isPermaLink="false">http://www.bbc.co.uk/news/health-21579394</guid>  
  <pubDate>Tue, 26 Feb 2013 00:28:31 GMT</pubDate>  
  <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/66064000/jpg/_66064884_c0016428-geriatric_care-spl.jpg"/>  
  <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/66064000/jpg/_66064885_c0016428-geriatric_care-spl.jpg"/> 
</item>

If markup doen't contain image url info

 List<Element> foreignMarkups = (List<Element>) entry.getForeignMarkup();
 for (Element foreignMarkup : foreignMarkups) {
  String imgURL = foreignMarkup.getAttribute("url").getValue(); 
    //read width and height
 }

and entry.getEnclosures() too. Moreover I looked at entry structure at debug mode and I haven't found any image url. I can only see media:thumbnail namespases in this structure

Upvotes: 1

Views: 652

Answers (1)

janih
janih

Reputation: 2234

Try Rome's media module to read those urls:

import com.rometools.modules.mediarss.MediaEntryModule;
import com.rometools.modules.mediarss.types.Thumbnail;
import com.rometools.rome.feed.module.Module;
...
for (Module module : entry.getModules()) {
    if (module instanceof MediaEntryModule) {
        MediaEntryModule media = (MediaEntryModule)module;
        for (Thumbnail thumb : media.getMetadata().getThumbnail()) {
            System.out.println(thumb.getUrl());
        }
    }
}

You need rome-modules in your classpath for this to work.

Upvotes: 3

Related Questions