summaryrefslogtreecommitdiff
path: root/src/de/danoeh
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-12-31 18:55:43 +0100
committerdaniel oeh <daniel.oeh@gmail.com>2012-12-31 18:55:43 +0100
commit19297a1c255f331d5beaa1ccaa73948fc195597d (patch)
tree8411c1ead915284ca884bd055ac0573df59f938e /src/de/danoeh
parent09ae33ea909aa5b547170210919931f83d5d8952 (diff)
downloadAntennaPod-19297a1c255f331d5beaa1ccaa73948fc195597d.zip
Added support for media:content tag, fixes #82
Diffstat (limited to 'src/de/danoeh')
-rw-r--r--src/de/danoeh/antennapod/syndication/handler/SyndHandler.java9
-rw-r--r--src/de/danoeh/antennapod/syndication/namespace/NSMedia.java70
-rw-r--r--src/de/danoeh/antennapod/syndication/namespace/NSRSS20.java2
-rw-r--r--src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java2
-rw-r--r--src/de/danoeh/antennapod/syndication/util/SyndTypeUtils.java4
5 files changed, 82 insertions, 5 deletions
diff --git a/src/de/danoeh/antennapod/syndication/handler/SyndHandler.java b/src/de/danoeh/antennapod/syndication/handler/SyndHandler.java
index 4c73e72e8..f830f0933 100644
--- a/src/de/danoeh/antennapod/syndication/handler/SyndHandler.java
+++ b/src/de/danoeh/antennapod/syndication/handler/SyndHandler.java
@@ -9,6 +9,7 @@ import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.syndication.namespace.NSContent;
import de.danoeh.antennapod.syndication.namespace.NSITunes;
+import de.danoeh.antennapod.syndication.namespace.NSMedia;
import de.danoeh.antennapod.syndication.namespace.NSRSS20;
import de.danoeh.antennapod.syndication.namespace.NSSimpleChapters;
import de.danoeh.antennapod.syndication.namespace.Namespace;
@@ -101,13 +102,19 @@ public class SyndHandler extends DefaultHandler {
state.namespaces.put(uri, new NSSimpleChapters());
if (AppConfig.DEBUG)
Log.d(TAG, "Recognized SimpleChapters namespace");
+ } else if (uri.equals(NSMedia.NSURI)
+ && prefix.equals(NSMedia.NSTAG)) {
+ state.namespaces.put(uri, new NSMedia());
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Recognized media namespace");
}
}
}
private Namespace getHandlingNamespace(String uri, String qName) {
Namespace handler = state.namespaces.get(uri);
- if (handler == null && !state.defaultNamespaces.empty() && !qName.contains(":")) {
+ if (handler == null && !state.defaultNamespaces.empty()
+ && !qName.contains(":")) {
handler = state.defaultNamespaces.peek();
}
return handler;
diff --git a/src/de/danoeh/antennapod/syndication/namespace/NSMedia.java b/src/de/danoeh/antennapod/syndication/namespace/NSMedia.java
new file mode 100644
index 000000000..e480a0266
--- /dev/null
+++ b/src/de/danoeh/antennapod/syndication/namespace/NSMedia.java
@@ -0,0 +1,70 @@
+package de.danoeh.antennapod.syndication.namespace;
+
+import java.util.concurrent.TimeUnit;
+
+import org.xml.sax.Attributes;
+
+import android.util.Log;
+
+import de.danoeh.antennapod.AppConfig;
+import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.syndication.handler.HandlerState;
+import de.danoeh.antennapod.syndication.util.SyndTypeUtils;
+
+/** Processes tags from the http://search.yahoo.com/mrss/ namespace. */
+public class NSMedia extends Namespace {
+ private static final String TAG = "NSMedia";
+
+ public static final String NSTAG = "media";
+ public static final String NSURI = "http://search.yahoo.com/mrss/";
+
+ private static final String CONTENT = "content";
+ private static final String DOWNLOAD_URL = "url";
+ private static final String SIZE = "fileSize";
+ private static final String MIME_TYPE = "type";
+ private static final String DURATION = "duration";
+
+ @Override
+ public SyndElement handleElementStart(String localName, HandlerState state,
+ Attributes attributes) {
+ if (localName.equals(CONTENT)) {
+ String url = attributes.getValue(DOWNLOAD_URL);
+ String type = attributes.getValue(MIME_TYPE);
+ if (state.getCurrentItem().getMedia() == null
+ && url != null
+ && (SyndTypeUtils.enclosureTypeValid(type) || ((type = SyndTypeUtils
+ .getValidMimeTypeFromUrl(url)) != null))) {
+
+ long size = 0;
+ try {
+ size = Long.parseLong(attributes.getValue(SIZE));
+ } catch (NumberFormatException e) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Length attribute could not be parsed.");
+ }
+
+ int duration = 0;
+ try {
+ String durationStr = attributes.getValue(DURATION);
+ if (durationStr != null) {
+ duration = (int) TimeUnit.MILLISECONDS.convert(
+ Long.parseLong(durationStr), TimeUnit.SECONDS);
+ }
+ } catch (NumberFormatException e) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Duration attribute could not be parsed");
+ }
+
+ state.getCurrentItem().setMedia(
+ new FeedMedia(state.getCurrentItem(), url, size, type));
+ }
+ }
+ return new SyndElement(localName, this);
+ }
+
+ @Override
+ public void handleElementEnd(String localName, HandlerState state) {
+
+ }
+
+}
diff --git a/src/de/danoeh/antennapod/syndication/namespace/NSRSS20.java b/src/de/danoeh/antennapod/syndication/namespace/NSRSS20.java
index dfdf188db..a8c43800c 100644
--- a/src/de/danoeh/antennapod/syndication/namespace/NSRSS20.java
+++ b/src/de/danoeh/antennapod/syndication/namespace/NSRSS20.java
@@ -50,7 +50,7 @@ public class NSRSS20 extends Namespace {
String type = attributes.getValue(ENC_TYPE);
String url = attributes.getValue(ENC_URL);
if (state.getCurrentItem().getMedia() == null
- && (SyndTypeUtils.typeValid(type) || ((type = SyndTypeUtils
+ && (SyndTypeUtils.enclosureTypeValid(type) || ((type = SyndTypeUtils
.getValidMimeTypeFromUrl(url)) != null))) {
long size = 0;
diff --git a/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java b/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java
index 51c30e579..e3cdce534 100644
--- a/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java
+++ b/src/de/danoeh/antennapod/syndication/namespace/atom/NSAtom.java
@@ -73,7 +73,7 @@ public class NSAtom extends Namespace {
if (strSize != null)
size = Long.parseLong(strSize);
String type = attributes.getValue(LINK_TYPE);
- if (SyndTypeUtils.typeValid(type)
+ if (SyndTypeUtils.enclosureTypeValid(type)
|| (type = SyndTypeUtils
.getValidMimeTypeFromUrl(href)) != null) {
state.getCurrentItem().setMedia(
diff --git a/src/de/danoeh/antennapod/syndication/util/SyndTypeUtils.java b/src/de/danoeh/antennapod/syndication/util/SyndTypeUtils.java
index d989b7be1..fe7836d37 100644
--- a/src/de/danoeh/antennapod/syndication/util/SyndTypeUtils.java
+++ b/src/de/danoeh/antennapod/syndication/util/SyndTypeUtils.java
@@ -14,7 +14,7 @@ public class SyndTypeUtils {
}
- public static boolean typeValid(String type) {
+ public static boolean enclosureTypeValid(String type) {
if (type == null) {
return false;
} else {
@@ -33,7 +33,7 @@ public class SyndTypeUtils {
if (extension != null) {
String type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension);
- if (type != null && typeValid(type)) {
+ if (type != null && enclosureTypeValid(type)) {
return type;
}
}