From 74bcbc24e1ac1eef66b43e6fc7317cc8ff7fd506 Mon Sep 17 00:00:00 2001 From: Ben Hills Date: Thu, 7 Nov 2024 11:50:55 +0000 Subject: [PATCH] Implement fix for feed duplication bug. --- .../podcast/mobile_podcast_service.dart | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/services/podcast/mobile_podcast_service.dart b/lib/services/podcast/mobile_podcast_service.dart index bbe0b0cb..332e3b49 100644 --- a/lib/services/podcast/mobile_podcast_service.dart +++ b/lib/services/podcast/mobile_podcast_service.dart @@ -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'); @@ -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; } @@ -189,7 +192,7 @@ class MobilePodcastService extends PodcastService { final copyright = _format(loadedPodcast.copyright); final funding = []; final persons = []; - 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) { @@ -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, @@ -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.