Skip to content

Commit

Permalink
v1.9.112 (22-Jul-2023)
Browse files Browse the repository at this point in the history
Sửa lỗi không tự động đăng video được (lần 4):
WebDriverManager.Net not working with new chromedriver endpoints for Chrome since version 115
rosolko/WebDriverManager.Net#253

Signed-off-by: RauCu <[email protected]>
  • Loading branch information
RauCu committed Jul 21, 2023
1 parent 0e70b2c commit 3d7b450
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### v1.9.112 (22-Jul-2023)
Sửa lỗi không tự động đăng video được (lần 4):
WebDriverManager.Net not working with new chromedriver endpoints for Chrome since version 115
https://github.com/rosolko/WebDriverManager.Net/issues/253

### v1.9.111 (21-Jul-2023)
Sửa lỗi không tự động đăng video được (lần 3)

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Version>1.9.111</Version>
<Version>1.9.112</Version>
<Company>RauCu</Company>
<Copyright>Copyright (C) RauCu</Copyright>
<LangVersion>preview</LangVersion>
Expand Down
146 changes: 146 additions & 0 deletions YoutubeDownloader.Core/Utils/ChromeConfigOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System;
using System.IO;
using System.Net;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;

namespace YoutubeDownloader.Core.Utils
{
public partial class ChromeConfigOverride : ChromeConfig
{

private const string BaseVersionPatternUrl = "https://chromedriver.storage.googleapis.com/<version>/";
private const string LatestReleaseVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE";

private const string ExactReleaseVersionPatternUrl =
"https://chromedriver.storage.googleapis.com/LATEST_RELEASE_<version>";

private bool isHigher115Version = false;
private string myRawChromeBrowserVersion = "";

override public string GetName()
{
return "Chrome";
}

override public string GetUrl32()
{
return GetUrl();
}

override public string GetUrl64()
{
return GetUrl();
}

private string GetUrl()
{
#if NETSTANDARD
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var architectureExtension =
RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64
? "_arm64"
: "64";
return $"{BaseVersionPatternUrl}chromedriver_mac{architectureExtension}.zip";
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return $"{BaseVersionPatternUrl}chromedriver_linux64.zip";
}
#endif
if (isHigher115Version)
{
return "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/" + myRawChromeBrowserVersion + "/win32/chromedriver-win32.zip";
}
return $"{BaseVersionPatternUrl}chromedriver_win32.zip";
}

override public string GetBinaryName()
{
#if NETSTANDARD
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
var isWindows = true;
#endif
var suffix = isWindows ? ".exe" : string.Empty;
return $"chromedriver{suffix}";
}

override public string GetLatestVersion()
{
return GetLatestVersion(LatestReleaseVersionUrl);
}

private static string GetLatestVersion(string url)
{
var uri = new Uri(url);
var webRequest = WebRequest.Create(uri);
using (var response = webRequest.GetResponse())
{
using (var content = response.GetResponseStream())
{
if (content == null) throw new ArgumentNullException($"Can't get content from URL: {uri}");
using (var reader = new StreamReader(content))
{
var version = reader.ReadToEnd().Trim();
return version;
}
}
}
}

override public string GetMatchingBrowserVersion()
{
var rawChromeBrowserVersion = GetRawBrowserVersion();
if (string.IsNullOrEmpty(rawChromeBrowserVersion))
{
throw new Exception("Not able to get chrome version or not installed");
}

var chromeBrowserVersion = VersionHelper.GetVersionWithoutRevision(rawChromeBrowserVersion);

var url = ExactReleaseVersionPatternUrl.Replace("<version>", chromeBrowserVersion);
Version chromeVersion = new Version(chromeBrowserVersion);

if (chromeVersion >= new Version(115, 0, 0))
{
isHigher115Version = true;
myRawChromeBrowserVersion = rawChromeBrowserVersion;
return rawChromeBrowserVersion;
// url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/" + rawChromeBrowserVersion + "/win32/chromedriver-win32.zip";
}

return GetLatestVersion(url);
}

private string GetRawBrowserVersion()
{
#if NETSTANDARD
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return RegistryHelper.GetInstalledBrowserVersionOsx("Google Chrome", "--version");
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return RegistryHelper.GetInstalledBrowserVersionLinux(
"google-chrome", "--product-version",
"chromium", "--version",
"chromium-browser", "--version");
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return RegistryHelper.GetInstalledBrowserVersionWin("chrome.exe");
}

throw new PlatformNotSupportedException("Your operating system is not supported");
#else
return RegistryHelper.GetInstalledBrowserVersionWin("chrome.exe");
#endif
}

}
}
7 changes: 2 additions & 5 deletions YoutubeDownloader.Core/Utils/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
Expand Down Expand Up @@ -233,9 +232,7 @@ public static bool UploadVideo(IWebDriver driver, bool isShortVideo, string path
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.NUMPAD0);
Thread.Sleep(1000);
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.SUBTRACT);
Thread.Sleep(5000);
sim.Keyboard.KeyPress(VirtualKeyCode.ESCAPE);
Thread.Sleep(2000);
Thread.Sleep(1000);
sim.Keyboard.KeyPress(VirtualKeyCode.ESCAPE);

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
Expand Down Expand Up @@ -683,7 +680,7 @@ public static IWebDriver GetDriver()
if (chromeInstalled)
{
// https://www.nuget.org/packages/WebDriverManager/
new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
new DriverManager().SetUpDriver(new ChromeConfigOverride(), VersionResolveStrategy.MatchingBrowser);

// hide black windows
chromeDriverService = ChromeDriverService.CreateDefaultService();
Expand Down

0 comments on commit 3d7b450

Please sign in to comment.