コード例 #1
0
        public ChannelLayout(Channel c)
        {
            InitializeComponent();

            this.channel = c;

            linklblChannelDisplayName.Text = this.channel.display_name;

            try
            {
                pbChannelPicture.Load(this.channel.logo);
            }
            catch {

                pbChannelPicture.Load("http://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_150x150.png");
            }

            if (this.channel.live)
            {

                LiveChannel();

            }
            else {

                OfflineChannel();

            }

            if (this.channel.gameLive == null || this.channel.game == null)
            {

                this.panelGamePlaying.Visible = false;

            }
        }
コード例 #2
0
        // Twitch API Comment:
        // Returns a list of follows objects.
        public List<Channel> GetChannelsUserIsFollowing()
        {
            string hostURI = baseApiUrl + "users/" + this.TwitchUsername + "/follows/channels";

            JObject FollowingChannels = getData(hostURI);

            if (FollowingChannels != null)
            {

                foreach (JObject fc in FollowingChannels["follows"])
                {

                    JObject c = (JObject)fc["channel"];

                    Channel newChannel = new Channel();

                    newChannel.StreamClientName = this.StreamClientName;

                    newChannel.display_name = (string)c["display_name"];
                    newChannel.name = (string)c["name"];
                    newChannel.status = (string)c["status"];
                    newChannel.game = (string)c["game"];
                    newChannel.logo = (string)c["logo"];
                    newChannel.url = (string)c["url"];

                    newChannel.id = (int)c["_id"];
                    newChannel.views = (int)c["views"];

                    newChannel.updated_at = (DateTime)c["updated_at"];

                    // Check if stream is live
                    JObject StreamChannel = GetStreamChannelData((string)c["name"]);

                    if (StreamChannel != null)
                    {
                        if (StreamChannel["stream"].HasValues)
                        {
                            // Channel is Live

                            JObject cLive = (JObject)StreamChannel["stream"];

                            newChannel.live = true;

                            newChannel.gameLive = (string)cLive["game"];
                            newChannel.viewersLive = (int)cLive["viewers"];

                        }
                        else
                        {
                            newChannel.live = false;

                        }

                        Channels.Add(newChannel);

                    }
                    else { return null; }

                }

                return this.Channels;
            }

            return null;
        }
コード例 #3
0
        public ChannelLayoutPanel(Channel channel)
        {
            //

            Panel panelStreamText = new Panel();

            this.BorderStyle = BorderStyle.FixedSingle;

            this.Width = (410 - 25); // Shound not be a Hardcoded witdh

            this.Padding = (new Padding(0));
            //tlpStream.Margin = (new Padding(0));

            PictureBox pbStreamLogo = new PictureBox();

            string streamLogoUrl = channel.logo;
            pbStreamLogo.Size = new Size(100, 100);
            pbStreamLogo.SizeMode = PictureBoxSizeMode.StretchImage;
            pbStreamLogo.Load(streamLogoUrl);
            pbStreamLogo.Margin = (new Padding(0, 0, 0, 2));

            pbStreamLogo.Cursor = Cursors.Hand;

            pbStreamLogo.Click += new EventHandler((sender, e) => openURL(sender, e, channel.url));

            this.Controls.Add(pbStreamLogo);

            panelStreamText.Location = new Point(pbStreamLogo.Width + 10, 10);
            panelStreamText.Width = this.Width - pbStreamLogo.Width;

            LinkLabel lblDisplayname = new LinkLabel();
            lblDisplayname.Name = "lblDisplayname";
            lblDisplayname.Text = channel.display_name;
            lblDisplayname.Width = 10;
            lblDisplayname.AutoSize = true;
            lblDisplayname.Font = new Font(lblDisplayname.Font, FontStyle.Bold);
            lblDisplayname.LinkClicked += new LinkLabelLinkClickedEventHandler((sender, e) => openURL(sender, e, channel.url));

            formMain.Logger(">>> Channel Displayname: " + lblDisplayname.Text);

            Label lblLiveStatus = new Label();
            lblLiveStatus.Name = "lblLiveStatus";
            lblLiveStatus.Left = lblDisplayname.PreferredWidth + 5;
            lblLiveStatus.Top = 0;

            Label lblStatus = new Label();
            lblStatus.Name = "lblStatus";
            lblStatus.Left = 0;
            lblStatus.Top = 46;

            lblStatus.MaximumSize = new Size(this.Width - pbStreamLogo.Width - 20, 0);

            lblStatus.AutoSize = true;

            //lblStatus.Font = new Font(lblStatus.Font, FontStyle.Italic);

            if (channel.live)
            {

                lblLiveStatus.Text = "Live";
                lblLiveStatus.ForeColor = Color.Green;
                lblLiveStatus.Font = new Font(lblDisplayname.Font, FontStyle.Bold);

                Label lblLiveViewers = new Label();
                lblLiveViewers.Name = "lblLiveViewers";
                lblLiveViewers.Width = 0;
                lblLiveViewers.AutoSize = true;
                lblLiveViewers.Text = channel.viewersLive + " Viewers";
                lblLiveViewers.Location = new Point(panelStreamText.Width - lblLiveViewers.PreferredWidth - 20, 0);
                panelStreamText.Controls.Add(lblLiveViewers);

                Label lblPlaying = new Label();
                lblPlaying.Name = "lblLiveViewers";
                lblPlaying.Left = 0;
                lblPlaying.Top = 23;
                lblPlaying.AutoSize = true;
                lblPlaying.Text = "Playing: " + channel.gameLive;
                panelStreamText.Controls.Add(lblPlaying);

                lblStatus.Text = channel.status;

            }
            else
            {

                lblLiveStatus.Text = "Offline";
                lblLiveStatus.ForeColor = Color.Red;

                //lblStatus.Text = "<lblStatus:Offline>";

            }

            formMain.Logger(">>> LiveStatus: " + lblLiveStatus.Text);
            formMain.Logger(">>> Status: " + lblStatus.Text);

            panelStreamText.Controls.Add(lblDisplayname);
            panelStreamText.Controls.Add(lblLiveStatus);

            panelStreamText.Controls.Add(lblStatus);

            this.Controls.Add(panelStreamText);
        }
コード例 #4
0
ファイル: Streams.cs プロジェクト: WhyN92/WhyNsStreamWatcher
        private List<Control> UpdateStreams()
        {
            // Creating new TwitchAPI based on username
            twitchAPI = new TwitchAPI(Properties.Settings.Default.TwitchUsername);

            Label lblErrorStatus = new Label();
            lblErrorStatus.AutoSize = true;
            lblErrorStatus.Margin = new Padding(30);
            lblErrorStatus.Font = new Font(lblErrorStatus.Font, FontStyle.Bold);

            if (Properties.Settings.Default.TwitchUsername.Length != 0)
            {

                // List for Channel Controls
                List<Control> listStreamControls = new List<Control>();

                List<Channel> NewChannels;

                // Getting Twitch channels
                List<Channel> TwitchChannels = this.twitchAPI.GetChannelsUserIsFollowing();

                // Merging Channels from Stream Clients
                try
                {
                    NewChannels = new List<Channel>(TwitchChannels);
                }
                catch {

                    NewChannels = null;
                }

                // New List for Channels
                List<Channel> NewChangedChannels = new List<Channel>();

                // New Channel Object for Channel
                Channel ChangedChannel = new Channel();

                if (NewChannels != null)
                {

                    string OfflineStreamsText = string.Empty;
                    int i = 0;
                    foreach(Channel NewChannel in NewChannels)
                    {

                        ChangedChannel = NewChannel;

                        if (OldChannels != null)
                        {
                            foreach (Channel OldChannel in OldChannels)
                            {

                                if (NewChannel.id == OldChannel.id)
                                {
                                    // Checking for Changes and returning changed channel
                                    ChangedChannel = CheckForStreamChanges(NewChannel, OldChannel);

                                    break;
                                }

                            }
                        }
                        else
                        {
                            // If no OldChannels

                            // First time Notifications at Application Start
                            if (NewChannel.live)
                            {
                                // Channel Is Live!
                                ChangedChannel.IsLive = true;

                            }

                        }

                        // Adding Changed Channel to List
                        NewChangedChannels.Add(ChangedChannel);

                        // Showing Notification if Any
                        ShowNotification(ChangedChannel);

                        // Creating control for Channel
                        Control ChannelControl = new ChannelLayout(ChangedChannel);

                        if (ChangedChannel.live)
                        {

                            listStreamControls.Add(ChannelControl);

                        }
                        else if (Properties.Settings.Default.ShowOfflineStreams)
                        {

                            listStreamControls.Add(ChannelControl);
                            OfflineStreamsText = "";
                        }
                        else
                        {
                            i++;

                            OfflineStreamsText = "(" + i + " streams offline)";

                        }

                    }

                    this.lblStreamsOffline.Invoke(new UpdateOfflineStreamsLabelCallback(this.UpdateOfflineStreamsLabel), new object[] { OfflineStreamsText });

                    OldChannels = NewChangedChannels; // Or Should it be NewChannels? Testing will show!

                    return listStreamControls;

                }

                // No data from Stream Clients
                lblErrorStatus.Text = "Something went worng when getting data from Twitch.tv!\n\nMake sure the entered username is valid!\nIf it is, Try again later...";

            }
            else
            {
                // No Username
                lblErrorStatus.Text = "No Username Entered!";
            }

            // Creating Error Notification and Status
            NotificationForm nf = new NotificationForm(ui);
            nf.Title = "WhyNs Stream Watcher";
            nf.Message = lblErrorStatus.Text;

            Thread.Sleep(1000);

            this.panelStreams.Invoke(new ShowNotificationCallback(this.ShowNotification), new object[] { nf });

            return new List<Control>(new Control[] { lblErrorStatus });
        }
コード例 #5
0
ファイル: Streams.cs プロジェクト: WhyN92/WhyNsStreamWatcher
        private void ShowNotification(Channel channel)
        {
            ChannelLayout ChannelControl = new ChannelLayout(channel);
            //ChannelControl.Location = new Point(0, 0);

            NotificationForm ChannelNotification = new NotificationForm(ui);
            ChannelNotification.FormBorderStyle = FormBorderStyle.None;
            ChannelNotification.Size = new Size(ChannelControl.Size.Width, ChannelControl.Size.Height);
            ChannelNotification.CustomControl = ChannelControl;

            if (channel.IsLive && Properties.Settings.Default.ChannelNotificationIsLive)
            {

                this.panelStreams.Invoke(new ShowNotificationCallback(this.ShowNotification), new object[] { ChannelNotification });

            }
            else if (channel.IsLiveNow && Properties.Settings.Default.ChannelNotificationIsLiveNow)
            {

                this.panelStreams.Invoke(new ShowNotificationCallback(this.ShowNotification), new object[] { ChannelNotification });

            }
            else if (channel.IsOfflineNow && Properties.Settings.Default.ChannelNotificationIsOfflineNow)
            {

                this.panelStreams.Invoke(new ShowNotificationCallback(this.ShowNotification), new object[] { ChannelNotification });

            }
        }
コード例 #6
0
ファイル: Streams.cs プロジェクト: WhyN92/WhyNsStreamWatcher
        // Checking for Channel / Stream changes
        // By comparing NewChannel and OldChannel Data
        private Channel CheckForStreamChanges(Channel NewChannel, Channel OldChannel)
        {
            Channel ChangedChannel = NewChannel;

            // Channel Is Live Now!
            if (NewChannel.live && !OldChannel.live)
            {

                ChangedChannel.IsLiveNow = true;

            }

            // Channel Is Offline Now!
            if (!NewChannel.live && OldChannel.live)
            {

                ChangedChannel.IsOfflineNow = true;

            }

            // Channel Is (still) Live!
            if (NewChannel.live) {

                // Gets and save the Difference in viewers since last refresh
                ChangedChannel.viewersLiveDifference = (NewChannel.viewersLive - OldChannel.viewersLive);

            }

            return ChangedChannel;
        }