diff --git a/Youtuve downloader/Config.cs b/Youtuve downloader/Config.cs
index 0471aa6..03992e2 100644
--- a/Youtuve downloader/Config.cs
+++ b/Youtuve downloader/Config.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@@ -32,7 +31,7 @@ public static string Get(string key)
{
if (!File.Exists(configPath)) return null;
- return File.ReadAllText(configPath).Split('\n').FirstOrDefault(s => s.StartsWith(key + '=', StringComparison.InvariantCultureIgnoreCase)).Split('=').Last();
+ return File.ReadAllText(configPath).Split('\n').FirstOrDefault(s => s.StartsWith(key + '=', StringComparison.InvariantCultureIgnoreCase)).Split('=').Last().Trim('\r');
}
}
}
\ No newline at end of file
diff --git a/Youtuve downloader/Properties/AssemblyInfo.cs b/Youtuve downloader/Properties/AssemblyInfo.cs
index d043250..73c9e87 100644
--- a/Youtuve downloader/Properties/AssemblyInfo.cs
+++ b/Youtuve downloader/Properties/AssemblyInfo.cs
@@ -8,5 +8,4 @@
[assembly: AssemblyProduct("Youtube downloader")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: ComVisible(false)]
-
[assembly: Guid("b3b66ad0-ca13-4f35-9188-3d82431cc8c2")]
\ No newline at end of file
diff --git a/Youtuve downloader/YoutubeForm.Designer.cs b/Youtuve downloader/YoutubeForm.Designer.cs
index e0d886e..c573df2 100644
--- a/Youtuve downloader/YoutubeForm.Designer.cs
+++ b/Youtuve downloader/YoutubeForm.Designer.cs
@@ -49,8 +49,8 @@ private void InitializeComponent()
this.YoutubeLinkTextBox.Name = "YoutubeLinkTextBox";
this.YoutubeLinkTextBox.Size = new System.Drawing.Size(221, 35);
this.YoutubeLinkTextBox.TabIndex = 0;
- this.YoutubeLinkTextBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.YoutubeLinkTextBox_MouseClick);
this.YoutubeLinkTextBox.TextChanged += new System.EventHandler(this.YoutubeLinkTextBox_TextChanged);
+ this.YoutubeLinkTextBox.DoubleClick += new System.EventHandler(this.YoutubeLinkTextBox_DoubleClick);
//
// YoutubeLinkLabel
//
@@ -84,6 +84,7 @@ private void InitializeComponent()
//
// DownloadButton
//
+ this.DownloadButton.Enabled = false;
this.DownloadButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.DownloadButton.Location = new System.Drawing.Point(475, 7);
this.DownloadButton.Margin = new System.Windows.Forms.Padding(2);
diff --git a/Youtuve downloader/YoutubeForm.cs b/Youtuve downloader/YoutubeForm.cs
index 74362c2..5af5359 100644
--- a/Youtuve downloader/YoutubeForm.cs
+++ b/Youtuve downloader/YoutubeForm.cs
@@ -42,12 +42,7 @@ public YoutubeForm()
wc.DownloadProgressChanged += (s, e) => DownloadProgressBar.Value = e.ProgressPercentage * 10;
wc.DownloadFileCompleted += (s, e) => DownloadProgressBar.Value = 0;
}
-
- private void YoutubeLinkTextBox_MouseClick(object sender, MouseEventArgs e)
- {
- YoutubeLinkTextBox.SelectAll();
- }
-
+ private void YoutubeLinkTextBox_DoubleClick(object sender, EventArgs e) => YoutubeLinkTextBox.SelectAll();
private async void DownloadButton_Click(object sender, EventArgs e)
{
if (currentVideo == null) return;
@@ -122,9 +117,7 @@ await Task.Run(() =>
long videoBytesSize = streamInfo.Size.Bytes;
long audioBytesSize = audioStreamInfo.Size.Bytes;
-
double totalDataSize = videoBytesSize + audioBytesSize;
-
double videoPercentage = (videoBytesSize / totalDataSize) * 1000;
double audioPercentage = (audioBytesSize / totalDataSize) * 1000;
@@ -154,16 +147,22 @@ private void FormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
UpdateStreams();
}
- private static string GetVideoID(string url)
- {
- return url.Contains("v=") ? url.Split('?').Last().Split('&').First(s => s.StartsWith("v=", StringComparison.InvariantCultureIgnoreCase)).Split('=')[1] : url.Split('?')[0].Split('/').Last();
- }
-
+ private static string GetVideoID(string url) => url.Contains("v=") ? url.Split('?').Last().Split('&').First(s => s.StartsWith("v=", StringComparison.InvariantCultureIgnoreCase)).Split('=')[1] : url.Split('?')[0].Split('/').Last();
private async void YoutubeLinkTextBox_TextChanged(object sender, EventArgs e)
{
- YoutubeLinkTextBox.Text = GetVideoID(YoutubeLinkTextBox.Text);
+ DownloadButton.Enabled = false;
+
+ try
+ {
+ YoutubeLinkTextBox.Text = GetVideoID(YoutubeLinkTextBox.Text);
- currentVideo = await youtube.Videos.GetAsync(YoutubeLinkTextBox.Text);
+ currentVideo = await youtube.Videos.GetAsync(YoutubeLinkTextBox.Text);
+ }
+ catch(Exception ex)
+ {
+ MessageBox.Show("Error cannot find the video by the id\n\n" + ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
if (currentVideo != null)
{
@@ -186,6 +185,8 @@ private async void YoutubeLinkTextBox_TextChanged(object sender, EventArgs e)
VideoFotoPictureBox.Image = Image.FromStream(await (new WebClient()).OpenReadTaskAsync(new Uri(thumbnailUrl)));
UpdateStreams();
+
+ DownloadButton.Enabled = true;
}
}
@@ -234,13 +235,19 @@ private void VideoFotoPictureBox_Click(object sender, EventArgs e)
private static string ffmepgTempPath = Path.Combine(Path.GetTempPath(), "ffmepg.exe");
- private static async Task CheckAndDownloadFfmepg()
+ private async Task CheckAndDownloadFfmepg()
{
if (!File.Exists(ffmepgTempPath))
{
- if (MessageBox.Show("FFMEPG is not downloaded you want to download it to temp files?", Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) return;
+ if (MessageBox.Show("FFMPEG is not downloaded you want to download it to temp files?", Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
+ {
+ FormatComboBox.SelectedIndex++;
+ return;
+ }
await wc.DownloadFileTaskAsync("https://raw.githubusercontent.com/Mrgaton/FFMEPGDownload/main/ffmpeg.exe", ffmepgTempPath);
+
+ MessageBox.Show("Now you can download music videos in very high quality with sound", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@@ -264,6 +271,8 @@ private static async Task CombineAudioAndVideo(string videoPath, string audioPat
await proc.WaitForExitAsync();
}
+
+ // old crapy code
/*private async void DownloadFileWithProgress(string DownloadLink, string PathDe, bool WithLabel, ProgressBar LAbelsita)
{
DownloadButton.Text = "Descargando";
diff --git a/Youtuve downloader/Youtuve downloader.csproj b/Youtuve downloader/Youtuve downloader.csproj
index 60a8ff1..4534f97 100644
--- a/Youtuve downloader/Youtuve downloader.csproj
+++ b/Youtuve downloader/Youtuve downloader.csproj
@@ -39,11 +39,14 @@
false
- 3721679-youtube_108064.ico
+ youtube.ico
Youtuve_downloader.Program
+
+ true
+
..\packages\AngleSharp.1.0.7\lib\net472\AngleSharp.dll
@@ -269,7 +272,7 @@
-
+
diff --git a/Youtuve downloader/3721679-youtube_108064.ico b/Youtuve downloader/youtube.ico
similarity index 100%
rename from Youtuve downloader/3721679-youtube_108064.ico
rename to Youtuve downloader/youtube.ico