diff options
author | agibault <gibault.anthony@icloud.com> | 2022-01-04 11:46:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-04 11:46:27 +0100 |
commit | 92759d8d0519baa9d2bdc1acc08b02cc7a23afa8 (patch) | |
tree | 71c17eafeee8e86f6f04c419e7934ccda38ae6b6 /app/src/main | |
parent | 6154c8a282ce4b83654bf130ad506948fd2f2fc7 (diff) | |
download | AntennaPod-92759d8d0519baa9d2bdc1acc08b02cc7a23afa8.zip |
Try to get missing feed url from discover with a search (#5620)
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java | 45 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/discovery/ItunesPodcastSearcher.java | 10 |
2 files changed, 52 insertions, 3 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 9148a9949..9108940ea 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -27,10 +27,15 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NavUtils; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; +import com.google.android.material.snackbar.Snackbar; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter; import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.core.event.DownloadEvent; +import de.danoeh.antennapod.core.feed.FeedUrlNotFoundException; +import de.danoeh.antennapod.discovery.CombinedSearcher; +import de.danoeh.antennapod.discovery.PodcastSearchResult; import de.danoeh.antennapod.event.FeedListUpdateEvent; import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.core.glide.ApGlideSettings; @@ -105,6 +110,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private boolean isPaused; private boolean didPressSubscribe = false; + private boolean isFeedFoundBySearch = false; private Dialog dialog; @@ -246,11 +252,42 @@ public class OnlineFeedViewActivity extends AppCompatActivity { .observeOn(Schedulers.io()) .subscribe(this::startFeedDownload, error -> { - showNoPodcastFoundError(); - Log.e(TAG, Log.getStackTraceString(error)); + if (error instanceof FeedUrlNotFoundException) { + tryToRetrieveFeedUrlBySearch((FeedUrlNotFoundException) error); + } else { + showNoPodcastFoundError(); + Log.e(TAG, Log.getStackTraceString(error)); + } }); } + private void tryToRetrieveFeedUrlBySearch(FeedUrlNotFoundException error) { + Log.d(TAG, "Unable to retrieve feed url, trying to retrieve feed url from search"); + String url = searchFeedUrlByTrackName(error.getTrackName(), error.getArtistName()); + if (url != null) { + Log.d(TAG, "Successfully retrieve feed url"); + isFeedFoundBySearch = true; + startFeedDownload(url); + } else { + showNoPodcastFoundError(); + Log.d(TAG, "Failed to retrieve feed url"); + } + } + + private String searchFeedUrlByTrackName(String trackName, String artistName) { + CombinedSearcher searcher = new CombinedSearcher(); + String query = trackName + " " + artistName; + List<PodcastSearchResult> results = searcher.search(query).blockingGet(); + for (PodcastSearchResult result : results) { + if (result.feedUrl != null && result.author != null + && result.author.equalsIgnoreCase(artistName) && result.title.equalsIgnoreCase(trackName)) { + return result.feedUrl; + + } + } + return null; + } + private void startFeedDownload(String url) { Log.d(TAG, "Starting feed download"); url = URLChecker.prepareURL(url); @@ -381,6 +418,10 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private void showFeedInformation(final Feed feed, Map<String, String> alternateFeedUrls) { viewBinding.progressBar.setVisibility(View.GONE); viewBinding.feedDisplayContainer.setVisibility(View.VISIBLE); + if (isFeedFoundBySearch) { + int resId = R.string.no_feed_url_podcast_found_by_search; + Snackbar.make(findViewById(android.R.id.content), resId, Snackbar.LENGTH_LONG).show(); + } this.feed = feed; this.selectedDownloadUrl = feed.getDownload_url(); diff --git a/app/src/main/java/de/danoeh/antennapod/discovery/ItunesPodcastSearcher.java b/app/src/main/java/de/danoeh/antennapod/discovery/ItunesPodcastSearcher.java index 5f3dd5f61..81ce77ef8 100644 --- a/app/src/main/java/de/danoeh/antennapod/discovery/ItunesPodcastSearcher.java +++ b/app/src/main/java/de/danoeh/antennapod/discovery/ItunesPodcastSearcher.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.discovery; +import de.danoeh.antennapod.core.feed.FeedUrlNotFoundException; import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; @@ -85,7 +86,14 @@ public class ItunesPodcastSearcher implements PodcastSearcher { String resultString = response.body().string(); JSONObject result = new JSONObject(resultString); JSONObject results = result.getJSONArray("results").getJSONObject(0); - String feedUrl = results.getString("feedUrl"); + String feedUrlName = "feedUrl"; + if (!results.has(feedUrlName)) { + String artistName = results.getString("artistName"); + String trackName = results.getString("trackName"); + emitter.onError(new FeedUrlNotFoundException(artistName, trackName)); + return; + } + String feedUrl = results.getString(feedUrlName); emitter.onSuccess(feedUrl); } else { emitter.onError(new IOException(response.toString())); |