Esempio n. 1
0
        /// <summary>
        /// 将 Json 模型转换为 MusicInfoModel
        /// </summary>
        /// <param name="jsonObject">请求返回的 JSON 对象</param>
        /// <returns>转换成功的 MusicInfo 列表,如果失败返回 NULL</returns>
        private List <MusicInfoModel> ConvertJsonModelToMusicInfoModel(NetEaseResultModel jsonObject)
        {
            if (jsonObject.code != "200")
            {
                return(null);
            }
            if (jsonObject.result == null)
            {
                return(null);
            }
            if (jsonObject.result.tracks == null)
            {
                return(null);
            }

            List <MusicInfoModel> _result = new List <MusicInfoModel>();

            foreach (var _info in jsonObject.result.tracks)
            {
                _result.Add(new MusicInfoModel()
                {
                    Song   = _info.name,
                    Artist = _info.artists[0].name,
                    Album  = _info.album.name
                });
            }

            return(_result);
        }
Esempio n. 2
0
        /// <summary>
        /// 获得歌词列表当中首位歌曲JSON对象
        /// </summary>
        /// <param name="postParam">提交访问的参数</param>
        /// <returns>返回的JSON对象</returns>
        private (string, string) GetLyricJsonObject(object postParam)
        {
            NetEaseResultModel _result = _httpClient.Post <NetEaseResultModel>(@"http://music.163.com/api/search/get/web", postParam, @"http://music.163.com", "application/x-www-form-urlencoded");

            if (_result == null)
            {
                throw new ServiceUnavailableException("在getLyricJsonObject当中无法获得请求的资源,_result");
            }
            if (_result?.result.songCount == 0)
            {
                m_FaildCount++;
                throw new NotFoundLyricException("歌曲未搜索到任何结果,无法获取SID.");
            }

            // 请求歌词JSON数据
            NetEaseLyricModel _lyric = _httpClient.Get <NetEaseLyricModel>(@"http://music.163.com/api/song/lyric", new NetEaseLyricRequestModel(_result.result.songs[0].id), @"http://music.163.com");

            if (_lyric == null)
            {
                throw new ServiceUnavailableException("服务限制");
            }
            if (_lyric?.lrc == null)
            {
                throw new NotFoundLyricException("歌曲不存在歌词数据.");
            }
            return(_lyric.lrc.lyric, _lyric.tlyric.lyric);
        }
Esempio n. 3
0
        private async void _button_Click(object sender, System.EventArgs e)
        {
            GlobalContext.Instance.UIContext.DisableTopButtons();
            ClearAllContainer();

            var id = GetMusicDetailId();

            if (string.IsNullOrEmpty(id))
            {
                GlobalContext.Instance.UIContext.EnableTopButtons();
                return;
            }

            try
            {
                NetEaseResultModel    jsonModel = RequestNetEase(id);
                List <MusicInfoModel> infos     = ConvertJsonModelToMusicInfoModel(jsonModel);
                await FillListView(infos);

                GlobalContext.Instance.MusicInfos.AddRange(infos);
                GlobalContext.Instance.UIContext.EnableTopButtons();
            }
            catch (ProxyException)
            {
                MessageBox.Show("代理服务器无法正常访问。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        private async void _button_Click(object sender, System.EventArgs e)
        {
            GlobalContext.Instance.UIContext.DisableTopButtons();
            ClearAllContainer();

            int _id = GetMusicDetailId();

            if (_id == 0)
            {
                GlobalContext.Instance.UIContext.EnableTopButtons();
                return;
            }
            NetEaseResultModel    _jsonModel = RequestNetEase(_id);
            List <MusicInfoModel> _infos     = ConvertJsonModelToMusicInfoModel(_jsonModel);

            await FillListView(_infos);

            GlobalContext.Instance.MusicInfos.AddRange(_infos);
            GlobalContext.Instance.UIContext.EnableTopButtons();
        }