コード例 #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
        public void HostRefresh()
        {
            TwitchList <Stream> followed = new TwitchList <Stream>();

            followed.List = AuthenticatedClient.HostStreamsList.ConvertAll(hostStream => hostStream.Stream);
            List <string> hosters = AuthenticatedClient.HostStreamsList.ConvertAll(hoster => hoster.HostLogin);

            AuthenticatedClient.ResetHostStreamList();
            m_offset = 0;
            RefreshStreamPanel(followed, true, hosters);
        }
コード例 #3
0
        private async void ReloadChannel()
        {
            if (!m_loadingChannel)
            {
                m_loadingChannel        = true;
                loaderStream.Visibility = Visibility.Visible;
                RemoveStackElement(false);
                FollowedStreams followedStream = await TwitchClient.GetFollowedStreamsAsyncV5(100);

                TwitchList <Stream> followed = new TwitchList <Stream>();
                followed.List = followedStream.Streams.OfType <Stream>().ToList();
                RefreshStreamPanel(followed, false);
            }
        }
コード例 #4
0
        private void UpdateSubscribers()
        {
            PagingInfo p = new PagingInfo();
            p.PageSize = 100;

            _subscribers.Clear();
            TwitchList<Subscription> temp = new TwitchList<Subscription>();

            //Twitch only allows requests for 100 subscribers at a time. 
            //Need to keep incrementing pages until you got all the subs.
            do
            {
                temp = twitchClient.GetSubscribers(pagingInfo: p);
                _subscribers.AddRange(temp.List.Select(t => t.User.DisplayName.ToLower()));
                p.Page++;
            }
            while (temp.Total > _subscribers.Count);
        }
コード例 #5
0
        private void UpdateSubscribers()
        {
            PagingInfo p = new PagingInfo();

            p.PageSize = 100;

            _subscribers.Clear();
            TwitchList <Subscription> temp = new TwitchList <Subscription>();

            //Twitch only allows requests for 100 subscribers at a time.
            //Need to keep incrementing pages until you got all the subs.
            do
            {
                temp = twitchClient.GetSubscribers(pagingInfo: p);
                _subscribers.AddRange(temp.List.Select(t => t.User.DisplayName.ToLower()));
                p.Page++;
            }while (temp.Total > _subscribers.Count);
        }
コード例 #6
0
        public static void CheckForFollowers(TwitchList<Follow> followers, Channel channel)
        {
            var followingChannel = ChannelMethods.GetFollowers(channel);

            var newFollowers = followingChannel
                .SelectMany(fc => followers.List
                    .Where(f => f.Channel.Id != fc.TwitchChannelId))
                    .AsQueryable();

            // användare som finns i databasen men inte finns i followers
            var followersToDelete = followers.List
                .SelectMany(f => followingChannel
                    .Where(fc => fc.TwitchChannelId != f.Channel.Id))
                    .AsQueryable();

            ChannelMethods.AddFollowers(channel, newFollowers);

            ChannelMethods.RemoveFollowers(channel, followersToDelete);
        }
コード例 #7
0
        private async void RefreshStreamPanel(TwitchList <Stream> p_followed, bool p_isHost, List <string> p_hosters = null)
        {
            for (int i = 0; i < p_followed.List.Count; i++)
            {
                Stream stream = p_followed.List[i];
                if (stream != null)
                {
                    // Create images preview.
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                    string url = stream.Preview.Large;
                    Uri    uri = new Uri(url);
                    var    bmp = new BitmapImage();
                    bmp.BeginInit();
                    bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    bmp.UriSource     = uri;
                    bmp.EndInit();
                    img.Source = bmp;

                    // Create Images cover.
                    System.Windows.Controls.Image img2 = new System.Windows.Controls.Image();
                    img2.HorizontalAlignment = HorizontalAlignment.Right;
                    img2.VerticalAlignment   = VerticalAlignment.Bottom;
                    img2.Stretch             = Stretch.None;
                    try
                    {
                        SearchGames sGame = await TwitchClient.SearchGamesAsyncV5(stream.Game);

                        Game game = sGame.Games[0];
                        img2.ToolTip = game.Name;
                        Uri         uri2 = new Uri(game.Box.Small);
                        BitmapImage bmp2 = new BitmapImage(uri2);
                        img2.Source = bmp2;
                    }
                    catch
                    {
                        img2.ToolTip = "I AM ERROR";
                        Uri         uri2 = new Uri(stream.Preview.Small);
                        BitmapImage bmp2 = new BitmapImage(uri2);
                        img2.Source = bmp2;
                    }

                    // Create grid.
                    Grid grid = new Grid();
                    grid.Margin = new Thickness(0, 10, 0, 0);
                    grid.Children.Add(img);
                    grid.Children.Add(img2);

                    // Create Textblock
                    string viewers   = stream.Viewers + " viewers";
                    double fps       = stream.AverageFps;
                    string framerate = String.Empty;
                    if (fps > 50)
                    {
                        framerate = "60";
                    }
                    string quality = " - Max quality: " + stream.VideoHeight + "p" + framerate;
                    string hoster  = String.Empty;
                    if (p_hosters != null)
                    {
                        hoster = "Hosted by " + p_hosters[i] + Environment.NewLine;
                    }
                    TextBlock title = new TextBlock();
                    title.Text         = hoster + viewers + quality + Environment.NewLine + stream.Channel.Status;
                    title.Height       = 60;
                    title.FontSize     = 15;
                    title.TextWrapping = TextWrapping.Wrap;
                    title.FontWeight   = FontWeights.Bold;
                    title.FontFamily   = Globals.OldNewspaperTypes;

                    // Create buttons.
                    Button myButton = new Button();
                    myButton.Content             = stream.Channel.Name;
                    myButton.FontFamily          = Globals.OldNewspaperTypes;
                    myButton.Click              += new RoutedEventHandler(startLoadedStream_Click);
                    myButton.MouseRightButtonUp += new MouseButtonEventHandler(CopyPastUsername_RightClick);

                    // Add image and button in the right panel.
                    if (p_isHost)
                    {
                        switch (i % 4)
                        {
                        case 0:
                            panelHostRight1.Children.Add(grid);
                            panelHostRight1.Children.Add(title);
                            panelHostRight1.Children.Add(myButton);
                            break;

                        case 1:
                            panelHostRight2.Children.Add(grid);
                            panelHostRight2.Children.Add(title);
                            panelHostRight2.Children.Add(myButton);
                            break;

                        case 2:
                            panelHostRight3.Children.Add(grid);
                            panelHostRight3.Children.Add(title);
                            panelHostRight3.Children.Add(myButton);
                            break;

                        case 3:
                            panelHostRight4.Children.Add(grid);
                            panelHostRight4.Children.Add(title);
                            panelHostRight4.Children.Add(myButton);
                            break;
                        }
                    }
                    else
                    {
                        switch (i % 4)
                        {
                        case 0:
                            panelRight1.Children.Add(grid);
                            panelRight1.Children.Add(title);
                            panelRight1.Children.Add(myButton);
                            break;

                        case 1:
                            panelRight2.Children.Add(grid);
                            panelRight2.Children.Add(title);
                            panelRight2.Children.Add(myButton);
                            break;

                        case 2:
                            panelRight3.Children.Add(grid);
                            panelRight3.Children.Add(title);
                            panelRight3.Children.Add(myButton);
                            break;

                        case 3:
                            panelRight4.Children.Add(grid);
                            panelRight4.Children.Add(title);
                            panelRight4.Children.Add(myButton);
                            break;
                        }
                    }
                }
            }
            if (p_isHost)
            {
                loaderHost.Visibility = Visibility.Hidden;
                m_loadingHost         = false;
            }
            else
            {
                loaderStream.Visibility = Visibility.Hidden;
                m_loadingChannel        = false;
            }
        }