From 8aff134c569cc70b7d8dbf96e221b567dcf8ec06 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Sun, 8 Nov 2015 01:09:03 +0000 Subject: [PATCH 01/19] 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 02/19] 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 03/19] 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 224e7a89695ade2ee03f4d5464d4d32081adc7ee Mon Sep 17 00:00:00 2001 From: chschtsch Date: Tue, 10 Nov 2015 19:50:04 +0300 Subject: [PATCH 04/19] update date extracting regex pattern + fix some strings in English --- .idea/dictionaries/the_scrabi.xml | 3 --- .idea/gradle.xml | 5 ++--- .idea/misc.xml | 2 +- .idea/vcs.xml | 2 +- app/app.iml | 8 ++++---- app/src/main/java/org/schabi/newpipe/Downloader.java | 1 + .../org/schabi/newpipe/youtube/YoutubeExtractor.java | 7 +++++-- app/src/main/res/values/strings.xml | 12 ++++++------ 8 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 .idea/dictionaries/the_scrabi.xml diff --git a/.idea/dictionaries/the_scrabi.xml b/.idea/dictionaries/the_scrabi.xml deleted file mode 100644 index bc8411615..000000000 --- a/.idea/dictionaries/the_scrabi.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index bd4202cb3..1bbc21dc2 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -3,10 +3,9 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f4..6564d52db 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 58221a4e6..eefc8deb7 100644 --- a/app/app.iml +++ b/app/app.iml @@ -92,12 +92,12 @@ + + + + - - - - \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index edf839ac2..43dcc6c41 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -37,6 +37,7 @@ public class Downloader { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); + con.setRequestProperty("Accept-Language", "en"); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); 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 8ba344361..3c659306b 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -288,8 +288,8 @@ public class YoutubeExtractor implements Extractor { videoInfo.upload_date = doc.select("strong[class=\"watch-time-text\"").first() .text(); - // Try to only use date not the text around it - videoInfo.upload_date = matchGroup1("([0-9.]*$)", videoInfo.upload_date); + // Extracting the date itself from header + videoInfo.upload_date = matchGroup1("([A-Za-z]{3}\\s[\\d]{1,2},\\s[\\d]{4}$)", videoInfo.upload_date); // description videoInfo.description = doc.select("p[id=\"eow-description\"]").first() @@ -320,6 +320,9 @@ public class YoutubeExtractor implements Extractor { // view count videoInfo.view_count = doc.select("div[class=\"watch-view-count\"]").first().text(); + // Extract view count from header + videoInfo.view_count = matchGroup1("([\\d]*$)", videoInfo.view_count); + // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() .select("li").first()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 41f6b5530..2ad31ef9c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,7 +4,7 @@ NewPipe Nothing found views - Uploaded at: + Published on No StreamPlayer found. You may want to install one. Install one Cancel @@ -45,9 +45,9 @@ Video Audio - Next Video - Show next and similar Videos. - Url not Supported. - Similar Videos - Video Content Country + Next video + Show next and similar videos + URL not supported. + Similar videos + Preferable content location \ No newline at end of file From 61a09e97cad822d40effe8f02a90b5843dee86af Mon Sep 17 00:00:00 2001 From: chschtsch Date: Tue, 10 Nov 2015 19:55:58 +0300 Subject: [PATCH 05/19] update colors (implementing redesign suggested by @darkon5) --- .../java/org/schabi/newpipe/youtube/YoutubeExtractor.java | 3 --- app/src/main/res/values/colors.xml | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) 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 3c659306b..dcf9d35ed 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -320,9 +320,6 @@ public class YoutubeExtractor implements Extractor { // view count videoInfo.view_count = doc.select("div[class=\"watch-view-count\"]").first().text(); - // Extract view count from header - videoInfo.view_count = matchGroup1("([\\d]*$)", videoInfo.view_count); - // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() .select("li").first()); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index b444b0725..93a3a82d1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,7 +1,7 @@ - #dd0000 - #bb0000 + #cd322e + #bc211d #000000 #66000000 \ No newline at end of file From 27b450f1e30a421b9bdf7d36193bd818aa8f809a Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Tue, 10 Nov 2015 17:09:26 +0000 Subject: [PATCH 06/19] 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 07/19] 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 From 862b5aaef64a2fe21e42ba7dfb0cc5e1c909b161 Mon Sep 17 00:00:00 2001 From: chschtsch Date: Tue, 10 Nov 2015 20:26:20 +0300 Subject: [PATCH 08/19] update layout (implementing redesign suggested by @darkon5) & set english as a default language for content --- .../newpipe/VideoInfoItemViewCreator.java | 2 +- .../newpipe/youtube/YoutubeExtractor.java | 2 + app/src/main/res/drawable/budy.png | Bin 3372 -> 0 bytes app/src/main/res/drawable/dummi_thumbnail.png | Bin 2654 -> 0 bytes .../layout-land/fragment_videoitem_detail.xml | 4 +- .../fragment_videoitem_detail.xml | 4 +- .../res/layout/fragment_videoitem_detail.xml | 40 +++++++++++------- app/src/main/res/layout/video_item.xml | 2 +- app/src/main/res/values/dimentxt.xml | 6 +++ 9 files changed, 39 insertions(+), 21 deletions(-) delete mode 100644 app/src/main/res/drawable/budy.png delete mode 100644 app/src/main/res/drawable/dummi_thumbnail.png diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java index e6618ddbf..d15d6b86a 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java @@ -51,7 +51,7 @@ public class VideoInfoItemViewCreator { } if(info.thumbnail == null) { - holder.itemThumbnailView.setImageResource(R.drawable.dummi_thumbnail); + holder.itemThumbnailView.setImageResource(R.drawable.dummy_thumbnail); } else { holder.itemThumbnailView.setImageBitmap(info.thumbnail); } 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 dcf9d35ed..1b4359baa 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -320,6 +320,8 @@ public class YoutubeExtractor implements Extractor { // view count videoInfo.view_count = doc.select("div[class=\"watch-view-count\"]").first().text(); + videoInfo.view_count = matchGroup1("([0-9,]*$)", videoInfo.view_count); + // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() .select("li").first()); diff --git a/app/src/main/res/drawable/budy.png b/app/src/main/res/drawable/budy.png deleted file mode 100644 index 1b414ffa7e5d7530e7e79b21fc931cadd4df2f13..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3372 zcmb_fi9gg^8=s}DW6gfO40j6Agd}O~L$*dnw;LI2)@*|sy9qJ&Z6aZ0`D^ZHP*6RWyzl8J??$~g!lJ(e#<%M`90@6=Q-#5eNOU4+<5^$89oREB4A;T#e;X} z!Og=3o|RXsXyA1y#Mt5z54fUuu2DdlH^|&R1n3VP+)!iX!Z1)N9cp?d)Gp97l;j%h z0U?n{XrF-VA?~h09_YYeufipa3R&sk)Vr)Dz_IxQ-C0O)C;VI6BTk$ zMq;MsIfpD&P!=%AQ#JkuN5MP~g_53@8Z|M#!+!q$dix`vJ|%dp{;2mubjEczPd1_* zhi=b>^R%p(RBP~C%62^7XI@lx@$%v>$MXWYdi83_lj2|PWHm!EQ>o03AX)CJMa2~Q zofm;pi99XBGpkaNte!dB<99B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5ltaNbn1_lmRgGSnPOZiHLk7fC^pv4Qh^6{#gVNTQLw!G)rjJB zsu<_G8phk(MOTh%lW$Upu$M|as6S#V0ykd2r;|~#X+)V1w8(iq-7-aSY6pi0kkIeL Y`&9ohc)97&22M5*3sW4n%Gf3Dzk|#_`2YX_ diff --git a/app/src/main/res/drawable/dummi_thumbnail.png b/app/src/main/res/drawable/dummi_thumbnail.png deleted file mode 100644 index 24230b261e2f1b48cb929f3ee564cef0288d075f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2654 zcmd^Bi$BxrAD=XrRj4MHBm530np5U*N}ZMLxVB_2GzF~hS2QKGc^(xE>V-Rc zg?o}Og-4wWy9kMjirRlUlfL7YjKx4CNDdu|4Jt z24nu~c!%uEpM|6AtI`Nd)m++mjSl36WLYH8)kyF85?(A2@!s8=yMRR`aBV)UugBHK zuOHUX)Erw|L-EG02{D@t?OA~ei?aDvqcNGxRxTU60}P z;}G9=J?)m5wwysKDsv=Mm)T=}_zyQcVSEjCZzqD@A5>+yMh0rvmIdT%@$rTPLW@`| zX3CBHmSeLYQQcp=jxH}B=<4bk1%}GY%b&bL_?=0Cjm|BU5-Uh8ot-Cz9ZE;P$4lnrM1Q_b3ndajf>M~l#s0$M(x288uMRGt?`M&nIeQ>zi(?{B3qM~%_Cn7 zHk#Qoi>W_^tgjcc$wRzA8+u7eaqpM+TmzQ|ZS9sTjoN*!AZw!x-}swNO--*}y<){2 z!u|qWI$2Y^!Usu;-B_2-H)+~67beJ0OT!)>sFoYQ?g@nJ=;&0k**aWO_u8>tnOJ)z z1r+ktIV=6!#r-oa3zOa7vB%XnT8Y-?H>AFmH$WIaFJ(+q6fnzVe9`QWo4pgT&)P+^ zJgc4yDnOr_Y7@=EF)TkNA79_r_IB6&f&!jM6fEpWQmtH4 z-Etmf*cxh^aqHHtsqn)+qR89+#cJ`Gy#*Y(;e=d%lvEeL+u7N9aQ}(zDX?Al*;_ne zMKtKaXpUrH;PfY{QXT-lI^dCgnZz_^+D86y-1`?QiTqO!-=p=P1}wb zZr{UZvIU|V23lENyM;1CiL0)zK9AIGURk*=#1u88z^Ko%v$eZjtPTP$$6~wOOZ$F` zpuOIS7%rWiopq=ilAeH5%<%OAW##2OKjaOO2qNZZ`O7Sy)&^SVB`^G69e0w79y?|M;;aX0Id(WLV(g-XFqdmXz>^hNKIoy8-u) zdKF%Zit3kmc`W3)&ez_VzINc?L4V*Q5Ef#Rx`D09hTinkAh!5Aa>?cvErgfWljB$f zkS&M3nH_i$V5PhDd~k4?_;G!*y0#5}dU`s2q!KKksXRE54GK&3H}e8u+&f|8LdoWn zCiuU#(pul)(a_W@Yyn^+v-iuZnn!oRrr9^0PATo9>sXR<5%y!>L}{CXuU>5iad&oh z)-X0%o8hrp?GnBMd=I}6g}`4QhUD^i0|NsGj<7stFOrCcw*QW3C{`5B_ZB5pRaLgO zwnzdk)eN7N@pOm8T~RZ_9mju2llaQ@jg!jC%BG~Nr1NTp#&|3b~Jf;rcC!vYlP*P(Vj^x zfuIgYC1D%x1I{P_iLaa6$3a5DvJ0<^!!)41W_TpDtH>`hh3>?%(7<3Ym34JS1VXeS z?2-d(cso!5$a#uLoFQr0Jizv-Ez}l&)u-lK7SSqRK7YOglzu>HfJ`bV=g_iKGffLv zpiU0d<@S9T>gsaas-oQetNra1*wJ%0{j>Tj=O3({%%DfHB;H*XA+8|n|iP0hg4U#n+w7z`#j z`Q-996m#=L;GM7aA>kqTeOFdsie+jm=wVoaFPD~ + android:src="@drawable/dummy_thumbnail"/> + android:src="@drawable/buddy" /> + android:src="@drawable/dummy_thumbnail"/> + android:src="@drawable/buddy" /> + android:src="@drawable/dummy_thumbnail"/> + android:text="Video title placeholder"/> + android:src="@drawable/buddy" /> + android:textStyle="bold" + android:textSize="@dimen/text_video_uploader_size" + android:textAppearance="?android:attr/textAppearanceLarge" + android:text="username" /> + android:text="81,754 views" /> + android:text="100" /> + android:text="20" /> + android:text="Published on Jan 01 1975" /> @@ -204,10 +214,10 @@ + android:layout_margin="20dp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/video_item.xml b/app/src/main/res/layout/video_item.xml index d25f524b6..e20e38ce2 100644 --- a/app/src/main/res/layout/video_item.xml +++ b/app/src/main/res/layout/video_item.xml @@ -12,7 +12,7 @@ android:scaleType="centerCrop" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" - android:src="@drawable/dummi_thumbnail"/> + android:src="@drawable/dummy_thumbnail"/> 11sp 12sp 12sp + 14sp + 14sp + 12sp + 14sp + 14sp + 14sp \ No newline at end of file From c589b03dcbd4f8f2f85fa8377f31f877a05bc86b Mon Sep 17 00:00:00 2001 From: chschtsch Date: Tue, 10 Nov 2015 20:28:05 +0300 Subject: [PATCH 09/19] rollback setting English as a default language for content --- app/src/main/java/org/schabi/newpipe/Downloader.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/Downloader.java b/app/src/main/java/org/schabi/newpipe/Downloader.java index 43dcc6c41..edf839ac2 100644 --- a/app/src/main/java/org/schabi/newpipe/Downloader.java +++ b/app/src/main/java/org/schabi/newpipe/Downloader.java @@ -37,7 +37,6 @@ public class Downloader { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); - con.setRequestProperty("Accept-Language", "en"); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); From 7ff43caf964d22788a019d0fe1ce72d0d3cd075d Mon Sep 17 00:00:00 2001 From: chschtsch Date: Tue, 10 Nov 2015 20:36:35 +0300 Subject: [PATCH 10/19] tryna merge dem files --- .../java/org/schabi/newpipe/youtube/YoutubeExtractor.java | 7 +++++-- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) 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 c77ced40f..2b7fbf8e4 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -288,8 +288,8 @@ public class YoutubeExtractor implements Extractor { videoInfo.upload_date = doc.select("strong[class=\"watch-time-text\"").first() .text(); - // Try to only use date not the text around it - videoInfo.upload_date = matchGroup1("([0-9.]*$)", videoInfo.upload_date); + // Extracting the date itself from header + videoInfo.upload_date = matchGroup1("([A-Za-z]{3}\\s[\\d]{1,2},\\s[\\d]{4}$)", videoInfo.upload_date); // description videoInfo.description = doc.select("p[id=\"eow-description\"]").first() @@ -320,6 +320,9 @@ public class YoutubeExtractor implements Extractor { // view count videoInfo.view_count = doc.select("div[class=\"watch-view-count\"]").first().text(); + // Extracting the number of views from header + videoInfo.view_count = matchGroup1("([0-9,]*$)", videoInfo.view_count); + // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() .select("li").first()); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d61ab8489..a86ea5544 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,5 +49,5 @@ Show next and similar videos URL not supported. Similar videos - Preferable content language + Preferable content language \ No newline at end of file From 731321b1f9016c6594dc78c4ce644b35cb29049f Mon Sep 17 00:00:00 2001 From: chschtsch Date: Tue, 10 Nov 2015 20:50:15 +0300 Subject: [PATCH 11/19] tryna merge dem files --- app/src/main/res/drawable/buddy.png | Bin 0 -> 3372 bytes app/src/main/res/drawable/dummy_thumbnail.png | Bin 0 -> 2654 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/src/main/res/drawable/buddy.png create mode 100644 app/src/main/res/drawable/dummy_thumbnail.png diff --git a/app/src/main/res/drawable/buddy.png b/app/src/main/res/drawable/buddy.png new file mode 100644 index 0000000000000000000000000000000000000000..1b414ffa7e5d7530e7e79b21fc931cadd4df2f13 GIT binary patch literal 3372 zcmb_fi9gg^8=s}DW6gfO40j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dm)9NMt|D6>J5oFLtszzMZO%>B z-jbKzE9tC}DirDM8!`DE94Jf$@eJLN#7o&;eqNQj8uoMcm6ZSp5+=dC-M7vm5UpFz z^?7wQ+eQ!Ne%p0>ws-qaxTvW}1be*sz-9omaFq9jOjbw7`K9ozRnJ%F*X~IkC}ie- z7zHU<^`_!Ut_MSlMEm@~MEqX^f>YIGltps`cV%$^b9b6LU41Z}t;82ObV`k4#*C!R z?k{oS_j=w0_Bv<(1oGwb+E%BJKYM)-6n=gabRflgPM!snm}XXXM-odt8vEXa2A>X> z%e?bpG?hNj+@;ar-)Xt&*u}{qHIT8#Zr^y~3bhe(pR9f_s>d5Qxl<4*0U5uJTTdFf z5I0yIt3X#`;NqbQ5ltaNbn1_lmRgGSnPOZiHLk7fC^pv4Qh^6{#gVNTQLw!G)rjJB zsu<_G8phk(MOTh%lW$Upu$M|as6S#V0ykd2r;|~#X+)V1w8(iq-7-aSY6pi0kkIeL Y`&9ohc)97&22M5*3sW4n%Gf3Dzk|#_`2YX_ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/dummy_thumbnail.png b/app/src/main/res/drawable/dummy_thumbnail.png new file mode 100644 index 0000000000000000000000000000000000000000..24230b261e2f1b48cb929f3ee564cef0288d075f GIT binary patch literal 2654 zcmd^Bi$BxrAD=XrRj4MHBm530np5U*N}ZMLxVB_2GzF~hS2QKGc^(xE>V-Rc zg?o}Og-4wWy9kMjirRlUlfL7YjKx4CNDdu|4Jt z24nu~c!%uEpM|6AtI`Nd)m++mjSl36WLYH8)kyF85?(A2@!s8=yMRR`aBV)UugBHK zuOHUX)Erw|L-EG02{D@t?OA~ei?aDvqcNGxRxTU60}P z;}G9=J?)m5wwysKDsv=Mm)T=}_zyQcVSEjCZzqD@A5>+yMh0rvmIdT%@$rTPLW@`| zX3CBHmSeLYQQcp=jxH}B=<4bk1%}GY%b&bL_?=0Cjm|BU5-Uh8ot-Cz9ZE;P$4lnrM1Q_b3ndajf>M~l#s0$M(x288uMRGt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v zpiU0d<@S9T>gsaas-oQetNra1*wJ%0{j>Tj=O3({%%DfHB;H*XA+8|n|iP0hg4U#n+w7z`#j z`Q-996m#=L;GM7aA>kqTeOFdsie+jm=wVoaFPD~ Date: Tue, 10 Nov 2015 20:51:39 +0100 Subject: [PATCH 12/19] New version number 0.6.0 and some fixes: * moved on to version 0.6.0 * fixed youtube url sicnature encryption (vevo videos can be watched again) * removed play action from the ActionBar * rolled back changes for hiding the InfoBar inside PlayVideoActivity * some small layout changes * removed some files to be ignored (mostly inside .idea directory) * etc --- .gitignore | 1 + .idea/gradle.xml | 18 --- .idea/misc.xml | 46 -------- .idea/vcs.xml | 2 +- app/.gitignore | 2 +- app/app.iml | 103 ------------------ app/build.gradle | 4 +- .../org/schabi/newpipe/ActionBarHandler.java | 15 +-- .../org/schabi/newpipe/PlayVideoActivity.java | 5 +- .../newpipe/youtube/YoutubeExtractor.java | 14 ++- .../newpipe/youtube/YoutubeSearchEngine.java | 1 - .../res/drawable/ic_file_download_black.png | Bin 0 -> 209 bytes .../res/layout/fragment_videoitem_detail.xml | 2 +- app/src/main/res/menu/videoitem_detail.xml | 15 +-- 14 files changed, 23 insertions(+), 205 deletions(-) delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 app/app.iml create mode 100644 app/src/main/res/drawable/ic_file_download_black.png diff --git a/.gitignore b/.gitignore index 09cade508..62f840669 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /captures .idea/gradle.xml .idea/misc.xml +/app/app.iml diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 1bbc21dc2..000000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1a3eaffb4..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 6564d52db..94a25f7f4 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore index 6bcbd4f70..d9a86a57c 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,3 +1,3 @@ .gitignore /build -app/app.iml +app.iml diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index eefc8deb7..000000000 --- a/app/app.iml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 5e17108de..fb41271d9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.schabi.newpipe" minSdkVersion 15 targetSdkVersion 23 - versionCode 5 - versionName "0.5.0" + versionCode 6 + versionName "0.6.0" } buildTypes { release { diff --git a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java index c46a617b6..b9bef5cfd 100644 --- a/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/ActionBarHandler.java @@ -104,11 +104,9 @@ public class ActionBarHandler { } } else if(preferedFormat.equals("m4a")){ for(VideoInfo.AudioStream s : audioStreams) { - 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"); } } } @@ -125,15 +123,8 @@ public class ActionBarHandler { defaultPreferences = PreferenceManager.getDefaultSharedPreferences(activity); inflater.inflate(R.menu.videoitem_detail, menu); - MenuItem playItem = menu.findItem(R.id.menu_item_play); - MenuItem shareItem = menu.findItem(R.id.menu_item_share); MenuItem castItem = menu.findItem(R.id.action_play_with_kodi); - MenuItemCompat.setShowAsAction(playItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS - | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); - MenuItemCompat.setShowAsAction(shareItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM - | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); - castItem.setVisible(defaultPreferences .getBoolean(activity.getString(R.string.showPlayWidthKodiPreference), false)); @@ -143,9 +134,6 @@ public class ActionBarHandler { public boolean onItemSelected(MenuItem item) { int id = item.getItemId(); switch(id) { - case R.id.menu_item_play: - playVideo(); - return true; case R.id.menu_item_share: if(!videoTitle.isEmpty()) { Intent intent = new Intent(); @@ -235,7 +223,6 @@ public class ActionBarHandler { } public void downloadVideo() { - Log.d(TAG, "bla"); if(!videoTitle.isEmpty()) { String videoSuffix = "." + MediaFormat.getSuffixById(videoStreams[selectedStream].format); String audioSuffix = "." + MediaFormat.getSuffixById(audioStream.format); @@ -321,7 +308,7 @@ public class ActionBarHandler { } }); builder.create().show(); - Log.d(TAG, "Either no Streaming player for audio was installed, or something important crashed:"); + Log.e(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/PlayVideoActivity.java b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java index 81a8aec33..d05f721a2 100644 --- a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java +++ b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java @@ -253,10 +253,9 @@ public class PlayVideoActivity extends AppCompatActivity { | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); - } else { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); } + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); } private void adjustMediaControlMetrics() { 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 2b7fbf8e4..d6b4bb835 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -289,7 +289,8 @@ public class YoutubeExtractor implements Extractor { .text(); // Extracting the date itself from header - videoInfo.upload_date = matchGroup1("([A-Za-z]{3}\\s[\\d]{1,2},\\s[\\d]{4}$)", videoInfo.upload_date); + videoInfo.upload_date = + matchGroup1("([0-9]{2}\\.[0-9]{2}\\.[0-9]{4})", videoInfo.upload_date); // description videoInfo.description = doc.select("p[id=\"eow-description\"]").first() @@ -459,12 +460,13 @@ public class YoutubeExtractor implements Extractor { try { decryptionFuncName = matchGroup1("\\.sig\\|\\|([a-zA-Z0-9$]+)\\(", playerCode); - String functionPattern = "(function " + decryptionFuncName.replace("$", "\\$") + "\\([a-zA-Z0-9_]*\\)\\{.+?\\})"; + String functionPattern = "(var "+ decryptionFuncName.replace("$", "\\$") +"=function\\([a-zA-Z0-9_]*\\)\\{.+?\\})"; decryptionFunc = matchGroup1(functionPattern, playerCode); + decryptionFunc += ";"; helperObjectName = matchGroup1(";([A-Za-z0-9_\\$]{2})\\...\\(", decryptionFunc); - String helperPattern = "(var " + helperObjectName.replace("$", "\\$") + "=\\{.+?\\}\\};)function"; + String helperPattern = "(var " + helperObjectName.replace("$", "\\$") + "=\\{.+?\\}\\};)"; helperObject = matchGroup1(helperPattern, playerCode); } catch (Exception e) { @@ -477,13 +479,13 @@ public class YoutubeExtractor implements Extractor { return decryptionCode; } - private String decryptSignature(String encryptedSig, String decryptoinCode) { + private String decryptSignature(String encryptedSig, String decryptionCode) { Context context = Context.enter(); context.setOptimizationLevel(-1); Object result = null; try { ScriptableObject scope = context.initStandardObjects(); - context.evaluateString(scope, decryptoinCode, "decryptionCode", 1, null); + context.evaluateString(scope, decryptionCode, "decryptionCode", 1, null); Function decryptionFunc = (Function) scope.get("decrypt", scope); result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig}); } catch (Exception e) { @@ -501,7 +503,7 @@ public class YoutubeExtractor implements Extractor { return mat.group(1); } else { - Log.e(TAG, "failed to find pattern \""+pattern+"\""); + Log.e(TAG, "failed to find pattern \""+pattern+"\"inside of \""+input+"\""); new Exception("failed to find pattern \""+pattern+"\"").printStackTrace(); return ""; } 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 7d9631ac2..18bbf4337 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeSearchEngine.java @@ -64,7 +64,6 @@ public class YoutubeSearchEngine implements SearchEngine { //if we've been passed a valid language code, append it to the URL if(languageCode.length() > 0) { //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 { diff --git a/app/src/main/res/drawable/ic_file_download_black.png b/app/src/main/res/drawable/ic_file_download_black.png new file mode 100644 index 0000000000000000000000000000000000000000..8c83bffa7e4443c2f9bc5c037152366bbd2b2a8c GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeG3?%1&o4*=JaR&H=xB_ViXik240LWr43GxeO z_}|d-YF7`CTjJ^B7*fIb_UuMphX4_Wz@K-epY(rm$rSOv5x&UEQI+e--EU&)I|8Rx zn`YUVUt2QqqO7p8jPYX2Y1uALFv!Bh(&V7xf`I2(I$9v`=tPEz0uwjrB`PNJK1xr$ eb^X}yRc5jUbNLGR3)cYcXYh3Ob6Mw<&;$VajYK&B literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/fragment_videoitem_detail.xml b/app/src/main/res/layout/fragment_videoitem_detail.xml index 22fc077d8..698883608 100644 --- a/app/src/main/res/layout/fragment_videoitem_detail.xml +++ b/app/src/main/res/layout/fragment_videoitem_detail.xml @@ -214,7 +214,7 @@ - + + - - From 873564f2aa42e04955fab8c376ce0ee90684b586 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 10 Nov 2015 21:16:11 +0100 Subject: [PATCH 13/19] removed .idea folder --- .gitignore | 5 +---- .idea/.name | 1 - .idea/compiler.xml | 22 ---------------------- .idea/copyright/profiles_settings.xml | 3 --- .idea/modules.xml | 9 --------- .idea/runConfigurations.xml | 12 ------------ .idea/vcs.xml | 6 ------ 7 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 62f840669..f6e554c09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,8 @@ .gitignore .gradle /local.properties -/.idea/workspace.xml -/.idea/libraries .DS_Store /build /captures -.idea/gradle.xml -.idea/misc.xml /app/app.iml +/.idea diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 0c8ef9fd5..000000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -NewPipe \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43efa..000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf337..000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index ff02d86b4..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460d8..000000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f4..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 3411b5345044dbaf1eb355d6ba4e2a851773269c Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Wed, 11 Nov 2015 01:48:44 +0000 Subject: [PATCH 14/19] implemented optimised version of YoutubeExtractor.getVideoId(). new version uses a regular expression instead of creating a HashMap and looping over them. Needs testing before pushing to origin --- .../java/org/schabi/newpipe/MediaFormat.java | 2 +- .../newpipe/VideoItemDetailActivity.java | 3 +-- .../newpipe/youtube/YoutubeExtractor.java | 22 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/MediaFormat.java b/app/src/main/java/org/schabi/newpipe/MediaFormat.java index fb2a508c5..6a37c3fd7 100644 --- a/app/src/main/java/org/schabi/newpipe/MediaFormat.java +++ b/app/src/main/java/org/schabi/newpipe/MediaFormat.java @@ -24,7 +24,7 @@ package org.schabi.newpipe; public enum MediaFormat { // id name suffix mime type MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"), - v3GPP (0x1, "3GPP", "3gp", "video/3gpp"), + v3GPP (0x1, "3GPP", "3gp", "video/3gpp"), WEBM (0x2, "WebM", "webm", "video/webm"), M4A (0x3, "m4a", "m4a", "audio/mp4"), WEBMA (0x4, "WebM", "webm", "audio/webm"); diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java index 370ac2fb2..34d491233 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java @@ -67,8 +67,7 @@ public class VideoItemDetailActivity extends AppCompatActivity { arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, i); try { currentStreamingService = i; - extractor = ServiceList.getService(i) - .getExtractorInstance(); + extractor = ServiceList.getService(i).getExtractorInstance(); } catch (Exception e) { e.printStackTrace(); } 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 d6b4bb835..a9cf3807a 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -130,6 +130,26 @@ public class YoutubeExtractor implements Extractor { } } + @Override + public String getVideoId(String videoUrl) { + //https://www.youtube.com/watch?v=laF2D3QyAFQ + String id; + Pattern pat; + if(videoUrl.contains("youtube")) { + pat = Pattern.compile("youtube\\.com/watch\\?v=([a-zA-Z0-9_]{11})"); + } + else if(videoUrl.contains("youtu.be")) { + pat = Pattern.compile("youtu\\.be/([a-zA-Z0-9_]{11})"); + } + else { + Log.e(TAG, "Error could not parse url: " + videoUrl); + return ""; + } + Matcher mat = pat.matcher(videoUrl); + id = mat.group(1); + return (id == null ? "" : id); + } +/* @Override public String getVideoId(String videoUrl) { try { @@ -165,7 +185,7 @@ public class YoutubeExtractor implements Extractor { } return null; } - +*/ @Override public String getVideoUrl(String videoId) { return "https://www.youtube.com/watch?v=" + videoId; From 3bfc82f7c0d7c85585786cc8e2556a20da9ca112 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Wed, 11 Nov 2015 13:07:09 +0000 Subject: [PATCH 15/19] Refactoring YoutubeExtractor: -replaced single use of terrible_unescape_workaround_fuck(String) with call to URLDecoder.decode(String, String) * tested new regex implementation of YoutubeExtractor.getVideoId(String) - deleted old HashMap-based implementation of YoutubeExtractor.getVideoId(String) * Miscellaneous typo corrections * replaced direct page-scraping extraction of video publication date in YoutubeExtractor.getVideoInfo(String) with jsoup-based scrape of tag field in YYYY-MM-DD format *similarly, replaced direct page-scraping extraction of view count with tag field. Both tag fields still need to be formatted locale-specifically --- NewPipe.iml | 19 ---- .../newpipe/youtube/YoutubeExtractor.java | 87 ++++--------------- 2 files changed, 19 insertions(+), 87 deletions(-) delete mode 100644 NewPipe.iml diff --git a/NewPipe.iml b/NewPipe.iml deleted file mode 100644 index 8d3b0cd6c..000000000 --- a/NewPipe.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file 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 a9cf3807a..48f87fa9a 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -20,6 +20,7 @@ import org.xmlpull.v1.XmlPullParser; import java.io.StringReader; import java.net.URI; +import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; import java.util.Vector; @@ -113,7 +114,7 @@ public class YoutubeExtractor implements Extractor { JSONObject jsonObj = new JSONObject(jsonString); //---------------------------------- - // load an parse description code + // load and parse description code //---------------------------------- if (decryptionCode.isEmpty()) { JSONObject ytAssets = jsonObj.getJSONObject("assets"); @@ -149,43 +150,7 @@ public class YoutubeExtractor implements Extractor { id = mat.group(1); return (id == null ? "" : id); } -/* - @Override - public String getVideoId(String videoUrl) { - try { - URI uri = new URI(videoUrl); - if(uri.getHost().contains("youtube")) { - String query = uri.getFragment(); - if(query == null) { - query = uri.getQuery(); - } else { - query = query.replace("/watch?", ""); - } - String queryElements[] = query.split("&"); - Map queryArguments = new HashMap<>(); - for (String e : queryElements) { - String[] s = e.split("="); - queryArguments.put(s[0], s[1]); - } - return queryArguments.get("v"); - } else if(uri.getHost().contains("youtu.be")) { - // uri.getRawPath() does somehow not return the last character. - // so we do a workaround instead. - //return uri.getRawPath(); - String url[] = videoUrl.split("/"); - return url[url.length-1]; - } else { - Log.e(TAG, "Error could not parse url: " + videoUrl); - } - } catch(Exception e) { - Log.e(TAG, "Error could not parse url: " + videoUrl); - e.printStackTrace(); - return ""; - } - return null; - } -*/ @Override public String getVideoUrl(String videoId) { return "https://www.youtube.com/watch?v=" + videoId; @@ -198,18 +163,17 @@ public class YoutubeExtractor implements Extractor { Document doc = Jsoup.parse(site, siteUrl); - videoInfo.id = matchGroup1("v=([0-9a-zA-Z]*)", siteUrl); + videoInfo.id = matchGroup1("v=([0-9a-zA-Z]{10,})", siteUrl); videoInfo.age_limit = 0; videoInfo.webpage_url = siteUrl; - initService(site); //------------------------------------- // extracting form player args //------------------------------------- - JSONObject playerArgs = null; + JSONObject playerArgs; { try { String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site); @@ -221,6 +185,8 @@ public class YoutubeExtractor implements Extractor { // If we fail in this part the video is most likely not available. // Determining why is done later. videoInfo.videoAvailableStatus = VideoInfo.VIDEO_UNAVAILABLE; + //exit early, since we can't extract other args + return videoInfo; } } @@ -244,7 +210,7 @@ public class YoutubeExtractor implements Extractor { videoInfo.uploader = playerArgs.getString("author"); videoInfo.title = playerArgs.getString("title"); - //first attempt gating a small image version + //first attempt getting a small image version //in the html extracting part we try to get a thumbnail with a higher resolution videoInfo.thumbnail_url = playerArgs.getString("thumbnail_url"); videoInfo.duration = playerArgs.getInt("length_seconds"); @@ -263,7 +229,7 @@ public class YoutubeExtractor implements Extractor { } int itag = Integer.parseInt(tags.get("itag")); - String streamUrl = terrible_unescape_workaround_fuck(tags.get("url")); + String streamUrl = URLDecoder.decode(tags.get("url"), "UTF-8"); // if video has a signature: decrypt it and add it to the url if(tags.get("s") != null) { @@ -301,16 +267,19 @@ public class YoutubeExtractor implements Extractor { videoInfo.thumbnail_url = doc.select("link[itemprop=\"thumbnailUrl\"]").first() .attr("abs:href"); } catch(Exception e) { - Log.i(TAG, "Could not find high res Thumbnail. Use low res instead"); + Log.i(TAG, "Could not find high res Thumbnail. Using low res instead"); } // upload date - videoInfo.upload_date = doc.select("strong[class=\"watch-time-text\"").first() - .text(); + //videoInfo.upload_date = doc.select("strong[class=\"watch-time-text\"").first().text(); + videoInfo.upload_date = doc.select("meta[itemprop=datePublished]").attr("content"); // Extracting the date itself from header - videoInfo.upload_date = - matchGroup1("([0-9]{2}\\.[0-9]{2}\\.[0-9]{4})", videoInfo.upload_date); + //videoInfo.upload_date = + // matchGroup1("([0-9]{2}\\.[0-9]{2}\\.[0-9]{4})", videoInfo.upload_date); + + //TODO: Format date locale-specifically + // description videoInfo.description = doc.select("p[id=\"eow-description\"]").first() @@ -322,7 +291,6 @@ public class YoutubeExtractor implements Extractor { .getAllElements().select("button") .select("span").get(0).text(); - // dislikes videoInfo.dislike_count = doc.select("span[class=\"like-button-renderer \"]").first() .getAllElements().select("button") @@ -339,23 +307,18 @@ public class YoutubeExtractor implements Extractor { .attr("abs:data-thumb"); // view count - videoInfo.view_count = doc.select("div[class=\"watch-view-count\"]").first().text(); - - // Extracting the number of views from header - videoInfo.view_count = matchGroup1("([0-9,]*$)", videoInfo.view_count); + videoInfo.view_count = doc.select("meta[itemprop=interactionCount]").attr("content"); // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() .select("li").first()); - int i = 0; // related videos Vector relatedVideos = new Vector<>(); for(Element li : doc.select("ul[id=\"watch-related\"]").first().children()) { // first check if we have a playlist. If so leave them out if(li.select("a[class*=\"content-link\"]").first() != null) { relatedVideos.add(extractVideoInfoItem(li)); - i++; } } videoInfo.relatedVideos = relatedVideos.toArray(new VideoInfoItem[relatedVideos.size()]); @@ -436,6 +399,7 @@ public class YoutubeExtractor implements Extractor { e.printStackTrace(); } + //todo: check NullPointerException causing info.title = li.select("span[class=\"title\"]").first().text(); info.view_count = li.select("span[class*=\"view-count\"]").first().text(); info.uploader = li.select("span[class=\"g-hovercard\"]").first().text(); @@ -455,19 +419,6 @@ public class YoutubeExtractor implements Extractor { return info; } - private String terrible_unescape_workaround_fuck(String shit) { - String[] splitAtEscape = shit.split("%"); - String retval = ""; - retval += splitAtEscape[0]; - for(int i = 1; i < splitAtEscape.length; i++) { - String escNum = splitAtEscape[i].substring(0, 2); - char c = (char) Integer.parseInt(escNum,16); - retval += c; - retval += splitAtEscape[i].substring(2); - } - return retval; - } - private String loadDecryptionCode(String playerUrl) { String playerCode = Downloader.download(playerUrl); String decryptionFuncName = ""; @@ -523,7 +474,7 @@ public class YoutubeExtractor implements Extractor { return mat.group(1); } else { - Log.e(TAG, "failed to find pattern \""+pattern+"\"inside of \""+input+"\""); + Log.e(TAG, "failed to find pattern \""+pattern+"\" inside of \""+input+"\""); new Exception("failed to find pattern \""+pattern+"\"").printStackTrace(); return ""; } From c5084901b5d9bfcba0b7d639c3857c257dde3ddf Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Wed, 11 Nov 2015 13:08:53 +0000 Subject: [PATCH 16/19] removed commented-out code, added another TODO note --- .../java/org/schabi/newpipe/youtube/YoutubeExtractor.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 48f87fa9a..3eb825a92 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -271,13 +271,8 @@ public class YoutubeExtractor implements Extractor { } // upload date - //videoInfo.upload_date = doc.select("strong[class=\"watch-time-text\"").first().text(); videoInfo.upload_date = doc.select("meta[itemprop=datePublished]").attr("content"); - // Extracting the date itself from header - //videoInfo.upload_date = - // matchGroup1("([0-9]{2}\\.[0-9]{2}\\.[0-9]{4})", videoInfo.upload_date); - //TODO: Format date locale-specifically @@ -306,7 +301,7 @@ public class YoutubeExtractor implements Extractor { .select("img").first() .attr("abs:data-thumb"); - // view count + // view count TODO: format locale-specifically videoInfo.view_count = doc.select("meta[itemprop=interactionCount]").attr("content"); // next video From 67ba12660266100aef1b8b2fc7b29792ff1f569d Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Wed, 11 Nov 2015 16:23:22 +0000 Subject: [PATCH 17/19] implemented locale-specific formatting of view, like and dislike counts, and video published date --- .../java/org/schabi/newpipe/VideoInfo.java | 15 ++--- .../newpipe/VideoItemDetailActivity.java | 2 + .../newpipe/VideoItemDetailFragment.java | 50 +++++++++++++++-- .../schabi/newpipe/VideoItemListActivity.java | 2 +- .../newpipe/youtube/YoutubeExtractor.java | 56 +++++++++++-------- 5 files changed, 86 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/VideoInfo.java index 55aa3c8ee..2b8dfc8e9 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfo.java @@ -2,6 +2,8 @@ package org.schabi.newpipe; import android.graphics.Bitmap; import android.util.Log; + +import java.util.Date; import java.util.Vector; /** @@ -33,15 +35,15 @@ public class VideoInfo { public Bitmap thumbnail = null; public String webpage_url = ""; public String upload_date = ""; - public String view_count = ""; + public long view_count = 0; 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 int like_count = 0; + public int dislike_count = 0; public String average_rating = ""; public VideoStream[] videoStreams = null; public AudioStream[] audioStreams = null; @@ -64,11 +66,6 @@ public class VideoInfo { public String resolution = ""; } - protected static void formatNotKnown(int id) { - Log.e(TAG, "format not known: \"" + - Integer.toString(id) + "\". Call the programmers, they messed it up!"); - } - public static class AudioStream { public AudioStream(String url, int format, int bandwidth, int samplingRate) { this.url = url; this.format = format; @@ -78,7 +75,5 @@ public class VideoInfo { public int format = -1; public int bandwidth = -1; public int samplingRate = -1; - } - } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java index 34d491233..2ba09c189 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.NavUtils; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -60,6 +61,7 @@ public class VideoItemDetailActivity extends AppCompatActivity { // this means the video was called though another app if (getIntent().getData() != null) { videoUrl = getIntent().getData().toString(); + Log.i(TAG, "video URL passed:\"" + videoUrl + "\""); StreamingService[] serviceList = ServiceList.getServices(); Extractor extractor = null; for (int i = 0; i < serviceList.length; i++) { diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index aab57e23f..e27d02278 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -2,6 +2,7 @@ package org.schabi.newpipe; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; @@ -29,6 +30,11 @@ import android.widget.TextView; import android.view.MenuItem; import java.net.URL; +import java.text.DateFormat; +import java.text.NumberFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; import java.util.Vector; @@ -216,12 +222,31 @@ public class VideoItemDetailFragment extends Fragment { case VideoInfo.VIDEO_AVAILABLE: { videoTitleView.setText(info.title); uploaderView.setText(info.uploader); - viewCountView.setText(info.view_count + + Locale locale = getPreferredLocale(); + NumberFormat nf = NumberFormat.getInstance(locale); + String localisedViewCount = nf.format(info.view_count); + viewCountView.setText(localisedViewCount + " " + activity.getString(R.string.viewSufix)); - thumbsUpView.setText(info.like_count); - thumbsDownView.setText(info.dislike_count); + + + thumbsUpView.setText(nf.format(info.like_count)); + thumbsDownView.setText(nf.format(info.dislike_count)); + + //this is horribly convoluted + //TODO: find a better way to convert YYYY-MM-DD to a locale-specific date + //suggestions welcome + int year = Integer.parseInt(info.upload_date.substring(0, 4)); + int month = Integer.parseInt(info.upload_date.substring(5, 7)); + int date = Integer.parseInt(info.upload_date.substring(8, 10)); + Calendar cal = Calendar.getInstance(); + cal.set(year, month, date); + Date datum = cal.getTime(); + DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); + + String localisedDate = df.format(datum); uploadDateView.setText( - activity.getString(R.string.uploadDatePrefix) + " " + info.upload_date); + activity.getString(R.string.uploadDatePrefix) + " " + localisedDate); descriptionView.setText(Html.fromHtml(info.description)); descriptionView.setMovementMethod(LinkMovementMethod.getInstance()); @@ -369,6 +394,23 @@ public class VideoItemDetailFragment extends Fragment { } } + public Locale getPreferredLocale() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); + String languageKey = getContext().getString(R.string.searchLanguage); + String languageCode = "en";//i know the following lines defaults languageCode to "en", but java is picky about uninitialised values + languageCode = sp.getString(languageKey, "en"); + + if(languageCode.length() == 2) { + return new Locale(languageCode); + } + else if(languageCode.contains("_")) { + String country = languageCode + .substring(languageCode.indexOf("_"), languageCode.length()); + return new Locale(languageCode.substring(0, 2), country); + } + return Locale.getDefault(); + } + public boolean checkIfLandscape() { DisplayMetrics displayMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java index ffb1c9697..856497649 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java @@ -103,7 +103,7 @@ public class VideoItemListActivity extends AppCompatActivity super.onCreate(savedInstanceState); setContentView(R.layout.activity_videoitem_list); - //-------- remove this line when multiservice support is implemented ---------- + //------ todo: remove this line when multiservice support is implemented ------ currentStreamingServiceId = ServiceList.getIdOfService("Youtube"); //----------------------------------------------------------------------------- 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 3eb825a92..fe49cd97c 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -133,22 +133,27 @@ public class YoutubeExtractor implements Extractor { @Override public String getVideoId(String videoUrl) { - //https://www.youtube.com/watch?v=laF2D3QyAFQ - String id; + String id = ""; Pattern pat; + if(videoUrl.contains("youtube")) { - pat = Pattern.compile("youtube\\.com/watch\\?v=([a-zA-Z0-9_]{11})"); + pat = Pattern.compile("youtube\\.com/watch\\?v=([\\-a-zA-Z0-9_]{11})"); } else if(videoUrl.contains("youtu.be")) { - pat = Pattern.compile("youtu\\.be/([a-zA-Z0-9_]{11})"); + pat = Pattern.compile("youtu\\.be/([a-zA-Z0-9_-]{11})"); } else { Log.e(TAG, "Error could not parse url: " + videoUrl); return ""; } Matcher mat = pat.matcher(videoUrl); - id = mat.group(1); - return (id == null ? "" : id); + boolean foundMatch = mat.find(); + if(foundMatch){ + id = mat.group(1); + Log.i(TAG, "string \""+videoUrl+"\" matches!"); + } + Log.i(TAG, "string \""+videoUrl+"\" does not match."); + return id; } @Override @@ -163,7 +168,7 @@ public class YoutubeExtractor implements Extractor { Document doc = Jsoup.parse(site, siteUrl); - videoInfo.id = matchGroup1("v=([0-9a-zA-Z]{10,})", siteUrl); + videoInfo.id = matchGroup1("v=([0-9a-zA-Z_-]{11})", siteUrl); videoInfo.age_limit = 0; videoInfo.webpage_url = siteUrl; @@ -173,7 +178,7 @@ public class YoutubeExtractor implements Extractor { //------------------------------------- // extracting form player args //------------------------------------- - JSONObject playerArgs; + JSONObject playerArgs = null; { try { String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site); @@ -185,8 +190,6 @@ public class YoutubeExtractor implements Extractor { // If we fail in this part the video is most likely not available. // Determining why is done later. videoInfo.videoAvailableStatus = VideoInfo.VIDEO_UNAVAILABLE; - //exit early, since we can't extract other args - return videoInfo; } } @@ -277,23 +280,27 @@ public class YoutubeExtractor implements Extractor { // description - videoInfo.description = doc.select("p[id=\"eow-description\"]").first() - .html(); - + videoInfo.description = doc.select("p[id=\"eow-description\"]").first().html(); + String likesString = ""; + String dislikesString = ""; try { // likes - videoInfo.like_count = doc.select("span[class=\"like-button-renderer \"]").first() - .getAllElements().select("button") - .select("span").get(0).text(); - + likesString = doc.select("button.like-button-renderer-like-button").first() + .select("span.yt-uix-button-content").first().text(); + videoInfo.like_count = Integer.parseInt(likesString.replace(",", "")); // dislikes - videoInfo.dislike_count = doc.select("span[class=\"like-button-renderer \"]").first() - .getAllElements().select("button") - .select("span").get(2).text(); + dislikesString = doc.select("button.like-button-renderer-dislike-button").first() + .select("span.yt-uix-button-content").first().text(); + + videoInfo.dislike_count = Integer.parseInt(dislikesString.replace(",", "")); + } catch(NumberFormatException nfe) { + Log.e(TAG, "failed to parse likesString \""+likesString+"\" and dislikesString \""+ + dislikesString+"\" as integers"); } catch(Exception e) { // if it fails we know that the video does not offer dislikes. - videoInfo.like_count = "0"; - videoInfo.dislike_count = "0"; + e.printStackTrace(); + videoInfo.like_count = 0; + videoInfo.dislike_count = 0; } // uploader thumbnail @@ -301,8 +308,9 @@ public class YoutubeExtractor implements Extractor { .select("img").first() .attr("abs:data-thumb"); - // view count TODO: format locale-specifically - videoInfo.view_count = doc.select("meta[itemprop=interactionCount]").attr("content"); + // view count TODO: locale-specific formatting + String viewCountString = doc.select("meta[itemprop=interactionCount]").attr("content"); + videoInfo.view_count = Integer.parseInt(viewCountString); // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() From 145a7f8e0df5a0d6d235f6fd1d19dea3e5aea3d3 Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 12 Nov 2015 12:18:41 +0300 Subject: [PATCH 18/19] fix bug with parsing like/dislike count --- .../java/org/schabi/newpipe/youtube/YoutubeExtractor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 fe49cd97c..6d23ae038 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -287,12 +287,12 @@ public class YoutubeExtractor implements Extractor { // likes likesString = doc.select("button.like-button-renderer-like-button").first() .select("span.yt-uix-button-content").first().text(); - videoInfo.like_count = Integer.parseInt(likesString.replace(",", "")); + videoInfo.like_count = Integer.parseInt(likesString.replaceAll("[^\\d]", "")); // dislikes dislikesString = doc.select("button.like-button-renderer-dislike-button").first() .select("span.yt-uix-button-content").first().text(); - videoInfo.dislike_count = Integer.parseInt(dislikesString.replace(",", "")); + videoInfo.dislike_count = Integer.parseInt(dislikesString.replaceAll("[^\\d]", "")); } catch(NumberFormatException nfe) { Log.e(TAG, "failed to parse likesString \""+likesString+"\" and dislikesString \""+ dislikesString+"\" as integers"); From f13f9a066ac1faaad40c25d610ad5eeee90e01db Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Thu, 12 Nov 2015 15:51:22 +0000 Subject: [PATCH 19/19] updated README to include language-specific search feature --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 905208166..648a1e695 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ NewPipe does not use any Google framework libraries, or the YouTube API. It only * Download audio only (working but, but it could be better) * Open a video in Kodi * Show Next/Related videos +* Search Youtube in a specific language ## Coming Features