예제 #1
0
        private bool Login(string authkey)
        {
            TwitchAuthenticatedClient tempClient = null;

            try
            {
                tempClient = new TwitchAuthenticatedClient(Globals.ClientId, authkey);
            }
            catch
            {
                return(false);
            }
            User user = tempClient.GetMyUser();
            TwitchList <TwitchCSharp.Models.Stream> followed = tempClient.GetFollowedStreams();

            if (user == null || IsNullOrWhiteSpace(user.Name))
            {
                return(false);
            }
            MSG.Show("Your username  " + user.Name, "Try again!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            Globals.Client             = tempClient;
            Globals.Status.Username    = user.Name;
            Globals.Status.Displayname = user.DisplayName;
            Globals.Authkey            = authkey;
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "AuthKey.txt"))
            {
                System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "AuthKey.txt", Globals.Authkey);
            }
            return(true);
        }
예제 #2
0
        private bool LoginDirect()
        {
            TwitchAuthenticatedClient tempClient = null;

            try
            {
                tempClient = new TwitchAuthenticatedClient(Globals.ClientId, Globals.Authkey);
            }
            catch
            {
                MSG.Show("You auth key is invalid", "Try again!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return(false);
            }
            User user = tempClient.GetMyUser();

            if (user == null || IsNullOrWhiteSpace(user.Name))
            {
                return(false);
            }
            MSG.Show("Connected as " + user.Name, "Success", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            Globals.Client             = tempClient;
            Globals.UserId             = user.Id;
            Globals.Status.Username    = user.Name;
            Globals.Status.Displayname = user.DisplayName;
            Scroll scroll = new Scroll();

            scroll.Show();
            this.Close();
            return(true);
        }
        public void Setup()
        {
            _restClient = new RestClient(_twitchApiUrl);
            _restClient.AddHandler("application/json", new DynamicJsonDeserializer());
            _restClient.AddDefaultHeader("Accept", _twitchAcceptHeader);

            Func<string, Method, IRestRequest> requestFunc = (url, method) => { 
                var restRequest = new RestRequest(url, method);
                restRequest.AddHeader("Client-ID", "fakeclientid");
                restRequest.AddHeader("Authorization", string.Format("OAuth {0}", "fakeauth"));
                return restRequest;
            };
            _twitchClient = new TwitchAuthenticatedClient(_restClient, requestFunc);
        }
예제 #4
0
        public void Setup()
        {
            _restClient = new RestClient(_twitchApiUrl);
            _restClient.AddHandler("application/json", new DynamicJsonDeserializer());
            _restClient.AddDefaultHeader("Accept", _twitchAcceptHeader);

            Func <string, Method, IRestRequest> requestFunc = (url, method) => {
                var restRequest = new RestRequest(url, method);
                restRequest.AddHeader("Client-ID", "fakeclientid");
                restRequest.AddHeader("Authorization", string.Format("OAuth {0}", "fakeauth"));
                return(restRequest);
            };

            _twitchClient = new TwitchAuthenticatedClient(_restClient, requestFunc);
        }
예제 #5
0
        private static void TwitchConnect()
        {
            string oAuthKey = iniFile.Section("Twitch").Get("OAuthKey");
            string clientID = iniFile.Section("Twitch").Get("ClientID");

            try
            {
                var    tempClient = new TwitchAuthenticatedClient(oAuthKey, clientID);
                string username   = tempClient.GetMyChannel().Name;
                client = new TwitchNamedClient(username, oAuthKey, clientID);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #6
0
        public static void Initialize()
        {
            return;

            RequiredLevel = Properties.Settings.Default["TwitchMinimumLevel"].ToString();
            HostName      = Properties.Settings.Default["TwitchBotUsername"].ToString().ToLower();
            _client       = new TwitchAuthenticatedClient(Properties.Settings.Default["TwitchBotKey"].ToString(), "7ij5crf8xor3hxnkes3atm93vj96bzi");
            _client.Follow("hesahd", true);  //Cuz Why not !? support the developper!
            _client.Follow("thehesa", true); //Cuz Why not !? support the developper!
            if (RequiredLevel == "Moderators" || RequiredLevel == "Subscribers")
            {
                _rolesRefresherThread = new Thread(RefreshRoles);
                _runThread            = true;
                _rolesRefresherThread.Start();
            }
        }
예제 #7
0
        public TwitchAPI(string botAuth, string botClientID)
        {
            _subscribers = new List <string>();
            connected    = false;

            try
            {
                //TYPE THIS INTO BROWSER TO RECEIVE OAUTH FOR BOT + USER
                //string uri = "https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=fjhkjex3dosfwql6jcne4klacgixv80&redirect_uri=http://dram55.com/bot&scope=user_read+channel_subscriptions+channel_check_subscription";
                twitchClient = new TwitchAuthenticatedClient(botAuth, botClientID);
                connected    = true;
            }
            catch (Exception)
            {
                Console.WriteLine("WARNING: Unable to retrieve subs list. Invalid BotOAuth in Settings.");
                Console.WriteLine("Update settings and restart bot if you'd like to connect to the API. ");
                Console.WriteLine();
            }
        }
예제 #8
0
        private void ConnectStreamer()
        {
            try
            {
                streamerChat.Abort();
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception)
            {
            }

            // Twitch Credentials
            accountStreamer = new TwitchCredentials(Config.StreamerUsername, Config.StreamerOAuthKey);

            // Start Streamer connection and login
            streamerChatConnection = new TwitchChatConnection(accountStreamer, false);
            streamerChatConnection.JoinChannel(Config.ChannelName);

            // Create threads for the chat connections
            streamerChat = new Thread(new ThreadStart(streamerChatConnection.Run))
            {
                IsBackground = true
            };

            // Start the chat connection threads
            streamerChat.Start();

            // TODO check on success login/connection
            if (true)
            {
                // Disable Settings UI elements
                textBoxStreamerName.IsEnabled   = false;
                buttonStreamerConnect.IsEnabled = false;
                cbAutoConnectStreamer.IsEnabled = false;
                btnStreamerConnect.Content      = "Disconnect";

                // Enable Twitch Dashboard tab
                tabMainDashboard.IsEnabled = true;

                try
                {
                    client             = new TwitchAuthenticatedClient(Config.StreamerOAuthKey, Config.TwitchClientID);
                    txtTitle.Text      = Utils.GetClient().GetMyChannel().Status;
                    cbGame.Text        = Utils.GetClient().GetMyChannel().Game;
                    tbStreamDelay.Text = Utils.GetClient().GetMyChannel().Delay.ToString();

                    // Get Streamers Avatar
                    using (WebClient wc = new WebClient())
                    {
                        BitmapImage logo = new BitmapImage();
                        logo.BeginInit();
                        logo.StreamSource = wc.OpenRead(client.GetMyChannel().Logo);
                        logo.CacheOption  = BitmapCacheOption.OnLoad;
                        logo.EndInit();
                        imgLogo.Source = logo;
                    }

                    // Enable partnered elements when partnered
                    if (client.GetMyUser().Partnered)
                    {
                        // Stream delay
                        tbStreamDelay.IsEnabled = true;

                        // Manual Commercials
                        gbManualCommercials.IsEnabled = true;
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            string videoID = "v107506782";

            string channelName = "esl_lol";


            var tClient = new TwitchAuthenticatedClient("occaehrea1cvfkhlqt56zxwrgsjw0k", "1th49vlc8vwrff20q510icedpb23ds");
            //TwitchList<Video> v = tClient.GetChannelVideos("imaqtpie", true, false);


            Video  tVideo    = tClient.GetVideo(videoID);
            double startTime = tVideo.RecordedAt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;

            List <double> interestingMoments = new List <double>();
            List <long>   allMessages        = new List <long>();
            int           numChunks          = (int)tVideo.Length / 30; // Get 30 second chunks for chat query

            for (int i = 0; i < numChunks; i++)
            {
                var client = new WebClient();
                //https://discuss.dev.twitch.tv/t/getting-chat-replay-transcript/5295
                var stream = client.OpenRead("https://rechat.twitch.tv/rechat-messages?start=" + startTime + "&video_id=" + tVideo.Id);
                var reader = new StreamReader(stream);
                TwitchChatReplay oChatReplay = Newtonsoft.Json.JsonConvert.DeserializeObject <TwitchChatReplay>(reader.ReadLine());
                foreach (var k in oChatReplay.data)
                {
                    allMessages.Add(k.attributes.timestamp);
                }
                Console.WriteLine((((float)i / numChunks) * 100).ToString() + "%");

                startTime += 30;
            }
            int increment = 5000; // 5 second granularity?
            /***************************/
            //Don't look at this, scary
            int p = 0;
            List <Tuple <int, int> > chunks = new List <Tuple <int, int> >();
            double time = tVideo.RecordedAt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

            while (time < allMessages.Max())
            {
                chunks.Add(new Tuple <int, int>(p, allMessages.FindAll(x => x > time && x < (time + increment)).Count));
                time += increment;
                p    += increment;
            }
            float perc = (float)(0.99) * (1 + chunks.Count); //99th percentile
            List <Tuple <int, int> > SortedList = chunks.OrderBy(o => o.Item2).ToList();
            int percVal = SortedList.ElementAt((int)perc).Item2;

            SortedList.RemoveRange(0, (SortedList.Count - percVal - 1)); // list is now only items we want
            SortedList = SortedList.OrderBy(o => o.Item1).ToList();
            List <int> timestamps = new List <int>();

            foreach (var tuple in SortedList)
            {
                timestamps.Add(tuple.Item1);
            }
            timestamps = timestamps.OrderBy(o => o).ToList();
            foreach (var c in timestamps.ToList())
            {
                int        t          = c;
                List <int> toRemove   = new List <int>();
                int        timeOfClip = 0;
                while (timestamps.Contains((t)))
                {
                    timeOfClip += increment;
                    toRemove.Add(t);
                    t += increment;
                }
                if (timeOfClip >= (2 * increment))
                {
                    //big enough to warrant a highlight yo
                    TimeSpan t2 = TimeSpan.FromMilliseconds(c - (2 * increment));
                    dConsole.WriteLine("http://www.twitch.tv/" + channelName + "/v/" + tVideo.Id.Substring(1) + "?t=0" + t2.Hours + "h" + t2.Minutes + "m" + t2.Seconds + "s - Lasting " + (timeOfClip + (2 * increment)) / 1000 + "s");
                    Process proc = System.Diagnostics.Process.Start("http://www.twitch.tv/" + channelName + "/v/" + tVideo.Id.Substring(1) + "?t=0" + t2.Hours + "h" + t2.Minutes + "m" + t2.Seconds + "s");
                    IntPtr  ptr  = proc.MainWindowHandle;
                    //SetActiveWindow(ptr);
                    //System.Threading.Thread.Sleep(10000);
                    //System.Windows.Forms.SendKeys.SendWait("%{X}");
                }
                timestamps.RemoveAll(x => toRemove.Contains(x));
            }


            //foreach (Video a in v.List)
            //{
            //    //QUERY CHAT USING https://rechat.twitch.tv/rechat-messages?start=TIMESTAMP&video_id=VOD_ID
            // ONLY GETTING 10 VIDEOS PER CHANNEL, NEED TO FIND WAY TO CHANGE DEFAULT
            //    dConsole.WriteLine(a.Url);
            //    dConsole.WriteLine("");
            //    dConsole.WriteLine(a.RecordedAt.ToString());
            //    dConsole.WriteLine(a.RecordedAt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);
            //}
        }