如何从Rss中提取视频网址?

时间:2016-03-17 13:55:18

标签: rss rss-reader rome

我正在阅读包含视频网址的RSS Feed。 我使用ROME并没有成功提取它。 下面是RSS feed xml,我试图提取

我将不胜感激。

Rss Feed:

SyndFeed feed = null;
                try {
                    logger.info("Building feed for Url: " + feedUrl);
                    feed = new SyndFeedInput().build(reader);
                } catch (Exception e2) {
                    logger.error(e2);
                } finally {
                    try {
                        if (reader != null) {
                            reader.close();
                        }
                    } catch (IOException e) {
                        logger.error(e);
                    }
                }

                if (feed != null) {
                    logger.info("Feed from " + feedUrl + " is not null, total of " + feed.getEntries().size() + " entries");
                    String feedTitle = feed.getTitle();

                    for (Object entryObj : feed.getEntries()) {
                        SyndEntryImpl entry = (SyndEntryImpl) entryObj;
                        String author = entry.getAuthor();

                        String uri = entry.getUri();
                        logger.info("reading object from feed " + uri);
                        String description = "";
                        if (entry.getDescription() != null) {
                            description = entry.getDescription().getValue();
                        }
                        String title = entry.getTitle();
                        Date publishedDate = entry.getPublishedDate();
                        List<?> categoryList = entry.getCategories();

                        String transcript = null;
                        List<Element> foreignMarkup = (List<Element>) entry.getForeignMarkup();
                        if (foreignMarkup != null && foreignMarkup.size() > 0) {
                            for (Element element : foreignMarkup) {
                                //get name
                                String name = element.getName();
                                if (name != null && name.equals("transcript")) {
                                    transcript = element.getText();
                                }
                            }
                        }
                        String link = entry.getLink();
                        Date currentTime = Calendar.getInstance().getTime();

                        String categoryStr = "";

                        for (Object category : categoryList) {
                            SyndCategory sc = (SyndCategory) category;
                            categoryStr += sc.getName() + ",";
                        }

                        //HERE IS THE INSERTION TO THE DB
                    }

                    logger.info("End reading from feed " + feedUrl);
                }

到目前为止,此代码工作正常:

INSERT INTO table EXEC proc;

谢谢!

1 个答案:

答案 0 :(得分:0)

如果<media:backlink>包含相关网址,那么提取它就是:

String backlink = null;
for (Element foreignMarkup : entry.getForeignMarkup()) {
    if (foreignMarkup.getNamespaceURI().equals("http://search.yahoo.com/mrss/")) {
        if (foreignMarkup.getName().equals("backlink")) {
            backlink = foreignMarkup.getValue();
        }
    }
}

如果您的应用程序的类路径中有rome-modules,则可以使用更多灵活性API of the media rss module

for (Module module : entry.getModules()) {
    if (module instanceof MediaEntryModule) {
        MediaEntryModule media = (MediaEntryModule)module;
        for (MediaContent mediaContent : media.getMediaContents()) {
            System.out.println(mediaContent.getReference());
        }               
    }
}