Skip to content

Commit

Permalink
Merge pull request #713 from TiA4f8R/regexes-yt-signatureciphers
Browse files Browse the repository at this point in the history
[YouTube] Consolidate the regular expressions used to find the cipher decryption function
  • Loading branch information
Stypox authored Aug 17, 2021
2 parents 89bab24 + f8309d5 commit d8179dc
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,12 @@ public long getLength() throws ParsingException {
return Long.parseLong(duration);
} catch (final Exception e) {
if (desktopStreamingData != null) {
final JsonArray adaptiveFormats = desktopStreamingData.getArray("adaptiveFormats");
final JsonArray adaptiveFormats = desktopStreamingData.getArray(ADAPTIVE_FORMATS);
final String durationMs = adaptiveFormats.getObject(0)
.getString("approxDurationMs");
return Math.round(Long.parseLong(durationMs) / 1000f);
} else if (mobileStreamingData != null) {
final JsonArray adaptiveFormats = mobileStreamingData.getArray("adaptiveFormats");
final JsonArray adaptiveFormats = mobileStreamingData.getArray(ADAPTIVE_FORMATS);
final String durationMs = adaptiveFormats.getObject(0)
.getString("approxDurationMs");
return Math.round(Long.parseLong(durationMs) / 1000f);
Expand Down Expand Up @@ -685,9 +685,11 @@ public String getErrorMessage() {
private static final String DEOBFUSCATION_FUNC_NAME = "deobfuscate";

private static final String[] REGEXES = {
"(?:\\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2})\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)",
"(?:\\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2,})\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)",
"\\bm=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(h\\.s\\)\\)",
"\\bc&&\\(c=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(c\\)\\)",
"([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;",
"\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;",
"\\b([\\w$]{2,})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;",
"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\("
};
private static final String STS_REGEX = "signatureTimestamp[=:](\\d+)";
Expand Down Expand Up @@ -931,8 +933,8 @@ private void storePlayerJs() throws ParsingException {

private boolean isCipherProtectedContent() {
if (desktopStreamingData != null) {
if (desktopStreamingData.has("adaptiveFormats")) {
final JsonArray adaptiveFormats = desktopStreamingData.getArray("adaptiveFormats");
if (desktopStreamingData.has(ADAPTIVE_FORMATS)) {
final JsonArray adaptiveFormats = desktopStreamingData.getArray(ADAPTIVE_FORMATS);
if (!isNullOrEmpty(adaptiveFormats)) {
for (final Object adaptiveFormat : adaptiveFormats) {
final JsonObject adaptiveFormatJsonObject = ((JsonObject) adaptiveFormat);
Expand All @@ -943,8 +945,8 @@ private boolean isCipherProtectedContent() {
}
}
}
if (desktopStreamingData.has("formats")) {
final JsonArray formats = desktopStreamingData.getArray("formats");
if (desktopStreamingData.has(FORMATS)) {
final JsonArray formats = desktopStreamingData.getArray(FORMATS);
if (!isNullOrEmpty(formats)) {
for (final Object format : formats) {
final JsonObject formatJsonObject = ((JsonObject) format);
Expand Down

0 comments on commit d8179dc

Please sign in to comment.