diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index 36c6772c8..5cdecef66 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -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(); } } diff --git a/app/src/main/java/org/schabi/newpipe/SearchEngine.java b/app/src/main/java/org/schabi/newpipe/SearchEngine.java index 68945661f..6d5509df7 100644 --- a/app/src/main/java/org/schabi/newpipe/SearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/SearchEngine.java @@ -32,7 +32,8 @@ public interface SearchEngine { public Vector resultList = new Vector<>(); } - Result search(String query, int page); - ArrayList suggestionList(String query); + + //Result search(String query, int page); + Result search(String query, int page, String contentCountry); } diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java index 3ba90c6db..8de38c102 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java @@ -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)); } diff --git a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java index 2cbe5bb33..0c13b66ea 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java @@ -49,7 +49,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") @@ -57,6 +58,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); @@ -162,25 +175,14 @@ public class YoutubeSearchEngine implements SearchEngine { } doc.getDocumentElement().normalize(); -// System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); - NodeList nList = doc.getElementsByTagName("CompleteSuggestion"); - for (int temp = 0; temp < nList.getLength(); temp++) { - Node nNode = nList.item(temp); -// System.out.println("\nCurrent Element :" + nNode.getNodeName()); - NodeList nList1 = doc.getElementsByTagName("suggestion"); - - Node nNode1 = nList1.item(temp); -// System.out.println("\nInside Item :" + nNode1.getNodeName()); - + Node nNode1 = nList1.item(temp) + ; if (nNode1.getNodeType() == Node.ELEMENT_NODE) { org.w3c.dom.Element eElement = (org.w3c.dom.Element) nNode1; - - System.out.println("final data : " + eElement.getAttribute("data")); - suggestions.add(eElement.getAttribute("data")); } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index e7c520aa4..d427b7022 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -24,4 +24,183 @@ m4a show_next_video + content_country + + + + + US + DZ + AR + AU + AT + AZ + BH + BY + BE + BA + BR + BG + CA + CL + CO + HR + CZ + DK + EG + EE + FI + FR + GE + DE + GH + GR + HK + HU + IS + IN + ID + IE + IL + IT + JP + JO + KZ + KE + KW + LV + LB + LY + LT + LU + MK + MY + MX + ME + MA + NL + NZ + NG + NO + OM + PE + PH + PL + PT + PR + QA + RO + RU + SA + SN + RS + SG + SK + SI + ZA + KR + ES + SE + CH + TW + TZ + TH + TN + TR + UG + UA + AE + GB + VN + YE + ZW + + + (None) + Worldwide (USA) + Algeria + Argentina + Australia + Austria + Azerbaijan + Bahrain + Belarus + Belgium + Bosnia and Herzegovina + Brazil + Bulgaria + Canada + Chile + Colombia + Croatia + Czech Republic + Denmark + Egypt + Estonia + Finland + France + Georgia + Germany + Ghana + Greece + Hong Kong + Hungary + Iceland + India + Indonesia + Ireland + Israel + Italy + Japan + Jordan + Kazakhstan + Kenya + Kuwait + Latvia + Lebanon + Libya + Lithuania + Luxembourg + Macedonia + Malaysia + Mexico + Montenegro + Morocco + Netherlands + New Zealand + Nigeria + Norway + Oman + Peru + Philippines + Poland + Portugal + Puerto Rico + Qatar + Romania + Russia + Saudi Arabia + Senegal + Serbia + Singapore + Slovakia + Slovenia + South Africa + South Korea + Spain + Sweden + Switzerland + Taiwan + Tanzania + Thailand + Tunisia + Turkey + Uganda + Ukraine + United Arab Emirates + United Kingdom + Vietnam + Yemen + Zimbabwe + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c4faeb88..7fafc3104 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,4 +49,5 @@ Show \"Next video\" item. Url not Supported. Similar Videos + Video Content Country \ No newline at end of file diff --git a/app/src/main/res/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml index e9250d4c9..bee161060 100644 --- a/app/src/main/res/xml/settings_screen.xml +++ b/app/src/main/res/xml/settings_screen.xml @@ -51,4 +51,10 @@ android:title="@string/showNextVideoTitle" android:defaultValue="true" /> + \ No newline at end of file