Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Fix signature deciphering
Browse files Browse the repository at this point in the history
  • Loading branch information
HaarigerHarald committed Apr 18, 2020
1 parent 7255ee5 commit b7aa047
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Jan 18 23:01:49 CET 2020
#Sat Apr 18 21:27:46 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\:https://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\:https://services.gradle.org/distributions/gradle-5.6.4-all.zip
1 change: 1 addition & 0 deletions sampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ android {
defaultConfig {
applicationId "at.huber.sampleDownload"
minSdkVersion 14
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 22
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ public abstract class YouTubeExtractor extends AsyncTask<String, Void, SparseArr
private static final Pattern patUrl = Pattern.compile("\"url\"\\s*:\\s*\"(.+?)\"");
private static final Pattern patCipher = Pattern.compile("\"cipher\"\\s*:\\s*\"(.+?)\"");
private static final Pattern patCipherUrl = Pattern.compile("url=(.+?)(\\\\\\\\u0026|\\z)");
private static final Pattern patYtPlayer = Pattern.compile("<\\s*script\\s*>((.+?)jsbin\\\\/(player(_ias)?-(.+?).js)(.+?))</\\s*script\\s*>");

private static final Pattern patVariableFunction = Pattern.compile("([{; =])([a-zA-Z$][a-zA-Z0-9$]{0,2})\\.([a-zA-Z$][a-zA-Z0-9$]{0,2})\\(");
private static final Pattern patFunction = Pattern.compile("([{; =])([a-zA-Z$_][a-zA-Z0-9$]{0,2})\\(");

private static final Pattern patDecryptionJsFile = Pattern.compile("jsbin\\\\/(player(_ias)?-(.+?).js)");
private static final Pattern patDecryptionJsFile = Pattern.compile("\\\\/s\\\\/player\\\\/([^\"]+?)\\.js");
private static final Pattern patSignatureDecFunction = Pattern.compile("\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;");

private static final SparseArray<Format> FORMAT_MAP = new SparseArray<>();
Expand Down Expand Up @@ -298,14 +297,12 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
try {
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
StringBuilder sbStreamMap = new StringBuilder();
while ((line = reader.readLine()) != null) {
// Log.d("line", line);
mat = patYtPlayer.matcher(line);
if (mat.find()) {
streamMap = line.replace("\\\"", "\"");
break;
}
sbStreamMap.append(line.replace("\\\"", "\""));
}
streamMap = sbStreamMap.toString();
} finally {
reader.close();
urlConnection.disconnect();
Expand All @@ -314,9 +311,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep

mat = patDecryptionJsFile.matcher(streamMap);
if (mat.find()) {
curJsFileName = mat.group(1).replace("\\/", "/");
if (mat.group(2) != null)
curJsFileName.replace(mat.group(2), "");
curJsFileName = mat.group(0).replace("\\/", "/");
if (decipherJsFileName == null || !decipherJsFileName.equals(curJsFileName)) {
decipherFunctions = null;
decipherFunctionName = null;
Expand Down Expand Up @@ -425,7 +420,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
private boolean decipherSignature(final SparseArray<String> encSignatures) throws IOException {
// Assume the functions don't change that much
if (decipherFunctionName == null || decipherFunctions == null) {
String decipherFunctUrl = "https://s.ytimg.com/yts/jsbin/" + decipherJsFileName;
String decipherFunctUrl = "https://youtube.com" + decipherJsFileName;

BufferedReader reader = null;
String javascriptFile;
Expand Down

0 comments on commit b7aa047

Please sign in to comment.