Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        public void SaveFile(String path)
        {
            if (m_ID3v1 == null)
            {
                MessageBox.Show("Nothing to save!");
                return;
            }

            m_ID3v1.TagVersion = (cmbID3v1.SelectedIndex == 0 ? ID3v1TagVersion.ID3v10 : ID3v1TagVersion.ID3v11);
            m_ID3v1.Artist     = txtArtist.Text;
            m_ID3v1.Title      = txtTitle.Text;
            m_ID3v1.Album      = txtAlbum.Text;
            m_ID3v1.GenreIndex = GenreHelper.GetGenreIndex(cmbGenre.Text);
            m_ID3v1.Year       = txtYear.Text;
            m_ID3v1.Comment    = txtComment.Text;
            Int32 trackNumber;

            Int32.TryParse(txtTrackNumber.Text, out trackNumber);
            m_ID3v1.TrackNumber = trackNumber;

            m_ID3v1.Save(path);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(GenreHelper.GetGenreIndex((string)value));
 }