Print log

This commit is contained in:
Martin Fietz 2016-03-08 09:47:04 +01:00
parent 5e7b328d83
commit d0126b54f1
7 changed files with 84 additions and 97 deletions

View File

@ -328,6 +328,7 @@ public class OnlineFeedViewActivity extends ActionBarActivity {
subscriber.onError(e); subscriber.onError(e);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
subscriber.onError(e); subscriber.onError(e);
} finally { } finally {
boolean rc = new File(feed.getFile_url()).delete(); boolean rc = new File(feed.getFile_url()).delete();

View File

@ -2,8 +2,6 @@ package de.danoeh.antennapod.core.syndication.namespace;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import java.util.Stack;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.syndication.handler.HandlerState; import de.danoeh.antennapod.core.syndication.handler.HandlerState;
import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.DateUtils;
@ -24,14 +22,10 @@ public class NSDublinCore extends Namespace {
@Override @Override
public void handleElementEnd(String localName, HandlerState state) { public void handleElementEnd(String localName, HandlerState state) {
if (state.getCurrentItem() != null && state.getTagstack().size() >= 2 && if (state.getCurrentItem() != null && state.getContentBuf() != null &&
state.getContentBuf() != null) { state.getTagstack() != null && state.getTagstack().size() >= 2) {
FeedItem currentItem = state.getCurrentItem(); FeedItem currentItem = state.getCurrentItem();
Stack<SyndElement> tagStack = state.getTagstack(); String top = state.getTagstack().peek().getName();
if(tagStack.size() < 2) {
return;
}
String top = tagStack.peek().getName();
String second = state.getSecondTag().getName(); String second = state.getSecondTag().getName();
if (DATE.equals(top) && ITEM.equals(second)) { if (DATE.equals(top) && ITEM.equals(second)) {
String content = state.getContentBuf().toString(); String content = state.getContentBuf().toString();
@ -39,4 +33,5 @@ public class NSDublinCore extends Namespace {
} }
} }
} }
} }

View File

@ -52,18 +52,15 @@ public class NSITunes extends Namespace {
@Override @Override
public void handleElementEnd(String localName, HandlerState state) { public void handleElementEnd(String localName, HandlerState state) {
if(state.getContentBuf() == null) {
return;
}
if (AUTHOR.equals(localName)) { if (AUTHOR.equals(localName)) {
if (state.getContentBuf() != null && state.getFeed() != null) { if (state.getFeed() != null) {
String author = state.getContentBuf().toString(); String author = state.getContentBuf().toString();
if(TextUtils.isEmpty(author)) {
return;
}
state.getFeed().setAuthor(author); state.getFeed().setAuthor(author);
} }
} else if (DURATION.equals(localName)) { } else if (DURATION.equals(localName)) {
if (state.getContentBuf() == null) {
return;
}
String duration = state.getContentBuf().toString(); String duration = state.getContentBuf().toString();
if(TextUtils.isEmpty(duration)) { if(TextUtils.isEmpty(duration)) {
return; return;
@ -86,9 +83,6 @@ public class NSITunes extends Namespace {
Log.e(NSTAG, Log.getStackTraceString(e)); Log.e(NSTAG, Log.getStackTraceString(e));
} }
} else if (SUBTITLE.equals(localName)) { } else if (SUBTITLE.equals(localName)) {
if (state.getContentBuf() == null) {
return;
}
String subtitle = state.getContentBuf().toString(); String subtitle = state.getContentBuf().toString();
if (TextUtils.isEmpty(subtitle)) { if (TextUtils.isEmpty(subtitle)) {
return; return;
@ -103,9 +97,6 @@ public class NSITunes extends Namespace {
} }
} }
} else if (SUMMARY.equals(localName)) { } else if (SUMMARY.equals(localName)) {
if (state.getContentBuf() == null) {
return;
}
String summary = state.getContentBuf().toString(); String summary = state.getContentBuf().toString();
if (TextUtils.isEmpty(summary)) { if (TextUtils.isEmpty(summary)) {
return; return;

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.syndication.namespace; package de.danoeh.antennapod.core.syndication.namespace;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -29,11 +30,15 @@ public class NSMedia extends Namespace {
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);
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null boolean validType;
&& url != null if(SyndTypeUtils.enclosureTypeValid(type)) {
&& (SyndTypeUtils.enclosureTypeValid(type) || ((type = SyndTypeUtils validType = true;
.getValidMimeTypeFromUrl(url)) != null))) { } else {
type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
validType = type != null;
}
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
url != null && validType) {
long size = 0; long size = 0;
try { try {
size = Long.parseLong(attributes.getValue(SIZE)); size = Long.parseLong(attributes.getValue(SIZE));
@ -41,19 +46,19 @@ public class NSMedia extends Namespace {
Log.e(TAG, "Length attribute could not be parsed."); Log.e(TAG, "Length attribute could not be parsed.");
} }
int duration = 0; int durationMs = 0;
String durationStr = attributes.getValue(DURATION); String durationStr = attributes.getValue(DURATION);
if (durationStr != null) { if (!TextUtils.isEmpty(durationStr)) {
try { try {
duration = (int) TimeUnit.MILLISECONDS.convert( long duration = Long.parseLong(durationStr);
Long.parseLong(durationStr), TimeUnit.SECONDS); durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "Duration attribute could not be parsed"); Log.e(TAG, "Duration attribute could not be parsed");
} }
} }
FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type); FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
if(duration > 0) { if(durationMs > 0) {
media.setDuration(duration); media.setDuration(durationMs);
} }
state.getCurrentItem().setMedia(media); state.getCurrentItem().setMedia(media);
} }

View File

@ -51,10 +51,15 @@ public class NSRSS20 extends Namespace {
} else if (ENCLOSURE.equals(localName)) { } else if (ENCLOSURE.equals(localName)) {
String type = attributes.getValue(ENC_TYPE); String type = attributes.getValue(ENC_TYPE);
String url = attributes.getValue(ENC_URL); String url = attributes.getValue(ENC_URL);
boolean validType;
if(SyndTypeUtils.enclosureTypeValid(type)) {
validType = true;
} else {
type = type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
validType = type != null;
}
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
(SyndTypeUtils.enclosureTypeValid(type) || ((type = SyndTypeUtils validType) {
.getValidMimeTypeFromUrl(url)) != null))) {
long size = 0; long size = 0;
try { try {
size = Long.parseLong(attributes.getValue(ENC_LEN)); size = Long.parseLong(attributes.getValue(ENC_LEN));
@ -115,7 +120,6 @@ public class NSRSS20 extends Namespace {
if (state.getTagstack().size() >= 3) { if (state.getTagstack().size() >= 3) {
third = state.getThirdTag().getName(); third = state.getThirdTag().getName();
} }
if (GUID.equals(top) && ITEM.equals(second)) { if (GUID.equals(top) && ITEM.equals(second)) {
// some feed creators include an empty or non-standard guid-element in their feed, which should be ignored // some feed creators include an empty or non-standard guid-element in their feed, which should be ignored
if (!TextUtils.isEmpty(content) && state.getCurrentItem() != null) { if (!TextUtils.isEmpty(content) && state.getCurrentItem() != null) {
@ -127,7 +131,7 @@ public class NSRSS20 extends Namespace {
state.getCurrentItem().setTitle(title); state.getCurrentItem().setTitle(title);
} else if (CHANNEL.equals(second) && state.getFeed() != null) { } else if (CHANNEL.equals(second) && state.getFeed() != null) {
state.getFeed().setTitle(title); state.getFeed().setTitle(title);
} else if (IMAGE.equals(second) && third != null && CHANNEL.equals(third)) { } else if (IMAGE.equals(second) && CHANNEL.equals(third)) {
if(state.getFeed() != null && state.getFeed().getImage() != null && if(state.getFeed() != null && state.getFeed().getImage() != null &&
state.getFeed().getImage().getTitle() == null) { state.getFeed().getImage().getTitle() == null) {
state.getFeed().getImage().setTitle(title); state.getFeed().getImage().setTitle(title);
@ -141,8 +145,7 @@ public class NSRSS20 extends Namespace {
} }
} else if (PUBDATE.equals(top) && ITEM.equals(second) && state.getCurrentItem() != null) { } else if (PUBDATE.equals(top) && ITEM.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content)); state.getCurrentItem().setPubDate(DateUtils.parse(content));
} else if (URL.equals(top) && IMAGE.equals(second) && third != null } else if (URL.equals(top) && IMAGE.equals(second) && CHANNEL.equals(third)) {
&& CHANNEL.equals(third)) {
// prefer itunes:image // prefer itunes:image
if(state.getFeed() != null && state.getFeed().getImage() != null && if(state.getFeed() != null && state.getFeed().getImage() != null &&
state.getFeed().getImage().getDownload_url() == null) { state.getFeed().getImage().getDownload_url() == null) {

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.syndication.namespace.atom; package de.danoeh.antennapod.core.syndication.namespace.atom;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -65,21 +66,21 @@ public class NSAtom extends Namespace {
@Override @Override
public SyndElement handleElementStart(String localName, HandlerState state, public SyndElement handleElementStart(String localName, HandlerState state,
Attributes attributes) { Attributes attributes) {
if (localName.equals(ENTRY)) { if (ENTRY.equals(localName)) {
state.setCurrentItem(new FeedItem()); state.setCurrentItem(new FeedItem());
state.getItems().add(state.getCurrentItem()); state.getItems().add(state.getCurrentItem());
state.getCurrentItem().setFeed(state.getFeed()); state.getCurrentItem().setFeed(state.getFeed());
} else if (localName.matches(isText)) { } else if (localName.matches(isText)) {
String type = attributes.getValue(TEXT_TYPE); String type = attributes.getValue(TEXT_TYPE);
return new AtomText(localName, this, type); return new AtomText(localName, this, type);
} else if (localName.equals(LINK)) { } else if (LINK.equals(localName)) {
String href = attributes.getValue(LINK_HREF); String href = attributes.getValue(LINK_HREF);
String rel = attributes.getValue(LINK_REL); String rel = attributes.getValue(LINK_REL);
SyndElement parent = state.getTagstack().peek(); SyndElement parent = state.getTagstack().peek();
if (parent.getName().matches(isFeedItem)) { if (parent.getName().matches(isFeedItem)) {
if (rel == null || rel.equals(LINK_REL_ALTERNATE)) { if (LINK_REL_ALTERNATE.equals(rel)) {
state.getCurrentItem().setLink(href); state.getCurrentItem().setLink(href);
} else if (rel.equals(LINK_REL_ENCLOSURE)) { } else if (LINK_REL_ENCLOSURE.equals(rel)) {
String strSize = attributes.getValue(LINK_LENGTH); String strSize = attributes.getValue(LINK_LENGTH);
long size = 0; long size = 0;
try { try {
@ -90,40 +91,45 @@ public class NSAtom extends Namespace {
Log.d(TAG, "Length attribute could not be parsed."); Log.d(TAG, "Length attribute could not be parsed.");
} }
String type = attributes.getValue(LINK_TYPE); String type = attributes.getValue(LINK_TYPE);
if (SyndTypeUtils.enclosureTypeValid(type) boolean validType;
|| (type = SyndTypeUtils.getValidMimeTypeFromUrl(href)) != null) { if(SyndTypeUtils.enclosureTypeValid(type)) {
validType = true;
} else {
type = SyndTypeUtils.getValidMimeTypeFromUrl(href);
validType = type != null;
}
if (validType) {
FeedItem currItem = state.getCurrentItem(); FeedItem currItem = state.getCurrentItem();
if(!currItem.hasMedia()) { if(currItem != null && !currItem.hasMedia()) {
currItem.setMedia(new FeedMedia(currItem, href, size, type)); currItem.setMedia(new FeedMedia(currItem, href, size, type));
} }
} }
} else if (rel.equals(LINK_REL_PAYMENT)) { } else if (LINK_REL_PAYMENT.equals(rel)) {
state.getCurrentItem().setPaymentLink(href); state.getCurrentItem().setPaymentLink(href);
} }
} else if (parent.getName().matches(isFeed)) { } else if (parent.getName().matches(isFeed)) {
if (rel == null || rel.equals(LINK_REL_ALTERNATE)) { if (LINK_REL_ALTERNATE.equals(rel)) {
String type = attributes.getValue(LINK_TYPE); String type = attributes.getValue(LINK_TYPE);
/* /*
* Use as link if a) no type-attribute is given and * Use as link if a) no type-attribute is given and
* feed-object has no link yet b) type of link is * feed-object has no link yet b) type of link is
* LINK_TYPE_HTML or LINK_TYPE_XHTML * LINK_TYPE_HTML or LINK_TYPE_XHTML
*/ */
if ((type == null && state.getFeed().getLink() == null) if (state.getFeed() != null &&
|| (type != null && (type.equals(LINK_TYPE_HTML) ((type == null && state.getFeed().getLink() == null) ||
|| type.equals(LINK_TYPE_XHTML)))) { (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)))) {
state.getFeed().setLink(href); state.getFeed().setLink(href);
} else if (type != null && (type.equals(LINK_TYPE_ATOM) } else if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
|| type.equals(LINK_TYPE_RSS))) {
// treat as podlove alternate feed // treat as podlove alternate feed
String title = attributes.getValue(LINK_TITLE); String title = attributes.getValue(LINK_TITLE);
if (title == null) { if (TextUtils.isEmpty(title)) {
title = href; title = href;
} }
state.addAlternateFeedUrl(title, href); state.addAlternateFeedUrl(title, href);
} }
} else if (rel.equals(LINK_REL_PAYMENT)) { } else if (LINK_REL_PAYMENT.equals(rel) && state.getFeed() != null) {
state.getFeed().setPaymentLink(href); state.getFeed().setPaymentLink(href);
} else if (rel.equals(LINK_REL_NEXT)) { } else if (LINK_REL_NEXT.equals(rel) && state.getFeed() != null) {
state.getFeed().setPaged(true); state.getFeed().setPaged(true);
state.getFeed().setNextPageLink(href); state.getFeed().setNextPageLink(href);
} }
@ -134,11 +140,13 @@ public class NSAtom extends Namespace {
@Override @Override
public void handleElementEnd(String localName, HandlerState state) { public void handleElementEnd(String localName, HandlerState state) {
if (localName.equals(ENTRY)) { if (ENTRY.equals(localName)) {
if (state.getCurrentItem() != null && if (state.getCurrentItem() != null &&
state.getTempObjects().containsKey(NSITunes.DURATION)) { state.getTempObjects().containsKey(NSITunes.DURATION)) {
if (state.getCurrentItem().hasMedia()) { FeedItem currentItem = state.getCurrentItem();
state.getCurrentItem().getMedia().setDuration((Integer) state.getTempObjects().get(NSITunes.DURATION)); if (currentItem.hasMedia()) {
Integer duration = (Integer) state.getTempObjects().get(NSITunes.DURATION);
currentItem.getMedia().setDuration(duration);
} }
state.getTempObjects().remove(NSITunes.DURATION); state.getTempObjects().remove(NSITunes.DURATION);
} }
@ -163,47 +171,32 @@ public class NSAtom extends Namespace {
textElement.setContent(content); textElement.setContent(content);
} }
if (top.equals(ID)) { if (ID.equals(top)) {
if (second.equals(FEED)) { if (FEED.equals(second) && state.getFeed() != null) {
state.getFeed().setFeedIdentifier(content); state.getFeed().setFeedIdentifier(content);
} else if (second.equals(ENTRY)) { } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setItemIdentifier(content); state.getCurrentItem().setItemIdentifier(content);
} }
} else if (top.equals(TITLE)) { } else if (TITLE.equals(top) && textElement != null) {
if (FEED.equals(second) && state.getFeed() != null) {
if (second.equals(FEED)) {
state.getFeed().setTitle(textElement.getProcessedContent()); state.getFeed().setTitle(textElement.getProcessedContent());
} else if (second.equals(ENTRY)) { } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setTitle( state.getCurrentItem().setTitle(textElement.getProcessedContent());
textElement.getProcessedContent());
}
} else if (top.equals(SUBTITLE)) {
if (second.equals(FEED)) {
state.getFeed().setDescription(
textElement.getProcessedContent());
}
} else if (top.equals(CONTENT)) {
if (second.equals(ENTRY)) {
state.getCurrentItem().setDescription(
textElement.getProcessedContent());
}
} else if (top.equals(UPDATED)) {
if (second.equals(ENTRY)
&& state.getCurrentItem().getPubDate() == null) {
state.getCurrentItem().setPubDate(
DateUtils.parse(content));
}
} else if (top.equals(PUBLISHED)) {
if (second.equals(ENTRY)) {
state.getCurrentItem().setPubDate(
DateUtils.parse(content));
}
} else if (top.equals(IMAGE)) {
if(state.getFeed().getImage() == null) {
state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
} }
} else if (SUBTITLE.equals(top) && FEED.equals(second) && textElement != null &&
state.getFeed() != null) {
state.getFeed().setDescription(textElement.getProcessedContent());
} else if (CONTENT.equals(top) && ENTRY.equals(second) && textElement != null &&
state.getCurrentItem() != null) {
state.getCurrentItem().setDescription(textElement.getProcessedContent());
} else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null &&
state.getCurrentItem().getPubDate() == null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
} else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
} else if (IMAGE.equals(top) && state.getFeed() != null && state.getFeed().getImage() == null) {
state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
} }
} }
} }

View File

@ -30,8 +30,7 @@ public class SyndTypeUtils {
if (url != null) { if (url != null) {
String extension = FilenameUtils.getExtension(url); String extension = FilenameUtils.getExtension(url);
if (extension != null) { if (extension != null) {
String type = MimeTypeMap.getSingleton() String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
.getMimeTypeFromExtension(extension);
if (type != null && enclosureTypeValid(type)) { if (type != null && enclosureTypeValid(type)) {
return type; return type;
} }