protected override bool GetLatestVersionWindows(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); try { // https://www.ffmpeg.org/download.html // https://www.gyan.dev/ffmpeg/builds/packages/ // Load the release version page // https://www.gyan.dev/ffmpeg/builds/release-version using HttpClient httpClient = new(); mediaToolInfo.Version = httpClient.GetStringAsync("https://www.gyan.dev/ffmpeg/builds/release-version").Result; // Create download URL and the output filename using the version number mediaToolInfo.FileName = $"ffmpeg-{mediaToolInfo.Version}-full_build.7z"; mediaToolInfo.Url = $"https://www.gyan.dev/ffmpeg/builds/packages/{mediaToolInfo.FileName}"; } catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name)) { return(false); } return(true); }
protected override bool GetLatestVersionWindows(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); try { // Download latest release file // https://mkvtoolnix.download/latest-release.xml.gz using HttpClient httpClient = new(); Stream releaseStream = httpClient.GetStreamAsync("https://mkvtoolnix.download/latest-release.xml.gz").Result; // Get XML from Gzip using GZipStream gzstream = new(releaseStream, CompressionMode.Decompress); using StreamReader sr = new(gzstream); string xml = sr.ReadToEnd(); // Get the version number from XML MkvToolXmlSchema.MkvToolnixReleases mkvtools = MkvToolXmlSchema.MkvToolnixReleases.FromXml(xml); mediaToolInfo.Version = mkvtools.LatestSource.Version; // Create download URL and the output fileName using the version number // E.g. https://mkvtoolnix.download/windows/releases/18.0.0/mkvtoolnix-64-bit-18.0.0.7z mediaToolInfo.FileName = $"mkvtoolnix-64-bit-{mediaToolInfo.Version}.7z"; mediaToolInfo.Url = $"https://mkvtoolnix.download/windows/releases/{mediaToolInfo.Version}/{mediaToolInfo.FileName}"; } catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name)) { return(false); } return(true); }
protected override bool GetLatestVersionWindows(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); try { // Load the download page // TODO: Find a more reliable way of getting the last released version number // https://www.7-zip.org/download.html using HttpClient httpClient = new(); string downloadPage = httpClient.GetStringAsync("https://www.7-zip.org/download.html").Result; // Extract the version number from the page source // E.g. "Download 7-Zip 18.05 (2018-04-30) for Windows" const string pattern = @"Download\ 7-Zip\ (?<major>.*?)\.(?<minor>.*?)\ \((?<date>.*?)\)\ for\ Windows"; Regex regex = new(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); Match match = regex.Match(downloadPage); Debug.Assert(match.Success); mediaToolInfo.Version = $"{match.Groups["major"].Value}.{match.Groups["minor"].Value}"; // Create download URL and the output filename using the version number // E.g. https://www.7-zip.org/a/7z1805-extra.7z mediaToolInfo.FileName = $"7z{match.Groups["major"].Value}{match.Groups["minor"].Value}-extra.7z"; mediaToolInfo.Url = $"https://www.7-zip.org/a/{mediaToolInfo.FileName}"; } catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name)) { return(false); } return(true); }
protected override bool GetLatestVersionWindows(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); try { // Get the latest release version number from github releases // https://api.github.com/repos/handbrake/handbrake/releases/latest if (!Download.DownloadString(new Uri(@"https://api.github.com/repos/handbrake/handbrake/releases/latest"), out string json)) { return(false); } JObject releases = JObject.Parse(json); // "tag_name": "1.2.2", JToken versiontag = releases["tag_name"]; Debug.Assert(versiontag != null); mediaToolInfo.Version = versiontag.ToString(); // Create download URL and the output filename using the version number // https://github.com/HandBrake/HandBrake/releases/download/1.3.2/HandBrakeCLI-1.3.2-win-x86_64.zip mediaToolInfo.FileName = $"HandBrakeCLI-{mediaToolInfo.Version}-win-x86_64.zip"; mediaToolInfo.Url = $"https://github.com/HandBrake/HandBrake/releases/download/{mediaToolInfo.Version}/{mediaToolInfo.FileName}"; } catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name)) { return(false); } return(true); }
public int CompareTo(MediaToolInfo toolInfo) { if (toolInfo == null) { throw new ArgumentNullException(nameof(toolInfo)); } int result = string.Compare(FileName, toolInfo.FileName, StringComparison.OrdinalIgnoreCase); if (result != 0) { return(result); } result = ModifiedTime.CompareTo(toolInfo.ModifiedTime); if (result != 0) { return(result); } result = Size.CompareTo(toolInfo.Size); if (result != 0) { return(result); } return(string.Compare(Version, toolInfo.Version, StringComparison.OrdinalIgnoreCase)); }
protected override bool GetLatestVersionLinux(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); // TODO return(false); }
protected override bool GetLatestVersionWindows(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); try { // Load the release history page // https://raw.githubusercontent.com/MediaArea/MediaInfo/master/History_CLI.txt using HttpClient httpClient = new(); string historyPage = httpClient.GetStringAsync("https://raw.githubusercontent.com/MediaArea/MediaInfo/master/History_CLI.txt").Result; // Read each line until we find the first version line // E.g. Version 17.10, 2017-11-02 using StringReader sr = new(historyPage); string line; while (true) { // Read the line line = sr.ReadLine(); if (line == null) { break; } // See if the line starts with "Version" line = line.Trim(); if (line.IndexOf("Version", StringComparison.Ordinal) == 0) { break; } } if (string.IsNullOrEmpty(line)) { throw new NotImplementedException(); } // Extract the version number from the line // E.g. Version 17.10, 2017-11-02 const string pattern = @"Version\ (?<version>.*?),"; Regex regex = new(pattern); Match match = regex.Match(line); Debug.Assert(match.Success); mediaToolInfo.Version = match.Groups["version"].Value; // Create download URL and the output filename using the version number // E.g. https://mediaarea.net/download/binary/mediainfo/17.10/MediaInfo_CLI_17.10_Windows_x64.zip mediaToolInfo.FileName = $"MediaInfo_CLI_{mediaToolInfo.Version}_Windows_x64.zip"; mediaToolInfo.Url = $"https://mediaarea.net/download/binary/mediainfo/{mediaToolInfo.Version}/{mediaToolInfo.FileName}"; } catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name)) { return(false); } return(true); }
public void Copy(MediaToolInfo toolInfo) { // Do not assign to self if (Equals(toolInfo)) { return; } // Copy values ToolType = toolInfo.ToolType; ToolFamily = toolInfo.ToolFamily; FileName = toolInfo.FileName; ModifiedTime = toolInfo.ModifiedTime; Size = toolInfo.Size; Url = toolInfo.Url; Version = toolInfo.Version; }
public override bool GetInstalledVersion(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); // Get version const string commandline = "-version"; int exitCode = Command(commandline, out string output, out string error); if (exitCode != 0 || error.Length > 0) { return(false); } // First line as version // E.g. Windows : "ffmpeg version 4.3.1-2020-11-19-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers" // E.g. Linux : "ffmpeg version 4.3.1-1ubuntu0~20.04.sav1 Copyright (c) 2000-2020 the FFmpeg developers" string[] lines = output.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); // Extract the short version number // Match word for ffmpeg or ffprobe const string pattern = @"([^\s]+)\ version\ (?<version>.*?)-"; Regex regex = new(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); Match match = regex.Match(lines[0]); Debug.Assert(match.Success); mediaToolInfo.Version = match.Groups["version"].Value; // Get tool filename mediaToolInfo.FileName = GetToolPath(); // Get other attributes if we can read the file if (File.Exists(mediaToolInfo.FileName)) { FileInfo fileInfo = new(mediaToolInfo.FileName); mediaToolInfo.ModifiedTime = fileInfo.LastWriteTimeUtc; mediaToolInfo.Size = fileInfo.Length; } return(true); }
public override bool GetInstalledVersion(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); // Get version const string commandline = "--version"; int exitCode = Command(commandline, out string output); if (exitCode != 0) { return(false); } // First line as version // E.g. Windows : "mkvmerge v51.0.0 ('I Wish') 64-bit" // E.g. Linux : "mkvmerge v51.0.0 ('I Wish') 64-bit" string[] lines = output.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); // Extract the short version number // Match word for mkvmerge or mkvpropedit const string pattern = @"([^\s]+)\ v(?<version>.*?)\ \("; Regex regex = new(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); Match match = regex.Match(lines[0]); Debug.Assert(match.Success); mediaToolInfo.Version = match.Groups["version"].Value; // Get tool fileName mediaToolInfo.FileName = GetToolPath(); // Get other attributes if we can read the file if (File.Exists(mediaToolInfo.FileName)) { FileInfo fileInfo = new(mediaToolInfo.FileName); mediaToolInfo.ModifiedTime = fileInfo.LastWriteTimeUtc; mediaToolInfo.Size = fileInfo.Length; } return(true); }
public override bool GetInstalledVersion(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); // No version command, run with no arguments const string commandline = ""; int exitCode = Command(commandline, out string output); if (exitCode != 0) { return(false); } // First line as version // E.g. Windows : "7-Zip (a) 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21" // E.g. Linux : "7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21" string[] lines = output.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); // Extract the short version number const string pattern = @"7-Zip\ ([^\s]+)\ (?<version>.*?)\ "; Regex regex = new(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase); Match match = regex.Match(lines[0]); Debug.Assert(match.Success); mediaToolInfo.Version = match.Groups["version"].Value; // Get tool filename mediaToolInfo.FileName = GetToolPath(); // Get other attributes if we can read the file if (File.Exists(mediaToolInfo.FileName)) { FileInfo fileInfo = new(mediaToolInfo.FileName); mediaToolInfo.ModifiedTime = fileInfo.LastWriteTimeUtc; mediaToolInfo.Size = fileInfo.Length; } return(true); }
protected override bool GetLatestVersionLinux(out MediaToolInfo mediaToolInfo) { // Initialize mediaToolInfo = new MediaToolInfo(this); try { // https://www.ffmpeg.org/download.html // https://johnvansickle.com/ffmpeg/ // Load the release version page // https://johnvansickle.com/ffmpeg/release-readme.txt using HttpClient httpClient = new(); string readmePage = httpClient.GetStringAsync("https://johnvansickle.com/ffmpeg/release-readme.txt").Result; // Read each line until we find the build and version lines // build: ffmpeg-5.0-amd64-static.tar.xz // version: 5.0 using StringReader sr = new(readmePage); string buildLine = "", versionLine = ""; while (true) { // Read the line and trim whitespace string line = sr.ReadLine(); if (line == null) { // No more lines to read break; } line = line.Trim(); // See if the line starts with "version:" or "build:" if (line.IndexOf("version:", StringComparison.Ordinal) == 0) { versionLine = line; } if (line.IndexOf("build:", StringComparison.Ordinal) == 0) { buildLine = line; } // Do we have both lines if (!string.IsNullOrEmpty(versionLine) && !string.IsNullOrEmpty(buildLine)) { // Done break; } } // Did we find the version and build if (string.IsNullOrEmpty(versionLine) || string.IsNullOrEmpty(buildLine)) { throw new NotImplementedException(); } // Extract the build and version number from the lines const string versionPattern = @"version:\ (?<version>.*?)"; const string buildPattern = @"build:\ (?<build>.*?)"; Regex regex = new(versionPattern); Match match = regex.Match(versionLine); Debug.Assert(match.Success); mediaToolInfo.Version = match.Groups["version"].Value; regex = new Regex(buildPattern); match = regex.Match(buildLine); Debug.Assert(match.Success); mediaToolInfo.FileName = match.Groups["build"].Value; // Create download URL and the output filename // E.g. https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz // E.g. https://johnvansickle.com/ffmpeg/releases/ffmpeg-5.0-amd64-static.tar.xz mediaToolInfo.Url = $"https://johnvansickle.com/ffmpeg/releases/{mediaToolInfo.FileName}"; } catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name)) { return(false); } return(true); }
public bool GetLatestVersion(out MediaToolInfo mediaToolInfo) { // Windows or Linux // TODO: Mac may work the same as Linux, but untested return(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? GetLatestVersionWindows(out mediaToolInfo) : GetLatestVersionLinux(out mediaToolInfo)); }
protected abstract bool GetLatestVersionLinux(out MediaToolInfo mediaToolInfo);
// Latest downloadable version protected abstract bool GetLatestVersionWindows(out MediaToolInfo mediaToolInfo);
// Installed version information retrieved from the tool commandline public abstract bool GetInstalledVersion(out MediaToolInfo mediaToolInfo);