Beispiel #1
0
        public static async Task <List <TwitchChannel> > GetFollowedChannels(string login)
        {
            List <TwitchChannel> singleEntryList = new List <TwitchChannel> {
                new TwitchChannel("", login)
            };

            await FetchChannelInformation(singleEntryList);

            string userId = singleEntryList[0].UserId;

            if (string.IsNullOrEmpty(userId))
            {
                return(null);
            }

            string url      = TwitchApiBaseUrl + "users/follows?from_id=" + userId;
            var    response = await HTTPGetSafe(url);

            var followedChannels = JsonConvert.DeserializeObject <TwitchFollowedChannels>(response);

            var channels = new List <TwitchChannel>();

            foreach (var followedChannel in followedChannels.data)
            {
                var newChannel = new TwitchChannel(followedChannel.to_id, string.Empty)
                {
                    DisplayName = followedChannel.to_name
                };
                channels.Add(newChannel);
            }
            return(channels);
        }
Beispiel #2
0
 public void RemoveChannel(TwitchChannel twitchChannel)
 {
     if (twitchChannel == null)
     {
         return;
     }
     Channels.Remove(twitchChannel);
     SaveSettings();
     OnPropertyChanged("Channels");
 }
Beispiel #3
0
        public void AddChannel(TwitchChannel channel)
        {
            bool alreadyExistingChannelById    = Channels.FirstOrDefault(tc => tc.UserId == channel.UserId) != null;
            bool alreadyExistingChannelByLogin = Channels.FirstOrDefault(tc => tc.Login.ToLower().Equals(channel.Login.ToLower())) != null;

            if (alreadyExistingChannelById || (alreadyExistingChannelByLogin && channel.Login.Length > 0))
            {
                return;
            }
            Channels.Add(channel);
            SaveSettings();
            OnPropertyChanged("Channels");
        }
Beispiel #4
0
        public void AddChannel(string login)
        {
            if (string.IsNullOrEmpty(login))
            {
                return;
            }
            TwitchChannel newChannel = new TwitchChannel("", login);

            if (Channels.FirstOrDefault(tc => tc.Login.ToLower().Equals(login.ToLower())) != null)
            {
                return;
            }
            Channels.Add(newChannel);
            SaveSettings();
            OnPropertyChanged("Channels");
        }
        public static void StartLiveStream(TwitchChannel channel)
        {
            if (channel == null || /*!channel.IsOnline ||*/ string.IsNullOrEmpty(Settings.Instance.StreamlinkLocation))
            {
                return;
            }
            var process   = new Process();
            var startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                FileName    = Settings.Instance.StreamlinkLocation,
                Arguments   = GetStreamlinkArguments(channel)
            };

            process.StartInfo = startInfo;
            process.Start();
        }
Beispiel #6
0
        private static async Task <BitmapSource> DownloadPreviewImage(TwitchChannel channel)
        {
            string previewUrl = channel.PreviewImageURL;

            previewUrl = previewUrl.Replace("{width}", "1600");
            previewUrl = previewUrl.Replace("{height}", "900");

            BitmapSource bitmap = null;

            using (var response = await client.GetAsync(new Uri(previewUrl)))
            {
                if (response.IsSuccessStatusCode)
                {
                    using (var stream = new MemoryStream())
                    {
                        await response.Content.CopyToAsync(stream);

                        stream.Seek(0, SeekOrigin.Begin);
                        bitmap = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    }
                }
            }
            return(bitmap);
        }
 private void ChannelListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     SelectedChannel = ChannelListBox.SelectedItem as TwitchChannel;
     onSelectionChanged?.Invoke();
 }
Beispiel #8
0
        public static void ShowChannelOnlineNotification(TwitchChannel channel)
        {
            var window = new NotificationWindow(channel.DisplayName, channel.Description);

            ShowNewNotification(window);
        }
 private static string GetStreamlinkArguments(TwitchChannel channel)
 {
     return("twitch.tv/" + channel.Login + " " + Settings.Instance.SelectedQuality);
 }