Merge pull request #5493 from ByteHamster/apple-feeds
Open Apple podcast urls
This commit is contained in:
commit
b680d05e44
|
@ -315,6 +315,18 @@
|
||||||
<data android:scheme="https" />
|
<data android:scheme="https" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:pathPattern="/.*/podcast/.*" />
|
||||||
|
<data android:host="podcasts.apple.com" />
|
||||||
|
<data android:scheme="http" />
|
||||||
|
<data android:scheme="https" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND"/>
|
<action android:name="android.intent.action.SEND"/>
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,12 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ItunesPodcastSearcher implements PodcastSearcher {
|
public class ItunesPodcastSearcher implements PodcastSearcher {
|
||||||
private static final String ITUNES_API_URL = "https://itunes.apple.com/search?media=podcast&term=%s";
|
private static final String ITUNES_API_URL = "https://itunes.apple.com/search?media=podcast&term=%s";
|
||||||
|
private static final String PATTERN_BY_ID = ".*/podcasts\\.apple\\.com/.*/podcast/.*/id(\\d+).*";
|
||||||
|
|
||||||
public ItunesPodcastSearcher() {
|
public ItunesPodcastSearcher() {
|
||||||
}
|
}
|
||||||
|
@ -70,9 +73,12 @@ public class ItunesPodcastSearcher implements PodcastSearcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Single<String> lookupUrl(String url) {
|
public Single<String> lookupUrl(String url) {
|
||||||
|
Pattern pattern = Pattern.compile(PATTERN_BY_ID);
|
||||||
|
Matcher matcher = pattern.matcher(url);
|
||||||
|
final String lookupUrl = matcher.find() ? ("https://itunes.apple.com/lookup?id=" + matcher.group(1)) : url;
|
||||||
return Single.create(emitter -> {
|
return Single.create(emitter -> {
|
||||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||||
Request.Builder httpReq = new Request.Builder().url(url);
|
Request.Builder httpReq = new Request.Builder().url(lookupUrl);
|
||||||
try {
|
try {
|
||||||
Response response = client.newCall(httpReq.build()).execute();
|
Response response = client.newCall(httpReq.build()).execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
|
@ -92,7 +98,7 @@ public class ItunesPodcastSearcher implements PodcastSearcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean urlNeedsLookup(String url) {
|
public boolean urlNeedsLookup(String url) {
|
||||||
return url.contains("itunes.apple.com");
|
return url.contains("itunes.apple.com") || url.matches(PATTERN_BY_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue