Skip to content

Commit 1c78976

Browse files
committed
[YouTube] Expand regex to match n param decrypt function
Temporary solution
1 parent 6335823 commit 1c78976

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private String parseDecodeFunctionName(final String playerJsCode)
7070
@Nonnull
7171
private String parseDecodeFunction(final String playerJsCode, final String functionName)
7272
throws Parser.RegexException {
73-
Pattern functionPattern = Pattern.compile(functionName + "=function(.*?;)\n",
73+
Pattern functionPattern = Pattern.compile(functionName + "=function(.*?};)\n",
7474
Pattern.DOTALL);
7575
return "function " + functionName + Parser.matchGroup1(functionPattern, playerJsCode);
7676
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypterTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.Before;
44
import org.junit.Test;
5+
import org.mozilla.javascript.EvaluatorException;
56
import org.schabi.newpipe.downloader.DownloaderTestImpl;
67
import org.schabi.newpipe.extractor.NewPipe;
78
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -11,6 +12,7 @@
1112
import static org.hamcrest.CoreMatchers.equalTo;
1213
import static org.hamcrest.MatcherAssert.assertThat;
1314
import static org.junit.Assert.assertNotEquals;
15+
import static org.junit.Assert.fail;
1416

1517
public class YoutubeThrottlingDecrypterTest {
1618

@@ -19,6 +21,22 @@ public void setup() throws IOException {
1921
NewPipe.init(DownloaderTestImpl.getInstance());
2022
}
2123

24+
@Test
25+
public void testExtractFunction__success() throws ParsingException {
26+
String[] videoIds = {"jE1USQrs1rw", "CqxjzfudGAc", "goH-9MfQI7w", "KYIdr_7H5Yw", "J1WeqmGbYeI"};
27+
28+
final String encryptedUrl = "https://r6---sn-4g5ednek.googlevideo.com/videoplayback?expire=1626562120&ei=6AnzYO_YBpql1gLGkb_IBQ&ip=127.0.0.1&id=o-ANhBEf36Z5h-8U9DDddtPDqtS0ZNwf0XJAAigudKI2uI&itag=278&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&vprv=1&mime=video%2Fwebm&ns=TvecOReN0vPuXb3j_zq157IG&gir=yes&clen=2915100&dur=270.203&lmt=1608157174907785&keepalive=yes&fexp=24001373,24007246&c=WEB&txp=5535432&n=N9BWSTFT7vvBJrvQ&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&alr=yes&sig=AOq0QJ8wRQIgW6XnUDKPDSxiT0_KE_tDDMpcaCJl2Un5p0Fu9qZNQGkCIQDWxsDHi_s2BEmRqIbd1C5g_gzfihB7RZLsScKWNMwzzA%3D%3D&cpn=9r2yt3BqcYmeb2Yu&cver=2.20210716.00.00&redirect_counter=1&cm2rm=sn-4g5ezy7s&cms_redirect=yes&mh=Y5&mm=34&mn=sn-4g5ednek&ms=ltu&mt=1626540524&mv=m&mvi=6&pl=43&lsparams=mh,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRQIhAIUzxTn9Vw1-vm-_7OQ5-0h1M6AZsY9Bx1FlCCTeMICzAiADtGggbn4Znsrh2EnvyOsGnYdRGcbxn4mW9JMOQiInDQ%3D%3D&range=259165-480735&rn=11&rbuf=20190";
29+
30+
for (String videoId : videoIds) {
31+
try {
32+
final String decryptedUrl = new YoutubeThrottlingDecrypter(videoId).apply(encryptedUrl);
33+
assertNotEquals(encryptedUrl, decryptedUrl);
34+
} catch (EvaluatorException e) {
35+
fail("Failed to extract n param decrypt function for video " + videoId + "\n" + e);
36+
}
37+
}
38+
}
39+
2240
@Test
2341
public void testDecode__success() throws ParsingException {
2442
// URL extracted from browser with the dev tools

0 commit comments

Comments
 (0)