示例#1
0
        /// <summary>
        /// 获取音乐歌词列表
        /// </summary>
        /// <param name="info">歌词信息的实体类</param>
        /// <param name="objSearch">外部对象</param>
        /// <returns>返回的歌词列表</returns>
        public List<MusicLrcInfo> GetMusicLrcList(SearchMusicInfo info, ILRCSearch objSearch)
        {
            List<MusicLrcInfo> _lstMusicLrc = new List<MusicLrcInfo>();

            string _pageHTML;
            int TryTime = 1;   // 对于歌词信息之重试一次
            int tryCount = 0;   // 已重试次数

            // 重复请求页面,如果成功则跳出,失败则根据重试次数重新请求
            while (true)
            {
                // 请求页面
                NetworkRequest nwr = new NetworkRequest();
                PageRequestResults result = nwr.RequestPage(out _pageHTML, objSearch.CreateAllLrcUrl(info), objSearch.PageEncode());
                if (result == PageRequestResults.Success)
                {
                    // 如果请求成功,分析页面
                    _lstMusicLrc = objSearch.PageAnalysis(_pageHTML);
                    break;
                }
                else
                {
                    // 如果发送或接受失败 ,根据重试次数重发
                    if (tryCount < TryTime)
                    {
                        tryCount++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return _lstMusicLrc;
        }
示例#2
0
        /// <summary>
        /// 获取音乐歌词内容
        /// </summary>
        /// <param name="info">歌词信息的实体类</param>
        /// <param name="objSearch">外部对象</param>
        /// <returns>歌词字符串</returns>
        public string GetMusicLyric(MusicLrcInfo info, ILRCSearch objSearch)
        {
            string _pageHTML;
            int TryTime = 1;
            int tryCount = 0;   // 已重试次数

            // 重复请求页面,如果成功则跳出,失败则根据重试次数重新请求
            while (true)
            {
                // 请求页面,默认芊芊静听直接返回请求的字符串
                NetworkRequest nwr = new NetworkRequest();
                PageRequestResults result = nwr.RequestPage(out _pageHTML, objSearch.CreateLrcUrl(info),objSearch.PageEncode());
                if (result == PageRequestResults.Success)
                {
                    return _pageHTML;
                }
                else
                {
                    // 如果发送或接受失败 ,根据重试次数重发
                    if (tryCount < TryTime)
                    {
                        tryCount++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return string.Empty;
        }