summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorH. Lehmann <ByteHamster@users.noreply.github.com>2020-07-22 17:55:04 +0200
committerGitHub <noreply@github.com>2020-07-22 17:55:04 +0200
commit03190dfa20db70a72c6accfd9176126bd68467d6 (patch)
treefbf1be4df73eba3c1af87b50c8ad12c01fc1f94e /core/src/main
parenta3a5a58ae64999a91251205517242290724e2ae2 (diff)
parent51bbf1a5f9275e1d1bb526c43b0703ae13b349b9 (diff)
downloadAntennaPod-03190dfa20db70a72c6accfd9176126bd68467d6.zip
Merge pull request #4306 from ByteHamster/mime-type-media-content
Fixed mime type in media:content
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java222
1 files changed, 113 insertions, 109 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 638383223..30b01f0bc 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
@@ -14,114 +14,118 @@ import de.danoeh.antennapod.core.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";
- 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";
-
- private static final String DESCRIPTION = "description";
- private static final String DESCRIPTION_TYPE = "type";
-
- @Override
- public SyndElement handleElementStart(String localName, HandlerState state,
- Attributes attributes) {
- if (CONTENT.equals(localName)) {
- String url = attributes.getValue(DOWNLOAD_URL);
- String type = attributes.getValue(MIME_TYPE);
- String defaultStr = attributes.getValue(DEFAULT);
- String medium = attributes.getValue(MEDIUM);
- boolean validTypeMedia = false;
- boolean validTypeImage = false;
-
- boolean isDefault = "true".equals(defaultStr);
-
- if (MEDIUM_AUDIO.equals(medium) || MEDIUM_VIDEO.equals(medium)) {
- validTypeMedia = true;
- } else if (MEDIUM_IMAGE.equals(medium)) {
- validTypeImage = true;
- } else {
- 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 && validTypeMedia) {
- long size = 0;
- String sizeStr = attributes.getValue(SIZE);
- try {
- size = Long.parseLong(sizeStr);
- } catch (NumberFormatException e) {
- Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
- }
-
- int durationMs = 0;
- String durationStr = attributes.getValue(DURATION);
- if (!TextUtils.isEmpty(durationStr)) {
- try {
- 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) {
- media.setDuration(durationMs);
- }
- state.getCurrentItem().setMedia(media);
- } else if (state.getCurrentItem() != null && url != null && validTypeImage) {
- state.getCurrentItem().setImageUrl(url);
- }
- } else if (IMAGE.equals(localName)) {
- String url = attributes.getValue(IMAGE_URL);
- if (url != null) {
- if (state.getCurrentItem() != null) {
- state.getCurrentItem().setImageUrl(url);
- } else {
- if (state.getFeed().getImageUrl() == null) {
- state.getFeed().setImageUrl(url);
- }
- }
- }
- } 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);
- }
- }
- }
+ 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";
+ 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";
+
+ private static final String DESCRIPTION = "description";
+ private static final String DESCRIPTION_TYPE = "type";
+
+ @Override
+ public SyndElement handleElementStart(String localName, HandlerState state,
+ Attributes attributes) {
+ if (CONTENT.equals(localName)) {
+ String url = attributes.getValue(DOWNLOAD_URL);
+ String type = attributes.getValue(MIME_TYPE);
+ String defaultStr = attributes.getValue(DEFAULT);
+ String medium = attributes.getValue(MEDIUM);
+ boolean validTypeMedia = false;
+ boolean validTypeImage = false;
+
+ boolean isDefault = "true".equals(defaultStr);
+
+ if (MEDIUM_AUDIO.equals(medium)) {
+ validTypeMedia = true;
+ type = "audio/*";
+ } else if (MEDIUM_VIDEO.equals(medium)) {
+ validTypeMedia = true;
+ type = "video/*";
+ } else if (MEDIUM_IMAGE.equals(medium)) {
+ validTypeImage = true;
+ type = "image/*";
+ } else {
+ 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 && validTypeMedia) {
+ long size = 0;
+ String sizeStr = attributes.getValue(SIZE);
+ try {
+ size = Long.parseLong(sizeStr);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
+ }
+
+ int durationMs = 0;
+ String durationStr = attributes.getValue(DURATION);
+ if (!TextUtils.isEmpty(durationStr)) {
+ try {
+ 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) {
+ media.setDuration(durationMs);
+ }
+ state.getCurrentItem().setMedia(media);
+ } else if (state.getCurrentItem() != null && url != null && validTypeImage) {
+ state.getCurrentItem().setImageUrl(url);
+ }
+ } else if (IMAGE.equals(localName)) {
+ String url = attributes.getValue(IMAGE_URL);
+ if (url != null) {
+ if (state.getCurrentItem() != null) {
+ state.getCurrentItem().setImageUrl(url);
+ } else {
+ if (state.getFeed().getImageUrl() == null) {
+ state.getFeed().setImageUrl(url);
+ }
+ }
+ }
+ } 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);
+ }
+ }
+ }
}