コード例 #1
0
        public void InsertMP3(MP3FileDataType mp3, ref OperationResult op)
        {
            if (this.DataStore == null)
            {
                op.AddError("DataStore not set!");
                return;
            }

            InsertMP3FileInfo(mp3, ref op);

            if (!op.Success)
            {
                return;
            }

            InsertMP3Info(mp3, ref op);

            if (!op.Success)
            {
                return;
            }

            InsertMP3Artists(mp3, ref op);

            if (!op.Success)
            {
                return;
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void InsertMp3(MP3FileDataType mP3FileDataType, ref OperationResult op)
        {
            if (!mP3FileDataType.FileName.EndsWith("mp3", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }
            using (DbContextTransaction transaction = _mp3Context.Database.BeginTransaction())
            {
                try
                {
                    var tbFileInfo = new tbFileInfo
                    {
                        File_Name = mP3FileDataType.FileName,
                        Path      = mP3FileDataType.FilePath
                    };
                    _mp3Context.FileInfo.Add(tbFileInfo);
                    _mp3Context.SaveChanges();
                    var fiId = tbFileInfo.FileInfo_Id;

                    tbMp3Info tbMp3Info = new tbMp3Info
                    {
                        Album          = mP3FileDataType.Album,
                        Comments       = mP3FileDataType.Comments,
                        FileInfo_Id    = fiId,
                        Genre          = mP3FileDataType.Genre,
                        Song_Numeraton = mP3FileDataType.SongNumeration,
                        Song_Title     = mP3FileDataType.SongTitle,
                        Track          = mP3FileDataType.Track
                    };
                    _mp3Context.Mp3Info.Add(tbMp3Info);
                    _mp3Context.SaveChanges();
                    var miId = tbMp3Info.Mp3Info_Id;

                    foreach (var artist in mP3FileDataType.Artists)
                    {
                        tbArtist tbArtist = new tbArtist
                        {
                            Artist_Name = artist,
                            Mp3Info_Id  = miId
                        };
                        _mp3Context.Artist.Add(tbArtist);
                        _mp3Context.SaveChanges();
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    op.AddError($"Error inserting mp3 file: {mP3FileDataType.FilePath}");
                    op.AddException(ex);
                }
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
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>();
        }
コード例 #6
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 + "; ";
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
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;
            }
        }
コード例 #9
0
        public void InsertMP3FileInfo(MP3FileDataType mp3, ref OperationResult op)
        {
            if (this.DataStore == null)
            {
                op.AddError("DataStore not set!");
                return;
            }

            SetConnection(ref op);

            if (!op.Success)
            {
                return;
            }

            DataStore ds = this.DataStore;

            Dictionary <string, string> parms = new Dictionary <string, string>();

            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetFileInfo_File), mp3.FileName);
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetFileInfo_Path), mp3.FilePath);

            DataTable dt = ds.ExecuteSql(ds.Conn, SqlScriptEnum.GetFileInfo, parms, ref op);

            if (!op.Success)
            {
                return;
            }

            if (dt.Rows.Count > 0)
            {
                op.AddError(mp3.FileNamePath + " mp3 already exists!");
                return;
            }

            parms = new Dictionary <string, string>();
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertFileInfo_File), mp3.FileName);
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertFileInfo_Path), mp3.FilePath);

            ds.ExecuteSql(ds.Conn, SqlScriptEnum.InsertFileInfo, parms, ref op);
            if (!op.Success)
            {
                return;
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
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;
        }
コード例 #12
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);
            }
        }
コード例 #13
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);
            }
        }
コード例 #14
0
        public void InsertMP3Artists(MP3FileDataType mp3, ref OperationResult op)
        {
            if (this.DataStore == null)
            {
                op.AddError("DataStore not set!");
                return;
            }

            DataStore ds = this.DataStore;

            Dictionary <string, string> parms = new Dictionary <string, string>();

            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetFileInfo_File), mp3.FileName);
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetFileInfo_Path), mp3.FilePath);

            DataTable dt = ds.ExecuteSql(ds.Conn, SqlScriptEnum.GetFileInfo, parms, ref op);

            if (!op.Success)
            {
                return;
            }

            if (dt.Rows.Count < 1)
            {
                op.AddError(mp3.FileNamePath + " mp3 file info does not exists!");
                return;
            }

            parms = new Dictionary <string, string>();
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetMP3byFilePath_File), mp3.FileName);
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetMP3byFilePath_Path), mp3.FilePath);

            dt = ds.ExecuteSql(ds.Conn, SqlScriptEnum.GetMP3byFilePath, parms, ref op);
            if (!op.Success)
            {
                return;
            }

            if (dt.Rows.Count < 1)
            {
                op.AddError(mp3.FileNamePath + " mp3 info not exists!");
                return;
            }

            int?mid = BCHUtilities.GetInteger(dt.Rows[0]["Mp3Info_Id"].ToString());

            foreach (string artist in mp3.Artists)
            {
                parms = new Dictionary <string, string>();
                parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetArtist_File), mp3.FileName);
                parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetArtist_Path), mp3.FilePath);
                parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetArtist_Artist), artist.Trim());

                dt = ds.ExecuteSql(ds.Conn, SqlScriptEnum.GetArtist, parms, ref op);
                if (!op.Success)
                {
                    return;
                }

                if (dt.Rows.Count > 0)
                {
                    op.AddError(mp3.FileNamePath + ", Artist: " + artist + " mp3 already exists!");
                    break;
                }

                parms = new Dictionary <string, string>();
                parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertArtist_Mp3Info_Id), mid.ToString());
                parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertArtist_Artist), string.IsNullOrEmpty(artist.Trim()) ? null : artist.Trim());

                ds.ExecuteSql(ds.Conn, SqlScriptEnum.InsertArtist, parms, ref op);
                if (!op.Success)
                {
                    return;
                }
            }
        }
コード例 #15
0
        public void InsertMP3Info(MP3FileDataType mp3, ref OperationResult op)
        {
            if (this.DataStore == null)
            {
                op.AddError("DataStore not set!");
                return;
            }

            SetConnection(ref op);

            if (!op.Success)
            {
                return;
            }

            DataStore ds = this.DataStore;

            Dictionary <string, string> parms = new Dictionary <string, string>();

            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetFileInfo_File), mp3.FileName);
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetFileInfo_Path), mp3.FilePath);

            DataTable dt = ds.ExecuteSql(ds.Conn, SqlScriptEnum.GetFileInfo, parms, ref op);

            if (!op.Success)
            {
                return;
            }

            if (dt.Rows.Count < 1)
            {
                op.AddError(mp3.FileNamePath + " mp3 file info does not exists!");
                return;
            }

            int?fid = BCHUtilities.GetInteger(dt.Rows[0]["FileInfo_Id"].ToString());

            parms = new Dictionary <string, string>();
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetMP3byFilePath_File), mp3.FileName);
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.GetMP3byFilePath_Path), mp3.FilePath);

            dt = ds.ExecuteSql(ds.Conn, SqlScriptEnum.GetMP3byFilePath, parms, ref op);
            if (!op.Success)
            {
                return;
            }

            if (dt.Rows.Count > 0)
            {
                op.AddError(mp3.FileNamePath + " mp3 already exists!");
                return;
            }


            parms = new Dictionary <string, string>();
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_Album), string.IsNullOrEmpty(mp3.Album) ? null : mp3.Album.Trim());
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_Comments), string.IsNullOrEmpty(mp3.Comments) ? null : mp3.Comments.Trim());
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_FileInfo_Id), fid.ToString());
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_Genre), string.IsNullOrEmpty(mp3.Genre) ? null : mp3.Genre.Trim());
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_Song_Numeraton), string.IsNullOrEmpty(mp3.SongNumeration) ? null : mp3.SongNumeration.Trim());
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_Song_Tile), string.IsNullOrEmpty(mp3.SongTitle) ? null : mp3.SongTitle.Trim());
            parms.Add(ds.GetSqlScriptParam(SqlParamScriptEnum.InsertMP3_Track), mp3.Track == null ? null : mp3.Track.ToString());

            ds.ExecuteSql(ds.Conn, SqlScriptEnum.InsertMP3, parms, ref op);
            if (!op.Success)
            {
                return;
            }
        }