예제 #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);
        }
예제 #2
0
        /// <summary>
        /// 获取歌曲 SID 信息
        /// </summary>
        /// <param name="artist">艺术家</param>
        /// <param name="songName">歌曲名</param>
        private NetEaseSongModel GetMusicInfoByNetease(string artist, string songName)
        {
            string _artist    = m_netUtils.URL_Encoding(artist, Encoding.UTF8);
            string _title     = m_netUtils.URL_Encoding(songName, Encoding.UTF8);
            string _searchKey = $"{_artist}+{_title}";

            var _result = m_netUtils.Post <NetEaseResultModel>(url: @"http://music.163.com/api/search/get/web",
                                                               parameters: new NetEaseSearchRequestModel(_searchKey),
                                                               referer: "http://music.163.com",
                                                               mediaTypeValue: "application/x-www-form-urlencoded");

            return(_result.result.songs[0]);
        }
예제 #3
0
        /// <summary>
        /// 获取歌曲 SID 信息
        /// </summary>
        /// <param name="artist">艺术家</param>
        /// <param name="songName">歌曲名</param>
        private NetEaseSongModel GetMusicInfoByNetease(string artist, string songName)
        {
            string encodingAritst = _mNetUtils.URL_Encoding(artist, Encoding.UTF8);
            string encodingTitle  = _mNetUtils.URL_Encoding(songName, Encoding.UTF8);
            string searchKey      = $"{encodingAritst}+{encodingTitle}";

            var result = _mNetUtils.Post <NetEaseResultModel>(url: @"http://music.163.com/api/search/get/web",
                                                              parameters: new NetEaseSearchRequestModel(searchKey),
                                                              referer: "http://music.163.com",
                                                              mediaTypeValue: "application/x-www-form-urlencoded");

            var sidInfo = result?.result?.songs ?? throw new ServiceUnavailableException("专辑图像下载:请求 SID 时出错,没有 SID 数据.");

            if (sidInfo.Count == 0)
            {
                throw new ServiceUnavailableException("专题图像下载:请求 SID 时出错,SID 集合没有数据.");
            }

            return(result.result.songs[0]);
        }