Skip to content

Commit f8d117f

Browse files
committed
Merge remote-tracking branch 'origin/master' into dev
2 parents b9afc98 + ff61e28 commit f8d117f

3 files changed

Lines changed: 24 additions & 22 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void fetchPage() throws IOException, ExtractionException {
5656
}
5757

5858
protected void assertPageFetched() {
59-
if(!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
59+
if (!pageFetched) throw new IllegalStateException("Page is not fetched. Make sure you call fetchPage()");
6060
}
6161

6262
protected boolean isPageFetched() {

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,10 @@ public String getErrorMessage() {
698698

699699
private static final String VERIFIED_URL_PARAMS = "&has_verified=1&bpctr=9999999999";
700700

701-
private final static String DECYRYPTION_SIGNATURE_FUNCTION_REGEX =
701+
private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX =
702702
"([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;";
703+
private final static String DECRYPTION_SIGNATURE_FUNCTION_REGEX_2 =
704+
"\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;";
703705
private final static String DECRYPTION_AKAMAIZED_STRING_REGEX =
704706
"yt\\.akamaized\\.net/\\)\\s*\\|\\|\\s*.*?\\s*c\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(";
705707
private final static String DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX =
@@ -718,7 +720,8 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
718720

719721
final String playerUrl;
720722
// Check if the video is age restricted
721-
if (!doc.select("meta[property=\"og:restrictions:age\"]").isEmpty()) {
723+
Elements e = doc.select("meta[property=\"og:restrictions:age\"]");
724+
if (!e.isEmpty()) {
722725
final EmbeddedInfo info = getEmbeddedInfo();
723726
final String videoInfoUrl = getVideoInfoUrl(getId(), info.sts);
724727
final String infoPageResponse = downloader.get(videoInfoUrl, getExtractorLocalization()).responseBody();
@@ -794,7 +797,7 @@ private String getPlayerUrl(JsonObject playerConfig) throws ParsingException {
794797
private JsonObject getPlayerResponse() throws ParsingException {
795798
try {
796799
String playerResponseStr;
797-
if(playerArgs != null) {
800+
if (playerArgs != null) {
798801
playerResponseStr = playerArgs.getString("player_response");
799802
} else {
800803
playerResponseStr = videoInfoPage.get("player_response");
@@ -826,7 +829,7 @@ private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaExcepti
826829
final String sts = Parser.matchGroup1(stsPattern, embedPageContent);
827830
return new EmbeddedInfo(playerUrl, sts);
828831
} catch (Exception i) {
829-
// if it failes we simply reply with no sts as then it does not seem to be necessary
832+
// if it fails we simply reply with no sts as then it does not seem to be necessary
830833
return new EmbeddedInfo(playerUrl, "");
831834
}
832835

@@ -889,30 +892,28 @@ private String decryptSignature(String encryptedSig, String decryptionCode) thro
889892
}
890893

891894
private String getDecryptionFuncName(String playerCode) throws DecryptException {
892-
String decryptionFunctionName;
893-
// Cascading things in catch is ugly, but its faster than running a match before getting the actual name
894-
// to se if the function can actually be found with the given regex.
895-
// However if this cascading should propably be cleaned up somehow as it looks a bit weird.
896-
try {
897-
decryptionFunctionName = Parser.matchGroup1(DECYRYPTION_SIGNATURE_FUNCTION_REGEX, playerCode);
898-
} catch (Parser.RegexException re) {
895+
String[] decryptionFuncNameRegexes = {
896+
DECRYPTION_SIGNATURE_FUNCTION_REGEX_2,
897+
DECRYPTION_SIGNATURE_FUNCTION_REGEX,
898+
DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX,
899+
DECRYPTION_AKAMAIZED_STRING_REGEX
900+
};
901+
Parser.RegexException exception = null;
902+
for (String regex : decryptionFuncNameRegexes) {
899903
try {
900-
decryptionFunctionName = Parser.matchGroup1(DECRYPTION_AKAMAIZED_SHORT_STRING_REGEX, playerCode);
901-
} catch (Parser.RegexException re2) {
902-
try {
903-
decryptionFunctionName = Parser.matchGroup1(DECRYPTION_AKAMAIZED_STRING_REGEX, playerCode);
904-
} catch (Parser.RegexException re3) {
905-
throw new DecryptException("Could not find decrypt function with any of the given patterns.", re);
906-
}
904+
return Parser.matchGroup1(regex, playerCode);
905+
} catch (Parser.RegexException re) {
906+
if (exception == null)
907+
exception = re;
907908
}
908909
}
909-
return decryptionFunctionName;
910+
throw new DecryptException("Could not find decrypt function with any of the given patterns.", exception);
910911
}
911912

912913
@Nonnull
913914
private List<SubtitlesInfo> getAvailableSubtitlesInfo() throws SubtitlesException {
914915
// If the video is age restricted getPlayerConfig will fail
915-
if(isAgeRestricted) return Collections.emptyList();
916+
if (isAgeRestricted) return Collections.emptyList();
916917

917918
final JsonObject captions;
918919
if (!playerResponse.has("captions")) {
@@ -929,7 +930,7 @@ private List<SubtitlesInfo> getAvailableSubtitlesInfo() throws SubtitlesExceptio
929930
// This check is necessary since there may be cases where subtitles metadata do not contain caption track info
930931
// e.g. https://www.youtube.com/watch?v=-Vpwatutnko
931932
final int captionsSize = captionsArray.size();
932-
if(captionsSize == 0) return Collections.emptyList();
933+
if (captionsSize == 0) return Collections.emptyList();
933934

934935
List<SubtitlesInfo> result = new ArrayList<>();
935936
for (int i = 0; i < captionsSize; i++) {

extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public static String matchGroup(Pattern pat, String input, int group) throws Reg
6767
if (foundMatch) {
6868
return mat.group(group);
6969
} else {
70+
// only pass input to exception message when it is not too long
7071
if (input.length() > 1024) {
7172
throw new RegexException("failed to find pattern \"" + pat.pattern());
7273
} else {

0 commit comments

Comments
 (0)