//private bool AutoViewAccount2(Account account, string filterType, string title, string videoId, string recommendedVideoId, int durationMin, int durationMax, bool sub, bool like) //{ // var status = false; // FirefoxDriver driver = null; // try // { // var random = new Random(); // driver = Helper.CreateFirefoxDriver(account.Profile, account.Proxy, account.UserAgent); // if (driver != null) // { // driver.Navigate().GoToUrl("https://youtube.com"); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // var searchElement = driver.FindElementByXPath("//input[@id='search']"); // searchElement.SendKeys(title); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // searchElement.SendKeys(Keys.Enter); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // driver.Navigate().GoToUrl(driver.Url + "&sp=" + filterType); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // var videoElement = driver.FindElementsById("video-title").Where(x => x.Displayed && x.GetAttribute("href") != null && x.GetAttribute("href").Contains(videoId)).First(); // if (videoElement != null) // { // videoElement.Click(); // var duration = random.Next(durationMin, durationMax + 1); // Thread.Sleep(TimeSpan.FromSeconds(duration)); // UpdateDuration(videoId, duration); // // sub // if (sub) // { // try // { // var subscribeButton = driver.FindElementsById("subscribe-button").Where(x => x.Displayed).First(); // if (subscribeButton != null) // { // subscribeButton.Click(); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // var unsubModal = driver.FindElementsByXPath("//div[@id='scrollable']/yt-formatted-string[@class='line-text style-scope yt-confirm-dialog-renderer']").Where(x => x.Displayed).First(); // if (unsubModal != null) // { // // already sub // var actions = new Actions(driver); // actions.SendKeys(Keys.Escape).Perform(); // } // else // { // // not sub // var channelElement = driver.FindElementsByXPath("//div[@id='container']/div[@id='text-container']/yt-formatted-string[@id='text']/a[@class='yt-simple-endpoint style-scope yt-formatted-string']").Where(x => x.Displayed).First(); // if (channelElement != null) // { // var channelId = channelElement.GetAttribute("href").Split('/').Last(); // var channelName = channelElement.Text; // IncreaseSub(channelId, channelName, videoId); // } // } // } // } // catch (Exception e) // { // if (Helper.config.Log_Error == 1) Helper.LogError("View_Errors", e.Message); // } // } // if (like) // { // var likeButton = driver.FindElementsByXPath("//button[@id='button']/yt-icon[@class='style-scope ytd-toggle-button-renderer']").Where(x => x.Displayed).First(); // if (likeButton != null) // { // likeButton.Click(); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // } // } // try // { // // recommended video // var js = (IJavaScriptExecutor)driver; // var query = string.Format("document.querySelectorAll('[id=\"thumbnail\"]').forEach(function(e) {{ if (e.getAttribute('href') != null) e.setAttribute('href', '/watch?v={0}') }});", recommendedVideoId); // js.ExecuteScript(query); // var firstRightVideo = driver.FindElementsById("thumbnail").Where(x => x.Displayed && x.GetAttribute("href") != null).First(); // var actions = new Actions(driver); // actions.KeyDown(Keys.Control) // .Click(firstRightVideo) // .KeyUp(Keys.Control) // .Perform(); // Thread.Sleep(TimeSpan.FromSeconds(Helper.config.Action_Sleep)); // driver.Close(); // driver.SwitchTo().Window(driver.WindowHandles.Last()); // duration = random.Next(durationMin, durationMax + 1); // Thread.Sleep(TimeSpan.FromSeconds(duration)); // UpdateDuration(recommendedVideoId, duration); // } // catch (Exception e) // { // if (Helper.config.Log_Error == 1) Helper.LogError("View_Errors.txt", e.Message); // } // status = true; // } // } // else // { // ReportAccountError(account.Id, "Proxy bị lỗi"); // } // } // catch (Exception e) // { // if (Helper.config.Log_Error == 1) Helper.LogError("View_Errors.txt", e.Message); // ReportAccountError(account.Id, e.Message); // } // Helper.CloseBrowser(driver, true); // return status; //} public string StopAutoView() { var response = new AutoViewResponse { Status = true, Detail_Reason = "" }; stopThread = true; return(JsonConvert.SerializeObject(response)); }
public string AutoView(ViewData data) { var response = new AutoViewResponse { Status = false, Detail_Reason = "" }; try { stopThread = false; var thread = new Thread(() => ProcessAutoView(data)); thread.Start(); response.Status = true; } catch (Exception e) { response.Detail_Reason = e.Message; } return(JsonConvert.SerializeObject(response)); }