Skip to content

Commit

Permalink
Fixed Downloading on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftingDragon007 committed Jul 31, 2022
1 parent 70b6513 commit 7415d16
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions YouTubeDlpGui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public void OnDownloadButtonClicked()
var ytDlPDownloadUrl = GetYtDlpDownloadUrl();
instance.YtDlPath = GetYtDlpPath();
Dispatcher.UIThread.InvokeAsync(() => instance.StatusLabel.Text = "Downloading YT-Dlp...");
DownloadFile(ytDlPDownloadUrl, instance.YtDlPath);
if(Environment.OSVersion.Platform == PlatformID.Win32NT)
instance.YtDlPath = DownloadYtDlpWindows(ytDlPDownloadUrl, Path.Combine(Path.GetTempPath(), "yt-dlp.zip"));
else
DownloadFile(ytDlPDownloadUrl, instance.YtDlPath);
if (Environment.OSVersion.Platform.Equals(PlatformID.Unix) ||
Environment.OSVersion.Platform.Equals(PlatformID.MacOSX))
{
Expand Down Expand Up @@ -72,7 +75,8 @@ public void OnDownloadButtonClicked()
if (Environment.OSVersion.Platform.Equals(PlatformID.Win32NT) ||
Environment.OSVersion.Platform.Equals(PlatformID.MacOSX))
{
ZipFile.ExtractToDirectory(path, ffmpegFolderPath);
ZipFile.ExtractToDirectory(path, ffmpegFolderPath, true);
ffmpegFolderPath = Directory.GetDirectories(Directory.GetDirectories(ffmpegFolderPath).First()).First();
}
else
{
Expand All @@ -84,6 +88,7 @@ public void OnDownloadButtonClicked()
var ffmpegPath = Path.Combine(ffmpegFolderPath,
Environment.OSVersion.Platform.Equals(PlatformID.Win32NT) ? "ffmpeg.exe" : "ffmpeg");
if (!File.Exists(ffmpegPath))
{
Dispatcher.UIThread.InvokeAsync(() =>
{
instance.DownloadButton.IsEnabled = true;
Expand All @@ -94,6 +99,8 @@ public void OnDownloadButtonClicked()
instance.VideoDownloadPathButton.IsEnabled = true;
instance.ErrorTextBlock.Text = "Failed to download and extract ffmpeg";
});
return;
}

var format = "mp4";
var formattingMethod = "remux";
Expand Down Expand Up @@ -159,7 +166,7 @@ public void OnDownloadButtonClicked()
});

thread.Start();
instance.DownloadButton.Content = "Starting...";
instance.StatusLabel.Text = "Starting...";
instance.DownloadButton.IsEnabled = false;
instance.VideoDownloadPathTextBox.IsEnabled = false;
instance.UrlTextBox.IsEnabled = false;
Expand All @@ -168,6 +175,14 @@ public void OnDownloadButtonClicked()
instance.VideoDownloadPathButton.IsEnabled = false;
}

private string DownloadYtDlpWindows(string ytDlPDownloadUrl, string path)
{
DownloadFile(ytDlPDownloadUrl, path);
var folderPath = Path.Combine(Path.GetTempPath(), "yt-dlp");
ZipFile.ExtractToDirectory(path, folderPath, true);
return Path.Combine( folderPath, "yt-dlp.exe");
}

private void ExtractTarArchive(string path, string ffmpegFolderPath)
{
var process = new Process
Expand All @@ -191,7 +206,7 @@ private string GetYtDlpDownloadUrl()
{
PlatformID.Unix => "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux",
PlatformID.MacOSX => "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos",
PlatformID.Win32NT => "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_min.exe",
PlatformID.Win32NT => "https://github.com/yt-dlp/yt-dlp/releases/download/2022.07.18/yt-dlp_win.zip",
_ => throw new PlatformNotSupportedException("This platform is not supported!")
};
}
Expand Down Expand Up @@ -284,7 +299,7 @@ public string GetFfmpegDownloadUrl()
{
PlatformID.Unix => "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz",
PlatformID.MacOSX => "https://ffmpeg.zeranoe.com/builds/macos64/static/ffmpeg-latest-macos64-static.zip",
PlatformID.Win32NT => "https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.zip",
PlatformID.Win32NT => "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip",
_ => throw new PlatformNotSupportedException("This platform is not supported!")
};
}
Expand Down

0 comments on commit 7415d16

Please sign in to comment.