Пример #1
0
		/// <summary>
		/// 获取搜索的结果
		/// </summary>
		/// <returns></returns>
		private IEnumerable<ChannelSearchItem> GetSearchItems(string file)
		{
			List<ChannelSearchItem> items = new List<ChannelSearchItem>();
			try
			{
				bool isSearchFilterEnabled = true;
				Dispatcher.Invoke(new Action(() => { isSearchFilterEnabled = Settings.IsSearchFilterEnabled; }));

				//找出艺术家
				MatchCollection mc = Regex.Matches(file, @"<div class=\""result-item musician\"".*?>.*?</h3>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
				foreach(Match mm in mc)
				{
					string temp = mm.Groups[0].Value;
					string titleTemp = Regex.Match(temp, @"<a.*?class=\""nbg\"".*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
					string title = Regex.Match(titleTemp, @".*?title=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
					string link = Regex.Match(titleTemp, @".*?href=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
					string pictureTemp = Regex.Match(temp, @"<img.*?class=\""answer_pic\"".*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
					string picture = Regex.Match(pictureTemp, @".*?src=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
					Match ma = Regex.Match(temp, @".*?href=\""http://douban\.fm/\?context=([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline);
					string context = null;
					if (ma != null) context = ma.Groups[1].Value;
					ChannelSearchItem item = new ChannelSearchItem(title, picture, link, null, true, context);
					if (!isSearchFilterEnabled || !string.IsNullOrEmpty(item.Context))
						items.Add(item);
				}

				//找出专辑
                mc = Regex.Matches(file, @"<tr[^<>]*?class=\""item\""[^<>]*?>.*?</tr>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
				foreach (Match mm in mc)
				{
					string temp = mm.Groups[0].Value;
                    string titleTemp = Regex.Match(temp, @"<a[^<>]*?class=\""nbg\""[^<>]*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
                    string subject = Regex.Match(titleTemp, @"href=\""[^<>]*?subject/(\d+)", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
					string title = Regex.Match(titleTemp, @"title=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
					string link = Regex.Match(titleTemp, @"href=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    string pictureTemp = Regex.Match(temp, @"<img[^<>]*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
					string picture = Regex.Match(pictureTemp, @"src=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
					Match ma = Regex.Match(temp, @"href=\""http://douban\.fm/\?context=([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline);

					string context = null;
					if (ma.Success) context = ma.Groups[1].Value;
					if (string.IsNullOrEmpty(context))
					{
						context = MakeContext(subject);
					}
				
					ChannelSearchItem item = new ChannelSearchItem(title, picture, link, null, false, context);
					if (!isSearchFilterEnabled || !string.IsNullOrEmpty(item.Context))
						items.Add(item);
				}
			}
			catch { }

			return items;
		}
Пример #2
0
        /// <summary>
        /// 获取搜索的结果
        /// </summary>
        /// <returns></returns>
        private IEnumerable <ChannelSearchItem> GetSearchItems(string file)
        {
            List <ChannelSearchItem> items = new List <ChannelSearchItem>();

            try
            {
                bool isSearchFilterEnabled = true;
                Dispatcher.Invoke(new Action(() => { isSearchFilterEnabled = Settings.IsSearchFilterEnabled; }));

                //找出艺术家
                MatchCollection mc = Regex.Matches(file, @"<div class=\""result-item musician\"".*?>.*?</h3>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                foreach (Match mm in mc)
                {
                    string temp        = mm.Groups[0].Value;
                    string titleTemp   = Regex.Match(temp, @"<a.*?class=\""nbg\"".*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
                    string title       = Regex.Match(titleTemp, @".*?title=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    string link        = Regex.Match(titleTemp, @".*?href=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    string pictureTemp = Regex.Match(temp, @"<img.*?class=\""answer_pic\"".*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
                    string picture     = Regex.Match(pictureTemp, @".*?src=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    Match  ma          = Regex.Match(temp, @".*?href=\""http://douban\.fm/\?context=([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    string context     = null;
                    if (ma != null)
                    {
                        context = ma.Groups[1].Value;
                    }
                    ChannelSearchItem item = new ChannelSearchItem(title, picture, link, null, true, context);
                    if (!isSearchFilterEnabled || !string.IsNullOrEmpty(item.Context))
                    {
                        items.Add(item);
                    }
                }

                //找出专辑
                mc = Regex.Matches(file, @"<tr[^<>]*?class=\""item\""[^<>]*?>.*?</tr>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                foreach (Match mm in mc)
                {
                    string temp        = mm.Groups[0].Value;
                    string titleTemp   = Regex.Match(temp, @"<a[^<>]*?class=\""nbg\""[^<>]*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
                    string subject     = Regex.Match(titleTemp, @"href=\""[^<>]*?subject/(\d+)", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    string title       = Regex.Match(titleTemp, @"title=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    string link        = Regex.Match(titleTemp, @"href=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    string pictureTemp = Regex.Match(temp, @"<img[^<>]*?/?>", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[0].Value;
                    string picture     = Regex.Match(pictureTemp, @"src=\""([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[1].Value;
                    Match  ma          = Regex.Match(temp, @"href=\""http://douban\.fm/\?context=([^\""]+)\""", RegexOptions.IgnoreCase | RegexOptions.Singleline);

                    string context = null;
                    if (ma.Success)
                    {
                        context = ma.Groups[1].Value;
                    }
                    if (string.IsNullOrEmpty(context))
                    {
                        context = MakeContext(subject);
                    }

                    ChannelSearchItem item = new ChannelSearchItem(title, picture, link, null, false, context);
                    if (!isSearchFilterEnabled || !string.IsNullOrEmpty(item.Context))
                    {
                        items.Add(item);
                    }
                }
            }
            catch { }

            return(items);
        }