public void Defibrillate(audioInfo info) { setReadStream(info.serverAudioStream); abortnite = false; jumpstart = false; BufferThread = new Thread(new ThreadStart(readToStream)); BufferThread.Start(); //BREATHE YOU BASTARD }
void BaseClass.Initialize(string _url) { WebRequest request = WebRequest.Create(_url); HttpWebRequest webRequest = (HttpWebRequest)request; webRequest.UserAgent = values.userAgent; WebResponse response = webRequest.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. // The using block ensures the stream is automatically closed. using (Stream dataStream = response.GetResponseStream()) { // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); MatchCollection matches = Regex.Matches(responseFromServer, @"""compactVideoRenderer"":{.*?""title"".*?Text"":""(.*?)"".*?""lengthText"".*?simpleText"":""(\d+):(\d+).*?url"":""(.*?)"".*?shortBylineText"":{.*?text"":""(.*?)"""); for (int i = 0; i < 3; i++) { GroupCollection g = matches[i].Groups; musicInfos[i] = new musicInfo { name = OWStuff.MouseSens != -60 ? g[1].Value : (g[1].Value.Length > 15 ? g[1].Value.Substring(0, 14) : g[1].Value), url = "https://www.youtube.com" + g[4].Value, length = (uint)((Convert.ToInt32(g[2].Value) * 60) + Convert.ToInt32(g[3].Value)), artist = g[5].Value.EndsWith(" - Topic") ? g[5].Value.Substring(0, g[5].Value.Length - " - Topic".Length) : g[5].Value, audiourl = "" }; } Match meeem = Regex.Match(responseFromServer, @"{""player_response.*?}}}]}""}"); bool coolerResponse = false; if (!meeem.Success) { meeem = Regex.Match(responseFromServer, @"{""responseContext.*?}}}]}"); coolerResponse = true; } string pissoff = meeem.Captures[0].Value; pissoff = pissoff.Replace(@"}]}""}", @"}]}}"); //unstring value if (!coolerResponse) { pissoff = pissoff.Replace(@"{""player_response"":""{\""", @"{""player_response"":{\"""); //unstring value //pissoff = pissoff.Replace(@"{""responseContext"":""{\""", @"{""responseContext"":{\"""); //unstring value pissoff = pissoff.Replace(@"\""", @""""); pissoff = pissoff.Replace(@"\\", @"\"); pissoff = pissoff.Replace(@"\/", @"/"); } pissoff = System.Uri.UnescapeDataString(pissoff); dynamic stuff = "I'm stuff"; try { stuff = JObject.Parse(pissoff); } catch (Exception ex) { using (FileStream fs = new FileStream("I did a f*****g.whoopsie", FileMode.Create)) { byte[] bruhfunny = Encoding.UTF8.GetBytes(pissoff); fs.Write(bruhfunny, 0, bruhfunny.Length); } throw new Exception($"Error during parsing the player_response {ex.Message}"); } response.Close(); dynamic chosenone = "stinker"; foreach (dynamic format in coolerResponse ? stuff["streamingData"]["adaptiveFormats"] : stuff["player_response"]["streamingData"]["adaptiveFormats"]) { if (format["mimeType"].Value.StartsWith("audio") && format["audioQuality"] == "AUDIO_QUALITY_MEDIUM") { chosenone = format; //I don't know what it is but evem though it seems that I select the same codec here I still get unsupported url format exception sometimes. I don't know what causes it } } if (chosenone.GetType().ToString() == "System.String") { throw new Exception("Couldn't find any suitable format"); } int formatid = chosenone["itag"]; //this.contentlength = chosenone["contentLength"]; int bitrate = chosenone["bitrate"]; int approxlen = (Convert.ToInt32(chosenone["approxDurationMs"].Value) / 1000); Match matché = Regex.Match(responseFromServer, @"og:title"" content=""(.*?)""[\s\S]*?itemprop=""author""[\s\S]*?""name"" content=""(.*?)"""); GroupCollection gc = matché.Groups; coolerme = new musicInfo { name = OWStuff.MouseSens != -60 ? gc[1].Value : (gc[1].Value.Length > 15 ? gc[1].Value.Substring(0, 14) : gc[1].Value), //url = "https://www.youtube.com" + g[4].Value, length = (uint)approxlen, artist = gc[2].Value.EndsWith(" - Topic") ? gc[2].Value.Substring(0, gc[2].Value.Length - " - Topic".Length) : gc[2].Value, audiourl = "" }; Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = $"/C youtube-dl --get-url --print-traffic -f {formatid} {_url}"; process.StartInfo = startInfo; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); process.WaitForExit(); string hsc = "header: Set-Cookie:"; string url = "crikey"; WebRequest req; string youtubedlres = process.StandardOutput.ReadToEnd(); foreach (string line in youtubedlres.Split('\n')) { if (line.StartsWith("https")) { url = line; } } if (url == "crikey") { throw new Exception("youtube-dl has encountered an error"); } else { req = HttpWebRequest.Create(url); } HttpWebRequest httpreq = (HttpWebRequest)req; httpreq.CookieContainer = new CookieContainer(); foreach (string line in youtubedlres.Split('\n')) { if (line.Contains(hsc)) { string[] jar = line.Substring(hsc.Length - 1).Split(' '); foreach (string cookie in jar) { if (cookie.Length > 2) { string[] cokie = cookie.Split('='); if (cokie.Length > 1 && (cokie[0] != "expires" && cokie[0] != "Expires")) { Cookie _cookie = new Cookie(cokie[0], (cokie[1].EndsWith(";")) ? cokie[1].Substring(0, cokie[1].Length - 2) : cokie[1]); _cookie.Domain = "youtube.com"; httpreq.CookieContainer.Add(_cookie); } } } } } resp = httpreq.GetResponse(); me = new audioInfo() { contentLength = (uint)(bitrate / 8 * approxlen * 1.5), approximateLength = (uint)approxlen, bitrate = bitrate, serverAudioStream = resp.GetResponseStream(), RefUrl = url }; } }
public bufferedStream(audioInfo info) { audioInfo = info; stream = audioInfo.serverAudioStream; }