Beispiel #1
0
        private SongVO RequestSongVO(long songId, out string errorMsg)
        {
            SongUrls     songUrls     = api.GetSongsUrl(new long[] { songId });
            DetailResult detailResult = api.GetDetail(songId);

            return(NeteaseMusicUtils.GetSongVO(songUrls, detailResult, out errorMsg));
        }
Beispiel #2
0
        // 批量歌曲搜索
        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());
        }
Beispiel #3
0
        // 批量保存
        private void BatchSave()
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            try
            {
                saveDialog.FileName = "直接选择保存路径即可,无需修改此处内容";
                saveDialog.Filter   = "lrc文件(*.lrc)|*.lrc|txt文件(*.txt)|*.txt";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    string localFilePath = saveDialog.FileName.ToString();
                    // 获取文件后缀
                    string fileSuffix = localFilePath.Substring(localFilePath.LastIndexOf("."));
                    //获取文件路径,不带文件名
                    string filePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));

                    foreach (var item in globalSaveVOMap)
                    {
                        string       outputFileName = NeteaseMusicUtils.GetOutputName(item.Value.songVO, globalSearchInfo);
                        string       path           = filePath + "/" + NeteaseMusicUtils.GetSafeFilename(outputFileName) + fileSuffix;
                        StreamWriter sw             = new StreamWriter(path, false, NeteaseMusicUtils.GetEncoding(globalSearchInfo.Encoding));
                        sw.Write(NeteaseMusicUtils.GetOutputLyric(item.Value.lyricVO.Lyric, item.Value.lyricVO.TLyric, globalSearchInfo));
                        sw.Flush();
                        sw.Close();
                    }
                    MessageBox.Show(ErrorMsg.SAVE_SUCCESS, "提示");
                }
            }
            catch (Exception ew)
            {
                MessageBox.Show("批量保存失败,错误信息:\n" + ew.Message);
            }

            // 输出日志
            StringBuilder log = new StringBuilder();

            foreach (var songIdStr in globalSearchInfo.SearchIds)
            {
                if (globalSaveVOMap.ContainsKey(songIdStr))
                {
                    log.Append("ID: " + songIdStr + ", Result: success\r\n");
                }
                else
                {
                    log.Append("ID: " + songIdStr + ", Result: failure\r\n");
                }
            }
            UpdateLrcTextBox(log.ToString());
        }
Beispiel #4
0
        // 单个歌曲搜索
        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("");
        }
Beispiel #5
0
 // 更新前端歌词
 private void UpdateLrcTextBox(string replace)
 {
     if (replace != "")
     {
         textBox_lrc.Text = replace;
     }
     else
     {
         // 根据最新配置,更新输出歌词
         if (globalSaveVOMap != null && globalSaveVOMap.Count == 1)
         {
             // only loop one times
             foreach (var item in globalSaveVOMap)
             {
                 string outputLyric = NeteaseMusicUtils.GetOutputLyric(item.Value.lyricVO.Lyric, item.Value.lyricVO.TLyric, globalSearchInfo);
                 textBox_lrc.Text = outputLyric == "" ? ErrorMsg.LRC_NOT_EXIST : outputLyric;
             }
         }
     }
 }
Beispiel #6
0
        // 单个保存
        private void SingleSave(string songIdStr)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            try
            {
                SaveVO saveVO = new SaveVO();
                if (!globalSaveVOMap.TryGetValue(songIdStr, out saveVO))
                {
                    MessageBox.Show(ErrorMsg.MUST_SEARCH_BEFORE_SAVE, "提示");
                    return;
                }

                string outputFileName = NeteaseMusicUtils.GetOutputName(saveVO.songVO, globalSearchInfo);
                if (outputFileName == null)
                {
                    MessageBox.Show(ErrorMsg.FILE_NAME_IS_EMPTY, "提示");
                    return;
                }
                else
                {
                    outputFileName = NeteaseMusicUtils.GetSafeFilename(outputFileName);
                }

                saveDialog.FileName = outputFileName;
                saveDialog.Filter   = "lrc文件(*.lrc)|*.lrc|txt文件(*.txt)|*.txt";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter sw = new StreamWriter(saveDialog.FileName, false, NeteaseMusicUtils.GetEncoding(globalSearchInfo.Encoding));
                    sw.Write(textBox_lrc.Text);
                    sw.Flush();
                    sw.Close();
                    MessageBox.Show(ErrorMsg.SAVE_SUCCESS, "提示");
                }
            }
            catch (Exception ew)
            {
                MessageBox.Show("保存失败!错误信息:\n" + ew.Message);
            }
        }
Beispiel #7
0
        private LyricVO RequestLyricVO(long songId, SearchInfo searchInfo, out string errorMsg)
        {
            LyricResult lyricResult = api.GetLyric(songId);

            return(NeteaseMusicUtils.GetLyricVO(lyricResult, searchInfo, out errorMsg));
        }