From d4d696d83a298cb31a7c33afc559814248ea0204 Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Mon, 25 Jul 2016 09:44:17 +0100 Subject: [PATCH 1/5] Format NSMedia.java --- .../core/syndication/namespace/NSMedia.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 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 7a8b2bc03..7e4e090b4 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,19 +26,19 @@ public class NSMedia extends Namespace { @Override public SyndElement handleElementStart(String localName, HandlerState state, - Attributes attributes) { + Attributes attributes) { if (CONTENT.equals(localName)) { String url = attributes.getValue(DOWNLOAD_URL); String type = attributes.getValue(MIME_TYPE); - boolean validType; - if(SyndTypeUtils.enclosureTypeValid(type)) { - validType = true; - } else { - type = SyndTypeUtils.getValidMimeTypeFromUrl(url); - validType = type != null; - } - if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && - url != null && validType) { + boolean validType; + if (SyndTypeUtils.enclosureTypeValid(type)) { + validType = true; + } else { + type = SyndTypeUtils.getValidMimeTypeFromUrl(url); + validType = type != null; + } + if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && + url != null && validType) { long size = 0; String sizeStr = attributes.getValue(SIZE); try { @@ -51,14 +51,14 @@ public class NSMedia extends Namespace { String durationStr = attributes.getValue(DURATION); if (!TextUtils.isEmpty(durationStr)) { try { - long duration = Long.parseLong(durationStr); + long duration = Long.parseLong(durationStr); durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS); } catch (NumberFormatException e) { Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed"); } } FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type); - if(durationMs > 0) { + if (durationMs > 0) { media.setDuration(durationMs); } state.getCurrentItem().setMedia(media); @@ -71,5 +71,4 @@ public class NSMedia extends Namespace { public void handleElementEnd(String localName, HandlerState state) { } - -} +} \ No newline at end of file From 8a7029ed7830826dccefaa41fc44e418dfc52e30 Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Mon, 25 Jul 2016 10:05:44 +0100 Subject: [PATCH 2/5] Honor mrss' isDefault attribute --- .../core/syndication/namespace/NSMedia.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 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 7e4e090b4..965ff691e 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 @@ -23,6 +23,7 @@ public class NSMedia extends Namespace { private static final String SIZE = "fileSize"; private static final String MIME_TYPE = "type"; private static final String DURATION = "duration"; + private static final String DEFAULT = "isDefault"; @Override public SyndElement handleElementStart(String localName, HandlerState state, @@ -30,14 +31,21 @@ public class NSMedia extends Namespace { if (CONTENT.equals(localName)) { String url = attributes.getValue(DOWNLOAD_URL); String type = attributes.getValue(MIME_TYPE); + String defaultStr = attributes.getValue(DEFAULT); boolean validType; + boolean isDefault = false; if (SyndTypeUtils.enclosureTypeValid(type)) { validType = true; } else { type = SyndTypeUtils.getValidMimeTypeFromUrl(url); validType = type != null; } - if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && + + if (defaultStr == "true") + isDefault = true; + + if (state.getCurrentItem() != null && + (state.getCurrentItem().getMedia() == null || isDefault) && url != null && validType) { long size = 0; String sizeStr = attributes.getValue(SIZE); @@ -71,4 +79,5 @@ public class NSMedia extends Namespace { public void handleElementEnd(String localName, HandlerState state) { } -} \ No newline at end of file +} + From 9562f1922ae3279572cd192caea988958c9ff2d4 Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Mon, 25 Jul 2016 10:37:22 +0100 Subject: [PATCH 3/5] Support mrss' thumbnail Note, this only supports one image as that's all AntennaPod can at the moment. --- .../core/syndication/namespace/NSMedia.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 965ff691e..5b7f8f5c5 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 @@ -25,6 +25,9 @@ public class NSMedia extends Namespace { private static final String DURATION = "duration"; private static final String DEFAULT = "isDefault"; + private static final String IMAGE = "thumbnail"; + private static final String IMAGE_URL = "url"; + @Override public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) { @@ -71,6 +74,22 @@ public class NSMedia extends Namespace { } state.getCurrentItem().setMedia(media); } + } else if (IMAGE.equals(localName)) { + String url = attributes.getValue(IMAGE_URL); + if (url != null) { + FeedImage image = new FeedImage(); + image.setDownload_url(url); + + if (state.getCurrentItem() != null) { + image.setOwner(state.getCurrentItem()); + state.getCurrentItem().setImage(image); + } else { + if (state.getFeed().getImage() == null) { + image.setOwner(state.getFeed()); + state.getFeed().setImage(image); + } + } + } } return new SyndElement(localName, this); } From 0dfa36953bc50768a5fa6a31ec8e47391e0eb6bf Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Mon, 25 Jul 2016 13:21:29 +0100 Subject: [PATCH 4/5] Support mrss' description Reusing AtomText but it works perfectly. MRSS has "plain" and "html" types, fallsback to "plain" if null or invalid type --- .../core/syndication/namespace/NSMedia.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 5b7f8f5c5..46452085f 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 @@ -7,8 +7,10 @@ import org.xml.sax.Attributes; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.feed.FeedImage; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.syndication.handler.HandlerState; +import de.danoeh.antennapod.core.syndication.namespace.atom.AtomText; import de.danoeh.antennapod.core.syndication.util.SyndTypeUtils; /** Processes tags from the http://search.yahoo.com/mrss/ namespace. */ @@ -28,6 +30,9 @@ public class NSMedia extends Namespace { private static final String IMAGE = "thumbnail"; private static final String IMAGE_URL = "url"; + private static final String DESCRIPTION = "description"; + private static final String DESCRIPTION_TYPE = "type"; + @Override public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) { @@ -90,13 +95,22 @@ public class NSMedia extends Namespace { } } } + } else if (DESCRIPTION.equals(localName)) { + String type = attributes.getValue(DESCRIPTION_TYPE); + return new AtomText(localName, this, type); } return new SyndElement(localName, this); } @Override public void handleElementEnd(String localName, HandlerState state) { - + if (DESCRIPTION.equals(localName)) { + String content = state.getContentBuf().toString(); + if (state.getCurrentItem() != null && content != null && + state.getCurrentItem().getDescription() == null) { + state.getCurrentItem().setDescription(content); + } + } } } From 74e6b7476d5cfd2a8f43a441e10aa7e7e87b40b9 Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Mon, 25 Jul 2016 17:27:06 +0100 Subject: [PATCH 5/5] Amend string check --- .../antennapod/core/syndication/namespace/NSMedia.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 46452085f..839e2ae0c 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 @@ -41,7 +41,9 @@ public class NSMedia extends Namespace { String type = attributes.getValue(MIME_TYPE); String defaultStr = attributes.getValue(DEFAULT); boolean validType; - boolean isDefault = false; + + boolean isDefault = "true".equals(defaultStr); + if (SyndTypeUtils.enclosureTypeValid(type)) { validType = true; } else { @@ -49,9 +51,6 @@ public class NSMedia extends Namespace { validType = type != null; } - if (defaultStr == "true") - isDefault = true; - if (state.getCurrentItem() != null && (state.getCurrentItem().getMedia() == null || isDefault) && url != null && validType) {