@@ -216,7 +216,7 @@ public static boolean isHardcodedClientVersionValid() throws IOException, Extrac
216216 return response .length () > 50 ; // ensure to have a valid response
217217 }
218218
219- private static void getClientVersionAndKey () throws IOException , ExtractionException {
219+ private static void extractClientVersionAndKey () throws IOException , ExtractionException {
220220 final String url = "https://www.youtube.com/results?search_query=test" ;
221221 final String html = getDownloader ().get (url ).responseBody ();
222222 final JsonObject initialData = getInitialData (html );
@@ -259,11 +259,12 @@ private static void getClientVersionAndKey() throws IOException, ExtractionExcep
259259 contextClientVersion = Parser .matchGroup1 (pattern , html );
260260 if (!isNullOrEmpty (contextClientVersion )) {
261261 clientVersion = contextClientVersion ;
262+ break ;
262263 }
263264 } catch (Parser .RegexException ignored ) { }
264265 }
265266
266- if (shortClientVersion != null ) {
267+ if (! isNullOrEmpty ( clientVersion ) && ! isNullOrEmpty ( shortClientVersion ) ) {
267268 clientVersion = shortClientVersion ;
268269 }
269270
@@ -283,7 +284,7 @@ public static String getClientVersion() throws IOException, ExtractionException
283284 if (!isNullOrEmpty (clientVersion )) return clientVersion ;
284285 if (isHardcodedClientVersionValid ()) return clientVersion = HARDCODED_CLIENT_VERSION ;
285286
286- getClientVersionAndKey ();
287+ extractClientVersionAndKey ();
287288 if (isNullOrEmpty (key )) throw new ParsingException ("Could not extract client version" );
288289 return clientVersion ;
289290 }
@@ -294,7 +295,7 @@ public static String getClientVersion() throws IOException, ExtractionException
294295 public static String getKey () throws IOException , ExtractionException {
295296 if (!isNullOrEmpty (key )) return key ;
296297
297- getClientVersionAndKey ();
298+ extractClientVersionAndKey ();
298299 if (isNullOrEmpty (key )) throw new ParsingException ("Could not extract key" );
299300 return key ;
300301 }
0 commit comments