From 8aff134c569cc70b7d8dbf96e221b567dcf8ec06 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Sun, 8 Nov 2015 01:09:03 +0000 Subject: [PATCH 1/5] replaced content tountry selection with search language selection.Should now allows users to search for videos in their preferred language. Needs testing before pushing to origin. --- .../java/org/schabi/newpipe/Downloader.java | 34 +- .../schabi/newpipe/VideoItemListFragment.java | 8 +- .../newpipe/youtube/YoutubeSearchEngine.java | 23 +- app/src/main/res/values/settings_keys.xml | 330 ++++++++---------- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/settings_screen.xml | 8 +- 6 files changed, 210 insertions(+), 195 deletions(-) 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 From c87458590ca5b8680b061772b914789f72f391c8 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Sun, 8 Nov 2015 02:04:03 +0000 Subject: [PATCH 2/5] refactoring VideoInfo & VideoInfoItem, part 1: + created enum VideoFormat --- .../java/org/schabi/newpipe/VideoFormat.java | 46 +++++++ .../java/org/schabi/newpipe/VideoInfo.java | 117 ++++-------------- .../org/schabi/newpipe/VideoInfoItem.java | 3 +- 3 files changed, 75 insertions(+), 91 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/VideoFormat.java diff --git a/app/src/main/java/org/schabi/newpipe/VideoFormat.java b/app/src/main/java/org/schabi/newpipe/VideoFormat.java new file mode 100644 index 000000000..f72acbd4b --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/VideoFormat.java @@ -0,0 +1,46 @@ +package org.schabi.newpipe; + +/** + * Created by scc on 08/11/15. + */ +public enum VideoFormat { + // id name suffix mime type + MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"), + v3GPP (0x1, "3GPP", "3gp", "video/3gpp"), + WEBM (0x2, "WebM", "webm", "video/webm"), + M4A (0x3, "m4a", "m4a", "audio/mp4"), + WEBMA (0x4, "WebM", "webm", "audio/webm"); + + public final int id; + public final String name; + public final String suffix; + public final String mimeType; + + VideoFormat(int id, String name, String suffix, String mimeType) { + this.id = id; + this.name = name; + this.suffix = suffix; + this.mimeType = mimeType; + } + + public static String getNameById(int ident) { + for (VideoFormat vf : VideoFormat.values()) { + if(vf.id == ident) return vf.name; + } + return ""; + } + + public static String getSuffixById(int ident) { + for (VideoFormat vf : VideoFormat.values()) { + if(vf.id == ident) return vf.suffix; + } + return ""; + } + + public static String getMimeById(int ident) { + for (VideoFormat vf : VideoFormat.values()) { + if(vf.id == ident) return vf.mimeType; + } + return ""; + } +} diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/VideoInfo.java index 0e0e149dc..55aa3c8ee 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfo.java @@ -1,5 +1,9 @@ package org.schabi.newpipe; +import android.graphics.Bitmap; +import android.util.Log; +import java.util.Vector; + /** * Created by Christian Schabesberger on 26.08.15. * @@ -20,82 +24,36 @@ package org.schabi.newpipe; * along with NewPipe. If not, see . */ -import android.graphics.Bitmap; -import android.util.Log; - -import java.util.Vector; public class VideoInfo { + public String id = ""; + public String title = ""; + public String uploader = ""; + public String thumbnail_url = ""; + public Bitmap thumbnail = null; + public String webpage_url = ""; + public String upload_date = ""; + public String view_count = ""; + + public String uploader_thumbnail_url = ""; + public Bitmap uploader_thumbnail = null; + public String description = ""; + public int duration = -1; + public int age_limit = 0; + public String like_count = ""; + public String dislike_count = ""; + public String average_rating = ""; + public VideoStream[] videoStreams = null; + public AudioStream[] audioStreams = null; + public VideoInfoItem nextVideo = null; + public VideoInfoItem[] relatedVideos = null; + public int videoAvailableStatus = VIDEO_AVAILABLE; private static final String TAG = VideoInfo.class.toString(); - // format identifier - public static final int I_MPEG_4 = 0x0; - public static final int I_3GPP = 0x1; - public static final int I_WEBM = 0x2; - public static final int I_M4A = 0x3; - public static final int I_WEBMA = 0x4; - - // format name - public static final String F_MPEG_4 = "MPEG-4"; - public static final String F_3GPP = "3GPP"; - public static final String F_WEBM = "WebM"; - public static final String F_M4A = "m4a"; - public static final String F_WEBMA = "WebM"; - - // file suffix - public static final String C_MPEG_4 = "mp4"; - public static final String C_3GPP = "3gp"; - public static final String C_WEBM = "webm"; - public static final String C_M4A = "m4a"; - public static final String C_WEBMA = "webm"; - - // mimeType - public static final String M_MPEG_4 = "video/mp4"; - public static final String M_3GPP = "video/3gpp"; - public static final String M_WEBM = "video/webm"; - public static final String M_M4A = "audio/mp4"; - public static final String M_WEBMA = "audio/webm"; - public static final int VIDEO_AVAILABLE = 0x00; public static final int VIDEO_UNAVAILABLE = 0x01; - public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation; sound pretty draconian - - public static String getNameById(int id) { - switch(id) { - case I_MPEG_4: return F_MPEG_4; - case I_3GPP: return F_3GPP; - case I_WEBM: return F_WEBM; - case I_M4A: return F_M4A; - case I_WEBMA: return F_WEBMA; - default: formatNotKnown(id); - } - return ""; - } - - public static String getSuffixById(int id) { - switch(id) { - case I_MPEG_4: return C_MPEG_4; - case I_3GPP: return C_3GPP; - case I_WEBM: return C_WEBM; - case I_M4A: return C_M4A; - case I_WEBMA: return C_WEBMA; - default: formatNotKnown(id); - } - return ""; - } - - public static String getMimeById(int id) { - switch(id) { - case I_MPEG_4: return M_MPEG_4; - case I_3GPP: return M_3GPP; - case I_WEBM: return M_WEBM; - case I_M4A: return M_M4A; - case I_WEBMA: return M_WEBMA; - default: formatNotKnown(id); - } - return ""; - } + public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation public static class VideoStream { public VideoStream(String url, int format, String res) { @@ -123,25 +81,4 @@ public class VideoInfo { } - public String id = ""; - public String uploader = ""; - public String upload_date = ""; - public String uploader_thumbnail_url = ""; - public Bitmap uploader_thumbnail = null; - public String title = ""; - public String thumbnail_url = ""; - public Bitmap thumbnail = null; - public String description = ""; - public int duration = -1; - public int age_limit = 0; - public String webpage_url = ""; - public String view_count = ""; - public String like_count = ""; - public String dislike_count = ""; - public String average_rating = ""; - public VideoStream[] videoStreams = null; - public AudioStream[] audioStreams = null; - public VideoInfoItem nextVideo = null; - public VideoInfoItem[] relatedVideos = null; - public int videoAvailableStatus = VIDEO_AVAILABLE; } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java b/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java index e34f064b1..dca5f0edc 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java @@ -28,13 +28,14 @@ public class VideoInfoItem implements Parcelable { public String id = ""; public String title = ""; public String uploader = ""; - public String duration = ""; public String thumbnail_url = ""; public Bitmap thumbnail = null; public String webpage_url = ""; public String upload_date = ""; public String view_count = ""; + public String duration = ""; + protected VideoInfoItem(Parcel in) { id = in.readString(); title = in.readString(); From 2fc2fa56c30e9985f93f5515adfae16e41ddb0fa Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Sun, 8 Nov 2015 02:22:40 +0000 Subject: [PATCH 3/5] refactoring VideoInfo & MediaFormat, part 2: * fixed errors caused by moving media format code to MediaFormat enum --- .../org/schabi/newpipe/ActionBarHandler.java | 16 +++++----- .../{VideoFormat.java => MediaFormat.java} | 10 +++---- .../newpipe/youtube/YoutubeExtractor.java | 30 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) rename app/src/main/java/org/schabi/newpipe/{VideoFormat.java => MediaFormat.java} (80%) diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index 5cdecef66..c46a617b6 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -77,7 +77,7 @@ public class ActionBarHandler { int defaultResolutionPos = 0; for(int i = 0; i < videoStreams.length; i++) { - itemArray[i] = VideoInfo.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution; + itemArray[i] = MediaFormat.getNameById(videoStreams[i].format) + " " + videoStreams[i].resolution; if(defaultResolution.equals(videoStreams[i].resolution)) { defaultResolutionPos = i; } @@ -98,14 +98,14 @@ public class ActionBarHandler { .getString(activity.getString(R.string.defaultAudioFormatPreference), "webm"); if(preferedFormat.equals("webm")) { for(VideoInfo.AudioStream s : audioStreams) { - if(s.format == VideoInfo.I_WEBMA) { + if(s.format == MediaFormat.WEBMA.id) { audioStream = s; } } } else if(preferedFormat.equals("m4a")){ for(VideoInfo.AudioStream s : audioStreams) { - Log.d(TAG, VideoInfo.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth)); - if(s.format == VideoInfo.I_M4A && + Log.d(TAG, MediaFormat.getMimeById(s.format) + " : " + Integer.toString(s.bandwidth)); + if(s.format == MediaFormat.M4A.id && (audioStream == null || audioStream.bandwidth > s.bandwidth)) { audioStream = s; Log.d(TAG, "last choosen"); @@ -196,7 +196,7 @@ public class ActionBarHandler { intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(videoStreams[selectedStream].url), - VideoInfo.getMimeById(videoStreams[selectedStream].format)); + MediaFormat.getMimeById(videoStreams[selectedStream].format)); intent.putExtra(Intent.EXTRA_TITLE, videoTitle); intent.putExtra("title", videoTitle); @@ -237,8 +237,8 @@ public class ActionBarHandler { public void downloadVideo() { Log.d(TAG, "bla"); if(!videoTitle.isEmpty()) { - String videoSuffix = "." + VideoInfo.getSuffixById(videoStreams[selectedStream].format); - String audioSuffix = "." + VideoInfo.getSuffixById(audioStream.format); + String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format); + String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format); Bundle args = new Bundle(); args.putString(DownloadDialog.FILE_SUFFIX_VIDEO, videoSuffix); args.putString(DownloadDialog.FILE_SUFFIX_AUDIO, audioSuffix); @@ -297,7 +297,7 @@ public class ActionBarHandler { try { intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(audioStream.url), - VideoInfo.getMimeById(audioStream.format)); + MediaFormat.getMimeById(audioStream.format)); intent.putExtra(Intent.EXTRA_TITLE, videoTitle); intent.putExtra("title", videoTitle); activity.startActivity(intent); // HERE !!! diff --git a/app/src/main/java/org/schabi/newpipe/VideoFormat.java b/app/src/main/java/org/schabi/newpipe/MediaFormat.java similarity index 80% rename from app/src/main/java/org/schabi/newpipe/VideoFormat.java rename to app/src/main/java/org/schabi/newpipe/MediaFormat.java index f72acbd4b..8d41d606d 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoFormat.java +++ b/app/src/main/java/org/schabi/newpipe/MediaFormat.java @@ -3,7 +3,7 @@ package org.schabi.newpipe; /** * Created by scc on 08/11/15. */ -public enum VideoFormat { +public enum MediaFormat { // id name suffix mime type MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"), v3GPP (0x1, "3GPP", "3gp", "video/3gpp"), @@ -16,7 +16,7 @@ public enum VideoFormat { public final String suffix; public final String mimeType; - VideoFormat(int id, String name, String suffix, String mimeType) { + MediaFormat(int id, String name, String suffix, String mimeType) { this.id = id; this.name = name; this.suffix = suffix; @@ -24,21 +24,21 @@ public enum VideoFormat { } public static String getNameById(int ident) { - for (VideoFormat vf : VideoFormat.values()) { + for (MediaFormat vf : MediaFormat.values()) { if(vf.id == ident) return vf.name; } return ""; } public static String getSuffixById(int ident) { - for (VideoFormat vf : VideoFormat.values()) { + for (MediaFormat vf : MediaFormat.values()) { if(vf.id == ident) return vf.suffix; } return ""; } public static String getMimeById(int ident) { - for (VideoFormat vf : VideoFormat.values()) { + for (MediaFormat vf : MediaFormat.values()) { if(vf.id == ident) return vf.mimeType; } return ""; diff --git a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java index 9cca7feea..1c5c1ffe9 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -3,7 +3,6 @@ package org.schabi.newpipe.youtube; import android.util.Log; import android.util.Xml; -import org.json.JSONException; import org.json.JSONObject; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -14,6 +13,7 @@ import org.mozilla.javascript.Function; import org.mozilla.javascript.ScriptableObject; import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Extractor; +import org.schabi.newpipe.MediaFormat; import org.schabi.newpipe.VideoInfo; import org.schabi.newpipe.VideoInfoItem; import org.xmlpull.v1.XmlPullParser; @@ -57,16 +57,16 @@ public class YoutubeExtractor implements Extractor { public static int resolveFormat(int itag) { switch(itag) { // video - case 17: return VideoInfo.I_3GPP; - case 18: return VideoInfo.I_MPEG_4; - case 22: return VideoInfo.I_MPEG_4; - case 36: return VideoInfo.I_3GPP; - case 37: return VideoInfo.I_MPEG_4; - case 38: return VideoInfo.I_MPEG_4; - case 43: return VideoInfo.I_WEBM; - case 44: return VideoInfo.I_WEBM; - case 45: return VideoInfo.I_WEBM; - case 46: return VideoInfo.I_WEBM; + case 17: return MediaFormat.v3GPP.id; + case 18: return MediaFormat.MPEG_4.id; + case 22: return MediaFormat.MPEG_4.id; + case 36: return MediaFormat.v3GPP.id; + case 37: return MediaFormat.MPEG_4.id; + case 38: return MediaFormat.MPEG_4.id; + case 43: return MediaFormat.WEBM.id; + case 44: return MediaFormat.WEBM.id; + case 45: return MediaFormat.WEBM.id; + case 46: return MediaFormat.WEBM.id; default: //Log.i(TAG, "Itag " + Integer.toString(itag) + " not known or not supported."); return -1; @@ -344,10 +344,10 @@ public class YoutubeExtractor implements Extractor { if(currentTagIsBaseUrl && (currentMimeType.contains("audio"))) { int format = -1; - if(currentMimeType.equals(VideoInfo.M_WEBMA)) { - format = VideoInfo.I_WEBMA; - } else if(currentMimeType.equals(VideoInfo.M_M4A)) { - format = VideoInfo.I_M4A; + if(currentMimeType.equals(MediaFormat.WEBMA.mimeType)) { + format = MediaFormat.WEBMA.id; + } else if(currentMimeType.equals(MediaFormat.M4A.mimeType)) { + format = MediaFormat.M4A.id; } audioStreams.add(new VideoInfo.AudioStream(parser.getText(), format, currentBandwidth, currentSamplingRate)); From 27b450f1e30a421b9bdf7d36193bd818aa8f809a Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Tue, 10 Nov 2015 17:09:26 +0000 Subject: [PATCH 4/5] minor commit: -removed now-redundant language code check --- .../java/org/schabi/newpipe/VideoItemListFragment.java | 4 ++-- .../schabi/newpipe/youtube/YoutubeSearchEngine.java | 10 ++-------- app/src/main/res/xml/settings_screen.xml | 4 +--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java index ce606697d..c9f6c0cd7 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java @@ -94,9 +94,9 @@ public class VideoItemListFragment extends ListFragment { try { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); String searchLanguageKey = getContext().getString(R.string.searchLanguage); - String searchLanguage = sp.getString(searchLanguageKey, ""); + String searchLanguage = sp.getString(searchLanguageKey, "en"); SearchEngine.Result result = engine.search(query, page, searchLanguage); - Log.i(TAG, "countryCode passed:\""+searchLanguage+"\""); + Log.i(TAG, "language code 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 79939aa5f..7d9631ac2 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java @@ -61,23 +61,17 @@ public class YoutubeSearchEngine implements SearchEngine { String site; String url = builder.build().toString(); - //if we've been passed a valid, non-empty language code, append it to the URL + //if we've been passed a valid language code, append it to the URL if(languageCode.length() > 0) { - if(languageCode.length() == 2) { + //assert Pattern.matches("[a-z]{2}(-([A-Z]{2}|[0-9]{1,3}))?", languageCode); Log.i(TAG, "URI: \""+builder+"\""); site = Downloader.download(url, languageCode); - } - else { - Log.e(TAG, "invalid language code passed to search(): \""+languageCode+"\""); - site = Downloader.download(url); - } } else { 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/xml/settings_screen.xml b/app/src/main/res/xml/settings_screen.xml index 251f4b202..a72dc87df 100644 --- a/app/src/main/res/xml/settings_screen.xml +++ b/app/src/main/res/xml/settings_screen.xml @@ -51,13 +51,11 @@ android:title="@string/showNextAndSimilarTitle" android:defaultValue="true" /> - + \ No newline at end of file From 596443bf5e68a24f6e61218db87a0599811ac573 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Tue, 10 Nov 2015 17:23:07 +0000 Subject: [PATCH 5/5] added licensing notice to MediaFormat --- .../java/org/schabi/newpipe/MediaFormat.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/MediaFormat.java b/app/src/main/java/org/schabi/newpipe/MediaFormat.java index 8d41d606d..fb2a508c5 100644 --- a/app/src/main/java/org/schabi/newpipe/MediaFormat.java +++ b/app/src/main/java/org/schabi/newpipe/MediaFormat.java @@ -1,7 +1,25 @@ package org.schabi.newpipe; /** - * Created by scc on 08/11/15. + * Created by Adam Howard on 08/11/15. + * + * Copyright (c) Christian Schabesberger + * and Adam Howard 2015 + * + * VideoListAdapter.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . */ public enum MediaFormat { // id name suffix mime type