// 批量歌曲搜索 private void BatchSearch(string[] ids) { Dictionary <string, string> resultMaps = new Dictionary <string, string>(); foreach (string songIdStr in ids) { // 1、参数校验 long songId = NeteaseMusicUtils.CheckInputId(songIdStr, SEARCH_TYPE_ENUM.SONG_ID, out string inputErrorMsg); if (inputErrorMsg != ErrorMsg.SUCCESS) { resultMaps.Add(songIdStr, inputErrorMsg); continue; } // 2、获取歌曲内容 SaveVO result; if (NeteaseMusicResultCache.Contains(songId)) { result = NeteaseMusicResultCache.Get(songId); } else { SongVO songVO = RequestSongVO(songId, out string songErrorMsg); if (songErrorMsg != ErrorMsg.SUCCESS) { resultMaps.Add(songIdStr, songErrorMsg); continue; } LyricVO lyricVO = RequestLyricVO(songId, globalSearchInfo, out string lyricErrorMsg); if (lyricErrorMsg != ErrorMsg.SUCCESS) { resultMaps.Add(songIdStr, lyricErrorMsg); continue; } result = new SaveVO(songIdStr, songVO, lyricVO); NeteaseMusicResultCache.Put(songId, result); } // 3、加入结果集 globalSaveVOMap.Add(songIdStr, NeteaseMusicResultCache.Get(songId)); resultMaps.Add(songIdStr, ErrorMsg.SEARCH_RESULT_STAGE); } // 输出日志 StringBuilder log = new StringBuilder(); log.Append("---Total:" + resultMaps.Count + ", Success:" + globalSaveVOMap.Count + ", Failure:" + (resultMaps.Count - globalSaveVOMap.Count) + "---\r\n"); foreach (KeyValuePair <string, string> kvp in resultMaps) { log.Append("ID: " + kvp.Key + ", Result: " + kvp.Value + "\r\n"); } UpdateLrcTextBox(log.ToString()); }
// 单个歌曲搜索 private void SingleSearchBySongId(string songIdStr) { // 1、参数校验 long songId = NeteaseMusicUtils.CheckInputId(songIdStr, SEARCH_TYPE_ENUM.SONG_ID, out string inputErrorMsg); if (inputErrorMsg != ErrorMsg.SUCCESS) { MessageBox.Show(inputErrorMsg, "提示"); return; } // 2、获取歌曲内容 SaveVO result; if (NeteaseMusicResultCache.Contains(songId)) { result = NeteaseMusicResultCache.Get(songId); } else { SongVO songVO = RequestSongVO(songId, out string songErrorMsg); if (songErrorMsg != ErrorMsg.SUCCESS) { MessageBox.Show(songErrorMsg, "提示"); return; } LyricVO lyricVO = RequestLyricVO(songId, globalSearchInfo, out string lyricErrorMsg); if (lyricErrorMsg != ErrorMsg.SUCCESS) { MessageBox.Show(lyricErrorMsg, "提示"); return; } result = new SaveVO(songIdStr, songVO, lyricVO); NeteaseMusicResultCache.Put(songId, result); } // 3、加入结果集 globalSaveVOMap.Add(songIdStr, NeteaseMusicResultCache.Get(songId)); // 4、前端设置 textBox_song.Text = result.songVO.Name; textBox_singer.Text = result.songVO.Singer; textBox_album.Text = result.songVO.Album; UpdateLrcTextBox(""); }