Skip to content

Commit

Permalink
1.5 (#3)
Browse files Browse the repository at this point in the history
* - Re-added timer to check on mp3 file conversions and implemented levenshtein to validate it's a file that needs to be converted
-  Added right-click menu on datagrid to clear it out
- Added right-click menu item to restart failed downloads/conversion
- Added right-click menu item to open data file directory
- Set default state to "paused" so user can make adjustments/fixes before starting process

* - Re-added timer to check on mp3 file conversions and implemented levenshtein to validate it's a file that needs to be converted
-  Added right-click menu on datagrid to clear it out
- Added right-click menu item to restart failed downloads/conversion
- Added right-click menu item to open data file directory
- Set default state to "paused" so user can make adjustments/fixes before starting process

* - Automatically creates the music output directory if it doesn't exist
  • Loading branch information
rkrehn authored Mar 8, 2024
1 parent 77efd1f commit 0936353
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 20 deletions.
46 changes: 41 additions & 5 deletions Form1.Designer.cs

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

91 changes: 77 additions & 14 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using TagLib;
using System.Diagnostics;
using Microsoft.VisualBasic;
using Fastenshtein;

namespace YTPD
{
Expand Down Expand Up @@ -80,12 +81,10 @@ private async void button1_Click(object sender, EventArgs e)
private async void timer1_Tick(object sender, EventArgs e)
{
// ensure a directory exists
if (!Directory.Exists(txt_Dir.Text))
{
MessageBox.Show("Directory does not exist! Please browse for a new directory.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
timer1.Enabled = false;
return;
}
if (!Directory.Exists(txt_Dir.Text)) Directory.CreateDirectory(txt_Dir.Text);

// turn it off while it's running
timer1.Enabled = false;

string artist = "";
string album = "";
Expand Down Expand Up @@ -113,7 +112,7 @@ private async void timer1_Tick(object sender, EventArgs e)
continue;
}

if(row.Cells[0].Value.ToString().ToLower().Contains("romeo"))
if (row.Cells[0].Value.ToString().ToLower().Contains("romeo"))
{
song = "";
}
Expand Down Expand Up @@ -184,7 +183,7 @@ private async void timer1_Tick(object sender, EventArgs e)
row.Cells["DL"].Value = "100";
dgv_downloads.Rows[row.Index].DefaultCellStyle.BackColor = Color.DarkRed;
dgv_downloads.Rows[row.Index].DefaultCellStyle.ForeColor = Color.White;
}
}
finally
{
if (!isConverting && fullpath.Length > 1)
Expand All @@ -201,6 +200,9 @@ private async void timer1_Tick(object sender, EventArgs e)
break;
}
}

// turn timer back on when done
timer1.Enabled = true;
}

static async Task ConvertFile(string inputFilePath, string fileExt)
Expand Down Expand Up @@ -437,7 +439,6 @@ private void button2_Click(object sender, EventArgs e)
}
}

timer1.Enabled = true;
}

private void txt_URL_TextChanged(object sender, EventArgs e)
Expand All @@ -457,14 +458,25 @@ private async void timer_convert_Tick(object sender, EventArgs e)
.ToArray();

Console.WriteLine("\nNon-mp3 files files:" + nonMp3Files.Length);

// converts non-mp3 to mp3
foreach (string nonMp3File in nonMp3Files)
{
if (!isConverting)
foreach (DataGridViewRow row in dgv_downloads.Rows)
{
isConverting = true;
await ConvertFile(nonMp3File, nonMp3File.Substring(nonMp3File.IndexOf('.')));
Console.WriteLine(nonMp3File);
isConverting = false;
if (row.Cells[0].Value == null || row.Cells[0].Value.ToString().Length == 0) continue;
// review levenshtein distance for mp3 file and song name so we only convert the mp3
string foundsong = nonMp3File.Substring(nonMp3File.LastIndexOf('\\') + 2);
foundsong = foundsong.Substring(foundsong.IndexOf('-') + 2, foundsong.LastIndexOf('.') - 4);
string cellsong = row.Cells["Song"].Value.ToString();
int lev = Levenshtein.Distance(foundsong, cellsong);

// if threshold is met, then convert non-mp3 to mp3
if (lev > 70)
{
await ConvertFile(nonMp3File, nonMp3File.Substring(nonMp3File.LastIndexOf('.')));
Console.WriteLine(nonMp3File);
}
}
}
}
Expand All @@ -483,6 +495,8 @@ private void btn_Pause_Click(object sender, EventArgs e)
{
isPaused = true;
timer1.Enabled = false;
timer_convert.Enabled = false;
timer_tag.Enabled = false;
btn_Pause.Visible = false;
btn_Resume.Visible = true;
}
Expand All @@ -491,6 +505,8 @@ private void btn_Resume_Click(object sender, EventArgs e)
{
isPaused = false;
timer1.Enabled = true;
timer_convert.Enabled = true;
timer_tag.Enabled = true;
btn_Pause.Visible = true;
btn_Resume.Visible = false;
}
Expand Down Expand Up @@ -569,5 +585,52 @@ private void dgv_downloads_CellDoubleClick(object sender, DataGridViewCellEventA
}
}
}

private void btn_secret_MouseDoubleClick(object sender, MouseEventArgs e)
{

}

private void dgv_downloads_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
}
}

private void menu_cleardata_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("Are you sure want to delete your data?", "YouTube Album Downloader", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

if (dr == DialogResult.Yes)
{
dgv_downloads.Rows.Clear();
SaveDataGridViewToCSV();
}
}

private void btn_secret_Click(object sender, EventArgs e)
{

}

private void openDataFileToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", Application.StartupPath);
}

private void RestartBadItems_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dgv_downloads.Rows)
{
if (row.Cells[0].Value == null || row.Cells[0].Value.ToString().Length == 0) continue;

if (row.Cells["Converted"].Value.ToString() == "No")
{
row.Cells["DL"].Value = "0";
}
}
}
}
}
3 changes: 3 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,7 @@
<metadata name="timer_convert.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>319, 17</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>446, 17</value>
</metadata>
</root>
3 changes: 2 additions & 1 deletion YTPD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fastenshtein" Version="1.0.0.8" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="Tools.InnoSetup" Version="6.2.2" />
<PackageReference Include="YoutubeExplode" Version="6.3.11" />
<PackageReference Include="YoutubeExplode" Version="6.3.12" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 0936353

Please sign in to comment.