Ejemplo n.º 1
0
        public void SaveTag(MusicInfoModel info, byte[] imgBytes, string lyric)
        {
            try
            {
                TagLib.File _info = TagLib.File.Create(info.Path);
                _info.Tag.Title         = info.SongName;
                _info.Tag.Performers[0] = info.Artist;
                _info.Tag.Album         = info.Album;

                if (imgBytes != null)
                {
                    // 将专辑图像数据添加进Mp3文件当中
                    var _picList = new List <TagLib.Picture>();
                    _picList.Add(new TagLib.Picture(new TagLib.ByteVector(imgBytes)));
                    _info.Tag.Pictures = _picList.ToArray();
                }

                if (!string.IsNullOrEmpty(lyric))
                {
                    _info.Tag.Lyrics = lyric;
                }

                _info.Save();
            }
            catch { }
        }
Ejemplo n.º 2
0
        public bool SaveMusicInfo(string filePath, MusicInfoModel musicInfo, out Exception E)
        {
            E = null;
            if (musicInfo == null)
            {
                return(false);
            }

            try
            {
                TagFile _file = TagFile.Create(filePath);

                _file.Tag.Title         = musicInfo.Song;
                _file.Tag.Performers[0] = musicInfo.Artist;
                _file.Tag.Album         = musicInfo.Album;

                _file.Save();

                return(true);
            }
            catch (Exception InnerE)
            {
                E = InnerE;
                return(false);
            }
        }
Ejemplo n.º 3
0
        public async Task <List <MusicInfoModel> > GetMusicInfosAsync(Dictionary <string, List <string> > musicFiles)
        {
            return(await Task.Run(() =>
            {
                ConcurrentDictionary <int, string> files = new ConcurrentDictionary <int, string>();
                int index = 0;
                foreach (var key in musicFiles)
                {
                    foreach (var _file in musicFiles[key.Key])
                    {
                        files.TryAdd(index, _file);
                        index++;
                    }
                }

                ConcurrentBag <MusicInfoModel> reuslt = new ConcurrentBag <MusicInfoModel>();

                Parallel.For(0, files.Count, (_index) =>
                {
                    MusicInfoModel info = GetMusicInfo(files[_index]);
                    info.Index = _index;
                    reuslt.Add(info);
                });

                return reuslt.ToList();
            }));
        }
Ejemplo n.º 4
0
 private void listView_MusicInfos_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listView_MusicInfos.SelectedItems.Count > 0)
     {
         var _tmpDic = new Dictionary <int, MusicInfoModel>();
         foreach (ListViewItem item in listView_MusicInfos.SelectedItems)
         {
             var _query = GlobalMember.AllMusics.Where(x => x.Key == item.Index).SingleOrDefault();
             _tmpDic.Add(_query.Key, _query.Value);
             // 获得第一个选中的ListItem作为专辑信息显示
             int _selectCount = item.Index;
             #region > 加载歌曲信息 <
             MusicInfoModel _info = GlobalMember.AllMusics[_selectCount];
             textBox_Aritst.Text     = _info.Artist;
             textBox_MusicTitle.Text = _info.SongName;
             textBox_Album.Text      = _info.Album;
             Stream _imgStream = GlobalMember.MusicTagPluginsManager.Plugins[0].LoadAlbumImg(_info.Path);
             if (_imgStream != null)
             {
                 pictureBox_AlbumImage.Image = Image.FromStream(_imgStream);
             }
             else
             {
                 pictureBox_AlbumImage.Image = null;
             }
             if (_info.IsBuildInLyric)
             {
                 textBox_Lryic.Text = GlobalMember.MusicTagPluginsManager.Plugins[0].LoadLyricText(_info.Path);
             }
             #endregion
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加一个歌曲信息到全局容器
 /// </summary>
 /// <param name="infos">歌曲信息</param>
 public void InsertMusicInfo(MusicInfoModel info)
 {
     lock (MusicInfos)
     {
         int _lastIndex = MusicInfos.Count == 0 ? 0 : MusicInfos[MusicInfos.Count - 1].Index;
         info.Status = MusicInfoEnum.Ready;
         info.Index  = _lastIndex++;
         MusicInfos.Add(info);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 向 CenterListView 当中添加条目
 /// </summary>
 /// <param name="info">要添加的音乐信息</param>
 public void InsertItemToCenterListView(MusicInfoModel info)
 {
     UIContext.Center_ListViewNF_MusicList.Items.Insert(info.Index, new ListViewItem(new string[]
     {
         info.Song,
         info.Artist,
         info.Album,
         info.TagType,
         "等待下载"
     }));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 一个安全添加歌曲信息的方法,并且填充 UI
 /// </summary>
 /// <param name="infos">需要添加的歌曲信息</param>
 public void InsertMusicInfoAndFillListView(MusicInfoModel info)
 {
     lock (MusicInfos)
     {
         int _lastIndex = MusicInfos.Count == 0 ? 0 : MusicInfos[MusicInfos.Count - 1].Index;
         info.Status = MusicInfoEnum.Ready;
         info.Index  = _lastIndex++;
         MusicInfos.Add(info);
         InsertItemToCenterListView(info);
     }
 }
Ejemplo n.º 8
0
        public MusicInfoModel GetMusicInfo(string filePath)
        {
            MusicInfoModel info     = new MusicInfoModel();
            string         fileName = Path.GetFileNameWithoutExtension(filePath);

            try
            {
                var _file = TagFile.Create(filePath);
                info.Song   = _file.Tag.Title;
                info.Artist = _file.Tag.FirstPerformer;
                if (!string.IsNullOrEmpty(_file.Tag.FirstAlbumArtist))
                {
                    info.Artist = _file.Tag.FirstAlbumArtist;
                }
                info.Album = _file.Tag.Album;

                if (string.IsNullOrEmpty(info.Song))
                {
                    info.Song = fileName;
                }
                if (string.IsNullOrEmpty(info.Artist))
                {
                    info.Artist = fileName;
                }

                info.TagType        = string.Join(@"/", _file.TagTypes);
                info.IsAlbumImg     = _file.Tag.Pictures.Length > 0 ? true : false;
                info.IsBuildInLyric = string.IsNullOrEmpty(_file.Tag.Lyrics);
                if (info.IsBuildInLyric)
                {
                    info.BuildInLyric = _file.Tag.Lyrics;
                }
            }
            catch (Exception)
            {
                info.Song           = fileName;
                info.Artist         = fileName;
                info.TagType        = "无";
                info.IsAlbumImg     = false;
                info.IsBuildInLyric = false;
            }
            finally
            {
                info.Extensions = Path.GetExtension(filePath);
                info.FilePath   = filePath;
            }

            return(info);
        }
Ejemplo n.º 9
0
        private void listView_LyricList_DragOver(object sender, DragEventArgs e)
        {
            var _path = ((string[])e.Data.GetData(DataFormats.FileDrop));

            if (_path.Length > 0)
            {
                MusicInfoModel _model = new MusicInfoModel
                {
                    Path = _path[0],
                };
                m_resourceModel.MusicTagUtils.LoadTag(_model.Path, _model);
                textBox_Artist.Text   = _model.Artist;
                textBox_SongName.Text = _model.SongName;
                button_Search_Click(sender, e);
            }
        }
Ejemplo n.º 10
0
        public bool DownlaodAblumImage(MusicInfoModel info, out byte[] imageData)
        {
            imageData = null;

            var _songModel = GetMusicInfoByNetease(info.Artist, info.Song);

            if (_songModel.id == 0)
            {
                return(false);
            }

            string _albumImg = GetAblumImageUrl(_songModel.id);

            imageData = new WebClient().DownloadData(_albumImg);
            return(true);
        }
Ejemplo n.º 11
0
        private string SavePath(MusicInfoModel info)
        {
            if (string.IsNullOrEmpty(info.FilePath))
            {
                string lyricsPath = Environment.CurrentDirectory + "\\Lyrics";
                if (!Directory.Exists(lyricsPath))
                {
                    Directory.CreateDirectory(lyricsPath);
                }
                return($"{lyricsPath}\\{info.Song.ReplaceBadCharOfFileName()}-{info.Artist.ReplaceBadCharOfFileName()}.lrc");
            }

            string fileName = Path.GetFileNameWithoutExtension(info.FilePath);

            return($"{Path.GetDirectoryName(info.FilePath)}\\{fileName}.lrc");
        }
Ejemplo n.º 12
0
        public void LoadTag(string path, MusicInfoModel info)
        {
            string _songName = null;
            string _artist   = null;
            string _fileName = Path.GetFileNameWithoutExtension(path);

            try
            {
                TagLib.File _info = TagLib.File.Create(path);
                _songName = _info.Tag.Title;
                _artist   = _info.Tag.FirstPerformer;
                string _album = _info.Tag.Album;

                if (string.IsNullOrEmpty(_songName))
                {
                    _songName = _fileName;
                }
                if (string.IsNullOrEmpty(_artist))
                {
                    _artist = _fileName;
                }

                info.TagType        = string.Join(",", _info.TagTypes);
                info.IsAlbumImg     = _info.Tag.Pictures.Length > 0 ? true : false;
                info.IsBuildInLyric = string.IsNullOrEmpty(_info.Tag.Lyrics);
                info.Album          = _album;
            }
            catch
            {
                if (string.IsNullOrEmpty(_songName))
                {
                    _songName = _fileName;
                }
                if (string.IsNullOrEmpty(_artist))
                {
                    _artist = string.Empty;
                }
                info.TagType        = "无";
                info.IsAlbumImg     = false;
                info.IsBuildInLyric = false;
                info.Album          = "无";
            }

            info.Artist   = _artist;
            info.SongName = _songName;
        }
Ejemplo n.º 13
0
 public void Init(MusicInfoModel musicInfo, string genre)
 {
     musicNameText.SetText(musicInfo.musicName);
     artistNameText.SetText(musicInfo.artistName);
     coverImage.sprite = musicInfo.coverImage;
     if (musicInfo.difficult < 10)
     {
         difficultText.text += "<size=30><color=blue>" + musicInfo.difficult.ToString() + "</color></size> / 12";
     }
     else
     {
         difficultText.text += "<size=30><color=red>" + musicInfo.difficult.ToString() + "</color></size> / 12";
     }
     Debug.Log(difficultText.text);
     gameObject.name = musicInfo.musicName;
     GetComponent <MusicLoader>().SetGenre(genre);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 快捷键检测
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="keyData"></param>
 /// <returns></returns>
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
     if (listView_MusicInfos.SelectedItems.Count != 0)
     {
         if (keyData == (Keys.Control | Keys.S))
         {
             int            _selectCount = listView_MusicInfos.Items.IndexOf(listView_MusicInfos.FocusedItem);
             MusicInfoModel _info        = GlobalMember.AllMusics[_selectCount];
             _info.Artist   = textBox_Aritst.Text;
             _info.SongName = textBox_MusicTitle.Text;
             _info.Album    = textBox_Album.Text;
             GlobalMember.MusicTagPluginsManager.Plugins[0].SaveTag(_info, null, textBox_Lryic.Text);
             MessageBox.Show("已经保存歌曲标签信息!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     return(false);
 }
Ejemplo n.º 15
0
        public List <MusicInfoModel> GetMusicInfos(Dictionary <string, List <string> > musicFiles)
        {
            List <MusicInfoModel> result = new List <MusicInfoModel>();

            int _index = 0;

            foreach (var key in musicFiles)
            {
                foreach (var file in musicFiles[key.Key])
                {
                    MusicInfoModel info = GetMusicInfo(file);
                    info.Index = _index;
                    result.Add(info);
                    _index++;
                }
            }

            return(result);
        }
Ejemplo n.º 16
0
        public void HandleEvent(SingleMusicInfoLoadEventData eventData)
        {
            ListViewNF listView = GlobalContext.Instance.UIContext.Center_ListViewNF_MusicList;

            int selectIndex = listView.SelectedItems[0].Index;

            IPluginAcquireMusicInfo acquire = _plugManager.GetPlugin <IPluginAcquireMusicInfo>();
            MusicInfoModel          info    = GlobalContext.Instance.MusicInfos[selectIndex];
            Stream imgStream = acquire.LoadAlbumImage(info.FilePath);

            // 填充歌曲信息到 UI
            if (imgStream != null)
            {
                GlobalContext.Instance.UIContext.Right_PictureBox_AlbumImage.Image = Image.FromStream(imgStream);
            }
            GlobalContext.Instance.UIContext.Right_TextBox_MusicTitle.Text        = info.Song;
            GlobalContext.Instance.UIContext.Right_TextBox_MusicArtist.Text       = info.Artist;
            GlobalContext.Instance.UIContext.Right_TextBox_MusicAblum.Text        = info.Album;
            GlobalContext.Instance.UIContext.Right_TextBox_MusicBuildInLyric.Text = info.BuildInLyric;
        }
Ejemplo n.º 17
0
        public bool DownlaodAblumImage(MusicInfoModel info, out byte[] imageData)
        {
            imageData = null;

            var songModel = GetMusicInfoByNetease(info.Artist, info.Song);

            if (songModel.id == 0)
            {
                return(false);
            }

            string albumImg = GetAblumImageUrl(songModel.id);

            if (albumImg == null)
            {
                throw new ServiceUnavailableException("专辑图像下载:没有找到图像的 Url 地址.");
            }

            imageData = new WebClient().DownloadData(albumImg);
            return(true);
        }