Exemplo n.º 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 = ID3v1Tag.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 = ID3v1Tag.DoesTagExist(m_Filename);
            ucID3v1.LoadFile(m_Filename);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public Audiofile GetTag(string filePath)
        {
            var hasTag   = ID3v1Tag.DoesTagExist(filePath);
            var filename = Path.GetFileName(filePath);
            var genres   = genreService.GetID3v1Genres();

            if (hasTag)
            {
                var tag       = new ID3v1Tag(filePath);
                var audioFile = mapper.Map(tag, new Audiofile(Guid.NewGuid()));
                audioFile.HasTag     = true;
                audioFile.Filename   = filename;
                audioFile.TagType    = TagType.ID3V1;
                audioFile.TagVersion = GetTagVersion(filePath);
                audioFile.Genre      = genres[tag.GenreIndex];

                return(audioFile);
            }
            else
            {
                return(new Audiofile(Guid.NewGuid())
                {
                    HasTag = false,
                    Filename = filename
                });
            }
        }
Exemplo n.º 4
0
        private void musicListStore_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems;
            string temp = "";

            cleartextbox();
            pictureBox.Image = null;
            LABimage.Text    = "";
            try
            {
                foreach (ListViewItem item in filename)
                {
                    if (item.SubItems.Count > 1)
                    {
                        temp += item.SubItems[1].Text + "\\" + item.SubItems[0].Text;
                    }
                }
                if (File.Exists(temp))
                {
                    if (ID3v2Tag.DoesTagExist(temp))
                    {
                        poptextboxV2(temp);
                    }
                    else if (ID3v1Tag.DoesTagExist(temp))
                    {
                        poptextboxV1(temp);
                    }
                }
            }//end of try
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }
Exemplo n.º 5
0
        private void LoadFile(string path)
        {
            m_Filename = path;

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

            btnSave.Enabled        = true;
            btnRemoveID3v2.Enabled = ID3v2Tag.DoesTagExist(m_Filename);
            btnRemoveID3v1.Enabled = ID3v1Tag.DoesTagExist(m_Filename);
        }
Exemplo n.º 6
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.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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
        }
Exemplo n.º 10
0
        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", "", "", "", "");
                }
            }
        }
Exemplo n.º 11
0
        private OperationResult <AudioMetaData> MetaDataForFileFromIdSharp(string fileName)
        {
            var sw = new Stopwatch();

            sw.Start();
            AudioMetaData result    = new AudioMetaData();
            var           isSuccess = false;

            try
            {
                result.Filename = fileName;
                IAudioFile audioFile = AudioFile.Create(fileName, true);
                if (ID3v2Tag.DoesTagExist(fileName))
                {
                    IID3v2Tag id3v2 = new ID3v2Tag(fileName);
                    result.Release         = id3v2.Album;
                    result.Artist          = id3v2.AlbumArtist ?? id3v2.Artist;
                    result.ArtistRaw       = id3v2.AlbumArtist ?? id3v2.Artist;
                    result.Genres          = id3v2.Genre?.Split(new char[] { ',', '\\' });
                    result.TrackArtist     = id3v2.OriginalArtist ?? id3v2.Artist ?? id3v2.AlbumArtist;
                    result.TrackArtistRaw  = id3v2.OriginalArtist;
                    result.AudioBitrate    = (int?)audioFile.Bitrate;
                    result.AudioChannels   = audioFile.Channels;
                    result.AudioSampleRate = (int)audioFile.Bitrate;
                    result.Disk            = ID3TagsHelper.ParseDiscNumber(id3v2.DiscNumber);
                    result.DiskSubTitle    = id3v2.SetSubtitle;
                    result.Images          = id3v2.PictureList?.Select(x => new AudioMetaDataImage
                    {
                        Data        = x.PictureData,
                        Description = x.Description,
                        MimeType    = x.MimeType,
                        Type        = (AudioMetaDataImageType)x.PictureType
                    }).ToArray();
                    result.Time              = audioFile.TotalSeconds > 0 ? ((decimal?)audioFile.TotalSeconds).ToTimeSpan() : null;
                    result.Title             = id3v2.Title.ToTitleCase(false);
                    result.TrackNumber       = ID3TagsHelper.ParseTrackNumber(id3v2.TrackNumber);
                    result.TotalTrackNumbers = ID3TagsHelper.ParseTotalTrackNumber(id3v2.TrackNumber);
                    var year = id3v2.Year ?? id3v2.RecordingTimestamp ?? id3v2.ReleaseTimestamp ?? id3v2.OriginalReleaseTimestamp;
                    result.Year = ID3TagsHelper.ParseYear(year);
                    isSuccess   = result.IsValid;
                }

                if (!isSuccess)
                {
                    if (ID3v1Tag.DoesTagExist(fileName))
                    {
                        IID3v1Tag id3v1 = new ID3v1Tag(fileName);
                        result.Release         = id3v1.Album;
                        result.Artist          = id3v1.Artist;
                        result.ArtistRaw       = id3v1.Artist;
                        result.AudioBitrate    = (int?)audioFile.Bitrate;
                        result.AudioChannels   = audioFile.Channels;
                        result.AudioSampleRate = (int)audioFile.Bitrate;
                        result.Time            = audioFile.TotalSeconds > 0 ? ((decimal?)audioFile.TotalSeconds).ToTimeSpan() : null;
                        result.Title           = id3v1.Title.ToTitleCase(false);
                        result.TrackNumber     = SafeParser.ToNumber <short?>(id3v1.TrackNumber);
                        var date = SafeParser.ToDateTime(id3v1.Year);
                        result.Year = date?.Year ?? SafeParser.ToNumber <int?>(id3v1.Year);
                        isSuccess   = result.IsValid;
                    }
                }
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, "MetaDataForFileFromTagLib Filename [" + fileName + "] Error [" + ex.Serialize() + "]");
            }
            sw.Stop();
            return(new OperationResult <AudioMetaData>
            {
                IsSuccess = isSuccess,
                OperationTime = sw.ElapsedMilliseconds,
                Data = result
            });
        }
Exemplo n.º 12
0
        public AlbumTrack(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            _path = path;

            if (ID3v2Tag.DoesTagExist(path))
            {
                ID3v2Tag id3v2 = new ID3v2Tag(path);
                DiscNumber  = id3v2.DiscNumber;
                TrackNumber = id3v2.TrackNumber;
                Artist      = id3v2.Artist;
                Title       = id3v2.Title;
                ReleaseDate = id3v2.Year;
                Album       = id3v2.Album;
                Genre       = id3v2.Genre;
                if (id3v2.PictureList != null && id3v2.PictureList.Count == 1)
                {
                    Picture = id3v2.PictureList[0];
                }
            }

            if (ID3v1Tag.DoesTagExist(path))
            {
                ID3v1Tag id3v1 = new ID3v1Tag(path);
                if (string.IsNullOrWhiteSpace(TrackNumber))
                {
                    TrackNumber = string.Format("{0}", id3v1.TrackNumber);
                }
                if (string.IsNullOrWhiteSpace(Artist))
                {
                    Artist = id3v1.Artist;
                }
                if (string.IsNullOrWhiteSpace(Title))
                {
                    Title = id3v1.Title;
                }
                if (string.IsNullOrWhiteSpace(ReleaseDate))
                {
                    ReleaseDate = id3v1.Year;
                }
                if (string.IsNullOrWhiteSpace(Album))
                {
                    Album = id3v1.Album;
                }
                if (string.IsNullOrWhiteSpace(Genre))
                {
                    Genre = GenreHelper.GenreByIndex[id3v1.GenreIndex];
                }
            }

            IAudioFile audioFile = AudioFile.Create(_path, throwExceptionIfUnknown: true);

            Bitrate      = audioFile.Bitrate;
            TotalSeconds = audioFile.TotalSeconds;

            // TODO: APE, Lyrics3

            // TODO: When no tags, try to guess from path and file names
            // TODO: Parse Tracks for TotalTracks
            // TODO: Parse Disc for TotalDiscs

            // Parse track # from TrackNumber including total tracks
            if (!string.IsNullOrWhiteSpace(TrackNumber))
            {
                if (TrackNumber.Contains('/'))
                {
                    TrackNumber = TrackNumber.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    // TODO: Set total tracks?
                }
            }

            // Parse disc # from DiscNumber including total discs
            if (!string.IsNullOrWhiteSpace(DiscNumber))
            {
                if (DiscNumber.Contains('/'))
                {
                    DiscNumber = DiscNumber.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    // TODO: Set total discs?
                }
            }
            else
            {
                DiscNumber = "1";
            }
        }
Exemplo n.º 13
0
 public bool HasTag(string filePath)
 => ID3v1Tag.DoesTagExist(filePath);
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        private void ScanDirectory(object p_oBasePath)
        {
            try
            {
                string sBasePath  = (string)p_oBasePath;
                int    iDirCount  = 0;
                int    iTotalDirs = 0;

                DirectoryInfo dirBase = new DirectoryInfo(sBasePath);

                DirectoryInfo[] subDirList = dirBase.GetDirectories("*", SearchOption.AllDirectories);
                iTotalDirs = subDirList.Length + 1;
                DirectoryInfo[] dirList = new DirectoryInfo[iTotalDirs];
                dirList[0] = dirBase;

                subDirList.CopyTo(dirList, 1);

                EnableCancelButton();

                foreach (DirectoryInfo dir in dirList)
                {
                    if (bCancelScanning)
                    {
                        return;
                    }

                    iDirCount++;

                    FileInfo[] fileList = dir.GetFiles("*.mp3");

                    foreach (FileInfo file in fileList)
                    {
                        if (bCancelScanning)
                        {
                            return;
                        }

                        if (ID3v2Tag.DoesTagExist(file.FullName))
                        {
                            IID3v2Tag id3 = new ID3v2Tag(file.FullName);

                            fileTrackList.Add(new Track
                            {
                                Artist       = id3.Artist,
                                Title        = id3.Title,
                                SubTitle     = id3.Subtitle,
                                Album        = id3.Album,
                                TrackNumber  = id3.TrackNumber,
                                ContentGroup = id3.ContentGroup,
                                FileName     = file.FullName,
                                FileSize     = file.Length
                            });
                        }
                        else if (ID3v1Tag.DoesTagExist(file.FullName))
                        {
                            ID3v1Tag id3 = new ID3v1Tag(file.FullName);

                            fileTrackList.Add(new Track
                            {
                                Artist   = id3.Artist,
                                Title    = id3.Title,
                                Album    = id3.Album,
                                FileName = file.FullName
                            });
                        }
                    }

                    UpdateFolderProgress(iDirCount, iTotalDirs);

                    //DisableCancelButton();
                }
            }
            finally
            {
                EndFolderScanning(new BindingList <Track>(fileTrackList));
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            string fileName = GetFileName(args);

            if (fileName == null)
            {
                return;
            }

            Console.WriteLine();
            Console.WriteLine(string.Format("File: {0}", fileName));
            Console.WriteLine();

            IAudioFile audioFile = AudioFile.Create(fileName, true);

            Console.WriteLine("Audio Info");
            Console.WriteLine();
            Console.WriteLine(string.Format("Type:      {0}", EnumUtils.GetDescription(audioFile.FileType)));
            Console.WriteLine(string.Format("Length:    {0}:{1:00}", (int)audioFile.TotalSeconds / 60, (int)audioFile.TotalSeconds % 60));
            Console.WriteLine(string.Format("Bitrate:   {0:#,0} kbps", (int)audioFile.Bitrate));
            Console.WriteLine(string.Format("Frequency: {0:#,0} Hz", audioFile.Frequency));
            Console.WriteLine(string.Format("Channels:  {0}", audioFile.Channels));
            Console.WriteLine();

            if (ID3v2Tag.DoesTagExist(fileName))
            {
                IID3v2Tag id3v2 = new ID3v2Tag(fileName);

                Console.WriteLine(EnumUtils.GetDescription(id3v2.Header.TagVersion));
                Console.WriteLine();

                Console.WriteLine(string.Format("Artist:    {0}", id3v2.Artist));
                Console.WriteLine(string.Format("Title:     {0}", id3v2.Title));
                Console.WriteLine(string.Format("Album:     {0}", id3v2.Album));
                Console.WriteLine(string.Format("Year:      {0}", id3v2.Year));
                Console.WriteLine(string.Format("Track:     {0}", id3v2.TrackNumber));
                Console.WriteLine(string.Format("Genre:     {0}", id3v2.Genre));
                Console.WriteLine(string.Format("Pictures:  {0}", id3v2.PictureList.Count));
                Console.WriteLine(string.Format("Comments:  {0}", id3v2.CommentsList.Count));
                Console.WriteLine();

                // Example of saving an ID3v2 tag
                //
                // id3v2.Title = "New song title";
                // id3v2.Save(fileName);
            }

            if (ID3v1Tag.DoesTagExist(fileName))
            {
                IID3v1Tag id3v1 = new ID3v1Tag(fileName);

                Console.WriteLine(EnumUtils.GetDescription(id3v1.TagVersion));
                Console.WriteLine();

                Console.WriteLine(string.Format("Artist:    {0}", id3v1.Artist));
                Console.WriteLine(string.Format("Title:     {0}", id3v1.Title));
                Console.WriteLine(string.Format("Album:     {0}", id3v1.Album));
                Console.WriteLine(string.Format("Year:      {0}", id3v1.Year));
                Console.WriteLine(string.Format("Comment:   {0}", id3v1.Comment));
                Console.WriteLine(string.Format("Track:     {0}", id3v1.TrackNumber));
                Console.WriteLine(string.Format("Genre:     {0}", GenreHelper.GenreByIndex[id3v1.GenreIndex]));
                Console.WriteLine();

                // Example of saving an ID3v1 tag
                //
                // id3v1.Title = "New song title";
                // id3v1.Save(fileName);
            }

            if (audioFile.FileType == AudioFileType.Flac)
            {
                VorbisComment vorbis = new VorbisComment(fileName);

                Console.WriteLine("Vorbis Comment");
                Console.WriteLine();

                Console.WriteLine(string.Format("Artist:    {0}", vorbis.Artist));
                Console.WriteLine(string.Format("Title:     {0}", vorbis.Title));
                Console.WriteLine(string.Format("Album:     {0}", vorbis.Album));
                Console.WriteLine(string.Format("Year:      {0}", vorbis.Year));
                Console.WriteLine(string.Format("Comment:   {0}", vorbis.Comment));
                Console.WriteLine(string.Format("Track:     {0}", vorbis.TrackNumber));
                Console.WriteLine(string.Format("Genre:     {0}", vorbis.Genre));
                Console.WriteLine(string.Format("Vendor:    {0}", vorbis.Vendor));
                Console.WriteLine();

                // Example of saving a Vorbis Comment
                //
                // vorbis.Title = "New song title";
                // vorbis.Save(fileName);
            }
        }
Exemplo n.º 17
0
        /// <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;
        }
Exemplo n.º 18
0
        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);
                    }
                }
            }
        }