/// <summary>Initialize LibVLC</summary> private void InitializeVlcPlayer() { vlcControl.VlcMediaPlayer.Manager.SetAppId("FoxIPTV", Application.ProductVersion, ""); vlcControl.VlcMediaPlayer.Manager.SetUserAgent("Fox IPTV", ""); vlcControl.VlcMediaPlayer.AudioVolume += (sender, args) => { TvCore.LogInfo($"[Audio] Volume: {vlcControl.Audio.Volume}"); }; vlcControl.VlcMediaPlayer.Log += (s, a) => { TvCore.LogInfo($"[Media] {a.Message}"); }; }
/// <summary>This is used to check for keyboard channel input</summary> private void TimerKeyboardEntry() { if (_numberEntryMode && _numberEntryModeTimeout == 1) { channelLabel.Text = string.Empty; channelNameLabel.Text = string.Empty; var newChannelNumber = uint.Parse(string.Join(string.Empty, _numberEntryDigits.Select(x => x.ToString()).ToArray())); _numberEntryMode = false; _numberEntryModeTimeout = 0; _numberEntryDigits.Clear(); if (!TvCore.ChannelIndexList.Contains(newChannelNumber)) { return; } TvCore.SetChannel((uint)TvCore.ChannelIndexList.IndexOf(newChannelNumber)); } else if (_numberEntryMode && _numberEntryModeTimeout > 0) { _numberEntryModeTimeout--; } }
/// <summary>The LibVLC Stopped event handler</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void VlcControl_Stopped(object sender, VlcMediaPlayerStoppedEventArgs e) { TvCore.LogDebug("[.NET] VlcControl_Stopped()"); this.InvokeIfRequired(() => { lock (_isClosingLock) { if (_isClosing) { TvCore.LogDebug("[.NET] Closing form..."); Application.Exit(); return; } } playerStatusLabel.Text = Resources.TvForm_Buffering; if (!Disposing && !_isErrorState) { ThreadPool.QueueUserWorkItem(state => { vlcControl.Play(TvCore.CurrentChannel.Stream); }); } }); }
/// <inheritdoc/> public TvForm() { TvCore.LogDebug("[.NET] TvForm(): Starting"); InitializeTvIcons(); InitializeComponent(); TvCore.ChannelChanged += TvCoreOnChannelChanged; TvCore.ProgrammeChanged += programme => this.InvokeIfRequired(GuiShow); InitializeStatusStrip(); InitializeContextMenu(); InitializeMouseCapturePanel(); InitializeVlcPlayer(); InitializeFormDefaults(); // Do initial resize... AspectRatioResize(); TvCore.LogDebug("[.NET] TvForm(): Finished starting"); }
/// <summary>Initialize the channel editor</summary> private void Initialize() { LoadAll(); treeViewAllChannels.AfterSelect += (s, a) => { if (_isChannelChanging || !_isInitialized) { return; } if (a.Node.Name == "NodeRoot" || a.Node.Name.StartsWith("NodeCat")) { if (a.Node.Name.StartsWith("NodeCat")) { a.Node.Expand(); treeViewAllChannels.SelectedNode = treeViewAllChannels.Nodes[0].Nodes[a.Node.Name].Nodes[0]; } UpdateGui(); } else { TvCore.SetChannel(uint.Parse(a.Node.Name)); } }; treeViewFavoriteChannels.AfterSelect += (s, a) => buttonFavoriteRemove.Enabled = a.Node.Name != "NodeRoot"; treeViewFavoriteChannels.NodeMouseDoubleClick += (s, a) => { if (_isChannelChanging || !_isInitialized) { return; } TvCore.SetChannel(uint.Parse(a.Node.Name)); }; TvCore.ChannelChanged += newChannel => { if (!_isInitialized) { return; } _isChannelChanging = true; UpdateGui(); _isChannelChanging = false; }; _isInitialized = true; }
/// <summary>The LibVLC EncounteredError event handler</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void VlcControl_EncounteredError(object sender, VlcMediaPlayerEncounteredErrorEventArgs e) { TvCore.LogError($"[.NET] VlcControl_EncounteredError({e})"); this.InvokeIfRequired(() => { SetErrorState(); playerStatusLabel.Text = Resources.TvForm_Error; }); }
/// <summary>The LibVLC EndReached event handler</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void VlcControl_EndReached(object sender, VlcMediaPlayerEndReachedEventArgs e) { TvCore.LogDebug($"[.NET] VlcControl_EndReached({e})"); this.InvokeIfRequired(() => { playerStatusLabel.Text = Resources.TvForm_Buffering; ThreadPool.QueueUserWorkItem(state => vlcControl.Play(TvCore.CurrentChannel.Stream)); }); }
private static async Task Main() { TvCore.LogInfo("[.NET] Main(): Starting Windows Application..."); Application.ApplicationExit += (sender, args) => TvCore.LogInfo("[.NET] Main(): Quitting Windows Application..."); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); TvCore.LogDebug("[.NET] Main(): Begin Auth Check"); if (!await TvCore.CurrentService.IsAuthenticated()) { TvCore.LogDebug("[.NET] Main(): Not Already Authenticated"); retry: var loginForm = new LoginForm(); var dResult = loginForm.ShowDialog(); if (dResult != DialogResult.OK) { return; } TvCore.ServiceSelected = loginForm.servicesComboBox.SelectedIndex; TvCore.CurrentService.Data = new JObject(); foreach (var field in TvCore.CurrentService.Fields) { var fieldControl = loginForm.Controls.Find(field.Key, false).FirstOrDefault(); if (fieldControl is null) { continue; } TvCore.CurrentService.Data.Add(field.Key, fieldControl.Text); } TvCore.CurrentService.SaveAuthentication = loginForm.rememberMeCheckBox.Checked; if (!await TvCore.CurrentService.IsAuthenticated()) { TvCore.LogDebug("[.NET] Main(): Authentication details incorrect, service rejected them, retrying."); goto retry; } } Application.Run(new TvForm()); }
/// <summary>Handle the Form's Closing event to hide form instead of closing it</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void TvForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason != CloseReason.UserClosing) { TvCore.LogDebug("[.NET] Closing main TvForm"); return; } e.Cancel = true; ToggleVisibility(); }
/// <summary>The LibVLC Playing event handler</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void VlcControl_Playing(object sender, VlcMediaPlayerPlayingEventArgs e) { TvCore.LogDebug("[.NET] VlcControl_Playing()"); ThreadPool.QueueUserWorkItem(state => { _currentMedia = vlcControl.GetCurrentMedia(); }); this.InvokeIfRequired(() => { playerStatusLabel.Text = Resources.TvForm_Playing; }); }
public async Task <Tuple <List <Channel>, List <Programme> > > Process() { if (_authData == null && Data == null) { return(null); } TvCore.LogDebug($"[{Title}] Process(): Starting data processing..."); var item1 = await ProcessChannels(); var item2 = await ProcessGuide(); return(new Tuple <List <Channel>, List <Programme> >(item1, item2)); }
/// <summary>A <see cref="Button"/> click handler, used to remove a favorite from the favorite channels list</summary> /// <param name="sender">The sender of this event</param> /// <param name="e">The event arguments</param> private void ButtonFavoriteRemove_Click(object sender, EventArgs e) { var channelIdx = int.Parse(treeViewFavoriteChannels.SelectedNode.Name); var channel = TvCore.Channels.Find(x => x.Index == TvCore.ChannelIndexList[channelIdx]); if (channel == null) { TvCore.LogError("[.NET] Channel was not found when removing a favorite channel"); return; } TvCore.RemoveFavoriteChannel(channel.Id); LoadAll(); }
/// <summary>Toggle the main form's visibility</summary> private void ToggleVisibility() { if (Visible) { TvCore.LogDebug("[.NET] Hiding main TvForm"); Hide(); } else { TvCore.LogDebug("[.NET] Showing main TvForm"); Show(); } TvCore.Settings.Visibility = Visible; TvCore.Settings.Save(); }
/// <summary>Initialize the right click menu</summary> private void InitializeContextMenu() { toolStripMenuItemChannelUp.Click += (sender, args) => TvCore.ChangeChannel(true); toolStripMenuItemChannelDown.Click += (sender, args) => TvCore.ChangeChannel(false); toolStripMenuItemWindowState.Click += (sender, args) => ToggleVisibility(); toolStripMenuItemMute.Click += (sender, args) => ToggleMute(); toolStripMenuItemStatusBar.Click += (sender, args) => ToggleStatusStrip(); toolStripMenuItemClosedCaptioning.Click += (sender, args) => ToggleClosedCaptioning(); toolStripMenuItemBorders.Click += (sender, args) => ToggleBorders(); toolStripMenuItemFullscreen.Click += (sender, args) => FullscreenSet(!TvCore.Settings.Fullscreen); toolStripMenuItemAlwaysOnTop.Click += (sender, args) => ToggleAlwaysOnTop(); toolStripMenuItemGuide.Click += (sender, args) => ToggleGuideForm(); toolStripMenuItemChannelEditor.Click += (sender, args) => ToggleChannelsForm(); toolStripMenuItemAbout.Click += (sender, args) => _aboutForm.ShowDialog(this); toolStripMenuItemQuit.Click += (sender, args) => Quit(); }
/// <summary>Handler for TVCore's channel changed event</summary> /// <param name="channel">The new channel we are changing to</param> private void TvCoreOnChannelChanged(uint channel) { this.InvokeIfRequired(() => { TvCore.LogDebug($"[.NET] TvCoreOnChannelChanged({channel})"); RemoveErrorState(); TvCore.Settings.Channel = channel; TvCore.Settings.Save(); _ccDetected = false; ccOptionsDropDownButton.Visible = false; ThreadPool.QueueUserWorkItem(state => vlcControl.Stop()); _currentMedia = null; _currentTvIconData = null; GuiShow(); }); }
private async Task <List <Channel> > ProcessChannels() { TvCore.LogDebug($"[{Title}] ProcessChannels() Start..."); var progressPercentage = ProgressUpdater.Item1; progressPercentage.Report(0); var categoryRaw = await TvCore.DownloadStringAndCache(BuildUri(ChannelCategoriesUrl), ChannelCategoryCacheFilename, CacheTimeChannelsInHours); var categoryDictionary = JArray.Parse(categoryRaw).ToDictionary(k => k["category_id"].ToString(), v => v["category_name"].ToString()); var channelRaw = await TvCore.DownloadStringAndCache(BuildUri(ChannelUrl), ChannelCacheFilename, CacheTimeChannelsInHours); var channelArray = JArray.Parse(channelRaw); var channelList = new List <Channel>(); foreach (var chan in channelArray) { try { var group = chan["category_id"].ToString(); if (!string.IsNullOrWhiteSpace(group) && categoryDictionary.ContainsKey(group)) { group = categoryDictionary[group]; } channelList.Add(new Channel { Index = chan["num"].ToObject <uint>(), Id = chan["epg_channel_id"].ToString(), Name = chan["name"].ToString(), Logo = Uri.TryCreate(chan["stream_icon"].ToString(), UriKind.Absolute, out var result) ? result : null, Group = group, Stream = new Uri($"{BuildUri(VideoLiveStreamUrl)}{chan["stream_id"]}.ts") }); }
/// <summary>The Form Load handler, which starts TVCore's functionality</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private async void TvForm_Load(object sender, EventArgs e) { TvCore.ChannelLoadPercentageChanged += percentage => this.InvokeIfRequired(() => { channelStatusProgressBar.Value = percentage; labelStatus.Text = string.Format(Resources.TvForm_LoadingBarMessage, channelStatusProgressBar.Value, guideStatusProgressBar.Value); }); TvCore.GuideLoadPercentageChanged += percentage => this.InvokeIfRequired(() => { guideStatusProgressBar.Value = percentage; labelStatus.Text = string.Format(Resources.TvForm_LoadingBarMessage, channelStatusProgressBar.Value, guideStatusProgressBar.Value); }); await TvCore.Start(); channelStatusLabel.Text = Resources.TvForm_ChannelsLoaded; guideStatusLabel.Text = Resources.TvForm_GuideLoaded; guideStatusProgressBar.Visible = channelStatusProgressBar.Visible = false; labelStatus.Visible = false; _isInitialized = true; if (TvCore.Settings.ChannelEditorOpen) { _channelsForm.Show(this); } if (TvCore.Settings.GuideOpen) { _guideForm.Show(this); } TvCore.SetChannel(TvCore.Settings.Channel); }
public async Task <bool> IsAuthenticated() { TvCore.LogDebug($"[{Title}] IsAuthenticated() called..."); var authDataFile = Path.Combine(TvCore.UserStoragePath, ServiceDataFilename); Uri domainUri = null; Uri authUrl; if (!File.Exists(authDataFile)) { TvCore.LogDebug($"[{Title}] IsAuthenticated(): No authentication file found..."); if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password) || string.IsNullOrWhiteSpace(Services)) { TvCore.LogError($"[{Title}] IsAuthenticated(): Username/Password/ServiceURL is empty"); return(false); } if (!Uri.IsWellFormedUriString(Services, UriKind.Absolute)) { TvCore.LogError($"[{Title}] IsAuthenticated(): ServiceURL is not a well formed link"); return(false); } domainUri = new Uri(Services); authUrl = new Uri($"http://{domainUri.DnsSafeHost}/{string.Format(AuthenticationUrl, Username, Password)}"); SaveAuthentication = true; } else { _authData = JsonConvert.DeserializeObject <AuthResponse>(File.ReadAllText(authDataFile).Unprotect()); authUrl = new Uri(BuildUri(AuthenticationUrl)); } TvCore.LogDebug($"[{Title}] IsAuthenticated(): Checking server authentication..."); using (var wc = new WebClient()) { wc.Headers.Add("user-agent", TvCore.ServiceUserAgentString); try { var data = await wc.DownloadStringTaskAsync(authUrl); _authData = JsonConvert.DeserializeObject <AuthResponse>(data); _authData.Server.UserUrl = domainUri?.DnsSafeHost ?? string.Empty; _authData.Server.UserPort = domainUri?.Port ?? 0; TvCore.LogDebug($"[{Title}] IsAuthenticated(): Checking server connection SUCCESS! IsAuthenticated: {_authData.User.Authenticated}"); } catch (Exception ex) { TvCore.LogError($"[{Title}] IsAuthenticated(): Checking server authentication ERROR: {ex.Message}"); return(false); } } if (_authData == null) { return(false); } if (_authData.User.Authenticated != 1) { return(false); } TvCore.LogDebug($"[{Title}] IsAuthenticated(): Server authentication SUCCESS! Server address: {_authData.Server.Url}"); if (!SaveAuthentication) { TvCore.LogDebug($"[{Title}] IsAuthenticated(): Not Saving User Authentication..."); TvCore.LogInfo($"[{Title}] Log-in successful"); return(true); } TvCore.LogDebug($"[{Title}] IsAuthenticated(): Saving auth data..."); File.WriteAllText(authDataFile, JsonConvert.SerializeObject(_authData).Protect()); TvCore.LogInfo($"[{Title}] Log-in successful"); return(true); }
/// <summary>Direct LibVLC to the directory containing libvlc.dll</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void VlcControl_VlcLibDirectoryNeeded(object sender, VlcLibDirectoryNeededEventArgs e) { TvCore.LogDebug("[.NET] VlcControl_VlcLibDirectoryNeeded()"); e.VlcLibDirectory = new DirectoryInfo(TvCore.LibraryPath); }
/// <summary>The KeyUp handler for hot keys</summary> /// <param name="sender">The object that triggered the event</param> /// <param name="e">The event arguments</param> private void TvForm_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Z) { Opacity -= .1; if (Opacity < 0) { Opacity = 0; } TvCore.LogDebug($"[.NET] Opacity Set {Opacity}"); } if (e.KeyCode == Keys.X) { Opacity += .1; if (Opacity > 1) { Opacity = 1; } TvCore.LogDebug($"[.NET] Opacity Set {Opacity}"); } if (e.KeyCode == Keys.B) { ToggleBorders(); } if (e.KeyCode == Keys.A) { ToggleAlwaysOnTop(); } if (e.KeyCode == Keys.F) { ToggleFullscreen(); } if (e.KeyCode == Keys.S) { ToggleStatusStrip(); } if (e.KeyCode == Keys.I) { GuiShow(); } if (e.KeyCode == Keys.H) { ToggleVisibility(); } if (e.KeyCode == Keys.G) { ToggleGuideForm(); } if (e.KeyCode == Keys.T) { ToggleChannelsForm(); } if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) { TvCore.ChangeChannel(e.KeyCode == Keys.PageUp); } if (e.KeyCode == Keys.Space) { ToggleMute(); } if (e.KeyCode == Keys.C) { ToggleClosedCaptioning(); } if (e.KeyCode == Keys.Enter && _numberEntryMode) { _numberEntryModeTimeout = 1; } if (e.KeyCode == Keys.Back && _numberEntryMode && _numberEntryDigits.Count > 0) { if (_numberEntryDigits.Count == 1) { _numberEntryMode = false; _numberEntryModeTimeout = 0; _numberEntryDigits.Clear(); GuiHide(); } else { _numberEntryModeTimeout = 20; _numberEntryDigits.RemoveAt(_numberEntryDigits.Count - 1); GuiShow(); } } if (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 || e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) { var digitPressed = e.KeyCode - (e.KeyCode < Keys.NumPad0 ? Keys.D0 : Keys.NumPad0); if (!_numberEntryMode) { _numberEntryMode = true; } _numberEntryModeTimeout = 20; _numberEntryDigits.Add(digitPressed); GuiShow(); } }