Skip to content

Commit

Permalink
Detect re-posted episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalmage committed Dec 4, 2023
1 parent 2e76dc8 commit 4ac08c7
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java
Expand Up @@ -253,27 +253,37 @@ public static synchronized Feed updateFeed(Context context, Feed newFeed, boolea
}

FeedItem oldItem = searchFeedItemByIdentifyingValue(savedFeed.getItems(), item);
if (!newFeed.isLocalFeed() && oldItem == null) {
oldItem = searchFeedItemGuessDuplicate(savedFeed.getItems(), item);
if (!newFeed.isLocalFeed()) {
if (oldItem != null) {
Log.d(TAG, "Repaired duplicate: " + oldItem + ", " + item);
DBWriter.addDownloadStatus(new DownloadResult(savedFeed,
item.getTitle(), DownloadError.ERROR_PARSER_EXCEPTION_DUPLICATE, false,
"The podcast host changed the ID of an existing episode instead of just "
+ "updating the episode itself. AntennaPod still refreshed the feed and "
+ "attempted to repair it."
+ "\n\nOriginal episode:\n" + duplicateEpisodeDetails(oldItem)
+ "\n\nNow the feed contains:\n" + duplicateEpisodeDetails(item)));
oldItem.setItemIdentifier(item.getItemIdentifier());

if (oldItem.isPlayed() && oldItem.getMedia() != null) {
EpisodeAction action = new EpisodeAction.Builder(oldItem, EpisodeAction.PLAY)
.currentTimestamp()
.started(oldItem.getMedia().getDuration() / 1000)
.position(oldItem.getMedia().getDuration() / 1000)
.total(oldItem.getMedia().getDuration() / 1000)
.build();
SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, action);
// Detect case where a feed item is re-posted to the feed with
// an identical guid but a new timestamp.
Date oldItemPubDate = oldItem.getPubDate();
if (oldItemPubDate.before(item.getPubDate())) {
Log.d(TAG, "Detected re-posted episode: " + item.getTitle());
oldItem = null;
}
} else {
oldItem = searchFeedItemGuessDuplicate(savedFeed.getItems(), item);
if (oldItem != null) {
Log.d(TAG, "Repaired duplicate: " + oldItem + ", " + item);
DBWriter.addDownloadStatus(new DownloadResult(savedFeed,
item.getTitle(), DownloadError.ERROR_PARSER_EXCEPTION_DUPLICATE, false,
"The podcast host changed the ID of an existing episode instead of just "
+ "updating the episode itself. AntennaPod still refreshed the feed and "
+ "attempted to repair it."
+ "\n\nOriginal episode:\n" + duplicateEpisodeDetails(oldItem)
+ "\n\nNow the feed contains:\n" + duplicateEpisodeDetails(item)));
oldItem.setItemIdentifier(item.getItemIdentifier());

if (oldItem.isPlayed() && oldItem.getMedia() != null) {
EpisodeAction action = new EpisodeAction.Builder(oldItem, EpisodeAction.PLAY)
.currentTimestamp()
.started(oldItem.getMedia().getDuration() / 1000)
.position(oldItem.getMedia().getDuration() / 1000)
.total(oldItem.getMedia().getDuration() / 1000)
.build();
SynchronizationQueueSink.enqueueEpisodeActionIfSynchronizationIsActive(context, action);
}
}
}
}
Expand Down

0 comments on commit 4ac08c7

Please sign in to comment.