Ejemplo n.º 1
0
        private void btnRemoveID3v2_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 ID3v2 tag from '{0}'?", Path.GetFileName(m_Filename)), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    bool success = ID3v2Tag.RemoveTag(m_Filename);
                    if (success)
                    {
                        MessageBox.Show("ID3v2 tag successfully removed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("ID3v2 tag not found", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            btnRemoveID3v2.Enabled = ID3v2Tag.DoesTagExist(m_Filename);
            ucID3v2.LoadFile(m_Filename);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        private void poptextboxV2(string fdir)
        {
            TXTfilename.Text = fdir;
            pictureBox.Image = null;
            LABimage.Text    = "";
            if (ID3v2Tag.DoesTagExist(fdir))
            {
                RDOver2.Checked = true;

                var id3v2 = new ID3v2Tag(fdir);
                CMBartist.Text  = id3v2.Artist;
                CMBtitle.Text   = id3v2.Title;
                CMBalbum.Text   = id3v2.Album;
                CMBgenre.Text   = id3v2.Genre;
                CMBtrack.Text   = id3v2.TrackNumber;
                CMByear.Text    = id3v2.Year;
                CMBcomment.Text = id3v2.CommentsList.ToString();
                if (id3v2.CommentsList.Count > 0)
                {
                    CMBcomment.Text = id3v2.CommentsList[0].Value;
                }
                if (id3v2.PictureList.Count > 0)
                {
                    pictureBox.Image = id3v2.PictureList[0].Picture;
                    LABimage.Text    = id3v2.PictureList[0].Description.ToString() + "\r\n" + id3v2.PictureList[0].Picture.Size.ToString() + "\r\n" + id3v2.PictureList[0].PictureExtension.ToString();
                }
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
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
        }
Ejemplo n.º 9
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", "", "", "", "");
                }
            }
        }
        /// <summary>
        ///     Sets the track album cover.
        /// </summary>
        /// <param name="track">The track.</param>
        /// <param name="image">The image.</param>
        public static void SetTrackAlbumCover(Track track, Image image)
        {
            if (track == null)
            {
                return;
            }
            if (image == null)
            {
                return;
            }
            if (!ID3v2Tag.DoesTagExist(track.Filename))
            {
                return;
            }

            var tags = new ID3v2Tag(track.Filename);

            if (tags.PictureList.Count > 0)
            {
                tags.PictureList.Clear();
            }

            var picture = tags.PictureList.AddNew();

            if (picture != null)
            {
                picture.PictureType = PictureType.CoverFront;
                picture.MimeType    = "image/jpeg";

                using (var stream = new MemoryStream())
                {
                    ImageHelper.SaveJpg(stream, image);
                    picture.PictureData = stream.ToArray();
                }
            }
            tags.Save(track.Filename);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Loads the track details from the tags in the associate mp3
        /// </summary>
        /// <param name="track">The track to load the details of.</param>
        /// <param name="updateLength">if set to <c>true</c> [update length].</param>
        public static void LoadTrack(Track track, bool updateLength = true)
        {
            if (!File.Exists(track.Filename))
            {
                return;
            }
            if (!track.Filename.ToLower().EndsWith(".mp3"))
            {
                return;
            }

            DebugHelper.WriteLine("Library - LoadTrack - " + track.Description);

            GuessTrackDetailsFromFileName(track);

            var dateLastModified = GetTrackLastModified(track.Filename);

            track.LastModified = dateLastModified;

            if (ID3v2Tag.DoesTagExist(track.Filename))
            {
                var tags = new ID3v2Tag(track.Filename);

                if (!string.IsNullOrEmpty(tags.Artist))
                {
                    track.Artist = tags.Artist.Trim();
                }
                if (!string.IsNullOrEmpty(tags.Artist))
                {
                    track.AlbumArtist = tags.Artist.Trim();
                }
                if (!string.IsNullOrEmpty(tags.Title))
                {
                    track.Title = tags.Title.Trim();
                }
                if (!string.IsNullOrEmpty(tags.Album))
                {
                    track.Album = tags.Album.Trim();
                }
                if (!string.IsNullOrEmpty(tags.Genre))
                {
                    track.Genre = tags.Genre.Trim();
                }
                if (!string.IsNullOrEmpty(tags.InitialKey))
                {
                    var tagKey = tags.InitialKey.Trim();
                    track.Key = KeyHelper.ParseKey(tagKey);
                }

                LoadArtistAndAlbumArtist(track);

                if (tags.LengthMilliseconds.HasValue)
                {
                    track.Length = (decimal)tags.LengthMilliseconds / 1000M;
                }

                decimal bpm;
                if (decimal.TryParse(tags.BPM, out bpm))
                {
                    track.Bpm = bpm;
                }

                track.Bpm      = BpmHelper.NormaliseBpm(track.Bpm);
                track.EndBpm   = track.Bpm;
                track.StartBpm = track.Bpm;
                track.Bpm      = BpmHelper.GetAdjustedBpmAverage(track.StartBpm, track.EndBpm);

                int trackNumber;
                var trackNumberTag = (tags.TrackNumber + "/").Split('/')[0].Trim();
                if (int.TryParse(trackNumberTag, out trackNumber))
                {
                    track.TrackNumber = trackNumber;
                }

                if (GenreCode.IsGenreCode(track.Genre))
                {
                    track.Genre = GenreCode.GetGenre(track.Genre);
                }
                if (track.Artist == "")
                {
                    track.Artist = NoValue;
                }
                if (track.AlbumArtist == "")
                {
                    track.AlbumArtist = NoValue;
                }
                if (track.Title == "")
                {
                    track.Title = NoValue;
                }
                if (track.Album == "")
                {
                    track.Album = NoValue;
                }
                if (track.Genre == "")
                {
                    track.Genre = NoValue;
                }
            }

            track.OriginalDescription = track.Description;
            track.FullLength          = track.Length;


            var audioFile = AudioFile.Create(track.Filename, true);

            track.Bitrate = audioFile.Bitrate;
            track.Length  = audioFile.TotalSeconds;

            if (updateLength)
            {
                UpdateLength(track);
            }

            //UpdateKey(track);

            track.Bpm = BpmHelper.GetAdjustedBpmAverage(track.StartBpm, track.EndBpm);

            track.OriginalDescription = track.Description;

            if (track.EndBpm == 0 || track.EndBpm == 100)
            {
                track.EndBpm = track.Bpm;
            }
            if (track.StartBpm == 0 || track.StartBpm == 100)
            {
                track.StartBpm = track.Bpm;
            }
        }
Ejemplo n.º 12
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
            });
        }
Ejemplo n.º 13
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";
            }
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
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));
            }
        }
        /// <summary>
        ///     Loads and caches an album cover.
        /// </summary>
        /// <param name="track">The track.</param>
        public static void LoadAlbumCover(Track track)
        {
            try
            {
                var path = Path.GetDirectoryName(track.Filename);
                if (path == null)
                {
                    return;
                }

                var albumArtImagePath = Path.Combine(path, "AlbumArtSmall.jpg");
                var folderImagePath   = Path.Combine(path, "folder.jpg");

                var albumArtImageDate = DateTime.MinValue;
                if (File.Exists(albumArtImagePath))
                {
                    albumArtImageDate = File.GetLastWriteTime(albumArtImagePath);
                }

                var folderImageDate = DateTime.MinValue;
                if (File.Exists(folderImagePath))
                {
                    folderImageDate = File.GetLastWriteTime(folderImagePath);
                }

                if (!File.Exists(folderImagePath))
                {
                    if (ID3v2Tag.DoesTagExist(track.Filename))
                    {
                        var tags = new ID3v2Tag(track.Filename);
                        if (tags.PictureList.Count > 0)
                        {
                            using (Image folderImage = new Bitmap(tags.PictureList[0].Picture))
                            {
                                ImageHelper.SaveJpg(folderImagePath, folderImage);
                            }
                        }
                    }
                }

                if (!File.Exists(albumArtImagePath) || albumArtImageDate < folderImageDate)
                {
                    if (File.Exists(folderImagePath))
                    {
                        using (Image image = new Bitmap(folderImagePath))
                        {
                            using (var smallImage = ImageHelper.Resize(image, new Size(150, 150)))
                            {
                                ImageHelper.SaveJpg(albumArtImagePath, smallImage);
                                File.SetAttributes(albumArtImagePath, FileAttributes.Hidden);
                            }
                        }
                    }
                }

                if (File.Exists(albumArtImagePath))
                {
                    Image image = new Bitmap(albumArtImagePath);
                    AlbumCovers.Add(track.Album, image);
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 18
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;
        }
Ejemplo n.º 19
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);
                    }
                }
            }
        }