private async Task<bool> Process() { // get html as string string pageHtml = await new StreamReader(Response.GetResponseStream()).ReadToEndAsync(); // get json from html Match match = Regex.Match(pageHtml, "ytplayer.config *?= *?({.+?});"); if (match.Success) { JObject json = JObject.Parse(match.Groups[1].Value); _title = json["args"]["title"].ToString(); string[] rawQualities = json["args"]["adaptive_fmts"].ToString().Split(new char[] {','}); List<YouTubeFile> qualities = new List<YouTubeFile>(rawQualities.Length); foreach (string rawQuality in rawQualities) { qualities.Add(new YouTubeFile(rawQuality)); } _hqVideo = YouTubeFile.HighestQualityMP4Video(qualities); _hqAudio = YouTubeFile.HighestQualityMP4Audio(qualities); Console.WriteLine("Video\nitag: {0}\nbitrate: {1}\nurl:{2}\n\n", _hqVideo.Itag, _hqVideo.Bitrate, _hqAudio.Url); Console.WriteLine("Audio\nitag: {0}\nbitrate: {1}\nurl:{2}\n\n", _hqAudio.Itag, _hqAudio.Bitrate, _hqAudio.Url); if (String.IsNullOrEmpty(_hqVideo.Signature) || String.IsNullOrEmpty(_hqAudio.Signature)) { await downloadDecipheringFunction(json["assets"]["js"].ToString()); } return true; } return false; }
private Uri generateUrl(YouTubeFile file) { if (String.IsNullOrEmpty(file.S)) { return new Uri(String.Format("{0}&ratebypass=yes", file.Url)); } else { string signature = decipherSignature(file.S); // add ratebypass and signature arguments to url return new Uri(String.Format("{0}&ratebypass=yes&signature={1}", file.Url, signature)); } }