From fc32377ce7bfa51049619c639603e9e419f53a50 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Wed, 4 Nov 2015 00:29:30 +0000 Subject: [PATCH] added check and exception reporting to YoutubeExtractor:matchGroup1, so that a failed match doesn't go unnoticed --- .../schabi/newpipe/youtube/YoutubeExtractor.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 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 223b200e3..9cca7feea 100644 --- a/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/youtube/YoutubeExtractor.java @@ -154,9 +154,8 @@ public class YoutubeExtractor implements Extractor { JSONObject ytAssets = null; String dashManifest; { - String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site); - try { + String jsonString = matchGroup1("ytplayer.config\\s*=\\s*(\\{.*?\\});", site); JSONObject jsonObj = new JSONObject(jsonString); playerArgs = jsonObj.getJSONObject("args"); ytAssets = jsonObj.getJSONObject("assets"); @@ -461,7 +460,15 @@ public class YoutubeExtractor implements Extractor { private String matchGroup1(String pattern, String input) { Pattern pat = Pattern.compile(pattern); Matcher mat = pat.matcher(input); - mat.find(); - return mat.group(1); + boolean foundMatch = mat.find(); + if(foundMatch){ + return mat.group(1); + } + else { + Log.e(TAG, "failed to find pattern \""+pattern+"\""); + new Exception("failed to find pattern \""+pattern+"\"").printStackTrace(); + return ""; + } + } }