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
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,4 +24,183 @@
|
|||
</string-array>
|
||||
<string name="defaultAudioFormat">m4a</string>
|
||||
<string name="showNextVideo">show_next_video</string>
|
||||
<string name="contentCountry">content_country</string>
|
||||
<!-- TODO: scrape these programmatically, then store in a local cache -->
|
||||
<!-- alternatively, load these from some local android data store -->
|
||||
<string-array name="countryCodes">
|
||||
<item></item><!--NONE-->
|
||||
<item>US</item>
|
||||
<item>DZ</item>
|
||||
<item>AR</item>
|
||||
<item>AU</item>
|
||||
<item>AT</item>
|
||||
<item>AZ</item>
|
||||
<item>BH</item>
|
||||
<item>BY</item>
|
||||
<item>BE</item>
|
||||
<item>BA</item>
|
||||
<item>BR</item>
|
||||
<item>BG</item>
|
||||
<item>CA</item>
|
||||
<item>CL</item>
|
||||
<item>CO</item>
|
||||
<item>HR</item>
|
||||
<item>CZ</item>
|
||||
<item>DK</item>
|
||||
<item>EG</item>
|
||||
<item>EE</item>
|
||||
<item>FI</item>
|
||||
<item>FR</item>
|
||||
<item>GE</item>
|
||||
<item>DE</item>
|
||||
<item>GH</item>
|
||||
<item>GR</item>
|
||||
<item>HK</item>
|
||||
<item>HU</item>
|
||||
<item>IS</item>
|
||||
<item>IN</item>
|
||||
<item>ID</item>
|
||||
<item>IE</item>
|
||||
<item>IL</item>
|
||||
<item>IT</item>
|
||||
<item>JP</item>
|
||||
<item>JO</item>
|
||||
<item>KZ</item>
|
||||
<item>KE</item>
|
||||
<item>KW</item>
|
||||
<item>LV</item>
|
||||
<item>LB</item>
|
||||
<item>LY</item>
|
||||
<item>LT</item>
|
||||
<item>LU</item>
|
||||
<item>MK</item>
|
||||
<item>MY</item>
|
||||
<item>MX</item>
|
||||
<item>ME</item>
|
||||
<item>MA</item>
|
||||
<item>NL</item>
|
||||
<item>NZ</item>
|
||||
<item>NG</item>
|
||||
<item>NO</item>
|
||||
<item>OM</item>
|
||||
<item>PE</item>
|
||||
<item>PH</item>
|
||||
<item>PL</item>
|
||||
<item>PT</item>
|
||||
<item>PR</item>
|
||||
<item>QA</item>
|
||||
<item>RO</item>
|
||||
<item>RU</item>
|
||||
<item>SA</item>
|
||||
<item>SN</item>
|
||||
<item>RS</item>
|
||||
<item>SG</item>
|
||||
<item>SK</item>
|
||||
<item>SI</item>
|
||||
<item>ZA</item>
|
||||
<item>KR</item>
|
||||
<item>ES</item>
|
||||
<item>SE</item>
|
||||
<item>CH</item>
|
||||
<item>TW</item>
|
||||
<item>TZ</item>
|
||||
<item>TH</item>
|
||||
<item>TN</item>
|
||||
<item>TR</item>
|
||||
<item>UG</item>
|
||||
<item>UA</item>
|
||||
<item>AE</item>
|
||||
<item>GB</item>
|
||||
<item>VN</item>
|
||||
<item>YE</item>
|
||||
<item>ZW</item>
|
||||
</string-array>
|
||||
<string-array name="countryNames">
|
||||
<item>(None)</item>
|
||||
<item>Worldwide (USA)</item>
|
||||
<item>Algeria</item>
|
||||
<item>Argentina</item>
|
||||
<item>Australia</item>
|
||||
<item>Austria</item>
|
||||
<item>Azerbaijan</item>
|
||||
<item>Bahrain</item>
|
||||
<item>Belarus</item>
|
||||
<item>Belgium</item>
|
||||
<item>Bosnia and Herzegovina</item>
|
||||
<item>Brazil</item>
|
||||
<item>Bulgaria</item>
|
||||
<item>Canada</item>
|
||||
<item>Chile</item>
|
||||
<item>Colombia</item>
|
||||
<item>Croatia</item>
|
||||
<item>Czech Republic</item>
|
||||
<item>Denmark</item>
|
||||
<item>Egypt</item>
|
||||
<item>Estonia</item>
|
||||
<item>Finland</item>
|
||||
<item>France</item>
|
||||
<item>Georgia</item>
|
||||
<item>Germany</item>
|
||||
<item>Ghana</item>
|
||||
<item>Greece</item>
|
||||
<item>Hong Kong</item>
|
||||
<item>Hungary</item>
|
||||
<item>Iceland</item>
|
||||
<item>India</item>
|
||||
<item>Indonesia</item>
|
||||
<item>Ireland</item>
|
||||
<item>Israel</item>
|
||||
<item>Italy</item>
|
||||
<item>Japan</item>
|
||||
<item>Jordan</item>
|
||||
<item>Kazakhstan</item>
|
||||
<item>Kenya</item>
|
||||
<item>Kuwait</item>
|
||||
<item>Latvia</item>
|
||||
<item>Lebanon</item>
|
||||
<item>Libya</item>
|
||||
<item>Lithuania</item>
|
||||
<item>Luxembourg</item>
|
||||
<item>Macedonia</item>
|
||||
<item>Malaysia</item>
|
||||
<item>Mexico</item>
|
||||
<item>Montenegro</item>
|
||||
<item>Morocco</item>
|
||||
<item>Netherlands</item>
|
||||
<item>New Zealand</item>
|
||||
<item>Nigeria</item>
|
||||
<item>Norway</item>
|
||||
<item>Oman</item>
|
||||
<item>Peru</item>
|
||||
<item>Philippines</item>
|
||||
<item>Poland</item>
|
||||
<item>Portugal</item>
|
||||
<item>Puerto Rico</item>
|
||||
<item>Qatar</item>
|
||||
<item>Romania</item>
|
||||
<item>Russia</item>
|
||||
<item>Saudi Arabia</item>
|
||||
<item>Senegal</item>
|
||||
<item>Serbia</item>
|
||||
<item>Singapore</item>
|
||||
<item>Slovakia</item>
|
||||
<item>Slovenia</item>
|
||||
<item>South Africa</item>
|
||||
<item>South Korea</item>
|
||||
<item>Spain</item>
|
||||
<item>Sweden</item>
|
||||
<item>Switzerland</item>
|
||||
<item>Taiwan</item>
|
||||
<item>Tanzania</item>
|
||||
<item>Thailand</item>
|
||||
<item>Tunisia</item>
|
||||
<item>Turkey</item>
|
||||
<item>Uganda</item>
|
||||
<item>Ukraine</item>
|
||||
<item>United Arab Emirates</item>
|
||||
<item>United Kingdom</item>
|
||||
<item>Vietnam</item>
|
||||
<item>Yemen</item>
|
||||
<item>Zimbabwe</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -49,4 +49,5 @@
|
|||
<string name="showNextVideoTitle">Show \"Next video\" item.</string>
|
||||
<string name="urlNotSupportedText">Url not Supported.</string>
|
||||
<string name="showSimilarVideosButtonText">Similar Videos</string>
|
||||
<string name="contentCountryTitle">Video Content Country</string>
|
||||
</resources>
|
|
@ -51,4 +51,10 @@
|
|||
android:title="@string/showNextVideoTitle"
|
||||
android:defaultValue="true" />
|
||||
|
||||
<ListPreference
|
||||
android:key="@string/contentCountry"
|
||||
android:title="@string/contentCountryTitle"
|
||||
android:entries="@array/countryNames"
|
||||
android:entryValues="@array/countryCodes"
|
||||
android:defaultValue="" /> <!-- default will include no country code in URL-->
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue