//Filter by Track Grenre Done button private void metroButton8_Click(object sender, EventArgs e) { FileStream FS = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); List <MP3Tag_and_nameOf_MP3> list = new List <MP3Tag_and_nameOf_MP3>(); while (FS.Position < FS.Length) { MP3Tag_and_nameOf_MP3 Tag = (MP3Tag_and_nameOf_MP3)BF.Deserialize(FS); if (Tag.Genere == metroComboBox5.SelectedItem.ToString()) { list.Add(Tag); } } FS.Close(); FileStream fs = new FileStream("mp3.txt", FileMode.Truncate); fs.Close(); FileStream F = new FileStream("mp3.txt", FileMode.Open); for (int i = 0; i < list.Count; i++) { BF.Serialize(F, list[i]); } F.Close(); MessageBox.Show("You have chosen: " + list.Count().ToString() + " song for Genere: " + list[0].Genere); }
//add comment void edit_comment() { paths sort = new paths(); string[] files = sort.get_files(); FileStream s = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter b = new BinaryFormatter(); List <MP3Tag_and_nameOf_MP3> List = new List <MP3Tag_and_nameOf_MP3>(); while (s.Position < s.Length) { MP3Tag_and_nameOf_MP3 m = (MP3Tag_and_nameOf_MP3)b.Deserialize(s); List.Add(m); } s.Close(); for (int i = 0; i < List.Count(); i++) { for (int j = 0; j < files.Count(); j++) { if (Path.GetFileName(files[j]) == List[i].Mp3_Name) { s = new FileStream(files[j], FileMode.Open); byte[] tag = new byte[128]; s.Seek(s.Length - 128, SeekOrigin.Begin); s.Read(tag, 0, 128); Array.Clear(tag, 97, 30); tag[97] = byte.Parse((List[i].Comment)); s.Write(tag, 0, 128); s.Close(); break; } } } }
public MP3Tag_and_nameOf_MP3 getTag() { string title, artist, album, year, comment, genere; title = artist = album = year = comment = genere = ""; stream.Seek(stream.Length - 128, SeekOrigin.Begin); stream.Read(tagData, 0, SIZE); stream.Close(); byte b1 = tagData[0]; byte b2 = tagData[1]; byte b3 = tagData[2]; if ((char)b1 != 'T' || (char)b2 != 'A' || (char)b3 != 'G') { throw new Exception("Not an MP3 Format File"); } for (int i = 3; i < 33; i++) { if (tagData[i] != 0) { title += (char)tagData[i]; } } for (int i = 33; i < 63; i++) { if (tagData[i] != 0) { artist += (char)tagData[i]; } } for (int i = 63; i < 93; i++) { if (tagData[i] != 0) { album += (char)tagData[i]; } } for (int i = 93; i < 97; i++) { if (tagData[i] != 0) { year += (char)tagData[i]; } } comment = tagData[97].ToString(); genere = tagData[127].ToString(); MP3Tag_and_nameOf_MP3 tag = new MP3Tag_and_nameOf_MP3(title, artist, album, year, comment, genere, name_of_path); return(tag); }
private void bunifuFlatButton2_Click(object sender, EventArgs e) { FolderBrowserDialog FBD2 = new FolderBrowserDialog(); MessageBox.Show("choose the detination of stored items "); if (FBD2.ShowDialog() == DialogResult.OK) { List <MP3Tag_and_nameOf_MP3> list = new List <MP3Tag_and_nameOf_MP3>(); FileStream fs = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); while (fs.Position != fs.Length) { MP3Tag_and_nameOf_MP3 Tag = new MP3Tag_and_nameOf_MP3(); Tag = (MP3Tag_and_nameOf_MP3)bf.Deserialize(fs); list.Add(Tag); } paths s = new paths(); string from_file = s.get_from_path(); string to_file = FBD2.SelectedPath.ToString(); DirectoryInfo dir = new DirectoryInfo(from_file); if (!dir.Exists) { throw new Exception("source directory doesnot exist " + from_file); } if (!Directory.Exists(to_file)) { Directory.CreateDirectory(to_file); } FileInfo[] fil = dir.GetFiles(); for (int i = 0; i < list.Count; i++) { for (int j = 0; j < s.get_files().Count(); j++) { if (list[i].Mp3_Name == Path.GetFileName(s.get_files()[j])) { string temp = Path.Combine(to_file, fil[j].Name); fil[j].CopyTo(temp); } } } } }
private void bunifuFlatButton3_Click(object sender, EventArgs e) { FileStream fs = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); List <MP3Tag_and_nameOf_MP3> list = new List <MP3Tag_and_nameOf_MP3>(); while (fs.Position != fs.Length) { MP3Tag_and_nameOf_MP3 tag = (MP3Tag_and_nameOf_MP3)bf.Deserialize(fs); list.Add(tag); } fs.Close(); FileStream fs3 = new FileStream("mp3.txt", FileMode.Open); for (int j = 0; j < list.Count; j++) { bf.Serialize(fs3, list[j]); } dataGridView2.DataSource = list; fs3.Close(); }
//Fills the Title combobox public void TitleComboBox() { FileStream FS = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); List <string> list = new List <string>(); int count = 0; while (FS.Position < FS.Length) { MP3Tag_and_nameOf_MP3 Tag = (MP3Tag_and_nameOf_MP3)BF.Deserialize(FS); if (list.Count == 0) { metroComboBox1.Items.Add(Tag.Title); list.Add(Tag.Title); continue; } for (int i = 0; i < list.Count; i++) { if (list[i] == Tag.Title) { count++; } } if (count == 0) { metroComboBox1.Items.Add(Tag.Title); list.Add(Tag.Title); } count = 0; } FS.Close(); }
private void metroButton3_Click(object sender, EventArgs e) { FileStream fs = new FileStream("mp3.txt", FileMode.Truncate); fs.Close(); fs = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); int count = 0; for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++) { for (int j = 0; j < files.Count(); j++) { if (checkedListBox1.CheckedItems[i].ToString() == Path.GetFileName(files[j])) { MP3Reader MR = new MP3Reader(files[j]); MP3Tag_and_nameOf_MP3 Tag = MR.getTag(); BF.Serialize(fs, Tag); count++; break; } } } fs.Close(); MessageBox.Show("You have Added: " + count + " MP3 files successfully"); ArtistComboBox(); TitleComboBox(); GenreComboBox(); AlbumComboBox(); YearComboBox(); }
private void bunifuTileButton11_Click(object sender, EventArgs e) { paths s = new paths(); List <MP3Tag_and_nameOf_MP3> list = new List <MP3Tag_and_nameOf_MP3>(); FileStream fm = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter BF = new BinaryFormatter(); List <MP3Tag_and_nameOf_MP3> lis = new List <MP3Tag_and_nameOf_MP3>(); while (fm.Position != fm.Length) { MP3Tag_and_nameOf_MP3 tag = (MP3Tag_and_nameOf_MP3)BF.Deserialize(fm); lis.Add(tag); } fm.Close(); FileStream fs2 = new FileStream("mp3.txt", FileMode.Truncate); fs2.Close(); int i = 0; for (int m = 0; m < lis.Count; m++) { for (int n = 0; n < s.get_files().Length; n++) { if (lis[m].Mp3_Name == Path.GetFileName(s.get_files()[n])) { MP3Reader MR = new MP3Reader(s.get_files()[n]); MP3Tag_and_nameOf_MP3 tag = MR.getTag(); Mp3FileReader reader = new Mp3FileReader(s.get_files()[n]); TimeSpan duration = reader.TotalTime; list.Add(tag); list[i].Duration = duration; reader.Close(); } } i++; } sort_by_Durat D = new sort_by_Durat(); list.Sort(D); for (int k = 0; k < list.Count; k++) { list[k].Comment = (k + 1) + ""; } for (int m = 0; m < list.Count; m++) { for (int n = m + 1; n < list.Count; n++) { if (list[m].Duration == list[n].Duration) { list[n].Comment = list[m].Comment; } } } int count = 0; int index = 0; for (int a = 0; a < list.Count; a++) { for (int b = 0; b < list.Count; b++) { if (list[b].Comment == a + 1 + "") { count++; index = b; } } if (count != 0) { for (int c = index + 1; c < list.Count; c++) { list[c].Comment = int.Parse(list[c].Comment) - count + 1 + ""; } } count = 0; } FileStream fs3 = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); for (int j = 0; j < list.Count; j++) { bf.Serialize(fs3, list[j]); } dataGridView2.DataSource = list; fs3.Close(); //edit comment edit_comment(); }
private void bunifuFlatButton4_Click(object sender, EventArgs e) { FileStream fs = new FileStream("mp3.txt", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); List <MP3Tag_and_nameOf_MP3> list = new List <MP3Tag_and_nameOf_MP3>(); while (fs.Position != fs.Length) { MP3Tag_and_nameOf_MP3 tag = (MP3Tag_and_nameOf_MP3)bf.Deserialize(fs); list.Add(tag); } fs.Close(); List <string> L = new List <string>(); foreach (string item in checkedListBox2.CheckedItems) { L.Add(item); } for (int i = 0; i < L.Count; i++) { if (L[i] == "Title") { int check; check = sort_by_Title(list, bf); if (check > 0 && L.Count == 1) { MessageBox.Show("Select Another Property"); } } else if (L[i] == "Artist") { int check; check = sort_by_Artist(list, bf); if (check > 0 && L.Count == 1) { MessageBox.Show("Select Another Property"); } else if (check > 0 && L.Count > 1 && L.Count == i + 1) { int c; for (int a = i - 1; a >= 0; a--) { if (L[a] == "Title") { c = sort_by_Title(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } } } } else if (L[i] == "Album") { int check; check = sort_by_Album(list, bf); if (check > 0 && L.Count == 1) { MessageBox.Show("Select Another Property"); } else if (check > 0 && L.Count > 1 && L.Count == i + 1) { int c; for (int a = i - 1; a >= 0; a--) { if (L[a] == "Title") { c = sort_by_Title(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } else if (L[a] == "Artist") { c = sort_by_Artist(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } } } } else if (L[i] == "Year") { int check; check = sort_by_Year(list, bf); if (check > 0 && L.Count == 1) { MessageBox.Show("Select Another Property"); } else if (check > 0 && L.Count > 1 && L.Count == i + 1) { int c; for (int a = i - 1; a >= 0; a--) { if (L[a] == "Title") { c = sort_by_Title(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } else if (L[a] == "Artist") { c = sort_by_Artist(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } else if (L[a] == "Album") { c = sort_by_Album(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } } } } else if (L[i] == "Genere") { int check; check = sort_by_Genere(list, bf); if (check > 0 && L.Count == 1) { MessageBox.Show("Select Another Property"); } else if (check > 0 && L.Count > 1 && L.Count == i + 1) { int c; for (int a = i - 1; a >= 0; a--) { if (L[a] == "Title") { c = sort_by_Title(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } else if (L[a] == "Artist") { c = sort_by_Artist(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } else if (L[a] == "Album") { c = sort_by_Album(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } else if (L[a] == "Year") { c = sort_by_Year(list, bf); if (c == 0) { break; } else if (c != 0 && a == 0) { MessageBox.Show("Select Another Property"); } } } } } } }