diff options
4 files changed, 92 insertions, 30 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 ec7ebe1ac..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 @@ -45,6 +45,7 @@ public class NSAtom extends Namespace { private static final String LINK_LENGTH = "length"; // rel-values private static final String LINK_REL_ALTERNATE = "alternate"; + private static final String LINK_REL_ARCHIVES = "archives"; private static final String LINK_REL_ENCLOSURE = "enclosure"; private static final String LINK_REL_PAYMENT = "payment"; private static final String LINK_REL_RELATED = "related"; @@ -94,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)); @@ -130,6 +129,17 @@ public class NSAtom extends Namespace { } state.addAlternateFeedUrl(title, href); } + } else if (LINK_REL_ARCHIVES.equals(rel) && state.getFeed() != null) { + String type = attributes.getValue(LINK_TYPE); + if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) { + String title = attributes.getValue(LINK_TITLE); + if (TextUtils.isEmpty(title)) { + title = href; + } + state.addAlternateFeedUrl(title, href); + } else if (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)) { + //A Link such as to a directory such as iTunes + } } else if (LINK_REL_PAYMENT.equals(rel) && state.getFeed() != null) { state.getFeed().setPaymentLink(href); } else if (LINK_REL_NEXT.equals(rel) && state.getFeed() != null) { @@ -206,7 +216,12 @@ public class NSAtom extends Namespace { state.getFeed().setImage(new FeedImage(state.getFeed(), content, null)); } else if (AUTHOR.equals(second) && state.getFeed() != null) { if (AUTHOR_NAME.equals(top)) { - state.getFeed().setAuthor(content); + String currentName = state.getFeed().getAuthor(); + if (currentName == null) { + state.getFeed().setAuthor(content); + } else { + state.getFeed().setAuthor(currentName + ", " + content); + } } } } 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..5b12fa772 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,25 +19,45 @@ 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 * the type is not supported, this method will return null. */ public static String getValidMimeTypeFromUrl(String url) { - if (url != null) { - String extension = FilenameUtils.getExtension(url); - if (extension != null) { - String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); - if (type != null && enclosureTypeValid(type)) { - return type; - } - } + String type = getMimeTypeFromUrl(url); + if (enclosureTypeValid(type)) { + return type; + } else { + return null; } - 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) { + return null; + } + String extension = FilenameUtils.getExtension(url); + if (extension == null) { + return null; + } + + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); } } |