diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index edf839ac2..b6d22c44e 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -1,6 +1,7 @@ package org.schabi.newpipe; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; @@ -29,12 +30,25 @@ import java.net.UnknownHostException; public class Downloader { private static final String USER_AGENT = "Mozilla/5.0"; - public static String download(String siteUrl) { - StringBuffer response = new StringBuffer(); + public static String download(String siteUrl, String language) { + String ret = ""; try { URL url = new URL(siteUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestProperty("Accept-Language", language); + ret = dl(con); + } + catch(Exception e) { + e.printStackTrace(); + } + return ret; + } + + private static String dl(HttpURLConnection con) { + StringBuffer response = new StringBuffer(); + + try { con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); @@ -57,4 +71,20 @@ public class Downloader { } return response.toString(); } + + + public static String download(String siteUrl) { + String ret = ""; + + try { + URL url = new URL(siteUrl); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + ret = dl(con); + } + catch(Exception e) { + e.printStackTrace(); + } + + return ret; + } } diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java index 8de38c102..ce606697d 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java @@ -93,10 +93,10 @@ public class VideoItemListFragment extends ListFragment { public void run() { try { 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+"\""); + String searchLanguageKey = getContext().getString(R.string.searchLanguage); + String searchLanguage = sp.getString(searchLanguageKey, ""); + SearchEngine.Result result = engine.search(query, page, searchLanguage); + Log.i(TAG, "countryCode passed:\""+searchLanguage+"\""); 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 b2b1beeac..79939aa5f 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,7 @@ public class YoutubeSearchEngine implements SearchEngine { private static final String TAG = YoutubeSearchEngine.class.toString(); @Override - public Result search(String query, int page, String countryCode) { + public Result search(String query, int page, String languageCode) { //String contentCountry = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string., ""); Uri.Builder builder = new Uri.Builder(); builder.scheme("https") @@ -59,20 +59,25 @@ public class YoutubeSearchEngine implements SearchEngine { .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"); + String site; + String url = builder.build().toString(); + //if we've been passed a valid, non-empty language code, append it to the URL + if(languageCode.length() > 0) { + if(languageCode.length() == 2) { Log.i(TAG, "URI: \""+builder+"\""); + site = Downloader.download(url, languageCode); } else { - Log.e(TAG, "invalid country code passed to search(): \""+countryCode+"\""); + Log.e(TAG, "invalid language code passed to search(): \""+languageCode+"\""); + site = Downloader.download(url); } } - String url = builder.build().toString(); + else { + site = Downloader.download(url); + } - String site = Downloader.download(url); + + //String site = Downloader.download(url); Document doc = Jsoup.parse(site, url); Result result = new Result(); Element list = doc.select("ol[class=\"item-section\"]").first(); diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index d427b7022..3c4b90e65 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -24,183 +24,163 @@ m4a show_next_video - content_country + search_language - - - 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 + + af + az + id + ms + ca + cs + da + de + et + en-GB + en + es + es-419 + eu + fil + fr + fr-CA + gl + hr + zu + is + it + sw + lv + lt + hu + nl + no + uz + pl + pt-PT + pt + ro + sq + sk + sl + fi + sv + vi + tr + bg + ky + kk + mk + mn + ru + sr + uk + el + hy + iw + ur + ar + fa + ne + mr + hi + bn + pa + gu + ta + te + kn + ml + si + th + lo + my + ka + am + km + zh-CN + zh-TW + zh-HK + ja + ko - - (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 + + Afrikaans + Azərbaycan + Bahasa Indonesia + Bahasa Malaysia + Català + Čeština + Dansk + Deutsch + Eesti + English (UK) + English (US) + Español (España) + Español (Latinoamérica) + Euskara + Filipino + Français + Français (Canada) + Galego + Hrvatski + IsiZulu + Íslenska + Italiano + Kiswahili + Latviešu valoda + Lietuvių + Magyar + Nederlands + Norsk + O‘zbek + Polski + Português + Português (Brasil) + Română + Shqip + Slovenčina + Slovenščina + Suomi + Svenska + Tiếng Việt + Türkçe + Български + Кыргызча + Қазақ Тілі + Македонски + Монгол + Русский + Српски + Українська + Ελληνικά + Հայերեն + עברית + اردو + العربية + فارسی + नेपाली + मराठी + हिन्दी + বাংলা + ਪੰਜਾਬੀ + ગુજરાતી + தமிழ் + తెలుగు + ಕನ್ನಡ + മലയാളം + සිංහල + ภาษาไทย + ລາວ + ဗမာ + ქართული + አማርኛ + ខ្មែរ + 中文 (简体) + 中文 (繁體) + 中文 (香港) + 日本語 + 한국어 \ 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 7fafc3104..83e4c4ce0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,5 +49,5 @@ Show \"Next video\" item. Url not Supported. Similar Videos - Video Content Country + Video Search Language \ 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 bee161060..16bed15a4 100644 --- a/app/src/main/res/xml/settings_screen.xml +++ b/app/src/main/res/xml/settings_screen.xml @@ -52,9 +52,9 @@ android:defaultValue="true" /> \ No newline at end of file