Use country code instead of language for top itunes feed
This commit is contained in:
parent
04dd39021c
commit
3bbe6d55f7
@ -1,6 +1,8 @@
|
||||
package de.danoeh.antennapod.discovery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
|
||||
@ -21,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ItunesTopListLoader {
|
||||
private static final String TAG = "ITunesTopListLoader";
|
||||
private final Context context;
|
||||
|
||||
public ItunesTopListLoader(Context context) {
|
||||
@ -29,11 +32,11 @@ public class ItunesTopListLoader {
|
||||
|
||||
public Single<List<PodcastSearchResult>> loadToplist(int limit) {
|
||||
return Single.create((SingleOnSubscribe<List<PodcastSearchResult>>) emitter -> {
|
||||
String lang = Locale.getDefault().getLanguage();
|
||||
String country = Locale.getDefault().getCountry();
|
||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||
String feedString;
|
||||
try {
|
||||
feedString = getTopListFeed(client, lang, limit);
|
||||
feedString = getTopListFeed(client, country, limit);
|
||||
} catch (IOException e) {
|
||||
feedString = getTopListFeed(client, "us", limit);
|
||||
}
|
||||
@ -74,11 +77,12 @@ public class ItunesTopListLoader {
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private String getTopListFeed(OkHttpClient client, String language, int limit) throws IOException {
|
||||
String url = "https://itunes.apple.com/%s/rss/toppodcasts/limit="+limit+"/explicit=true/json";
|
||||
private String getTopListFeed(OkHttpClient client, String country, int limit) throws IOException {
|
||||
String url = "https://itunes.apple.com/%s/rss/toppodcasts/limit=" + limit + "/explicit=true/json";
|
||||
Log.d(TAG, "Feed URL " + String.format(url, country));
|
||||
Request.Builder httpReq = new Request.Builder()
|
||||
.header("User-Agent", ClientConfig.USER_AGENT)
|
||||
.url(String.format(url, language));
|
||||
.url(String.format(url, country));
|
||||
|
||||
try (Response response = client.newCall(httpReq.build()).execute()) {
|
||||
if (response.isSuccessful()) {
|
||||
@ -95,7 +99,7 @@ public class ItunesTopListLoader {
|
||||
JSONArray entries = feed.getJSONArray("entry");
|
||||
|
||||
List<PodcastSearchResult> results = new ArrayList<>();
|
||||
for (int i=0; i < entries.length(); i++) {
|
||||
for (int i = 0; i < entries.length(); i++) {
|
||||
JSONObject json = entries.getJSONObject(i);
|
||||
results.add(PodcastSearchResult.fromItunesToplist(json));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user