diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 30745a60d..a18d7d1d0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -273,8 +273,8 @@ public class DownloadService extends Service { if (type == Feed.FEEDFILETYPE_FEED) { Log.d(TAG, "Handling completed Feed Download"); - FeedSyncTask task = new FeedSyncTask(DownloadService.this, request); - boolean success = task.run(); + FeedSyncTask feedSyncTask = new FeedSyncTask(DownloadService.this, request); + boolean success = feedSyncTask.run(); if (success) { if (request.getFeedfileId() == 0) { @@ -283,18 +283,20 @@ public class DownloadService extends Service { // we create a 'successful' download log if the feed's last refresh failed List log = DBReader.getFeedDownloadLog(request.getFeedfileId()); if (log.size() > 0 && !log.get(0).isSuccessful()) { - saveDownloadStatus(task.getDownloadStatus()); + saveDownloadStatus(feedSyncTask.getDownloadStatus()); } if (!request.isInitiatedByUser()) { // Was stored in the database before and not initiated manually - newEpisodesNotification.showIfNeeded(DownloadService.this, task.getSavedFeed()); + newEpisodesNotification.showIfNeeded(DownloadService.this, feedSyncTask.getSavedFeed()); } if (downloader.permanentRedirectUrl != null) { DBWriter.updateFeedDownloadURL(request.getSource(), downloader.permanentRedirectUrl); + } else if (feedSyncTask.getRedirectUrl() != null) { + DBWriter.updateFeedDownloadURL(request.getSource(), feedSyncTask.getRedirectUrl()); } } else { DBWriter.setFeedLastUpdateFailed(request.getFeedfileId(), true); - saveDownloadStatus(task.getDownloadStatus()); + saveDownloadStatus(feedSyncTask.getDownloadStatus()); } } else if (type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { Log.d(TAG, "Handling completed FeedMedia Download"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java index 07670bff3..e3010fe24 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java @@ -14,6 +14,7 @@ public class FeedSyncTask { private final Context context; private Feed savedFeed; private final FeedParserTask task; + private FeedHandlerResult feedHandlerResult; public FeedSyncTask(Context context, DownloadRequest request) { this.request = request; @@ -22,15 +23,15 @@ public class FeedSyncTask { } public boolean run() { - FeedHandlerResult result = task.call(); + feedHandlerResult = task.call(); if (!task.isSuccessful()) { return false; } - savedFeed = DBTasks.updateFeed(context, result.feed, false); + savedFeed = DBTasks.updateFeed(context, feedHandlerResult.feed, false); // If loadAllPages=true, check if another page is available and queue it for download final boolean loadAllPages = request.getArguments().getBoolean(DownloadRequest.REQUEST_ARG_LOAD_ALL_PAGES); - final Feed feed = result.feed; + final Feed feed = feedHandlerResult.feed; if (loadAllPages && feed.getNextPageLink() != null) { feed.setId(savedFeed.getId()); DBTasks.loadNextPageOfFeed(context, feed, true); @@ -46,4 +47,8 @@ public class FeedSyncTask { public Feed getSavedFeed() { return savedFeed; } + + public String getRedirectUrl() { + return feedHandlerResult.redirectUrl; + } } diff --git a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandler.java b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandler.java index 6b364fa73..dd9cb836b 100644 --- a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandler.java +++ b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandler.java @@ -31,6 +31,6 @@ public class FeedHandler { saxParser.parse(inputSource, handler); inputStreamReader.close(); - return new FeedHandlerResult(handler.state.feed, handler.state.alternateUrls); + return new FeedHandlerResult(handler.state.feed, handler.state.alternateUrls, handler.state.redirectUrl); } } diff --git a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandlerResult.java b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandlerResult.java index 43b3387a0..6db3ca47f 100644 --- a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandlerResult.java +++ b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/FeedHandlerResult.java @@ -11,9 +11,11 @@ public class FeedHandlerResult { public final Feed feed; public final Map alternateFeedUrls; + public final String redirectUrl; - public FeedHandlerResult(Feed feed, Map alternateFeedUrls) { + public FeedHandlerResult(Feed feed, Map alternateFeedUrls, String redirectUrl) { this.feed = feed; this.alternateFeedUrls = alternateFeedUrls; + this.redirectUrl = redirectUrl; } } diff --git a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/HandlerState.java b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/HandlerState.java index 706a328e8..650931fc1 100644 --- a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/HandlerState.java +++ b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/HandlerState.java @@ -26,6 +26,7 @@ public class HandlerState { * URL of the feed, the value is the title */ public final Map alternateUrls; + public String redirectUrl = null; private final ArrayList items; private FeedItem currentItem; private FeedFunding currentFunding; diff --git a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Itunes.java b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Itunes.java index 9c57d4ef3..cb4bcb8a7 100644 --- a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Itunes.java +++ b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Itunes.java @@ -23,6 +23,7 @@ public class Itunes extends Namespace { public static final String DURATION = "duration"; private static final String SUBTITLE = "subtitle"; private static final String SUMMARY = "summary"; + private static final String NEW_FEED_URL = "new-feed-url"; @Override public SyndElement handleElementStart(String localName, HandlerState state, @@ -76,6 +77,8 @@ public class Itunes extends Namespace { } else if (Rss20.CHANNEL.equals(state.getSecondTag().getName()) && state.getFeed() != null) { state.getFeed().setDescription(content); } + } else if (NEW_FEED_URL.equals(localName) && content.trim().startsWith("http")) { + state.redirectUrl = content.trim(); } } }