|
39 | 39 | import java.time.OffsetDateTime; |
40 | 40 | import java.time.format.DateTimeFormatter; |
41 | 41 | import java.util.*; |
| 42 | +import java.util.regex.Pattern; |
42 | 43 |
|
43 | 44 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; |
44 | 45 | import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; |
@@ -527,9 +528,31 @@ public List<VideoStream> getVideoStreams() throws ExtractionException { |
527 | 528 | final List<VideoStream> videoStreams = new ArrayList<>(); |
528 | 529 |
|
529 | 530 | try { |
| 531 | + getDeobfuscationCode(); |
| 532 | + final String playerCode = NewPipe.getDownloader() |
| 533 | + .get(playerJsUrl, getExtractorLocalization()).responseBody(); |
| 534 | + Pattern pattern = Pattern.compile("b=a\\.get\\(\"n\"\\)\\)&&\\(b=(\\w+)\\(b\\),a\\.set\\(\"n\",b\\)"); |
| 535 | + String functionName = Parser.matchGroup1(pattern, playerCode); |
| 536 | + Pattern functionPattern = Pattern.compile(functionName + "=function(.*?;)\n", Pattern.DOTALL); |
| 537 | + String function = "function " + functionName + Parser.matchGroup1(functionPattern, playerCode); |
| 538 | + |
| 539 | + Context context = Context.enter(); |
| 540 | + context.setOptimizationLevel(-1); |
| 541 | + ScriptableObject scope = context.initSafeStandardObjects(); |
| 542 | + |
530 | 543 | for (final Map.Entry<String, ItagItem> entry : getItags(FORMATS, ItagItem.ItagType.VIDEO).entrySet()) { |
531 | 544 | final ItagItem itag = entry.getValue(); |
532 | | - final VideoStream videoStream = new VideoStream(entry.getKey(), false, itag); |
| 545 | + final String url = entry.getKey(); |
| 546 | + Pattern nValuePattern = Pattern.compile("[&?]n=([^&]+)"); |
| 547 | + String nValue = Parser.matchGroup1(nValuePattern, url); |
| 548 | + |
| 549 | + context.evaluateString(scope, function, functionName, 1, null); |
| 550 | + final Function jsFunction = (Function) scope.get(functionName, scope); |
| 551 | + Object result = jsFunction.call(context, scope, scope, new Object[]{nValue}); |
| 552 | + String newNValue = Objects.toString(result, nValue); |
| 553 | + String newUrl = nValuePattern.matcher(url).replaceFirst(newNValue); |
| 554 | + System.out.println("aaaaaa " + nValue + " - " + newNValue); |
| 555 | + final VideoStream videoStream = new VideoStream(newUrl, false, itag); |
533 | 556 | if (!Stream.containSimilarStream(videoStream, videoStreams)) { |
534 | 557 | videoStreams.add(videoStream); |
535 | 558 | } |
|
0 commit comments