-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
bin/ | ||
obj/ | ||
Driver_Notes/ | ||
User Data/ | ||
|
||
*.exe | ||
*.log | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using CommandLine; | ||
|
||
namespace PlexAutoIntroSkip | ||
{ | ||
public class ProgramOptions | ||
{ | ||
[Option('d', "debug", Required = false, HelpText = "Show console window.")] | ||
public bool ShowConsoleWindow { get; set; } | ||
|
||
[Option('m', "manual-driver", Required = false, HelpText = "Manually handle MS Edge Web Driver.")] | ||
public bool ManualHandleWebDriver { get; set; } | ||
|
||
[Option('w', "wait-time", Required = false, Default = 2500, | ||
HelpText = "Time to wait after Skip Button becomes visible before clicking.")] | ||
public int SkipButtonWaitTime { get; set; } | ||
|
||
[Value(0, MetaName = "plex-url", HelpText = "Plex URL to use.")] | ||
public string PlexUrl { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Net; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace PlexAutoIntroSkip | ||
{ | ||
public static class WebDriverManager | ||
{ | ||
public static readonly string MsEdgeDriverFilePath = Path.GetFullPath(@"./edgedriver_win64/msedgedriver.exe"); | ||
|
||
public static readonly string MsEdgeDriverDirectoryName = "edgedriver_win64"; | ||
|
||
public static readonly string MsEdgeDriverFileName = "msedgedriver.exe"; | ||
|
||
private static readonly string _stableChannelLatestVersionAddress = "https://msedgedriver.azureedge.net/LATEST_STABLE"; | ||
|
||
private static readonly string _stableChannelAddress = "https://msedgedriver.azureedge.net/<<VERSION>>/edgedriver_win64.zip"; | ||
|
||
private static readonly Regex _msEdgeDriverVersionRegEx = new(@"(\d+\.\d+\.\d+)"); | ||
|
||
public static void AutoUpdate() | ||
{ | ||
var webClient = new WebClient(); | ||
var httpStream = webClient.OpenRead(_stableChannelLatestVersionAddress); | ||
var streamReader = new StreamReader(httpStream); | ||
var latestVersion = streamReader.ReadLine(); | ||
|
||
streamReader.Close(); | ||
httpStream.Close(); | ||
|
||
var currentVersion = string.Empty; | ||
if (File.Exists(MsEdgeDriverFilePath)) | ||
{ | ||
currentVersion = GetMsEdgeDriverVersion(MsEdgeDriverFilePath); | ||
} | ||
|
||
if (currentVersion != _msEdgeDriverVersionRegEx.Match(latestVersion).Value) | ||
{ | ||
var downloadFileName = $"./{MsEdgeDriverDirectoryName}.zip"; | ||
|
||
webClient.DownloadFile(_stableChannelAddress.Replace("<<VERSION>>", latestVersion), downloadFileName); | ||
ZipFile.ExtractToDirectory(downloadFileName, MsEdgeDriverDirectoryName, overwriteFiles: true); | ||
} | ||
|
||
webClient.Dispose(); | ||
} | ||
|
||
private static string GetMsEdgeDriverVersion(string msEdgeDriverPath) | ||
{ | ||
var msEdgeDriver = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = msEdgeDriverPath, | ||
Arguments = "--version", | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true, | ||
CreateNoWindow = true, | ||
} | ||
}; | ||
|
||
msEdgeDriver.Start(); | ||
while (msEdgeDriver.StandardOutput.EndOfStream == false) | ||
{ | ||
return _msEdgeDriverVersionRegEx.Match(msEdgeDriver.StandardOutput.ReadLine()).Value; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} |