@@ -677,8 +677,10 @@ public String getErrorMessage() {
677677
678678 private static final String VERIFIED_URL_PARAMS = "&has_verified=1&bpctr=9999999999" ;
679679
680- private final static String DECYRYPTION_SIGNATURE_FUNCTION_REGEX =
680+ private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX =
681681 "([\\ w$]+)\\ s*=\\ s*function\\ ((\\ w+)\\ )\\ {\\ s*\\ 2=\\ s*\\ 2\\ .split\\ (\" \" \\ )\\ s*;" ;
682+ private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX_2 =
683+ "\\ b([\\ w$]{2})\\ s*=\\ s*function\\ ((\\ w+)\\ )\\ {\\ s*\\ 2=\\ s*\\ 2\\ .split\\ (\" \" \\ )\\ s*;" ;
682684 private final static String DECRYPTION_AKAMAIZED_STRING_REGEX =
683685 "yt\\ .akamaized\\ .net/\\ )\\ s*\\ |\\ |\\ s*.*?\\ s*c\\ s*&&\\ s*d\\ .set\\ ([^,]+\\ s*,\\ s*(:encodeURIComponent\\ s*\\ ()([a-zA-Z0-9$]+)\\ (" ;
684686 private final static String DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX =
@@ -697,7 +699,8 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
697699
698700 final String playerUrl ;
699701 // Check if the video is age restricted
700- if (!doc .select ("meta[property=\" og:restrictions:age\" ]" ).isEmpty ()) {
702+ Elements e = doc .select ("meta[property=\" og:restrictions:age\" ]" );
703+ if (!e .isEmpty ()) {
701704 final EmbeddedInfo info = getEmbeddedInfo ();
702705 final String videoInfoUrl = getVideoInfoUrl (getId (), info .sts );
703706 final String infoPageResponse = downloader .get (videoInfoUrl , getExtractorLocalization ()).responseBody ();
@@ -773,7 +776,7 @@ private String getPlayerUrl(JsonObject playerConfig) throws ParsingException {
773776 private JsonObject getPlayerResponse () throws ParsingException {
774777 try {
775778 String playerResponseStr ;
776- if (playerArgs != null ) {
779+ if (playerArgs != null ) {
777780 playerResponseStr = playerArgs .getString ("player_response" );
778781 } else {
779782 playerResponseStr = videoInfoPage .get ("player_response" );
@@ -805,7 +808,7 @@ private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaExcepti
805808 final String sts = Parser .matchGroup1 (stsPattern , embedPageContent );
806809 return new EmbeddedInfo (playerUrl , sts );
807810 } catch (Exception i ) {
808- // if it failes we simply reply with no sts as then it does not seem to be necessary
811+ // if it fails we simply reply with no sts as then it does not seem to be necessary
809812 return new EmbeddedInfo (playerUrl , "" );
810813 }
811814
@@ -868,30 +871,28 @@ private String decryptSignature(String encryptedSig, String decryptionCode) thro
868871 }
869872
870873 private String getDecryptionFuncName (String playerCode ) throws DecryptException {
871- String decryptionFunctionName ;
872- // Cascading things in catch is ugly, but its faster than running a match before getting the actual name
873- // to se if the function can actually be found with the given regex.
874- // However if this cascading should propably be cleaned up somehow as it looks a bit weird.
875- try {
876- decryptionFunctionName = Parser .matchGroup1 (DECYRYPTION_SIGNATURE_FUNCTION_REGEX , playerCode );
877- } catch (Parser .RegexException re ) {
874+ String [] decryptionFuncNameRegexes = {
875+ DECRYPTION_SIGNATURE_FUNCTION_REGEX_2 ,
876+ DECRYPTION_SIGNATURE_FUNCTION_REGEX ,
877+ DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX ,
878+ DECRYPTION_AKAMAIZED_STRING_REGEX
879+ };
880+ Parser .RegexException exception = null ;
881+ for (String regex : decryptionFuncNameRegexes ) {
878882 try {
879- decryptionFunctionName = Parser .matchGroup1 (DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX , playerCode );
880- } catch (Parser .RegexException re2 ) {
881- try {
882- decryptionFunctionName = Parser .matchGroup1 (DECRYPTION_AKAMAIZED_STRING_REGEX , playerCode );
883- } catch (Parser .RegexException re3 ) {
884- throw new DecryptException ("Could not find decrypt function with any of the given patterns." , re );
885- }
883+ return Parser .matchGroup1 (regex , playerCode );
884+ } catch (Parser .RegexException re ) {
885+ if (exception == null )
886+ exception = re ;
886887 }
887888 }
888- return decryptionFunctionName ;
889+ throw new DecryptException ( "Could not find decrypt function with any of the given patterns." , exception ) ;
889890 }
890891
891892 @ Nonnull
892893 private List <SubtitlesInfo > getAvailableSubtitlesInfo () throws SubtitlesException {
893894 // If the video is age restricted getPlayerConfig will fail
894- if (isAgeRestricted ) return Collections .emptyList ();
895+ if (isAgeRestricted ) return Collections .emptyList ();
895896
896897 final JsonObject captions ;
897898 if (!playerResponse .has ("captions" )) {
@@ -908,7 +909,7 @@ private List<SubtitlesInfo> getAvailableSubtitlesInfo() throws SubtitlesExceptio
908909 // This check is necessary since there may be cases where subtitles metadata do not contain caption track info
909910 // e.g. https://www.youtube.com/watch?v=-Vpwatutnko
910911 final int captionsSize = captionsArray .size ();
911- if (captionsSize == 0 ) return Collections .emptyList ();
912+ if (captionsSize == 0 ) return Collections .emptyList ();
912913
913914 List <SubtitlesInfo > result = new ArrayList <>();
914915 for (int i = 0 ; i < captionsSize ; i ++) {
0 commit comments