diff options
Diffstat (limited to 'core')
4 files changed, 68 insertions, 20 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java index 839e2ae0c..f2cfc2e57 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java @@ -26,6 +26,11 @@ public class NSMedia extends Namespace { private static final String MIME_TYPE = "type"; private static final String DURATION = "duration"; private static final String DEFAULT = "isDefault"; + private static final String MEDIUM = "medium"; + + private static final String MEDIUM_IMAGE = "image"; + private static final String MEDIUM_AUDIO = "audio"; + private static final String MEDIUM_VIDEO = "video"; private static final String IMAGE = "thumbnail"; private static final String IMAGE_URL = "url"; @@ -40,20 +45,31 @@ public class NSMedia extends Namespace { String url = attributes.getValue(DOWNLOAD_URL); String type = attributes.getValue(MIME_TYPE); String defaultStr = attributes.getValue(DEFAULT); - boolean validType; + String medium = attributes.getValue(MEDIUM); + boolean validTypeMedia = false; + boolean validTypeImage = false; boolean isDefault = "true".equals(defaultStr); - if (SyndTypeUtils.enclosureTypeValid(type)) { - validType = true; + if (MEDIUM_AUDIO.equals(medium) || MEDIUM_VIDEO.equals(medium)) { + validTypeMedia = true; + } else if (MEDIUM_IMAGE.equals(medium)) { + validTypeImage = true; } else { - type = SyndTypeUtils.getValidMimeTypeFromUrl(url); - validType = type != null; + if (type == null) { + type = SyndTypeUtils.getMimeTypeFromUrl(url); + } + + if (SyndTypeUtils.enclosureTypeValid(type)) { + validTypeMedia = true; + } else if (SyndTypeUtils.imageTypeValid(type)) { + validTypeImage = true; + } } if (state.getCurrentItem() != null && (state.getCurrentItem().getMedia() == null || isDefault) && - url != null && validType) { + url != null && validTypeMedia) { long size = 0; String sizeStr = attributes.getValue(SIZE); try { @@ -77,6 +93,12 @@ public class NSMedia extends Namespace { media.setDuration(durationMs); } state.getCurrentItem().setMedia(media); + } else if (state.getCurrentItem() != null && url != null && validTypeImage) { + FeedImage image = new FeedImage(); + image.setDownload_url(url); + image.setOwner(state.getCurrentItem()); + + state.getCurrentItem().setImage(image); } } else if (IMAGE.equals(localName)) { String url = attributes.getValue(IMAGE_URL); diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java index c91444552..90dd67a0b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java @@ -53,14 +53,17 @@ public class NSRSS20 extends Namespace { } else if (ENCLOSURE.equals(localName)) { String type = attributes.getValue(ENC_TYPE); String url = attributes.getValue(ENC_URL); - boolean validType; + boolean validType = false; + boolean validUrl = !TextUtils.isEmpty(url); + + if (type == null) { + type = SyndTypeUtils.getMimeTypeFromUrl(url); + } + if(SyndTypeUtils.enclosureTypeValid(type)) { validType = true; - } else { - type = SyndTypeUtils.getValidMimeTypeFromUrl(url); - validType = type != null; } - boolean validUrl = !TextUtils.isEmpty(url); + if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && validType && validUrl) { long size = 0; diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java index 5443678ea..b14f84c7a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java @@ -95,14 +95,12 @@ public class NSAtom extends Namespace { Log.d(TAG, "Length attribute could not be parsed."); } String type = attributes.getValue(LINK_TYPE); - boolean validType; - if(SyndTypeUtils.enclosureTypeValid(type)) { - validType = true; - } else { - type = SyndTypeUtils.getValidMimeTypeFromUrl(href); - validType = type != null; + + if (type == null) { + type = SyndTypeUtils.getMimeTypeFromUrl(href); } - if (validType) { + + if(SyndTypeUtils.enclosureTypeValid(type)) { FeedItem currItem = state.getCurrentItem(); if(currItem != null && !currItem.hasMedia()) { currItem.setMedia(new FeedMedia(currItem, href, size, type)); diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java index d228b9ef7..3c92805b2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/util/SyndTypeUtils.java @@ -6,8 +6,10 @@ import org.apache.commons.io.FilenameUtils; /** Utility class for handling MIME-Types of enclosures */ public class SyndTypeUtils { - private static final String VALID_MIMETYPE = "audio/.*" + "|" + "video/.*" + private static final String VALID_MEDIA_MIMETYPE = "audio/.*" + "|" + "video/.*" + "|" + "application/ogg"; + private static final String VALID_IMAGE_MIMETYPE = "image/.*"; + private SyndTypeUtils() { @@ -17,10 +19,18 @@ public class SyndTypeUtils { if (type == null) { return false; } else { - return type.matches(VALID_MIMETYPE); + return type.matches(VALID_MEDIA_MIMETYPE); + } + } + public static boolean imageTypeValid(String type) { + if (type == null) { + return false; + } else { + return type.matches(VALID_IMAGE_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 @@ -38,4 +48,19 @@ public class SyndTypeUtils { } return null; } + + /** + * Should be used if mime-type of enclosure tag is not supported. This + * method will return the mime-type of the file extension. + */ + public static String getMimeTypeFromUrl(String url) { + if (url != null) { + String extension = FilenameUtils.getExtension(url); + if (extension != null) { + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } + } + return null; + } + } |