Skip to content

Commit

Permalink
First release rancio
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrgaton committed Feb 11, 2024
1 parent d6cf659 commit 92368e6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Youtuve downloader/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -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');
}
}
}
1 change: 0 additions & 1 deletion Youtuve downloader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
[assembly: AssemblyProduct("Youtube downloader")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: ComVisible(false)]

[assembly: Guid("b3b66ad0-ca13-4f35-9188-3d82431cc8c2")]
3 changes: 2 additions & 1 deletion Youtuve downloader/YoutubeForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 26 additions & 17 deletions Youtuve downloader/YoutubeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,9 +117,7 @@ private async void DownloadButton_Click(object sender, EventArgs e)

long videoBytesSize = streamInfo.Size.Bytes;
long audioBytesSize = audioStreamInfo.Size.Bytes;

double totalDataSize = videoBytesSize + audioBytesSize;

double videoPercentage = (videoBytesSize / totalDataSize) * 1000;
double audioPercentage = (audioBytesSize / totalDataSize) * 1000;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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";
Expand Down
7 changes: 5 additions & 2 deletions Youtuve downloader/Youtuve downloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>3721679-youtube_108064.ico</ApplicationIcon>
<ApplicationIcon>youtube.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Youtuve_downloader.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="AngleSharp, Version=1.0.7.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
<HintPath>..\packages\AngleSharp.1.0.7\lib\net472\AngleSharp.dll</HintPath>
Expand Down Expand Up @@ -269,7 +272,7 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="3721679-youtube_108064.ico" />
<Content Include="youtube.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.6.5.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.5.5\build\Fody.targets')" />
Expand Down
File renamed without changes.

0 comments on commit 92368e6

Please sign in to comment.