From 140b480f8293353280084c634392a349c2e9b27a Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 31 Jan 2017 12:22:54 +0100 Subject: [PATCH] url signature fix * fixed stacktrace * changed player url * took regex fix from youtube-dl final fix taken from youtube-dl --- .../org/schabi/newpipe/detail/StreamInfoWorker.java | 5 ++++- .../java/org/schabi/newpipe/extractor/Parser.java | 12 ++++++++++-- .../services/youtube/YoutubeStreamExtractor.java | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java index dd1ae9f5a..17a4572bd 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java +++ b/app/src/main/java/org/schabi/newpipe/detail/StreamInfoWorker.java @@ -125,10 +125,13 @@ public class StreamInfoWorker { e.printStackTrace(); } catch (YoutubeStreamExtractor.DecryptException de) { // custom service related exceptions + ErrorActivity.reportError(h, a, de, VideoItemDetailFragment.class, null, + ErrorActivity.ErrorInfo.make(ErrorActivity.REQUESTED_STREAM, + service.getServiceInfo().name, videoUrl, R.string.youtube_signature_decryption_error)); h.post(new Runnable() { @Override public void run() { - onStreamInfoReceivedListener.onError(R.string.youtube_signature_decryption_error); + a.finish(); } }); de.printStackTrace(); diff --git a/app/src/main/java/org/schabi/newpipe/extractor/Parser.java b/app/src/main/java/org/schabi/newpipe/extractor/Parser.java index b68d01fa7..8e70f751c 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/Parser.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/Parser.java @@ -42,15 +42,23 @@ public class Parser { } public static String matchGroup1(String pattern, String input) throws RegexException { + return matchGroup(pattern, input, 1); + } + + public static String matchGroup(String pattern, String input, int group) throws RegexException { Pattern pat = Pattern.compile(pattern); Matcher mat = pat.matcher(input); boolean foundMatch = mat.find(); if (foundMatch) { - return mat.group(1); + return mat.group(group); } else { //Log.e(TAG, "failed to find pattern \""+pattern+"\" inside of \""+input+"\""); - throw new RegexException("failed to find pattern \""+pattern+" inside of "+input+"\""); + if(input.length() > 1024) { + throw new RegexException("failed to find pattern \""+pattern); + } else { + throw new RegexException("failed to find pattern \"" + pattern + " inside of " + input + "\""); + } } } diff --git a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index 63642e973..6dd0daa7c 100644 --- a/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/app/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -791,10 +791,15 @@ public class YoutubeStreamExtractor extends StreamExtractor { try { Downloader downloader = NewPipe.getDownloader(); + if(!playerUrl.contains("https://youtube.com")) { + //sometimes the https://youtube.com part does not get send with + //than we have to add it by hand + playerUrl = "https://youtube.com" + playerUrl; + } String playerCode = downloader.download(playerUrl); decryptionFuncName = - Parser.matchGroup1("\\.sig\\|\\|([a-zA-Z0-9$]+)\\(", playerCode); + Parser.matchGroup("([\"\\'])signature\\1\\s*,\\s*([a-zA-Z0-9$]+)\\(", playerCode, 2); String functionPattern = "(" + decryptionFuncName.replace("$", "\\$")