public static Track Getv2tags(string fname) { var mytrack = new Track("", "", "", "", "", "", "", ""); if (File.Exists(fname)) { var id3 = new ID3v2Tag(fname); mytrack.Album = id3.Album; mytrack.Artist = id3.Artist; mytrack.Title = id3.Title; mytrack.Trackno = id3.TrackNumber.ToString(); mytrack.Year = id3.Year; } return mytrack; }
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); } } } }
public void Addrecord(Track mytrack) { if (!File.Exists(this.myPath)) createxmltile("Root"); var doc = new XmlDocument(); doc.Load(this.myPath); XmlNode newXMLNode = doc.SelectSingleNode("Root"); XmlElement newElem = doc.CreateElement("Record"); newElem.SetAttribute("ID", Stripescape(mytrack.Filename)); XmlElement firstnewElem = doc.CreateElement("Tagtype"); firstnewElem.InnerText = mytrack.Tagtype; newElem.AppendChild(firstnewElem); XmlElement firstelement = doc.CreateElement("Title"); firstelement.InnerText = Stripescape(mytrack.Title); newElem.AppendChild(firstelement); XmlElement secondelement = doc.CreateElement("Artist"); secondelement.InnerText = Stripescape(mytrack.Artist); newElem.AppendChild(secondelement); XmlElement thirdelement = doc.CreateElement("Album"); thirdelement.InnerText = Stripescape(mytrack.Album); newElem.AppendChild(thirdelement); XmlElement fourthelement = doc.CreateElement("Trackno"); fourthelement.InnerText = mytrack.Trackno; newElem.AppendChild(fourthelement); XmlElement fifthelement = doc.CreateElement("Year"); fifthelement.InnerText = mytrack.Year; newElem.AppendChild(fifthelement); XmlElement sixthhelement = doc.CreateElement("Genre"); sixthhelement.InnerText = mytrack.Genre; newElem.AppendChild(sixthhelement); doc.DocumentElement.InsertAfter(newElem, doc.DocumentElement.LastChild); doc.Save(this.myPath); }
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); } }
public void ModifyRecord(Track mytrack) { try { var doc = new XmlDocument(); doc.Load(this.myPath); string myid = Stripescape(mytrack.Filename); XmlNode nodes = doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]"); if (nodes == null) { Addrecord(mytrack); return; } doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Tagtype").InnerText = mytrack.Tagtype; doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Title").InnerText = Stripescape(mytrack.Title); doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Artist").InnerText = Stripescape(mytrack.Artist); doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Album").InnerText = Stripescape(mytrack.Album); doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Trackno").InnerText = mytrack.Trackno; doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Year").InnerText = mytrack.Year; doc.SelectSingleNode("//Root/Record[@ID=" + "'" + myid + "'" + "]/Genre").InnerText = mytrack.Genre; doc.Save(this.myPath); doc = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void tagFromFilenameToolStripMenuItem_Click(object sender, EventArgs e) { var tagfilewin = new FRMtagfile(); ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; foreach (ListViewItem item in filename) { tagfilewin.Addtrack(item.SubItems[1].Text + "\\" + item.SubItems[0].Text); } if (tagfilewin.ShowDialog(this) == DialogResult.OK) { for (int x = 0; x <= tagfilewin.Gettrack_Count() - 1; x++) { var mytrack = new Track(tagfilewin.getartist(x), tagfilewin.gettitle(x), tagfilewin.getalbum(x), tagfilewin.getyear(x), tagfilewin.gettracknumber(x), tagfilewin.getgenre(x), tagfilewin.getfilename(x), "V1/V2"); Miscutils.Savev1tag(mytrack); Miscutils.Savev2tag(mytrack); // Miscutils.Updaterecord(tagfilewin.getfilename(x), tagfilewin.getalbum(x), tagfilewin.getartist(x), tagfilewin.getgenre(x), tagfilewin.gettitle(x), tagfilewin.gettracknumber(x), tagfilewin.getyear(x)); } } foreach (ListViewItem item in filename) { ReloadlistviewV1(item); } }
private void Onaddtolistview(Track mytrack) { if (this.musicListStore.InvokeRequired) { OnaddtolistviewDelegate d = new OnaddtolistviewDelegate(Onaddtolistview); this.Invoke(d, new object[] { mytrack }); } else { ListViewItem lvi; string[] aHeaders = new string[9]; aHeaders[0] = Path.GetFileName(mytrack.Filename); aHeaders[1] = Path.GetDirectoryName(mytrack.Filename); aHeaders[2] = mytrack.Tagtype; aHeaders[3] = mytrack.Title; aHeaders[4] = mytrack.Artist; aHeaders[5] = mytrack.Album; aHeaders[6] = mytrack.Trackno; aHeaders[7] = mytrack.Year; aHeaders[8] = mytrack.Genre; lvi = new ListViewItem(aHeaders); musicListStore.Items.Add(lvi); } }
private void LSVsearch_SelectedIndexChanged(object sender, EventArgs e) { if (LSVsearch.SelectedItems.Count > 0) { BindingList<Track> trackList = new BindingList<Track>(); FRMretag retagwin = new FRMretag(); ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; Bitmap cimage; int i = 1; ListViewItem lvItem = LSVsearch.SelectedItems[0]; string asin = lvItem.SubItems[0].Text; retagwin.Artist = lvItem.SubItems[1].Text; retagwin.Album = lvItem.SubItems[2].Text; trackList = sitem.getgnutracks(asin); retagwin.Year = trackList[0].Year; retagwin.Genre = trackList[0].Genre; for (int y = 0; y <= trackList.Count - 1; y++) { retagwin.Addnewtrack(trackList[y].Trackno, trackList[y].Title); } foreach (ListViewItem item in filename) { retagwin.Addtrack(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, item.SubItems[3].Text); i++; } if (retagwin.ShowDialog(this) == DialogResult.OK) { string[] tn = new string[2]; for (int x = 0; x <= retagwin.gettrack_count() - 1; x++) { if (x <= retagwin.getnewtrack_count() - 1) { tn = retagwin.getnewtrackname(x); int tnum = Convert.ToInt16(tn[0]); if (retagwin.isimage()) { cimage = retagwin.Getimage(); var mytrack = new Track(retagwin.Artist, tn[1], retagwin.Album, retagwin.Year, tn[0], retagwin.Genre, retagwin.gettrackname(x), "V1//V2", cimage); Miscutils.Savev1tag(mytrack); Miscutils.Savev2tag(mytrack); } else { var mytrack = new Track(retagwin.Artist, tn[1], retagwin.Album, retagwin.Year, tn[0], retagwin.Genre, retagwin.gettrackname(x), "V1//V2"); Miscutils.Savev1tag(mytrack); Miscutils.Savev2tag(mytrack); } // Miscutils.Updaterecord(retagwin.gettrackname(x), retagwin.Album, retagwin.Artist, retagwin.Genre, tn[1], tnum.ToString(), retagwin.Year); } } foreach (ListViewItem item in filename) { ReloadlistviewV1(item); // } } } }
private Track Getkeepv2(string fname) { var mytrack = new Track(); string tagstrV1 = ""; if (ID3v1Tag.DoesTagExist(fname)) tagstrV1 = "V1"; var id3v2 = new ID3v2Tag(fname); mytrack.Filename = fname; if (CMBartist.Text == "#Keep#") { mytrack.Artist = id3v2.Artist; } else mytrack.Artist = CMBartist.Text; if (CMBtitle.Text == "#Keep#") { mytrack.Title = id3v2.Title; } else mytrack.Title = CMBtitle.Text; if (CMBalbum.Text == "#Keep#") { mytrack.Album = id3v2.Album; } else mytrack.Album = CMBalbum.Text; if (CMBgenre.Text == "#Keep#") { mytrack.Genre = id3v2.Genre; } else mytrack.Genre = CMBgenre.Text; if (CMBtrack.Text == "#Keep#") { mytrack.Trackno = id3v2.TrackNumber.ToString(); } else mytrack.Trackno = CMBtrack.Text; if (CMByear.Text == "#Keep#") { mytrack.Year = id3v2.Year; } else mytrack.Year = CMByear.Text; if (pictureBox.Image != null) { mytrack.coverimage = (Bitmap)pictureBox.Image; } mytrack.Tagtype = tagstrV1 + "/" + "V2"; //CMBcomment.Text = id3v2.CommentsList[0].Value; return mytrack; // } // else return mytrack = null; }
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 BTNsavetag_Click(object sender, EventArgs e) { var mytrackv1 = new Track(); var mytrackv2 = new Track(); string fname = ""; ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; foreach (ListViewItem item in filename) { fname = (item.SubItems[1].Text + "\\" + item.SubItems[0].Text); { var mytrack = new Track(); mytrack = Getkeepv1(fname); Miscutils.Savev1tag(mytrack); ReloadlistviewV1(item); } // result = MessageBox.Show(string.Format("Save ID3v2 tag from '{0}'?", Path.GetFileName(TXTfilename.Text)), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); // if (result == DialogResult.Yes) { var mytrack = new Track(); mytrack = Getkeepv2(fname); Miscutils.Savev2tag(mytrack); ReloadlistviewV2(item); } } }
private void addImageToolStripMenuItem_Click(object sender, EventArgs e) { FRMImage addimage = new FRMImage(); ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; var trackxml = new XMLutils(appPath + "\\trackxml.xml"); addimage.Artist = filename[0].SubItems[4].Text; addimage.Album = filename[0].SubItems[5].Text; if (addimage.ShowDialog(this) == DialogResult.OK) { foreach (ListViewItem item in filename) { string fname = item.SubItems[1].Text + "\\" + item.SubItems[0].Text; var id3v2 = new ID3v2Tag(fname); var mytrack = new Track(); mytrack.Filename = fname; mytrack.Artist = id3v2.Artist; mytrack.Title = id3v2.Title; mytrack.Album = id3v2.Album; mytrack.Genre = id3v2.Genre; mytrack.Trackno = id3v2.TrackNumber.ToString(); mytrack.Year = id3v2.Year; if (addimage.Getimage() != null) { mytrack.coverimage = addimage.Getimage(); } Miscutils.Savev2tag(mytrack); //ReloadlistviewV2(fname); } } }
private string Getnewtrack(string fname) { string ntn = COMBrename.Text; Track mytrack = new Track("", "", "", "", "", "", "", ""); string extn = Path.GetExtension(fname); if (ID3v1Tag.DoesTagExist(fname)) { mytrack = Miscutils.Getv1tags(fname); } else if (ID3v2Tag.DoesTagExist(fname)) { mytrack = Miscutils.Getv2tags(fname); } if (ntn.Contains("%TRACKNUMBER%")) { ntn = ntn.Replace("%TRACKNUMBER%", Miscutils.PaddedNumber(mytrack.Trackno)); } if (ntn.Contains("%ARTIST%")) { ntn = ntn.Replace("%ARTIST%", mytrack.Artist); } if (ntn.Contains("%ALBUM%")) { ntn = ntn.Replace("%ALBUM%", mytrack.Album); } if (ntn.Contains("%TITLE%")) { ntn = ntn.Replace("%TITLE%", mytrack.Title); } if (ntn.Contains("%FILENAME%")) { ntn = ntn.Replace("%FILENAME%", Path.GetFileNameWithoutExtension(fname)); } ntn = Miscutils.stripchar(ntn); if (TXTrepbefore.Text != "") { ntn = ntn.Replace(TXTrepbefore.Text, TXTrepafter.Text); } return ntn + extn; }
public static Boolean Savev2tag(Track mytrack) { if (!File.Exists(mytrack.Filename)) { MessageBox.Show("File Does not exist " + mytrack.Filename); return false; } var trackxml = new XMLutils(appPath + "\\trackxml.xml"); removeID3v2(mytrack.Filename); var id3 = new ID3v2Tag(mytrack.Filename); if (!String.IsNullOrEmpty(mytrack.Filename) && File.Exists(mytrack.Filename)) { id3.Album = mytrack.Album; id3.Artist = mytrack.Artist; id3.Title = mytrack.Title; id3.TrackNumber = mytrack.Trackno; id3.Year = mytrack.Year; id3.Genre = mytrack.Genre; if (mytrack.coverimage !=null) { id3.PictureList.Clear(); IAttachedPicture picture = id3.PictureList.AddNew(); picture.PictureData = ConvertBitMapToByteArray(mytrack.coverimage); picture.PictureType = PictureType.CoverFront; } id3.Save(mytrack.Filename); trackxml.ModifyRecord(mytrack); } if (ID3v2Tag.DoesTagExist(mytrack.Filename)) { trackxml.Updaterecord(mytrack.Filename); return (true); } else return (false); }
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; } }