From 7fe1e07048ffe9e80bd6e722e7a8b30922fb2e55 Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Wed, 5 Oct 2016 17:34:05 +0100 Subject: Support multiple author tags in a feed --- .../danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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..89070155b 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 @@ -206,7 +206,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); + } } } } -- cgit v1.2.3 From 85e08a270aab885f6630cde668e3ba2df30b10e9 Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Thu, 6 Oct 2016 09:40:18 +0100 Subject: Suport archive RSS/Atom links as alternate feeds --- .../antennapod/core/syndication/namespace/atom/NSAtom.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 89070155b..5443678ea 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"; @@ -130,6 +131,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) { -- cgit v1.2.3 From 0f7fe57454c8fd3c312daa479b2e141a39d56f6b Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Tue, 11 Oct 2016 14:54:46 +0100 Subject: Add support for images in mrss content SyndTypeUtils.getValidMimeTypeFromUrl is now unused and SyndTypeUtils.getMimeTypeFromUrl is used instead. It gets the mime type from the file extension, but dosen't check it so this function can how be used for both images or media files. --- .../core/syndication/namespace/NSMedia.java | 34 ++++++++++++++++++---- .../core/syndication/namespace/NSRSS20.java | 13 +++++---- .../core/syndication/namespace/atom/NSAtom.java | 12 ++++---- .../core/syndication/util/SyndTypeUtils.java | 29 ++++++++++++++++-- 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; + } + } -- cgit v1.2.3 From 2c17e033972a0498a15b58f9fb206c6d8d025d5b Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Thu, 13 Oct 2016 05:56:26 +0100 Subject: Improve readablilty --- .../core/syndication/util/SyndTypeUtils.java | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) 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 3c92805b2..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 @@ -37,16 +37,12 @@ public class SyndTypeUtils { * 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; } /** @@ -54,13 +50,14 @@ public class SyndTypeUtils { * 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); - } + if (url == null) { + return null; + } + String extension = FilenameUtils.getExtension(url); + if (extension == null) { + return null; } - return null; - } + return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } } -- cgit v1.2.3