Pkmmte / PkRSS

A powerful RSS feed manager for Android
Apache License 2.0
100 stars 23 forks source link

pullImage from <description> did not work every time #38

Open GerhardPue opened 7 years ago

GerhardPue commented 7 years ago

it works fine if the description looks like

<description><![CDATA[<img width="150" height="150" src="https://pic150x150.jpg" ]]></description>

but it ditnt work if

<description><![CDATA[  <div>
    <a href...... > <img src="https://pic150x150.jpg" /></a> 
</div>.................... ]]></description>

to you have e solution for changing Rss2Parser

private String pullImageLink(String encoded) {
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            XmlPullParser xpp = factory.newPullParser();

            xpp.setInput(new StringReader(encoded));
            int eventType = xpp.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                if (eventType == XmlPullParser.START_TAG && "img".equals(xpp.getName())) {
                    int count = xpp.getAttributeCount();
                    for (int x = 0; x < count; x++) {
                        if (xpp.getAttributeName(x).equalsIgnoreCase("src"))
                            return pattern.matcher(xpp.getAttributeValue(x)).replaceAll("");
                    }
                }
                eventType = xpp.next();
            }
        }
        catch (Exception e) {
            log(TAG, "Error pulling image link from description!\n" + e.getMessage(), Log.WARN);
        }

        return "";
    }