Esempio n. 1
0
 /// <summary>
 /// 创建音乐获取URL
 /// </summary>
 /// <param name="info">音乐搜索信息</param>
 /// <returns>URL</returns>
 public string CreateMusicUrl(SearchMusicInfo info)
 {
     try
     {
         string baiduQuickUrl = "http://box.zhangmen.baidu.com/x?op=12&count=1&title={0}$${1}$$$$";
         return string.Format(baiduQuickUrl, new object[] { info.MusicName, info.SingerName });
     }
     catch
     {
         return string.Empty;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 创建音乐获取URL
 /// </summary>
 /// <param name="info">音乐搜索信息</param>
 /// <returns>URL</returns>
 public string CreateMusicUrl(SearchMusicInfo info)
 {
     try
     {
         string baiduUrl = "http://mp3.baidu.com/m?f=ms&rf=idx&tn=baidump3&ct=134217728&lf=&rn=&word={0}&lm={1}";
         return string.Format(baiduUrl, new object[] { info.MusicName + CommonSymbol.SYMBOL_SPACE + info.SingerName, info.MusicFormat.ToString("D") });
     }
     catch
     {
         return string.Empty;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 创建所有歌词获取地址
 /// </summary>
 /// <param name="info">歌词搜索信息</param>
 /// <returns></returns>
 public string CreateAllLrcUrl(SearchMusicInfo info)
 {
     try
     {
         //千千静听歌词搜索列表地址
         string TTLrcUrl = "http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?sh?Artist={0}&Title={1}";
         return string.Format(TTLrcUrl, new object[] { EncodeConverter.ToHexString(info.SingerName), EncodeConverter.ToHexString(info.MusicName) });
     }
     catch(Exception ex)
     {
         Console.WriteLine(ex.StackTrace.ToString());
         return string.Empty;
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 创建音乐获取URL
 /// </summary>
 /// <param name="info">音乐搜索信息</param>
 /// <returns>URL</returns>
 public string CreateMusicUrl(SearchMusicInfo info)
 {
     try
     {
         int ntype = 0;//ALL
         switch (info.MusicFormat)
         {
             case SearchMusicFormat.MP3:
                 ntype = 1;
                 break;
             case SearchMusicFormat.WMA:
                 ntype = 2;
                 break;
         }
         string sosoUrl = "http://cgi.music.soso.com/fcgi-bin/m.q?w={0}&p=1&t={1}";
         return string.Format(sosoUrl, new object[] { info.MusicName + CommonSymbol.SYMBOL_SPACE + info.SingerName, ntype.ToString() });
     }
     catch
     {
         return string.Empty;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 搜索歌词列表方法
 /// </summary>
 /// <param name="info">搜索信息</param>
 /// <returns>歌词列表</returns>
 public List<MusicLrcInfo> SearchL(SearchMusicInfo info)
 {
     Crawler crawler = new Crawler();
     List<MusicLrcInfo> lstMusic = new List<MusicLrcInfo>();
     foreach (var item in mcc.LRCSearcher)
     {
         //根据加载的插件所提供的方法,获取歌词信息
         lstMusic.AddRange(crawler.GetMusicLrcList(info, item));
     }
     return lstMusic;
 }
Esempio n. 6
0
        /// <summary>
        /// 搜索歌曲方法
        /// </summary>
        /// <param name="info">搜索信息</param>
        /// <returns>歌曲列表</returns>
        public List<MusicInfo> SearchM(SearchMusicInfo info)
        {
            Crawler crawler = new Crawler();
            List<MusicInfo> lstMusic = new List<MusicInfo>();

            // 遍历插件,搜索音乐
            foreach (var item in mcc.MusicSearcher)
            {
                //根据加载的插件所提供的方法,获取音乐信息
                lstMusic.AddRange(crawler.GetMusicList(info, item.Value));
            }
            MusicDistinctHelper.Distinct(ref lstMusic);
            //TODO:在各自的插件中过滤MusicFormat后,在这里是否最终输出也过滤一次
            return lstMusic;
        }
Esempio n. 7
0
        /// <summary>
        /// 搜索歌曲
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Thread searchThread = new Thread(
                    delegate()
                    {
                        SearchMusicInfo info = new SearchMusicInfo() { MusicName = EncodeConverter.UrlEncode(textBox1.Text.Trim()), MusicFormat = SearchMusicFormat.MP3 };
                        var list = Finder.SearchM(info);
                        info.MusicName = textBox1.Text;
                        var lstlrc = Finder.SearchL(info);

                        //多线程使用UI控件
                        this.Invoke(new Action<List<MusicInfo>, List<MusicLrcInfo>>(DataBind), new object[] { list, lstlrc });
                    });
                searchThread.IsBackground = true;
                searchThread.Start();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
        /// <summary>
        /// 获取音乐信息列表
        /// </summary>
        /// <param name="info">歌曲信息的实体类</param>
        /// <param name="objSearch">外部对象</param>
        /// <returns>音乐列表</returns>
        public List<MusicInfo> GetMusicList(SearchMusicInfo info,IMusicSearch objSearch)
        {
            List<MusicInfo> _musicList = new List<MusicInfo>();

            string _pageHTML;
            int tryCount = 0;   // 已重试次数
            int outTimeTry = 1; // 超时重试

            // 重复请求页面,如果成功则跳出,失败则根据重试次数重新请求
            while (true)
            {
                // 请求页面
                NetworkRequest nwr = new NetworkRequest ();
                PageRequestResults result = nwr.RequestPage(out _pageHTML, objSearch.CreateMusicUrl(info), objSearch.PageEncode());
                if (result == PageRequestResults.Success)
                {
                    // 如果请求成功,分析页面
                    _musicList = objSearch.PageAnalysis(_pageHTML);
                    break;
                }
                else if (result == PageRequestResults.TimeOut)
                {
                    // 超时时自动重试一次
                    if (outTimeTry > 0)
                    {
                        outTimeTry--;
                        continue;
                    }

                    // 根据重试次数重发
                    if (tryCount < SearchConfig.TIME_OUT)
                    {
                        tryCount++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (result == PageRequestResults.ReceiveFailure || result == PageRequestResults.SendFailure)
                {
                    // 如果发送或接受失败 ,根据重试次数重发
                    if (tryCount < SearchConfig.TIME_OUT)
                    {
                        tryCount++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (result == PageRequestResults.ConnectFailure)
                {
                    // 如果连接失败,不重发
                    break;
                }
                else
                {
                    // 其他情况也不重发
                    break;
                }
            }
            return _musicList;
        }