@@ -75,7 +75,7 @@ private YoutubeParsingHelper() {
7575
7676 private static final String [] HARDCODED_YOUTUBE_MUSIC_KEY =
7777 {"AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30" , "67" , "0.1" };
78- private static String [] youtubeMusicKeys ;
78+ private static String [] youtubeMusicKey ;
7979
8080 private static boolean keyAndVersionExtracted = false ;
8181 private static Boolean areHardcodedClientVersionAndKeyValidValue = null ;
@@ -341,7 +341,7 @@ public static boolean areHardcodedClientVersionAndKeyValid() throws IOException,
341341
342342 private static void extractClientVersionAndKey () throws IOException , ExtractionException {
343343 // Don't extract the client version and the innertube key if it has been already extracted
344- if (! keyAndVersionExtracted ) return ;
344+ if (keyAndVersionExtracted ) return ;
345345 // Don't provide a search term in order to have a smaller response
346346 final String url = "https://www.youtube.com/results?search_query=" ;
347347 final Map <String , List <String >> headers = new HashMap <>();
@@ -405,7 +405,6 @@ private static void extractClientVersionAndKey() throws IOException, ExtractionE
405405 try {
406406 key = Parser .matchGroup1 ("innertubeApiKey\" :\" ([0-9a-zA-Z_-]+?)\" " , html );
407407 } catch (final Parser .RegexException e2 ) {
408- keyAndVersionExtracted = false ;
409408 throw new ParsingException ("Could not extract client version and key" );
410409 }
411410 }
@@ -421,7 +420,7 @@ public static String getClientVersion() throws IOException, ExtractionException
421420 return clientVersion = HARDCODED_CLIENT_VERSION ;
422421 }
423422
424- if (! keyAndVersionExtracted ) extractClientVersionAndKey ();
423+ extractClientVersionAndKey ();
425424 return clientVersion ;
426425 }
427426
@@ -430,9 +429,11 @@ public static String getClientVersion() throws IOException, ExtractionException
430429 */
431430 public static String getKey () throws IOException , ExtractionException {
432431 if (!isNullOrEmpty (key )) return key ;
433- if (areHardcodedClientVersionAndKeyValid ()) return key = HARDCODED_KEY ;
432+ if (areHardcodedClientVersionAndKeyValid ()) {
433+ return key = HARDCODED_KEY ;
434+ }
434435
435- if (! keyAndVersionExtracted ) extractClientVersionAndKey ();
436+ extractClientVersionAndKey ();
436437 return key ;
437438 }
438439
@@ -465,7 +466,7 @@ public static void setNumberGenerator(Random random) {
465466 numberGenerator = random ;
466467 }
467468
468- public static boolean areHardcodedYoutubeMusicKeysValid () throws IOException ,
469+ public static boolean isHardcodedYoutubeMusicKeyValid () throws IOException ,
469470 ReCaptchaException {
470471 final String url =
471472 "https://music.youtube.com/youtubei/v1/music/get_search_suggestions?alt=json&key="
@@ -510,17 +511,15 @@ public static boolean areHardcodedYoutubeMusicKeysValid() throws IOException,
510511 headers .put ("Content-Type" , Collections .singletonList ("application/json" ));
511512
512513 final Response response = getDownloader ().post (url , headers , json );
513- final String responseBody = response .responseBody ();
514- final int responseCode = response .responseCode ();
515514 // Ensure to have a valid response
516- return responseBody .length () > 500 && responseCode == 200 ;
515+ return response . responseBody () .length () > 500 && response . responseCode () == 200 ;
517516 }
518517
519- public static String [] getYoutubeMusicKeys () throws IOException , ReCaptchaException ,
518+ public static String [] getYoutubeMusicKey () throws IOException , ReCaptchaException ,
520519 Parser .RegexException {
521- if (youtubeMusicKeys != null && youtubeMusicKeys .length == 3 ) return youtubeMusicKeys ;
522- if (areHardcodedYoutubeMusicKeysValid ()) {
523- return youtubeMusicKeys = HARDCODED_YOUTUBE_MUSIC_KEY ;
520+ if (youtubeMusicKey != null && youtubeMusicKey .length == 3 ) return youtubeMusicKey ;
521+ if (isHardcodedYoutubeMusicKeyValid ()) {
522+ return youtubeMusicKey = HARDCODED_YOUTUBE_MUSIC_KEY ;
524523 }
525524
526525 final String url = "https://music.youtube.com/" ;
@@ -552,7 +551,7 @@ public static String[] getYoutubeMusicKeys() throws IOException, ReCaptchaExcept
552551 }
553552 }
554553
555- return youtubeMusicKeys = new String []{key , clientName , clientVersion };
554+ return youtubeMusicKey = new String []{key , clientName , clientVersion };
556555 }
557556
558557 @ Nullable
0 commit comments