Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 对网易云 API 发起请求,获取歌单信息
        /// </summary>
        /// <param name="id">歌单 ID</param>
        private NetEaseResultModel RequestNetEase(int id)
        {
            var _jsonResult = _httpClient.Get("http://music.163.com/api/playlist/detail", new
            {
                id,
                offset     = 0,
                total      = true,
                limit      = 1000,
                n          = 1000,
                csrf_token = string.Empty
            }, "http://music.163.com");

            return(JsonConvert.DeserializeObject <NetEaseResultModel>(_jsonResult));
        }