Check file extension if mime-type is not supported
This commit is contained in:
parent
1f214573e9
commit
0b22262186
|
@ -10,6 +10,7 @@ import de.danoeh.antennapod.syndication.namespace.Namespace;
|
||||||
import de.danoeh.antennapod.syndication.namespace.SyndElement;
|
import de.danoeh.antennapod.syndication.namespace.SyndElement;
|
||||||
import de.danoeh.antennapod.syndication.namespace.rss20.NSRSS20;
|
import de.danoeh.antennapod.syndication.namespace.rss20.NSRSS20;
|
||||||
import de.danoeh.antennapod.syndication.util.SyndDateUtils;
|
import de.danoeh.antennapod.syndication.util.SyndDateUtils;
|
||||||
|
import de.danoeh.antennapod.syndication.util.SyndTypeUtils;
|
||||||
|
|
||||||
public class NSAtom extends Namespace {
|
public class NSAtom extends Namespace {
|
||||||
private static final String TAG = "NSAtom";
|
private static final String TAG = "NSAtom";
|
||||||
|
@ -72,10 +73,13 @@ public class NSAtom extends Namespace {
|
||||||
if (strSize != null)
|
if (strSize != null)
|
||||||
size = Long.parseLong(strSize);
|
size = Long.parseLong(strSize);
|
||||||
String type = attributes.getValue(LINK_TYPE);
|
String type = attributes.getValue(LINK_TYPE);
|
||||||
|
if (SyndTypeUtils.typeValid(type)
|
||||||
state.getCurrentItem().setMedia(
|
|| (type = SyndTypeUtils
|
||||||
new FeedMedia(state.getCurrentItem(), href,
|
.getValidMimeTypeFromUrl(href)) != null) {
|
||||||
size, type));
|
state.getCurrentItem().setMedia(
|
||||||
|
new FeedMedia(state.getCurrentItem(), href,
|
||||||
|
size, type));
|
||||||
|
}
|
||||||
} else if (rel.equals(LINK_REL_PAYMENT)) {
|
} else if (rel.equals(LINK_REL_PAYMENT)) {
|
||||||
state.getCurrentItem().setPaymentLink(href);
|
state.getCurrentItem().setPaymentLink(href);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import de.danoeh.antennapod.syndication.handler.HandlerState;
|
||||||
import de.danoeh.antennapod.syndication.namespace.Namespace;
|
import de.danoeh.antennapod.syndication.namespace.Namespace;
|
||||||
import de.danoeh.antennapod.syndication.namespace.SyndElement;
|
import de.danoeh.antennapod.syndication.namespace.SyndElement;
|
||||||
import de.danoeh.antennapod.syndication.util.SyndDateUtils;
|
import de.danoeh.antennapod.syndication.util.SyndDateUtils;
|
||||||
|
import de.danoeh.antennapod.syndication.util.SyndTypeUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SAX-Parser for reading RSS-Feeds
|
* SAX-Parser for reading RSS-Feeds
|
||||||
|
@ -39,8 +40,6 @@ public class NSRSS20 extends Namespace {
|
||||||
public final static String ENC_LEN = "length";
|
public final static String ENC_LEN = "length";
|
||||||
public final static String ENC_TYPE = "type";
|
public final static String ENC_TYPE = "type";
|
||||||
|
|
||||||
public final static String VALID_MIMETYPE = "audio/.*" + "|" + "video/.*" + "|" + "application/ogg";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SyndElement handleElementStart(String localName, HandlerState state,
|
public SyndElement handleElementStart(String localName, HandlerState state,
|
||||||
Attributes attributes) {
|
Attributes attributes) {
|
||||||
|
@ -51,19 +50,20 @@ public class NSRSS20 extends Namespace {
|
||||||
|
|
||||||
} else if (localName.equals(ENCLOSURE)) {
|
} else if (localName.equals(ENCLOSURE)) {
|
||||||
String type = attributes.getValue(ENC_TYPE);
|
String type = attributes.getValue(ENC_TYPE);
|
||||||
|
String url = attributes.getValue(ENC_URL);
|
||||||
if (state.getCurrentItem().getMedia() == null
|
if (state.getCurrentItem().getMedia() == null
|
||||||
&& (type.matches(VALID_MIMETYPE))) {
|
&& (SyndTypeUtils.typeValid(type) || ((type = SyndTypeUtils
|
||||||
|
.getValidMimeTypeFromUrl(url)) != null))) {
|
||||||
|
|
||||||
long size = 0;
|
long size = 0;
|
||||||
try {
|
try {
|
||||||
size = Long.parseLong(attributes
|
size = Long.parseLong(attributes.getValue(ENC_LEN));
|
||||||
.getValue(ENC_LEN));
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "Length attribute could not be parsed.");
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Length attribute could not be parsed.");
|
||||||
}
|
}
|
||||||
state.getCurrentItem().setMedia(
|
state.getCurrentItem().setMedia(
|
||||||
new FeedMedia(state.getCurrentItem(), attributes
|
new FeedMedia(state.getCurrentItem(), url, size, type));
|
||||||
.getValue(ENC_URL), size, attributes
|
|
||||||
.getValue(ENC_TYPE)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (localName.equals(IMAGE)) {
|
} else if (localName.equals(IMAGE)) {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package de.danoeh.antennapod.syndication.util;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
|
/** Utility class for handling MIME-Types of enclosures */
|
||||||
|
public class SyndTypeUtils {
|
||||||
|
|
||||||
|
private final static String VALID_MIMETYPE = "audio/.*" + "|" + "video/.*"
|
||||||
|
+ "|" + "application/ogg";
|
||||||
|
|
||||||
|
private SyndTypeUtils() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean typeValid(String type) {
|
||||||
|
return type.matches(VALID_MIMETYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be used if mime-type of enclosure tag is not supported. This
|
||||||
|
* method will check if the mime-type of the file extension is supported. If
|
||||||
|
* the type is not supported, this method will return null.
|
||||||
|
*/
|
||||||
|
public static String getValidMimeTypeFromUrl(String url) {
|
||||||
|
String extension = FilenameUtils.getExtension(url);
|
||||||
|
if (extension != null) {
|
||||||
|
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
|
||||||
|
extension);
|
||||||
|
if (typeValid(type)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue