Merge pull request #2137 from mfietz/2127-empty-download-url

Feed media is only valid when download url is not empty
This commit is contained in:
Martin Fietz 2016-10-08 09:48:02 +02:00 committed by GitHub
commit f0ef51aaad
2 changed files with 29 additions and 33 deletions

View File

@ -6,7 +6,6 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.syndication.namespace.NSContent;
import de.danoeh.antennapod.core.syndication.namespace.NSDublinCore;
@ -86,33 +85,27 @@ public class SyndHandler extends DefaultHandler {
state.defaultNamespaces.push(new NSAtom());
} else if (prefix.equals(NSAtom.NSTAG)) {
state.namespaces.put(uri, new NSAtom());
if (BuildConfig.DEBUG)
Log.d(TAG, "Recognized Atom namespace");
}
} else if (uri.equals(NSContent.NSURI)
&& prefix.equals(NSContent.NSTAG)) {
state.namespaces.put(uri, new NSContent());
if (BuildConfig.DEBUG)
Log.d(TAG, "Recognized Content namespace");
} else if (uri.equals(NSITunes.NSURI)
&& prefix.equals(NSITunes.NSTAG)) {
state.namespaces.put(uri, new NSITunes());
if (BuildConfig.DEBUG)
Log.d(TAG, "Recognized ITunes namespace");
} else if (uri.equals(NSSimpleChapters.NSURI)
&& prefix.matches(NSSimpleChapters.NSTAG)) {
state.namespaces.put(uri, new NSSimpleChapters());
if (BuildConfig.DEBUG)
Log.d(TAG, "Recognized SimpleChapters namespace");
} else if (uri.equals(NSMedia.NSURI)
&& prefix.equals(NSMedia.NSTAG)) {
state.namespaces.put(uri, new NSMedia());
if (BuildConfig.DEBUG)
Log.d(TAG, "Recognized media namespace");
} else if (uri.equals(NSDublinCore.NSURI)
&& prefix.equals(NSDublinCore.NSTAG)) {
state.namespaces.put(uri, new NSDublinCore());
if (BuildConfig.DEBUG)
Log.d(TAG, "Recognized DublinCore namespace");
}
}

View File

@ -20,25 +20,27 @@ import de.danoeh.antennapod.core.util.DateUtils;
*
*/
public class NSRSS20 extends Namespace {
private static final String TAG = "NSRSS20";
public static final String NSTAG = "rss";
public static final String NSURI = "";
private static final String NSTAG = "rss";
private static final String NSURI = "";
public static final String CHANNEL = "channel";
public static final String ITEM = "item";
public static final String GUID = "guid";
public static final String TITLE = "title";
public static final String LINK = "link";
public static final String DESCR = "description";
public static final String PUBDATE = "pubDate";
public static final String ENCLOSURE = "enclosure";
public static final String IMAGE = "image";
public static final String URL = "url";
public static final String LANGUAGE = "language";
private static final String GUID = "guid";
private static final String TITLE = "title";
private static final String LINK = "link";
private static final String DESCR = "description";
private static final String PUBDATE = "pubDate";
private static final String ENCLOSURE = "enclosure";
private static final String IMAGE = "image";
private static final String URL = "url";
private static final String LANGUAGE = "language";
public static final String ENC_URL = "url";
public static final String ENC_LEN = "length";
public static final String ENC_TYPE = "type";
private static final String ENC_URL = "url";
private static final String ENC_LEN = "length";
private static final String ENC_TYPE = "type";
@Override
public SyndElement handleElementStart(String localName, HandlerState state,
@ -55,11 +57,12 @@ public class NSRSS20 extends Namespace {
if(SyndTypeUtils.enclosureTypeValid(type)) {
validType = true;
} else {
type = type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
validType = type != null;
}
boolean validUrl = !TextUtils.isEmpty(url);
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
validType) {
validType && validUrl) {
long size = 0;
try {
size = Long.parseLong(attributes.getValue(ENC_LEN));
@ -70,8 +73,8 @@ public class NSRSS20 extends Namespace {
} catch (NumberFormatException e) {
Log.d(TAG, "Length attribute could not be parsed.");
}
state.getCurrentItem().setMedia(
new FeedMedia(state.getCurrentItem(), url, size, type));
FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
state.getCurrentItem().setMedia(media);
}
} else if (IMAGE.equals(localName)) {