/** * Read data from an item node in the RSS/XML podcast file and use it to set this episode's * fields. * * @param parser Podcast file parser, set to the start tag of the item to read. * @throws XmlPullParserException On parsing problems. * @throws IOException On I/O problems. */ void parse(XmlPullParser parser) throws XmlPullParserException, IOException { // Make sure we start at item tag parser.require(XmlPullParser.START_TAG, "", RSS.ITEM); // Look at all start tags of this item while (parser.nextTag() == XmlPullParser.START_TAG) { final String tagName = parser.getName(); // Episode title if (tagName.equalsIgnoreCase(RSS.TITLE)) name = Html.fromHtml(parser.nextText().trim()).toString(); // Episode online location else if (tagName.equalsIgnoreCase(RSS.LINK)) url = parser.nextText(); // Explicit info found else if (tagName.equalsIgnoreCase(RSS.EXPLICIT)) explicit = parseExplicit(parser.nextText()); // Episode media URL else if (tagName.equalsIgnoreCase(RSS.ENCLOSURE)) { mediaUrl = parser.getAttributeValue("", RSS.URL); parser.nextText(); } // Episode publication date (2 options) else if (tagName.equalsIgnoreCase(RSS.DATE) && pubDate == null) pubDate = parseDate(parser.nextText()); else if (tagName.equalsIgnoreCase(RSS.PUBDATE)) pubDate = parseDate(parser.nextText()); // Episode duration else if (tagName.equalsIgnoreCase(RSS.DURATION)) duration = parseDuration(parser.nextText()); // Episode description else if (tagName.equalsIgnoreCase(RSS.DESCRIPTION)) description = parser.nextText(); else if (isContentEncodedTag(parser)) content = parser.nextText(); // Unneeded node, skip... else ParserUtils.skipSubTree(parser); } // Make sure we end at item tag parser.require(XmlPullParser.END_TAG, "", RSS.ITEM); }
/** * @return The episode's duration as given by the podcast feed converted into a string 00:00:00. * This might not be available and therefore <code>null</code>. */ public String getDurationString() { return duration > 0 ? ParserUtils.formatTime(duration) : null; }