Now the feed is put in 1080p

This commit is contained in:
2023-04-19 11:47:02 +02:00
parent cbe78e5812
commit 4230696888
3 changed files with 71 additions and 5 deletions

View File

@@ -13,6 +13,9 @@ using OpenQA.Selenium.Firefox;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
namespace Selenium_Clean
{
@@ -73,16 +76,21 @@ namespace Selenium_Clean
return value;
}
private void btnStart_Click(object sender, EventArgs e)
{
string loginCookieValue = GetCookie(COOKIE_HOST, "login");
string loginSessionValue = GetCookie(COOKIE_HOST, "login-session");
{
string loginCookieName = "login";
string loginSessionCookieName = "login-session";
string loginCookieValue = GetCookie(COOKIE_HOST, loginCookieName);
string loginSessionValue = GetCookie(COOKIE_HOST, loginSessionCookieName);
int windowWidth = 1920;
int windowHeight = 1080;
var service = FirefoxDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory+@"geckodriver-v0.27.0-win32\geckodriver.exe");
service.Host = "127.0.0.1";
service.Port = 5555;
FirefoxOptions options = new FirefoxOptions();
options.AddArgument("--window-size=1920,1080");
options.AddArgument("--window-size="+windowWidth+","+windowHeight+"");
options.AddArgument("--disable-headless");
options.AddArgument("--disable-web-security");
options.AddArgument("--same-site-none-secure");
@@ -90,7 +98,61 @@ namespace Selenium_Clean
using (var driver = new FirefoxDriver(service,options))
{
driver.Navigate().GoToUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&autoplay=1&mute=1");
var loginCookie = new Cookie(loginCookieName, loginCookieValue, COOKIE_HOST, "/", DateTime.Now.AddDays(5));
var loginSessionCookie = new Cookie(loginSessionCookieName, loginSessionValue, COOKIE_HOST, "/", DateTime.Now.AddDays(5));
Actions actions = new Actions(driver);
driver.Navigate().GoToUrl("https://f1tv.formula1.com/");
driver.Manage().Cookies.AddCookie(loginCookie);
driver.Manage().Cookies.AddCookie(loginSessionCookie);
driver.Navigate().GoToUrl("https://f1tv.formula1.com/detail/1000005104/2022-bahrain-grand-prix?action=play");
//Waits for the page to fully load
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);
//Removes the cookie prompt
IWebElement conscentButton = driver.FindElement(By.Id("truste-consent-button"));
conscentButton.Click();
//Again waits for the page to fully load (when you accept cookies it takes a little time for the page to load)
//Cannot use The timeout because the feed loading is not really loading so there is not event or anything
Thread.Sleep(5000);
//Switches to the Data channel
try
{
IWebElement dataChannelButton = driver.FindElement(By.ClassName("data-button"));
dataChannelButton.Click();
}
catch (OpenQA.Selenium.NoSuchElementException error)
{
//If the data button does not exists its because the user is not connected
MessageBox.Show("Could not connect to the F1TV. Please connect to it using your account on chrome and if you already did please wait the process can take a few minuts");
driver.Dispose();
Application.Exit();
}
//Open settings
// Press the space key twice, this should make the setting button visible
actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform();
Thread.Sleep(1000);
//Clicks on the settings Icon
IWebElement settingsButton = driver.FindElement(By.ClassName("bmpui-ui-settingstogglebutton"));
settingsButton.Click();
IWebElement selectElement = driver.FindElement(By.ClassName("bmpui-ui-videoqualityselectbox"));
SelectElement select = new SelectElement(selectElement);
IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']"));
selectOption.Click();
//Makes the feed fullscreen
IWebElement fullScreenButton = driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
fullScreenButton.Click();
Thread.Sleep(5000);
//Now you can start taking screenshots
}
}
}

View File

@@ -49,6 +49,9 @@
<Reference Include="WebDriver, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.4.8.2\lib\net47\WebDriver.dll</HintPath>
</Reference>
<Reference Include="WebDriver.Support, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.Support.4.8.2\lib\net47\WebDriver.Support.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Selenium.Firefox.WebDriver" version="0.27.0" targetFramework="net472" />
<package id="Selenium.Support" version="4.8.2" targetFramework="net472" />
<package id="Selenium.WebDriver" version="4.8.2" targetFramework="net472" />
</packages>