示例#1
0
            public async override void Run()
            {
                if (AppSettings.Notifying)
                {
                    try
                    {
                        if (!ExtNotifications.NotificationHttpRequestInProgress && !_notificationStackExecutionInProgress)
                        {
                            _notificationStackExecutionInProgress = true;
                            var noteText = await ExtWebInterface.GetNotificationText("https://www.bitchute.com/notifications/");

                            var noteList = await ExtNotifications.DecodeHtmlNotifications(noteText);

                            ExtNotifications.SendNotifications(noteList);
                            _notificationStackExecutionInProgress = false;
                        }
                    }
                    catch {   }
                }
            }
示例#2
0
        /// <summary>
        /// starts/restarts the notifications,
        /// takes a ms int as the delay for starting,
        /// if this is called with no delay TheFragment5 sometimes
        /// is null or has issues when it's methods are called
        /// immediately after the app initially loads.
        ///
        /// Once the notifications are started this loop returns
        /// and invokes a long running TimerTask
        /// The reason for this is because the loop is
        /// stopping after a while so I am moving to a timer
        /// system for the long running task to see if that
        /// will prevent the loop from breaking.
        /// </summary>
        public static async void StartNotificationLoop(int delay, List <ExtNotifications.CustomNotification> initialNotifications = null, bool afterLogin = false)
        {
            NotificationLoopStartTimesInvoked++;
            //wait on a delay so that the cookie is ready when we make
            //httprequest for the notifications
            await Task.Delay(delay);

            //use a while loop to start the notifications
            //they move over to a service timer eventually to prevent the loop from breaking
            while (AppSettings.Notifying)
            {
                if (!ExtNotifications.NotificationHttpRequestInProgress && !_notificationStackExecutionInProgress && AppState.UserIsLoggedIn)
                {
                    if (initialNotifications == null)
                    {
                        _notificationStackExecutionInProgress = true;
                        var noteText = await ExtWebInterface.GetNotificationText("https://www.bitchute.com/notifications/");

                        var noteList = await ExtNotifications.DecodeHtmlNotifications(noteText);

                        if (noteList.Count > 0)
                        {
                            ExtNotifications.SendNotifications(noteList);
                            NotificationsHaveBeenSent = true;
                        }
                        _notificationStackExecutionInProgress = false;
                    }
                    else
                    {
                        ExtNotifications.SendNotifications(initialNotifications);
                    }
                }
                if (NotificationsHaveBeenSent)
                {
                    //check to make sure the timer isn't already started or the app will crash
                    if (!MainPlaybackSticky._notificationLongTimerSet)
                    {
                        try
                        {
                            //after the initial notifications are sent, start the long running service timer task
                            _timer.ScheduleAtFixedRate(_extTimerTask, 500000, 780000); // 780000
                            _notificationLongTimerSet = true;
                            return;
                        }
                        catch { }
                    }
                }
                if (NotificationLoopStartTimesInvoked > 1)
                {
                    NotificationLoopStartTimesInvoked--; break;
                }
                else if (!AppState.UserIsLoggedIn)
                {
                    await Task.Delay(220000);
                }
                //user is logged in but has not yet received a notification
                else
                {
                    await Task.Delay(220000);
                }
            }
        }
示例#3
0
        public static async Task <bool> GetObjectsFromHtmlResponse()
        {
            string h = "";

            if (!String.IsNullOrWhiteSpace(AppSettings.SessionState.Cfduid) &&
                !String.IsNullOrWhiteSpace(AppSettings.SessionState.CsrfToken) &&
                !String.IsNullOrWhiteSpace(AppSettings.SessionState.SessionId))
            {
                h = await ExtWebInterface.GetHtmlTextFromUrl("https://www.bitchute.com/notifications", false, true, true);
            }
            else if (String.IsNullOrWhiteSpace(AppSettings.SessionState.Cfduid) ||
                     String.IsNullOrWhiteSpace(AppSettings.SessionState.CsrfToken) ||
                     String.IsNullOrWhiteSpace(AppSettings.SessionState.SessionId))
            {
                AppSettings.SessionState.Cfduid    = "";
                AppSettings.SessionState.CsrfToken = "";
                AppSettings.SessionState.SessionId = "";
                h = await ExtWebInterface.GetHtmlTextFromUrl("https://www.bitchute.com/", true);

                var darkmodeCookie = "preferences={%22theme%22:%22night%22%2C%22autoplay%22:true}; ";
                CookieManager.Instance.SetCookie("https://www.bitchute.com/", darkmodeCookie);
            }
            else
            {
                var darkmodeCookie = "preferences={%22theme%22:%22night%22%2C%22autoplay%22:true}; ";
                CookieManager.Instance.SetCookie(".bitchute.com/", darkmodeCookie);
                h = await ExtWebInterface.GetHtmlTextFromUrl("https://www.bitchute.com/", true);
            }

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            try
            {
                doc.LoadHtml(h);
            }
            catch
            {
            }
            try
            {
                if (doc == null)
                {
                    return(false);
                }
                foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//title"))
                {
                    var _tagContents = node.InnerText;
                    if (_tagContents.Contains("Notifications"))
                    {
                        AppState.UserIsLoggedIn = true;
                        ExtNotifications.DecodeHtmlNotifications(h, true, null);
                    }
                    else
                    {
                        AppState.UserIsLoggedIn = false;
                        BitChute.Fragments.HomePageFrag.ShowLoginOnStartup = true;
                    }
                }
            }
            catch
            {
                //AppState.UserIsLoggedIn = false;
                BitChute.Fragments.HomePageFrag.ShowLoginOnStartup = true;
            }
            try
            {
                foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//link[@href]"))
                {
                    if (node.OuterHtml.Contains("/common.css"))
                    {
                        CssHelper.CommonCssUrl = await Task.FromResult("https://www.bitchute.com" + node.Attributes["href"].Value);
                    }
                    else if (node.OuterHtml.Contains("/video.css"))
                    {
                        CssHelper.VideoCssUrl = await Task.FromResult("https://www.bitchute.com" + node.Attributes["href"].Value);
                    }
                    //else if (node.OuterHtml.Contains("/bootstrap.min.css"))
                    //{
                    //    CssHelper.BootstrapCssUrl = await Task.FromResult(node.Attributes["href"].Value);
                    //}
                    //else if (node.OuterHtml.Contains("/search.css"))
                    //{
                    //    CssHelper.SearchCssUrl = await Task.FromResult("https://www.bitchute.com" + node.Attributes["href"].Value);
                    //}
                }
                foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//input[@name='csrfmiddlewaretoken']"))
                {
                    var csrf = Login.GetLatestCsrfToken(node.Attributes["value"].Value).Value;
                }

                CssHelper.GetCommonCss(CssHelper.CommonCssUrl, true, true, CssHelper.VideoCssUrl, "");//CssHelper.BootstrapCssUrl);
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
            return(false);
        }