Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Commit 8d53e2b

Browse files
authored
Merge pull request #2 from mrklintscher/master
Fix decipher
2 parents 9cd6591 + edd6487 commit 8d53e2b

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

YoutubeExtractor/ExampleApplication/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ private static void DownloadVideo(IEnumerable<VideoInfo> videoInfos)
8989
private static void Main()
9090
{
9191
// Our test youtube link
92-
const string link = "https://www.youtube.com/watch?v=YQHsXMglC9A";
92+
//const string link = "https://www.youtube.com/watch?v=D92-DmVmB8Y"; // -> needs deciphering
93+
94+
const string link = "https://www.youtube.com/watch?v=2a4Uxdy9TQY"; // -> needs no deciphering
9395

9496
/*
9597
* Get the available video formats.

YoutubeExtractor/YoutubeExtractor/Decipherer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static string DecipherWithVersion(string cipher, string cipherVersion)
1313
string js = HttpHelper.DownloadString(jsUrl);
1414

1515
//Find "yv" in this: c&&a.set(b,encodeURIComponent(yv(
16-
string functNamePattern = @"\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*([\w$]+)\("; //Regex Formed To Find Word or DollarSign
16+
string functNamePattern = @"(\w+)=function\(\w+\){(\w+)=\2\.split\(\x22{2}\);.*?return\s+\2\.join\(\x22{2}\)}"; //Regex Formed To Find Word or DollarSign
1717

1818
var funcName = Regex.Match(js, functNamePattern).Groups[1].Value;
1919

@@ -22,7 +22,7 @@ public static string DecipherWithVersion(string cipher, string cipherVersion)
2222
funcName = "\\" + funcName; //Due To Dollar Sign Introduction, Need To Escape
2323
}
2424

25-
string funcPattern = @"(?!h\.)" + @funcName + @"=function\(\w+\)\{.*?\}"; //Escape funcName string
25+
string funcPattern = @"(?!h\.)" + @funcName + @"=function\(\w+\)\{(.*?)\}"; //Escape funcName string
2626
var funcBody = Regex.Match(js, funcPattern, RegexOptions.Singleline).Value; //Entire sig function
2727
var lines = funcBody.Split(';'); //Each line in sig function
2828

YoutubeExtractor/YoutubeExtractor/DownloadUrlResolver.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,21 @@ private static IEnumerable<ExtractionInfo> ExtractDownloadUrls(JObject json)
187187
if (queries.ContainsKey("s") || queries.ContainsKey("sig"))
188188
{
189189
requiresDecryption = queries.ContainsKey("s");
190-
string signature = queries.ContainsKey("s") ? queries["s"] : queries["sig"];
191190

192-
url = string.Format("{0}&{1}={2}", queries["url"], SignatureQuery, signature);
191+
if (requiresDecryption)
192+
{
193+
string signature = queries.ContainsKey("s") ? queries["s"] : queries["sig"];
194+
195+
url = string.Format("{0}&{1}={2}", queries["url"], SignatureQuery, signature);
193196

194-
string fallbackHost = queries.ContainsKey("fallback_host") ? "&fallback_host=" + queries["fallback_host"] : String.Empty;
197+
string fallbackHost = queries.ContainsKey("fallback_host") ? "&fallback_host=" + queries["fallback_host"] : String.Empty;
195198

196-
url += fallbackHost;
199+
url += fallbackHost;
200+
}
201+
else
202+
{
203+
url = NormalizeUrl(s);
204+
}
197205
}
198206

199207
else
@@ -347,5 +355,10 @@ private class ExtractionInfo
347355

348356
public Uri Uri { get; set; }
349357
}
358+
359+
private static string NormalizeUrl(string url)
360+
{
361+
return url.Replace("\"", "").Replace("url=", "");
362+
}
350363
}
351364
}

0 commit comments

Comments
 (0)