Added Content Country selection setting. This changes the SearchEngine interface slightly. Still need a reliable test to prove whether YouTube is serving different search results based on the country code passed in the search query.
This commit is contained in:
parent
fc32377ce7
commit
fc707b6c7e
7 changed files with 212 additions and 4 deletions
|
|
@ -321,7 +321,7 @@ public class ActionBarHandler {
|
|||
}
|
||||
});
|
||||
builder.create().show();
|
||||
Log.d(TAG, "Either no Streaming player for audio was installed, or something importand crashed:");
|
||||
Log.d(TAG, "Either no Streaming player for audio was installed, or something important crashed:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,5 +31,6 @@ public interface SearchEngine {
|
|||
public Vector<VideoInfoItem> resultList = new Vector<>();
|
||||
}
|
||||
|
||||
Result search(String query, int page);
|
||||
//Result search(String query, int page);
|
||||
Result search(String query, int page, String contentCountry);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package org.schabi.newpipe;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
|
@ -90,7 +92,11 @@ public class VideoItemListFragment extends ListFragment {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SearchEngine.Result result = engine.search(query, page);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
String contentCountryKey = getContext().getString(R.string.contentCountry);
|
||||
String contentCountry = sp.getString(contentCountryKey, "");
|
||||
SearchEngine.Result result = engine.search(query, page, contentCountry);
|
||||
Log.i(TAG, "countryCode passed:\""+contentCountry+"\"");
|
||||
if(run) {
|
||||
h.post(new ResultRunnable(result, requestId));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.youtube;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
|
|
@ -38,7 +39,8 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||
private static final String TAG = YoutubeSearchEngine.class.toString();
|
||||
|
||||
@Override
|
||||
public Result search(String query, int page) {
|
||||
public Result search(String query, int page, String countryCode) {
|
||||
//String contentCountry = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string., "");
|
||||
Uri.Builder builder = new Uri.Builder();
|
||||
builder.scheme("https")
|
||||
.authority("www.youtube.com")
|
||||
|
|
@ -46,6 +48,18 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||
.appendQueryParameter("search_query", query)
|
||||
.appendQueryParameter("page", Integer.toString(page))
|
||||
.appendQueryParameter("filters", "video");
|
||||
|
||||
//if we've been passed a valid, non-empty country code, append it to the URL
|
||||
if(countryCode.length() > 0) {
|
||||
if(countryCode.length() == 2) {
|
||||
builder.appendQueryParameter("gl", countryCode);
|
||||
builder.appendQueryParameter("persist_gl", "1");
|
||||
Log.i(TAG, "URI: \""+builder+"\"");
|
||||
}
|
||||
else {
|
||||
Log.e(TAG, "invalid country code passed to search(): \""+countryCode+"\"");
|
||||
}
|
||||
}
|
||||
String url = builder.build().toString();
|
||||
|
||||
String site = Downloader.download(url);
|
||||
|
|
@ -115,4 +129,5 @@ public class YoutubeSearchEngine implements SearchEngine {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue