summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java45
-rw-r--r--app/src/main/java/de/danoeh/antennapod/discovery/ItunesPodcastSearcher.java10
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/FeedUrlNotFoundException.java26
-rw-r--r--core/src/main/res/values/strings.xml1
4 files changed, 79 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()));
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedUrlNotFoundException.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedUrlNotFoundException.java
new file mode 100644
index 000000000..93b7e5d84
--- /dev/null
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedUrlNotFoundException.java
@@ -0,0 +1,26 @@
+package de.danoeh.antennapod.core.feed;
+
+import java.io.IOException;
+
+public class FeedUrlNotFoundException extends IOException {
+ private final String artistName;
+ private final String trackName;
+
+ public FeedUrlNotFoundException(String url, String trackName) {
+ this.artistName = url;
+ this.trackName = trackName;
+ }
+
+ public String getArtistName() {
+ return artistName;
+ }
+
+ public String getTrackName() {
+ return trackName;
+ }
+
+ @Override
+ public String getMessage() {
+ return "Result does not specify a feed url";
+ }
+} \ No newline at end of file
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 5ed065793..dc3f390da 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -282,6 +282,7 @@
<string name="download_type_media">Media file</string>
<string name="download_request_error_dialog_message_prefix">An error occurred when trying to download the file:\u0020</string>
<string name="null_value_podcast_error">No podcast was provided that could be shown.</string>
+ <string name="no_feed_url_podcast_found_by_search">The suggested podcast did not have an RSS link, AntennaPod found a podcast that could match</string>
<string name="authentication_notification_title">Authentication required</string>
<string name="authentication_notification_msg">The resource you requested requires a username and a password</string>
<string name="confirm_mobile_download_dialog_title">Confirm Mobile Download</string>