public static Track Getv1tags(string fname) { Track mytrack = new Track("", "", "", "", "", "", "", ""); if (File.Exists(fname)) { var id3 = new ID3v1Tag(fname); mytrack.Album = id3.Album; mytrack.Artist = id3.Artist; mytrack.Title = id3.Title; mytrack.Trackno = id3.TrackNumber.ToString(); mytrack.Year = id3.Year; } return mytrack; }
public void ReloadlistviewV1(ListViewItem item) { string tagstring = "No Tag"; if (ID3v2Tag.DoesTagExist(item.SubItems[1].Text + "\\" + item.SubItems[0].Text)) { tagstring = "/V2"; } if (ID3v1Tag.DoesTagExist(item.SubItems[1].Text + "\\" + item.SubItems[0].Text)) { var id3 = new ID3v1Tag(item.SubItems[1].Text + "\\" + item.SubItems[0].Text); item.SubItems[2].Text = "V1" + tagstring; item.SubItems[3].Text = id3.Title; item.SubItems[4].Text = id3.Artist; item.SubItems[5].Text = id3.Album; item.SubItems[7].Text = id3.Year; item.SubItems[6].Text = id3.TrackNumber.ToString(); item.SubItems[8].Text = GenreHelper.GenreByIndex[id3.GenreIndex]; // Miscutils.Updaterecord(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, id3.Album, // id3.Artist, id3.GenreIndex.ToString(), id3.Title, id3.TrackNumber.ToString(), id3.Year); } else { item.SubItems[2].Text = tagstring; item.SubItems[3].Text = ""; item.SubItems[4].Text = ""; item.SubItems[5].Text = ""; item.SubItems[7].Text = ""; item.SubItems[6].Text = ""; item.SubItems[8].Text = ""; if (tagstring == "No Tag") { // Miscutils.Updaterecord(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, item.SubItems[1].Text, // "No Tag", "", "", "", ""); } } }
private void Runscan() { Int32 totalFiles = 0; string tagstrV1 = null; string tagstrV2 = null; DirectoryInfo di = new DirectoryInfo(Dir); FileInfo[] fileList = di.GetFiles("*.mp3", SearchOption.AllDirectories); totalFiles = fileList.Length; for (Int32 i = 0; i < totalFiles; i++) { tagstrV1 = string.Empty; tagstrV2 = string.Empty; // Currentfile(fileList[i].FullName); if (ID3v1Tag.DoesTagExist(fileList[i].FullName)) tagstrV1 = "V1"; if (ID3v2Tag.DoesTagExist(fileList[i].FullName)) tagstrV2 = "V2"; if (tagstrV1 == "V1" & tagstrV2 == "") { var id3 = new ID3v1Tag(fileList[i].FullName); var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], fileList[i].FullName, tagstrV1 + "/" + tagstrV2); if (OnListFiles != null) { OnListFiles(mytrack); } trackList.Add(mytrack); } if (tagstrV2 == "V2") { var id3 = new ID3v2Tag(fileList[i].FullName); if (id3.Genre == null) { id3.Genre = "none"; } try { var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber, id3.Genre, fileList[i].FullName, tagstrV1 + "/" + tagstrV2); if (OnListFiles != null) { OnListFiles(mytrack); } trackList.Add(mytrack); } catch (Exception) { trackList.RemoveAt(trackList.Count - 1); trackList.Add(new Track("", "", "", "", "", "", fileList[i].FullName, "Bad Tag")); } } if (tagstrV2 == "" & tagstrV1 == "") { var mytrack = new Track("", "", "", "", "", "", fileList[i].FullName, "No Tag"); if (OnListFiles != null) { OnListFiles(mytrack); } trackList.Add(mytrack); } if ((i % 100) == 0) { if (UpdateProgress != null) { UpdateProgress(i * 100 / totalFiles); } } } }
/// <summary>Saves the tag to the specified path.</summary> /// <param name="path">The full path of the file.</param> private void Save(string path) { if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path"); if (VorbisComment.VorbisComment.IsFlac(path)) { VorbisComment.VorbisComment vc = new VorbisComment.VorbisComment(path); vc.Title = Title; vc.Artist = Artist; vc.Album = Album; vc.Year = Year; vc.Genre = Genre; vc.TrackNumber = TrackNumber; vc.Comment = Comment; vc.Save(path); ID3v2Tag.RemoveTag(path); ID3v1Tag.RemoveTag(path); } else { ID3v2Tag id3v2 = new ID3v2Tag(path); id3v2.Title = Title; id3v2.Artist = Artist; id3v2.Album = Album; id3v2.Year = Year; id3v2.Genre = Genre; id3v2.TrackNumber = TrackNumber; if (id3v2.CommentsList.Count > 0) { id3v2.CommentsList[0].Description = Comment; } else { if (!string.IsNullOrEmpty(Comment)) id3v2.CommentsList.AddNew().Description = Comment; } ID3v1Tag id3v1 = new ID3v1Tag(path); id3v1.Title = Title; id3v1.Artist = Artist; id3v1.Album = Album; id3v1.Year = Year; id3v1.GenreIndex = GenreHelper.GetGenreIndex(Genre); id3v1.Comment = Comment; int trackNumber; if (int.TryParse(TrackNumber, out trackNumber)) { id3v1.TrackNumber = trackNumber; } else { // Handle ##/## format if (TrackNumber.Contains("/")) { if (int.TryParse(TrackNumber.Split('/')[0], out trackNumber)) id3v1.TrackNumber = trackNumber; else id3v1.TrackNumber = 0; } else { id3v1.TrackNumber = 0; } } id3v2.Save(path); id3v1.Save(path); } Read(path); }
/// <summary>Reads the tag from the specified stream.</summary> /// <param name="stream">The stream.</param> private void Read(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); bool id3v2Found = false; string tagVersion = string.Empty; // ID3v2 if (ID3v2Tag.DoesTagExist(stream)) { ID3v2Tag id3v2 = new ID3v2Tag(stream); Title = id3v2.Title; Artist = id3v2.Artist; Album = id3v2.Album; Year = id3v2.Year; Genre = id3v2.Genre; TrackNumber = id3v2.TrackNumber; if (id3v2.CommentsList.Count > 0) Comment = id3v2.CommentsList[0].Description; else Comment = null; tagVersion = EnumUtils.GetDescription(id3v2.Header.TagVersion); id3v2Found = true; } // ID3v1 if (ID3v1Tag.DoesTagExist(stream)) { ID3v1Tag id3v1 = new ID3v1Tag(stream); // Use ID3v1 fields if ID3v2 doesn't exist or field is blank if (!id3v2Found || string.IsNullOrEmpty(Title)) Title = id3v1.Title; if (!id3v2Found || string.IsNullOrEmpty(Artist)) Artist = id3v1.Artist; if (!id3v2Found || string.IsNullOrEmpty(Album)) Album = id3v1.Album; if (!id3v2Found || string.IsNullOrEmpty(Year)) Year = id3v1.Year; if (!id3v2Found || string.IsNullOrEmpty(Genre)) Genre = GenreHelper.GenreByIndex[id3v1.GenreIndex]; if (!id3v2Found || string.IsNullOrEmpty(TrackNumber)) TrackNumber = id3v1.TrackNumber.ToString(); if (!id3v2Found || string.IsNullOrEmpty(Comment)) Comment = id3v1.Comment; tagVersion += (!string.IsNullOrEmpty(tagVersion) ? ", " : "") + EnumUtils.GetDescription(id3v1.TagVersion); } // Vorbis Comment if (VorbisComment.VorbisComment.IsFlac(stream)) { VorbisComment.VorbisComment vc = new VorbisComment.VorbisComment(stream); Title = vc.Title; Artist = vc.Artist; Album = vc.Album; Year = vc.Year; Genre = vc.Genre; TrackNumber = vc.TrackNumber; Comment = vc.Comment; tagVersion = (!string.IsNullOrEmpty(tagVersion) ? ", " : "") + "Vorbis Comment"; } // No tag found if (string.IsNullOrEmpty(tagVersion)) { Title = null; Artist = null; Album = null; Year = null; Genre = null; TrackNumber = null; Comment = null; tagVersion = "None"; } // Set TagVersion TagVersion = tagVersion; }
public void Updaterecord(string filename) { string tagstring = ""; if (ID3v2Tag.DoesTagExist(filename)) { tagstring = "/V2"; if (ID3v1Tag.DoesTagExist(filename)) { tagstring = "V1" + tagstring; } var id3 = new ID3v2Tag(filename); var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber, id3.Genre, filename, tagstring); ModifyRecord(mytrack); } if (ID3v1Tag.DoesTagExist(filename) && tagstring == "") { tagstring = "V1"; var id3 = new ID3v1Tag(filename); var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], filename, tagstring); ModifyRecord(mytrack); } if (tagstring == "No Tag") { var mytrack = new Track("", "", "", "", "", "", filename, "No Tag"); ModifyRecord(mytrack); } }
private void poptextboxV1(string fdir) { TXTfilename.Text = fdir; if (ID3v1Tag.DoesTagExist(fdir)) { RDOver1.Checked = true; var id3v1 = new ID3v1Tag(fdir); CMBartist.Text = id3v1.Artist; CMBtitle.Text = id3v1.Title; CMBalbum.Text = id3v1.Album; CMBgenre.Text = GenreHelper.GenreByIndex[id3v1.GenreIndex]; CMBtrack.Text = id3v1.TrackNumber.ToString(); CMByear.Text = id3v1.Year; CMBcomment.Text = id3v1.Comment; } }
private Track Getkeepv1(string fname) { var mytrack = new Track(); string tagstrV2 = ""; if (ID3v2Tag.DoesTagExist(fname)) tagstrV2 = "V2"; var id3v1 = new ID3v1Tag(fname); mytrack.Filename = fname; if (CMBartist.Text == "#Keep#") { mytrack.Artist = id3v1.Artist; } else mytrack.Artist = CMBartist.Text; if (CMBtitle.Text == "#Keep#") { mytrack.Title = id3v1.Title; } else mytrack.Title = CMBtitle.Text; if (CMBalbum.Text == "#Keep#") { mytrack.Album = id3v1.Album; } else mytrack.Album = CMBalbum.Text; if (CMBgenre.Text == "#Keep#") { mytrack.Genre = GenreHelper.GenreByIndex[id3v1.GenreIndex]; } else mytrack.Genre = CMBgenre.Text; if (CMBtrack.Text == "#Keep#") { mytrack.Trackno = id3v1.TrackNumber.ToString(); } else mytrack.Trackno = CMBtrack.Text; if (CMByear.Text == "#Keep#") { mytrack.Year = id3v1.Year; } else mytrack.Year = CMByear.Text; mytrack.Tagtype = "V1" + "/" + tagstrV2; CMBcomment.Text = id3v1.Comment; return mytrack; // } // else return mytrack = null; }
private void BTNcopy_Click(object sender, EventArgs e) { if (musicListStore.SelectedItems.Count > 0) { var copywin = new FRMcopy(); string temp = ""; ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; copywin.GetGenre = musicListStore.SelectedItems[0].SubItems[8].Text; if (copywin.ShowDialog(this) == DialogResult.OK) { if (copywin.CopyV1) { foreach (ListViewItem item in filename) { temp = item.SubItems[1].Text + "\\" + item.SubItems[0].Text; if (File.Exists(temp) & ID3v1Tag.DoesTagExist(temp)) { var id3 = new ID3v1Tag(temp); Miscutils.Savev2tag(new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], temp, "V1/V2")); ReloadlistviewV2(item); } } } if (copywin.CopyV2) { foreach (ListViewItem item in filename) { temp = item.SubItems[1].Text + "\\" + item.SubItems[0].Text; if (File.Exists(temp) & ID3v2Tag.DoesTagExist(temp)) { var id3 = new ID3v2Tag(temp); string gen = copywin.GetGenre; Miscutils.Savev1tag(new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), gen, temp, "V1/V2")); ReloadlistviewV1(item); } } } } }//end musicstore setected }
public static Boolean Savev1tag(Track mytrack) { if (!File.Exists(mytrack.Filename)) { MessageBox.Show("File Does not exist " + mytrack.Filename); return false; } try { var trackxml = new XMLutils(appPath + "\\trackxml.xml"); removeID3v1(mytrack.Filename); var id3 = new ID3v1Tag(mytrack.Filename); if (!String.IsNullOrEmpty(mytrack.Filename) && File.Exists(mytrack.Filename)) { id3.Album = mytrack.Album; id3.Artist = mytrack.Artist; id3.Title = mytrack.Title; if (mytrack.Trackno.Contains("/")) { id3.TrackNumber = Convert.ToInt16(mytrack.Trackno.Substring(0, mytrack.Trackno.IndexOf("/"))); } else id3.TrackNumber = Convert.ToInt16(mytrack.Trackno); id3.Year = mytrack.Year; id3.GenreIndex = GenreHelper.GetGenreIndex(mytrack.Genre); // id3.Comment = comment; id3.Save(mytrack.Filename); trackxml.ModifyRecord(mytrack); } if (ID3v1Tag.DoesTagExist(mytrack.Filename)) { trackxml.Updaterecord(mytrack.Filename); return (true); } else return (false); } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }