Merge pull request #4306 from ByteHamster/mime-type-media-content
Fixed mime type in media:content
This commit is contained in:
commit
03190dfa20
@ -2,6 +2,8 @@ package de.test.antennapod.handler;
|
|||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
import de.danoeh.antennapod.core.feed.Feed;
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
|
import de.danoeh.antennapod.core.feed.MediaType;
|
||||||
|
import de.danoeh.antennapod.core.syndication.namespace.NSMedia;
|
||||||
import de.test.antennapod.util.syndication.feedgenerator.Rss2Generator;
|
import de.test.antennapod.util.syndication.feedgenerator.Rss2Generator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xmlpull.v1.XmlSerializer;
|
import org.xmlpull.v1.XmlSerializer;
|
||||||
@ -39,4 +41,23 @@ public class RssParserTest extends FeedParserTestBase {
|
|||||||
}, "UTF-8", 0);
|
}, "UTF-8", 0);
|
||||||
assertEquals(image, f2.getImageUrl());
|
assertEquals(image, f2.getImageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMediaContentMime() throws Exception {
|
||||||
|
Feed f1 = createTestFeed(0, false);
|
||||||
|
f1.setImageUrl(null);
|
||||||
|
Feed f2 = runFeedTest(f1, new Rss2Generator() {
|
||||||
|
@Override
|
||||||
|
protected void writeAdditionalAttributes(XmlSerializer xml) throws IOException {
|
||||||
|
xml.setPrefix(NSMedia.NSTAG, NSMedia.NSURI);
|
||||||
|
xml.startTag(null, "item");
|
||||||
|
xml.startTag(NSMedia.NSURI, "content");
|
||||||
|
xml.attribute(null, "url", "https://www.example.com/file.mp4");
|
||||||
|
xml.attribute(null, "medium", "video");
|
||||||
|
xml.endTag(NSMedia.NSURI, "content");
|
||||||
|
xml.endTag(null, "item");
|
||||||
|
}
|
||||||
|
}, "UTF-8", 0);
|
||||||
|
assertEquals(MediaType.VIDEO, f2.getItems().get(0).getMedia().getMediaType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,15 @@ public class NSMedia extends Namespace {
|
|||||||
|
|
||||||
boolean isDefault = "true".equals(defaultStr);
|
boolean isDefault = "true".equals(defaultStr);
|
||||||
|
|
||||||
if (MEDIUM_AUDIO.equals(medium) || MEDIUM_VIDEO.equals(medium)) {
|
if (MEDIUM_AUDIO.equals(medium)) {
|
||||||
validTypeMedia = true;
|
validTypeMedia = true;
|
||||||
|
type = "audio/*";
|
||||||
|
} else if (MEDIUM_VIDEO.equals(medium)) {
|
||||||
|
validTypeMedia = true;
|
||||||
|
type = "video/*";
|
||||||
} else if (MEDIUM_IMAGE.equals(medium)) {
|
} else if (MEDIUM_IMAGE.equals(medium)) {
|
||||||
validTypeImage = true;
|
validTypeImage = true;
|
||||||
|
type = "image/*";
|
||||||
} else {
|
} else {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = SyndTypeUtils.getMimeTypeFromUrl(url);
|
type = SyndTypeUtils.getMimeTypeFromUrl(url);
|
||||||
@ -66,9 +71,8 @@ public class NSMedia extends Namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.getCurrentItem() != null &&
|
if (state.getCurrentItem() != null && (state.getCurrentItem().getMedia() == null || isDefault)
|
||||||
(state.getCurrentItem().getMedia() == null || isDefault) &&
|
&& url != null && validTypeMedia) {
|
||||||
url != null && validTypeMedia) {
|
|
||||||
long size = 0;
|
long size = 0;
|
||||||
String sizeStr = attributes.getValue(SIZE);
|
String sizeStr = attributes.getValue(SIZE);
|
||||||
try {
|
try {
|
||||||
@ -117,8 +121,8 @@ public class NSMedia extends Namespace {
|
|||||||
public void handleElementEnd(String localName, HandlerState state) {
|
public void handleElementEnd(String localName, HandlerState state) {
|
||||||
if (DESCRIPTION.equals(localName)) {
|
if (DESCRIPTION.equals(localName)) {
|
||||||
String content = state.getContentBuf().toString();
|
String content = state.getContentBuf().toString();
|
||||||
if (state.getCurrentItem() != null && content != null &&
|
if (state.getCurrentItem() != null && content != null
|
||||||
state.getCurrentItem().getDescription() == null) {
|
&& state.getCurrentItem().getDescription() == null) {
|
||||||
state.getCurrentItem().setDescription(content);
|
state.getCurrentItem().setDescription(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user