private void UpdateTagInfo(string mp3File, string mp3MusicRootPath, bool useDirInfo, ref OperationResult op)
        {
            OperationResult _op = new OperationResult();

            try
            {
                bool            badfile = false;
                MP3FileDataType mp3     = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(mp3File,
                                                                                                     mp3MusicRootPath, ref _op);
                if (!_op.Success)
                {
                    badfile = true;
                }

                if (_op.Success)
                {
                    BCHMP3Utilities.SaveMp3IdInfo(mp3, ref _op);
                }

                if (!_op.Success && !badfile)
                {
                    badfile = true;
                }
            }
            catch (Exception ex)
            {
                _op.AddException(ex);
            }
            op.AddOperationResult(ref _op);
        }
示例#2
0
        public FrmMp3TagEditor()
        {
            InitializeComponent();

            cbGenre3v1.DataSource = BCHMP3Utilities.GetGenre();
            cbGenre3v2.DataSource = BCHMP3Utilities.GetGenre();
        }
        public List <string> EditMP3Tags(List <string> mp3Files, string mp3MusicRootPath, bool useFileInfo, ref OperationResult op)
        {
            OperationResult _op        = new OperationResult();
            int             cnt        = 0;
            bool            badfile    = false;
            List <string>   badMp3List = new List <string>();

            foreach (string mp3File in mp3Files)
            {
                badfile = false;
                cnt++;
                if (ProgressUpdate != null)
                {
                    ProgressUpdate(cnt);
                }
                try
                {
                    MP3FileDataType mp3 = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(mp3File,
                                                                                                     mp3MusicRootPath, ref _op);
                    if (!_op.Success)
                    {
                        badMp3List.Add(mp3File);
                        badfile = true;
                    }

                    if (_op.Success)
                    {
                        SaveMp3IdInfo(mp3, ref _op);
                    }

                    if (!_op.Success && !badfile)
                    {
                        badfile = true;
                        badMp3List.Add(mp3File);
                    }
                }
                catch (Exception ex)
                {
                    _op.AddException(ex);
                    if (!badfile)
                    {
                        badfile = true;
                        badMp3List.Add(mp3File);
                    }
                }
            }

            op.AddOperationResult(ref _op);

            return(badMp3List);
        }
示例#4
0
        private void TestMP3Parcing()
        {
            OperationResult op           = new OperationResult();
            string          fileNamePath = @"H:\Barry Hill\My Music\Music\R&B\Anita Baker\Giving You the Best That I Got\Anita Baker-01--Priceless.mp3";
            string          mscRtDir     = @"H:\Barry Hill\My Music\Music";

            textBox1.Text = fileNamePath;
            MP3FileDataType mp3 = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(fileNamePath, mscRtDir, ref op);

            Dictionary <string, string> dict = BCHUtilities.GetObjectNamePropDict <MP3FileDataType>(mp3, ref op);

            textBox2.Text       = BCHUtilities.DictionaryToString(dict, ";");
            listBox1.DataSource = dict.Values.ToList <string>();
        }
示例#5
0
        private void TestMP3FileNameConverter()
        {
            OperationResult op = new OperationResult();

            MP3FileDataType me = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(textBox1.Text, ref op);

            if (!op.Success)
            {
                MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            textBox2.Text = me.FileName + "; " + me.FilePath + "; ";
        }
        private void SaveMp3IdInfo(MP3FileDataType mp3, ref OperationResult op)
        {
            try
            {
                ID3Info id3 = new ID3Info(mp3.FileNamePath, true);

                string track = mp3.Track != null?mp3.Track.ToString() : "1";

                string        title     = !string.IsNullOrEmpty(mp3.SongTitleAndNumeration) ? GetMaxLen(mp3.SongTitleAndNumeration, 30) : string.Empty;
                string        artists   = !string.IsNullOrEmpty(mp3.ArtistsStrList) ? GetMaxLen(mp3.ArtistsStrList, 30) : string.Empty;
                string        album     = !string.IsNullOrEmpty(mp3.Album) ? GetMaxLen(mp3.Album, 30) : string.Empty;
                string        comments  = !string.IsNullOrEmpty(mp3.Comments) ? GetMaxLen(mp3.Comments, 28) : string.Empty;
                List <string> GenreList = BCHMP3Utilities.GetGenre();
                int           genreIndx = GenreList.Contains(mp3.Genre, StringComparer.CurrentCultureIgnoreCase)
                                    ?
                                          GenreList.FindIndex(
                    s =>
                    s.Trim().Equals(mp3.Genre.Trim(), StringComparison.CurrentCultureIgnoreCase))
                                    :
                                          GenreList.FindIndex(
                    s =>
                    s.Trim().Equals("Other", StringComparison.CurrentCultureIgnoreCase));

                id3.ID3v1Info.TrackNumber = byte.Parse(track);
                id3.ID3v1Info.Title       = title;
                id3.ID3v1Info.Artist      = artists;
                id3.ID3v1Info.Album       = album;
                id3.ID3v1Info.Comment     = comments;
                id3.ID3v1Info.Genre       = Convert.ToByte(genreIndx);


                id3.ID3v2Info.SetTextFrame("TRCK", track);
                id3.ID3v2Info.SetTextFrame("TIT2", title);
                id3.ID3v2Info.SetTextFrame("TPE1", artists);
                id3.ID3v2Info.SetTextFrame("TALB", album);
                id3.ID3v2Info.SetTextFrame("WCOM", comments);
                id3.ID3v2Info.SetTextFrame("TCON", GenreList[genreIndx]);

                id3.ID3v2Info.HaveTag = true;

                id3.Save();
            }
            catch (Exception ex)
            {
                op.AddException(ex);
            }
        }
示例#7
0
        private void btnGetMusicInfo_Click(object sender, EventArgs e)
        {
            if (!Path.GetExtension(ddtbMp3File.ItemText).ToLower().EndsWith(".mp3"))
            {
                MessageBox.Show("Please enter a valid MP3 file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            if (dddtbGetRootDir.ItemText.Trim().Length < 1)
            {
                MessageBox.Show("You must choose a music root folder!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            OperationResult op = new OperationResult();

            string mscRtDir     = dddtbGetRootDir.ItemText;
            string fileNamePath = ddtbMp3File.ItemText;

            try
            {
                MP3FileDataType me = ckbUseDirForInfo.Checked ? BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(fileNamePath, mscRtDir, ref op)
                    : BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(fileNamePath, ref op);

                if (!op.Success)
                {
                    MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                tbCalcTrack.Text = me.Track != null?me.Track.ToString() : string.Empty;

                tbCalcTitle.Text   = me.SongTitleAndNumeration ?? string.Empty;
                tbCalcArtists.Text = me.ArtistsStrList ?? string.Empty;
                tbCalcAlbum.Text   = me.Album ?? string.Empty;
                tbcalcComment.Text = me.Comments ?? string.Empty;
                tbCalcGenre.Text   = me.Genre ?? string.Empty;
            }
            catch (Exception ex)
            {
                op.AddException(ex);

                MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#8
0
        public void InsertMP3s(List <string> mp3List, string mp3RtDir, bool useFolderInfo, ref OperationResult op)
        {
            try
            {
                int cnt = 0;

                foreach (string mp3Item in mp3List)
                {
                    cnt++;
                    if (onCountChange != null)
                    {
                        onCountChange(cnt);
                    }

                    OperationResult _op = new OperationResult();
                    MP3FileDataType mp3 = useFolderInfo ?
                                          BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(mp3Item, mp3RtDir, ref _op)
                        : BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(mp3Item, ref _op);

                    if (!_op.Success)
                    {
                        op.AddOperationResult(ref _op);
                        continue;
                    }


                    InsertMP3(mp3, ref _op);

                    if (!_op.Success)
                    {
                        op.AddOperationResult(ref _op);
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                op.AddException(ex);
            }
        }
示例#9
0
        private void btnPopWithNameInfo_Click(object sender, EventArgs e)
        {
            OperationResult op = new OperationResult();

            if (!Path.GetExtension(ddtbMp3File.ItemText).ToLower().EndsWith(".mp3"))
            {
                MessageBox.Show("Please enter a valid MP3 file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MP3FileDataType me = ckbUseDirForInfo.Checked ? BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(ddtbMp3File.ItemText,
                                                                                                                       dddtbGetRootDir.ItemText, ref op) : BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(ddtbMp3File.ItemText, ref op);

            if (!op.Success)
            {
                MessageBox.Show(op.GetAllMessages("\n"), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            tbTrack3v1.Text = me.Track != null?me.Track.ToString() : string.Empty;

            tbTitle3v1.Text   = me.SongTitleAndNumeration ?? string.Empty;
            tbArtist3v1.Text  = me.ArtistsStrList ?? string.Empty;
            tbAlbum3v1.Text   = me.Album ?? string.Empty;
            tbComment3v1.Text = me.Comments ?? string.Empty;
            string genre = me.Genre ?? string.Empty;

            genre = string.IsNullOrEmpty(genre) || !BCHMP3Utilities.GetGenre().Contains(genre.Trim(),
                                                                                        StringComparer.CurrentCultureIgnoreCase) ? "150" : genre;
            cbGenre3v1.Genre = genre;

            tbTrack3v2.Text = me.Track != null?me.Track.ToString() : string.Empty;

            tbTitle3v2.Text   = me.SongTitleAndNumeration ?? string.Empty;
            tbArtist3v2.Text  = me.ArtistsStrList ?? string.Empty;
            tbAlbum3v2.Text   = me.Album ?? string.Empty;
            tbComment3v2.Text = me.Comments ?? string.Empty;
            cbGenre3v2.Genre  = me.Genre ?? string.Empty;
        }
示例#10
0
        private void InsertMP3s(List <string> mp3List, ref OperationResult op)
        {
            try
            {
                int cnt = 0;

                foreach (string mp3Item in mp3List)
                {
                    cnt++;
                    SetCount(cnt);

                    OperationResult _op = new OperationResult();
                    if (!mp3Item.EndsWith(".mp3"))
                    {
                        continue;
                    }
                    MP3FileDataType mp3 = BCHMP3Utilities.UseFileTagsToGetInfo(mp3Item, ref _op);

                    if (!_op.Success)
                    {
                        op.AddOperationResult(ref _op);
                        return;
                    }

                    _mp3Repository.InsertMp3(mp3, ref op);

                    if (!_op.Success)
                    {
                        op.AddOperationResult(ref _op);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                op.AddException(ex);
            }
        }
示例#11
0
        private void InsertMP3s(List <string> mp3List, string mp3RtDir, bool useFolderInfo, ref OperationResult op)
        {
            try
            {
                int cnt = 0;

                foreach (string mp3Item in mp3List)
                {
                    cnt++;
                    SetCount(cnt);

                    OperationResult _op = new OperationResult();
                    MP3FileDataType mp3 = useFolderInfo ?
                                          BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmtWithDirInfo(mp3Item, mp3RtDir, ref _op)
                        : BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(mp3Item, ref _op);

                    if (!_op.Success)
                    {
                        op.AddOperationResult(ref _op);
                        return;
                    }

                    _mp3Repository.InsertMp3(mp3, ref op);

                    if (!_op.Success)
                    {
                        op.AddOperationResult(ref _op);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                op.AddException(ex);
            }
        }
示例#12
0
 protected override void ConvertFileNameToMP3Info(string fileNameAndPath, ref OperationResult op)
 {
     this.MP3FileData = BCHMP3Utilities.ConvertFileNameToMP3InfoBCHFrmt(fileNameAndPath, ref op);
 }