diff options
Diffstat (limited to 'src/de/danoeh/antennapod/syndication/namespace')
3 files changed, 72 insertions, 2 deletions
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( |