Ejemplo n.º 1
0
 public Client(string ip, int port, TwitchUsher usher)
 {
     client = new TcpClient(ip, port);
     client.Client.Blocking = false;
     client.NoDelay = true;
     client.SendBufferSize = 10000;
     client.ReceiveBufferSize = 10000;
     _usher = usher;
 }
Ejemplo n.º 2
0
        public static TwitchUsher FromUser(string user)
        {
            HttpWebRequest req =
                (HttpWebRequest)WebRequest.Create("http://usher.twitch.tv/find/" + user + ".xml?type=live");

            req.Method = "GET";

            var resp = req.GetResponse();
            StreamReader reader = new StreamReader(resp.GetResponseStream());
            var str = reader.ReadToEnd();

            var doc = new HtmlDocument();
            doc.LoadHtml(str);

            var ret = new TwitchUsher();

            try
            {
                foreach (var node in doc.DocumentNode.SelectNodes("//live"))
                {
                    var strData = new StreamData();

                    if (node.SelectSingleNode("play") != null)
                        strData.PlayStream = node.SelectSingleNode("play").InnerText;
                    if (node.SelectSingleNode("video_height") != null)
                        strData.VideoHeight = node.SelectSingleNode("video_height").InnerText;
                    if (node.SelectSingleNode("token") != null)
                        strData.Token = node.SelectSingleNode("token").InnerText;
                    if (node.SelectSingleNode("connect") != null)
                        strData.Server = node.SelectSingleNode("connect").InnerText;

                    if (strData.Server.Contains("rtmp://"))
                        strData.Server = strData.Server.Substring(("rtmp://").Length);

                    if (strData.Server.Contains("/app"))
                        strData.Server = strData.Server.Remove(strData.Server.IndexOf("/app"));

                    ret.Streams.Add(strData);
                }
            }
            catch(Exception ex){}
            return ret;
        }