Update feed url when server returns itunes:new-feed-url (#6291)
This commit is contained in:
parent
73a6ff1f60
commit
e261514c5b
|
@ -273,8 +273,8 @@ public class DownloadService extends Service {
|
||||||
|
|
||||||
if (type == Feed.FEEDFILETYPE_FEED) {
|
if (type == Feed.FEEDFILETYPE_FEED) {
|
||||||
Log.d(TAG, "Handling completed Feed Download");
|
Log.d(TAG, "Handling completed Feed Download");
|
||||||
FeedSyncTask task = new FeedSyncTask(DownloadService.this, request);
|
FeedSyncTask feedSyncTask = new FeedSyncTask(DownloadService.this, request);
|
||||||
boolean success = task.run();
|
boolean success = feedSyncTask.run();
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
if (request.getFeedfileId() == 0) {
|
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
|
// we create a 'successful' download log if the feed's last refresh failed
|
||||||
List<DownloadStatus> log = DBReader.getFeedDownloadLog(request.getFeedfileId());
|
List<DownloadStatus> log = DBReader.getFeedDownloadLog(request.getFeedfileId());
|
||||||
if (log.size() > 0 && !log.get(0).isSuccessful()) {
|
if (log.size() > 0 && !log.get(0).isSuccessful()) {
|
||||||
saveDownloadStatus(task.getDownloadStatus());
|
saveDownloadStatus(feedSyncTask.getDownloadStatus());
|
||||||
}
|
}
|
||||||
if (!request.isInitiatedByUser()) {
|
if (!request.isInitiatedByUser()) {
|
||||||
// Was stored in the database before and not initiated manually
|
// 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) {
|
if (downloader.permanentRedirectUrl != null) {
|
||||||
DBWriter.updateFeedDownloadURL(request.getSource(), downloader.permanentRedirectUrl);
|
DBWriter.updateFeedDownloadURL(request.getSource(), downloader.permanentRedirectUrl);
|
||||||
|
} else if (feedSyncTask.getRedirectUrl() != null) {
|
||||||
|
DBWriter.updateFeedDownloadURL(request.getSource(), feedSyncTask.getRedirectUrl());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DBWriter.setFeedLastUpdateFailed(request.getFeedfileId(), true);
|
DBWriter.setFeedLastUpdateFailed(request.getFeedfileId(), true);
|
||||||
saveDownloadStatus(task.getDownloadStatus());
|
saveDownloadStatus(feedSyncTask.getDownloadStatus());
|
||||||
}
|
}
|
||||||
} else if (type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
} else if (type == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
Log.d(TAG, "Handling completed FeedMedia Download");
|
Log.d(TAG, "Handling completed FeedMedia Download");
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class FeedSyncTask {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Feed savedFeed;
|
private Feed savedFeed;
|
||||||
private final FeedParserTask task;
|
private final FeedParserTask task;
|
||||||
|
private FeedHandlerResult feedHandlerResult;
|
||||||
|
|
||||||
public FeedSyncTask(Context context, DownloadRequest request) {
|
public FeedSyncTask(Context context, DownloadRequest request) {
|
||||||
this.request = request;
|
this.request = request;
|
||||||
|
@ -22,15 +23,15 @@ public class FeedSyncTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean run() {
|
public boolean run() {
|
||||||
FeedHandlerResult result = task.call();
|
feedHandlerResult = task.call();
|
||||||
if (!task.isSuccessful()) {
|
if (!task.isSuccessful()) {
|
||||||
return false;
|
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
|
// 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 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) {
|
if (loadAllPages && feed.getNextPageLink() != null) {
|
||||||
feed.setId(savedFeed.getId());
|
feed.setId(savedFeed.getId());
|
||||||
DBTasks.loadNextPageOfFeed(context, feed, true);
|
DBTasks.loadNextPageOfFeed(context, feed, true);
|
||||||
|
@ -46,4 +47,8 @@ public class FeedSyncTask {
|
||||||
public Feed getSavedFeed() {
|
public Feed getSavedFeed() {
|
||||||
return savedFeed;
|
return savedFeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
return feedHandlerResult.redirectUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,6 @@ public class FeedHandler {
|
||||||
|
|
||||||
saxParser.parse(inputSource, handler);
|
saxParser.parse(inputSource, handler);
|
||||||
inputStreamReader.close();
|
inputStreamReader.close();
|
||||||
return new FeedHandlerResult(handler.state.feed, handler.state.alternateUrls);
|
return new FeedHandlerResult(handler.state.feed, handler.state.alternateUrls, handler.state.redirectUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,11 @@ public class FeedHandlerResult {
|
||||||
|
|
||||||
public final Feed feed;
|
public final Feed feed;
|
||||||
public final Map<String, String> alternateFeedUrls;
|
public final Map<String, String> alternateFeedUrls;
|
||||||
|
public final String redirectUrl;
|
||||||
|
|
||||||
public FeedHandlerResult(Feed feed, Map<String, String> alternateFeedUrls) {
|
public FeedHandlerResult(Feed feed, Map<String, String> alternateFeedUrls, String redirectUrl) {
|
||||||
this.feed = feed;
|
this.feed = feed;
|
||||||
this.alternateFeedUrls = alternateFeedUrls;
|
this.alternateFeedUrls = alternateFeedUrls;
|
||||||
|
this.redirectUrl = redirectUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ public class HandlerState {
|
||||||
* URL of the feed, the value is the title
|
* URL of the feed, the value is the title
|
||||||
*/
|
*/
|
||||||
public final Map<String, String> alternateUrls;
|
public final Map<String, String> alternateUrls;
|
||||||
|
public String redirectUrl = null;
|
||||||
private final ArrayList<FeedItem> items;
|
private final ArrayList<FeedItem> items;
|
||||||
private FeedItem currentItem;
|
private FeedItem currentItem;
|
||||||
private FeedFunding currentFunding;
|
private FeedFunding currentFunding;
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class Itunes extends Namespace {
|
||||||
public static final String DURATION = "duration";
|
public static final String DURATION = "duration";
|
||||||
private static final String SUBTITLE = "subtitle";
|
private static final String SUBTITLE = "subtitle";
|
||||||
private static final String SUMMARY = "summary";
|
private static final String SUMMARY = "summary";
|
||||||
|
private static final String NEW_FEED_URL = "new-feed-url";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SyndElement handleElementStart(String localName, HandlerState state,
|
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) {
|
} else if (Rss20.CHANNEL.equals(state.getSecondTag().getName()) && state.getFeed() != null) {
|
||||||
state.getFeed().setDescription(content);
|
state.getFeed().setDescription(content);
|
||||||
}
|
}
|
||||||
|
} else if (NEW_FEED_URL.equals(localName) && content.trim().startsWith("http")) {
|
||||||
|
state.redirectUrl = content.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue