commit
0cdc5aea47
|
@ -7,8 +7,10 @@ import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import de.danoeh.antennapod.core.feed.FeedImage;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
|
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;
|
import de.danoeh.antennapod.core.syndication.util.SyndTypeUtils;
|
||||||
|
|
||||||
/** Processes tags from the http://search.yahoo.com/mrss/ namespace. */
|
/** Processes tags from the http://search.yahoo.com/mrss/ namespace. */
|
||||||
|
@ -23,22 +25,35 @@ public class NSMedia extends Namespace {
|
||||||
private static final String SIZE = "fileSize";
|
private static final String SIZE = "fileSize";
|
||||||
private static final String MIME_TYPE = "type";
|
private static final String MIME_TYPE = "type";
|
||||||
private static final String DURATION = "duration";
|
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";
|
||||||
|
|
||||||
|
private static final String DESCRIPTION = "description";
|
||||||
|
private static final String DESCRIPTION_TYPE = "type";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SyndElement handleElementStart(String localName, HandlerState state,
|
public SyndElement handleElementStart(String localName, HandlerState state,
|
||||||
Attributes attributes) {
|
Attributes attributes) {
|
||||||
if (CONTENT.equals(localName)) {
|
if (CONTENT.equals(localName)) {
|
||||||
String url = attributes.getValue(DOWNLOAD_URL);
|
String url = attributes.getValue(DOWNLOAD_URL);
|
||||||
String type = attributes.getValue(MIME_TYPE);
|
String type = attributes.getValue(MIME_TYPE);
|
||||||
boolean validType;
|
String defaultStr = attributes.getValue(DEFAULT);
|
||||||
if(SyndTypeUtils.enclosureTypeValid(type)) {
|
boolean validType;
|
||||||
validType = true;
|
|
||||||
} else {
|
boolean isDefault = "true".equals(defaultStr);
|
||||||
type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
|
|
||||||
validType = type != null;
|
if (SyndTypeUtils.enclosureTypeValid(type)) {
|
||||||
}
|
validType = true;
|
||||||
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
|
} else {
|
||||||
url != null && validType) {
|
type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
|
||||||
|
validType = type != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.getCurrentItem() != null &&
|
||||||
|
(state.getCurrentItem().getMedia() == null || isDefault) &&
|
||||||
|
url != null && validType) {
|
||||||
long size = 0;
|
long size = 0;
|
||||||
String sizeStr = attributes.getValue(SIZE);
|
String sizeStr = attributes.getValue(SIZE);
|
||||||
try {
|
try {
|
||||||
|
@ -51,25 +66,50 @@ public class NSMedia extends Namespace {
|
||||||
String durationStr = attributes.getValue(DURATION);
|
String durationStr = attributes.getValue(DURATION);
|
||||||
if (!TextUtils.isEmpty(durationStr)) {
|
if (!TextUtils.isEmpty(durationStr)) {
|
||||||
try {
|
try {
|
||||||
long duration = Long.parseLong(durationStr);
|
long duration = Long.parseLong(durationStr);
|
||||||
durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
|
durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
|
Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
|
FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
|
||||||
if(durationMs > 0) {
|
if (durationMs > 0) {
|
||||||
media.setDuration(durationMs);
|
media.setDuration(durationMs);
|
||||||
}
|
}
|
||||||
state.getCurrentItem().setMedia(media);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (DESCRIPTION.equals(localName)) {
|
||||||
|
String type = attributes.getValue(DESCRIPTION_TYPE);
|
||||||
|
return new AtomText(localName, this, type);
|
||||||
}
|
}
|
||||||
return new SyndElement(localName, this);
|
return new SyndElement(localName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleElementEnd(String localName, HandlerState state) {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue