Пример #1
0
        private void btnRemoveID3v1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(m_Filename))
            {
                MessageBox.Show("No file loaded", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DialogResult result = MessageBox.Show(String.Format("Remove ID3v1 tag from '{0}'?", Path.GetFileName(m_Filename)), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    Boolean success = ID3v1Helper.RemoveTag(m_Filename);
                    if (success)
                    {
                        MessageBox.Show("ID3v1 tag successfully removed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("ID3v1 tag not found", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            btnRemoveID3v1.Enabled = ID3v1Helper.DoesTagExist(m_Filename);
            ucID3v1.LoadFile(m_Filename);
        }
Пример #2
0
        private void LoadFile(String path)
        {
            m_Filename = path;

            ucID3v2.LoadFile(m_Filename);
            ucID3v1.LoadFile(m_Filename);

            btnSave.Enabled        = true;
            btnRemoveID3v2.Enabled = ID3v2Helper.DoesTagExist(m_Filename);
            btnRemoveID3v1.Enabled = ID3v1Helper.DoesTagExist(m_Filename);
        }
Пример #3
0
        /// <summary>
        /// This method sets various audio file properties into a Dictionary
        /// </summary>
        /// <param name="source">source indicates the path to the file whose properties are to be extracted</param>
        /// <returns>Returns a Dictionary object where key => property name and value => property value</returns>
        public override StringDictionary GetProperties(string source)
        {
            if (IO.File.Exists(source))
            {
                try
                {
                    TagLib.File file = TagLib.File.Create(source);
                    TagLib.Tag  tags = file.Tag;

                    fileProperties["title"]   = tags.Title;
                    fileProperties["album"]   = tags.Album;
                    fileProperties["artist"]  = string.Join(",", tags.AlbumArtists);
                    fileProperties["year"]    = tags.Year.ToString();
                    fileProperties["track"]   = tags.Track.ToString();
                    fileProperties["genres"]  = string.Join(",", tags.Genres);
                    fileProperties["comment"] = tags.Comment;
                    fileProperties["length"]  = TimeSpan.Parse(file.Properties.Duration.Hours + ":" + file.Properties.Duration.Minutes + ":" + file.Properties.Duration.Seconds).ToString();
                }
                catch (Exception ex) //CorruptFileException
                {
                    if (ID3v1Helper.DoesTagExist(source))
                    {
                        IID3v1 id3v1 = ID3v1Helper.CreateID3v1(source);
                        fileProperties["title"]   = id3v1.Title;
                        fileProperties["album"]   = id3v1.Album;
                        fileProperties["artist"]  = id3v1.Artist;
                        fileProperties["year"]    = id3v1.Year;
                        fileProperties["track"]   = id3v1.TrackNumber.ToString();
                        fileProperties["comment"] = id3v1.Comment;
                    }
                    if (ID3v2Helper.DoesTagExist(source))
                    {
                        IID3v2   id3v2 = ID3v2Helper.CreateID3v2(source);
                        TimeSpan ts    = TimeSpan.FromMilliseconds(id3v2.LengthMilliseconds.Value);
                        fileProperties["length"] = TimeSpan.Parse(ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds).ToString();
                        fileProperties["genres"] = id3v2.Genre;
                    }
                    if (!(ID3v1Helper.DoesTagExist(source) && ID3v2Helper.DoesTagExist(source)))
                    {
                        RemoveFileSpecificKeys();
                    }
                }
                return(base.GetProperties(source));
            }
            else if (Win32Helper.PathExist(source))
            {
                RemoveFileSpecificKeys(); return(base.GetProperties(source));
            }
            return(null);
        }