summaryrefslogtreecommitdiff
path: root/core/src/main/java/de
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2020-08-15 19:48:23 +0200
committerByteHamster <info@bytehamster.com>2020-08-15 19:48:23 +0200
commitd8674e8050fd98961f7eaa9fa844eb03d8bbfb48 (patch)
tree14c3cf71186072ce6383610d2a07c57988af01ee /core/src/main/java/de
parent5a4cb23877c4d7a33b578ab8b726774586c7c851 (diff)
parent06315821d52d6b66d4c3c0adeac16ee627bfe782 (diff)
downloadAntennaPod-d8674e8050fd98961f7eaa9fa844eb03d8bbfb48.zip
Merge branch 'master' into develop
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/ProviderInstallerInterceptor.java18
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java4
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java2
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java5
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/handler/UnsupportedFeedtypeException.java3
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java222
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java4
7 files changed, 139 insertions, 119 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/ProviderInstallerInterceptor.java b/core/src/main/java/de/danoeh/antennapod/core/service/ProviderInstallerInterceptor.java
new file mode 100644
index 000000000..4fa1fc3d7
--- /dev/null
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/ProviderInstallerInterceptor.java
@@ -0,0 +1,18 @@
+package de.danoeh.antennapod.core.service;
+
+import androidx.annotation.NonNull;
+import okhttp3.Interceptor;
+import okhttp3.Response;
+
+import java.io.IOException;
+
+public class ProviderInstallerInterceptor implements Interceptor {
+ public static Runnable installer = () -> { };
+
+ @Override
+ @NonNull
+ public Response intercept(Chain chain) throws IOException {
+ installer.run();
+ return chain.proceed(chain.request());
+ }
+}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java b/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java
index 5fcf8317d..3676347f7 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java
@@ -7,10 +7,6 @@ import okhttp3.Response;
import java.io.IOException;
public class UserAgentInterceptor implements Interceptor {
-
- public UserAgentInterceptor() {
- }
-
@Override
public Response intercept(Chain chain) throws IOException {
return chain.proceed(chain.request().newBuilder()
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
index 889018c45..9d0b3c5ad 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java
@@ -32,6 +32,7 @@ import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import de.danoeh.antennapod.core.preferences.UserPreferences;
+import de.danoeh.antennapod.core.service.ProviderInstallerInterceptor;
import de.danoeh.antennapod.core.service.UserAgentInterceptor;
import de.danoeh.antennapod.core.storage.DBWriter;
import okhttp3.Cache;
@@ -116,6 +117,7 @@ public class AntennapodHttpClient {
}
return response;
});
+ builder.interceptors().add(new ProviderInstallerInterceptor());
builder.interceptors().add(new BasicAuthorizationInterceptor());
builder.networkInterceptors().add(new UserAgentInterceptor());
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
index ba7019fd9..e44aa716a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java
@@ -479,12 +479,9 @@ public class DownloadService extends Service {
}
handler.post(() -> {
downloads.add(downloader);
+ downloadExecutor.submit(downloader);
postDownloaders();
});
- // Needs to be done after postDownloaders() because otherwise,
- // it might take long before the progress bar circle starts spinning
- ClientConfig.installSslProvider(this);
- handler.post(() -> downloadExecutor.submit(downloader));
}
handler.post(this::queryDownloads);
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/handler/UnsupportedFeedtypeException.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/handler/UnsupportedFeedtypeException.java
index c9f9f19c8..11588967a 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/handler/UnsupportedFeedtypeException.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/handler/UnsupportedFeedtypeException.java
@@ -36,6 +36,9 @@ public class UnsupportedFeedtypeException extends Exception {
if (message != null) {
return message;
} else if (type == TypeGetter.Type.INVALID) {
+ if ("html".equals(rootElement)) {
+ return "The server returned a website, not a podcast feed";
+ }
return "Invalid type";
} else {
return "Type " + type + " not supported";
diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java
index 638383223..30b01f0bc 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSMedia.java
@@ -14,114 +14,118 @@ import de.danoeh.antennapod.core.syndication.util.SyndTypeUtils;
/** Processes tags from the http://search.yahoo.com/mrss/ namespace. */
public class NSMedia extends Namespace {
- private static final String TAG = "NSMedia";
-
- public static final String NSTAG = "media";
- public static final String NSURI = "http://search.yahoo.com/mrss/";
-
- private static final String CONTENT = "content";
- private static final String DOWNLOAD_URL = "url";
- private static final String SIZE = "fileSize";
- private static final String MIME_TYPE = "type";
- private static final String DURATION = "duration";
- private static final String DEFAULT = "isDefault";
- private static final String MEDIUM = "medium";
-
- private static final String MEDIUM_IMAGE = "image";
- private static final String MEDIUM_AUDIO = "audio";
- private static final String MEDIUM_VIDEO = "video";
-
- private static final String IMAGE = "thumbnail";
- private static final String IMAGE_URL = "url";
-
- private static final String DESCRIPTION = "description";
- private static final String DESCRIPTION_TYPE = "type";
-
- @Override
- public SyndElement handleElementStart(String localName, HandlerState state,
- Attributes attributes) {
- if (CONTENT.equals(localName)) {
- String url = attributes.getValue(DOWNLOAD_URL);
- String type = attributes.getValue(MIME_TYPE);
- String defaultStr = attributes.getValue(DEFAULT);
- String medium = attributes.getValue(MEDIUM);
- boolean validTypeMedia = false;
- boolean validTypeImage = false;
-
- boolean isDefault = "true".equals(defaultStr);
-
- if (MEDIUM_AUDIO.equals(medium) || MEDIUM_VIDEO.equals(medium)) {
- validTypeMedia = true;
- } else if (MEDIUM_IMAGE.equals(medium)) {
- validTypeImage = true;
- } else {
- if (type == null) {
- type = SyndTypeUtils.getMimeTypeFromUrl(url);
- }
-
- if (SyndTypeUtils.enclosureTypeValid(type)) {
- validTypeMedia = true;
- } else if (SyndTypeUtils.imageTypeValid(type)) {
- validTypeImage = true;
- }
- }
-
- if (state.getCurrentItem() != null &&
- (state.getCurrentItem().getMedia() == null || isDefault) &&
- url != null && validTypeMedia) {
- long size = 0;
- String sizeStr = attributes.getValue(SIZE);
- try {
- size = Long.parseLong(sizeStr);
- } catch (NumberFormatException e) {
- Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
- }
-
- int durationMs = 0;
- String durationStr = attributes.getValue(DURATION);
- if (!TextUtils.isEmpty(durationStr)) {
- try {
- long duration = Long.parseLong(durationStr);
- durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
- } catch (NumberFormatException e) {
- Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
- }
- }
- FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
- if (durationMs > 0) {
- media.setDuration(durationMs);
- }
- state.getCurrentItem().setMedia(media);
- } else if (state.getCurrentItem() != null && url != null && validTypeImage) {
- state.getCurrentItem().setImageUrl(url);
- }
- } else if (IMAGE.equals(localName)) {
- String url = attributes.getValue(IMAGE_URL);
- if (url != null) {
- if (state.getCurrentItem() != null) {
- state.getCurrentItem().setImageUrl(url);
- } else {
- if (state.getFeed().getImageUrl() == null) {
- state.getFeed().setImageUrl(url);
- }
- }
- }
- } else if (DESCRIPTION.equals(localName)) {
- String type = attributes.getValue(DESCRIPTION_TYPE);
- return new AtomText(localName, this, type);
- }
- return new SyndElement(localName, this);
- }
-
- @Override
- public void handleElementEnd(String localName, HandlerState state) {
- if (DESCRIPTION.equals(localName)) {
- String content = state.getContentBuf().toString();
- if (state.getCurrentItem() != null && content != null &&
- state.getCurrentItem().getDescription() == null) {
- state.getCurrentItem().setDescription(content);
- }
- }
- }
+ private static final String TAG = "NSMedia";
+
+ public static final String NSTAG = "media";
+ public static final String NSURI = "http://search.yahoo.com/mrss/";
+
+ private static final String CONTENT = "content";
+ private static final String DOWNLOAD_URL = "url";
+ private static final String SIZE = "fileSize";
+ private static final String MIME_TYPE = "type";
+ private static final String DURATION = "duration";
+ private static final String DEFAULT = "isDefault";
+ private static final String MEDIUM = "medium";
+
+ private static final String MEDIUM_IMAGE = "image";
+ private static final String MEDIUM_AUDIO = "audio";
+ private static final String MEDIUM_VIDEO = "video";
+
+ private static final String IMAGE = "thumbnail";
+ private static final String IMAGE_URL = "url";
+
+ private static final String DESCRIPTION = "description";
+ private static final String DESCRIPTION_TYPE = "type";
+
+ @Override
+ public SyndElement handleElementStart(String localName, HandlerState state,
+ Attributes attributes) {
+ if (CONTENT.equals(localName)) {
+ String url = attributes.getValue(DOWNLOAD_URL);
+ String type = attributes.getValue(MIME_TYPE);
+ String defaultStr = attributes.getValue(DEFAULT);
+ String medium = attributes.getValue(MEDIUM);
+ boolean validTypeMedia = false;
+ boolean validTypeImage = false;
+
+ boolean isDefault = "true".equals(defaultStr);
+
+ if (MEDIUM_AUDIO.equals(medium)) {
+ validTypeMedia = true;
+ type = "audio/*";
+ } else if (MEDIUM_VIDEO.equals(medium)) {
+ validTypeMedia = true;
+ type = "video/*";
+ } else if (MEDIUM_IMAGE.equals(medium)) {
+ validTypeImage = true;
+ type = "image/*";
+ } else {
+ if (type == null) {
+ type = SyndTypeUtils.getMimeTypeFromUrl(url);
+ }
+
+ if (SyndTypeUtils.enclosureTypeValid(type)) {
+ validTypeMedia = true;
+ } else if (SyndTypeUtils.imageTypeValid(type)) {
+ validTypeImage = true;
+ }
+ }
+
+ if (state.getCurrentItem() != null && (state.getCurrentItem().getMedia() == null || isDefault)
+ && url != null && validTypeMedia) {
+ long size = 0;
+ String sizeStr = attributes.getValue(SIZE);
+ try {
+ size = Long.parseLong(sizeStr);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "Size \"" + sizeStr + "\" could not be parsed.");
+ }
+
+ int durationMs = 0;
+ String durationStr = attributes.getValue(DURATION);
+ if (!TextUtils.isEmpty(durationStr)) {
+ try {
+ long duration = Long.parseLong(durationStr);
+ durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
+ } catch (NumberFormatException e) {
+ Log.e(TAG, "Duration \"" + durationStr + "\" could not be parsed");
+ }
+ }
+ FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
+ if (durationMs > 0) {
+ media.setDuration(durationMs);
+ }
+ state.getCurrentItem().setMedia(media);
+ } else if (state.getCurrentItem() != null && url != null && validTypeImage) {
+ state.getCurrentItem().setImageUrl(url);
+ }
+ } else if (IMAGE.equals(localName)) {
+ String url = attributes.getValue(IMAGE_URL);
+ if (url != null) {
+ if (state.getCurrentItem() != null) {
+ state.getCurrentItem().setImageUrl(url);
+ } else {
+ if (state.getFeed().getImageUrl() == null) {
+ state.getFeed().setImageUrl(url);
+ }
+ }
+ }
+ } else if (DESCRIPTION.equals(localName)) {
+ String type = attributes.getValue(DESCRIPTION_TYPE);
+ return new AtomText(localName, this, type);
+ }
+ return new SyndElement(localName, this);
+ }
+
+ @Override
+ public void handleElementEnd(String localName, HandlerState state) {
+ if (DESCRIPTION.equals(localName)) {
+ String content = state.getContentBuf().toString();
+ if (state.getCurrentItem() != null && content != null
+ && state.getCurrentItem().getDescription() == null) {
+ state.getCurrentItem().setDescription(content);
+ }
+ }
+ }
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java b/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java
index e1dffef97..ac7f4848c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java
@@ -41,7 +41,7 @@ public final class URLChecker {
String lowerCaseUrl = url.toLowerCase(); // protocol names are case insensitive
if (lowerCaseUrl.startsWith("feed://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");
- return url.replaceFirst("feed://", "http://");
+ return prepareURL(url.substring("feed://".length()));
} else if (lowerCaseUrl.startsWith("pcast://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast://");
return prepareURL(url.substring("pcast://".length()));
@@ -50,7 +50,7 @@ public final class URLChecker {
return prepareURL(url.substring("pcast:".length()));
} else if (lowerCaseUrl.startsWith("itpc")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing itpc:// with http://");
- return url.replaceFirst("itpc://", "http://");
+ return prepareURL(url.substring("itpc://".length()));
} else if (lowerCaseUrl.startsWith(AP_SUBSCRIBE)) {
if (BuildConfig.DEBUG) Log.d(TAG, "Removing antennapod-subscribe://");
return prepareURL(url.substring(AP_SUBSCRIBE.length()));