Skip to content

Commit

Permalink
Implement fix for feed duplication bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
amugofjava committed Nov 7, 2024
1 parent 95a1010 commit 74bcbc2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/services/podcast/mobile_podcast_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class MobilePodcastService extends PodcastService {
podcast_search.Podcast? loadedPodcast;
var imageUrl = podcast.imageUrl;
var thumbImageUrl = podcast.thumbImageUrl;
var sourceUrl = podcast.url;

if (!refresh) {
log.fine('Not a refresh so try to fetch from cache');
Expand All @@ -169,12 +170,14 @@ class MobilePodcastService extends PodcastService {
log.fine('Loading podcast from feed $url');
loadedPodcast = await _loadPodcastFeed(url: url);
tries = 0;
} on Exception {
if (tries > 0 && url.startsWith('https')) {
// Try the http only version - flesh out to setting later on
log.fine('Failed to load podcast. Fallback to http and try again');
} catch (e) {
if (tries > 0) {
//TODO: Needs improving to only fall back if original URL was http and we forced it up to https.
if (e is podcast_search.PodcastCertificateException && url.startsWith('https')) {
log.fine('Certificate error whilst fetching podcast. Fallback to http and try again');

url = url.replaceFirst('https', 'http');
url = url.replaceFirst('https', 'http');
}
} else {
rethrow;
}
Expand All @@ -189,7 +192,7 @@ class MobilePodcastService extends PodcastService {
final copyright = _format(loadedPodcast.copyright);
final funding = <Funding>[];
final persons = <Person>[];
final existingEpisodes = await repository.findEpisodesByPodcastGuid(loadedPodcast.url!);
final existingEpisodes = await repository.findEpisodesByPodcastGuid(sourceUrl);

// If imageUrl is null we have not loaded the podcast as a result of a search.
if (imageUrl == null || imageUrl.isEmpty || refresh) {
Expand All @@ -214,8 +217,8 @@ class MobilePodcastService extends PodcastService {
}

Podcast pc = Podcast(
guid: loadedPodcast.url,
url: loadedPodcast.url!,
guid: sourceUrl,
url: sourceUrl,
link: loadedPodcast.link,
title: title,
description: description,
Expand All @@ -228,7 +231,7 @@ class MobilePodcastService extends PodcastService {
);

/// We could be following this podcast already. Let's check.
var follow = await repository.findPodcastByGuid(loadedPodcast.url!);
var follow = await repository.findPodcastByGuid(sourceUrl);

if (follow != null) {
// We are, so swap in the stored ID so we update the saved version later.
Expand Down

0 comments on commit 74bcbc2

Please sign in to comment.