我正在开发一个适用于 Windows 8 的应用程序,该应用程序从博客 (wordpress RSS ) 下载内容。内容是带有标题和 youtube 链接的帖子。如何执行下载?
这个应用程序需要一个下载博客内容(帖子)的功能,该功能链接 yt 和标题(我正在尝试字典,但应用程序添加了不同的标题和链接。)
private ObservableCollection<FeedData> feeds = new ObservableCollection<FeedData>();
public ObservableCollection<FeedData> Feeds
{
get
{
return this.feeds;
}
}
public async Task GetFeedsAsync()
{
Task<FeedData> feed1 = this.GetFeedAsync("http://urlblog/?feed=rss2");
this.Feeds.Add(await feed1);
}
private async Task<FeedData> GetFeedAsync(string feedUriString)
{
SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri(feedUriString);
try
{
SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
FeedData feedData = new FeedData();
feedData.Title = feed.Title.Text;
if (feed.Subtitle != null && feed.Subtitle.Text != null)
{
feedData.Description = feed.Subtitle.Text;
}
// Use the date of the latest post as the last updated date.
feedData.PubDate = feed.Items[0].PublishedDate.DateTime;
foreach (SyndicationItem item in feed.Items)
{
FeedItem feedItem = new FeedItem();
feedItem.Title = item.Title.Text;
feedItem.PubDate = item.PublishedDate.DateTime;
feedItem.Author = item.Authors[0].Name;
if (feed.SourceFormat == SyndicationFormat.Atom10)
{
Match m = Regex.Match(
item.Summary.Text, @"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)", RegexOptions.IgnoreCase);
feedItem.Content = m.Groups[0].ToString();
feedItem.Content = m.Value;
feedItem.Link = new Uri("url" + item.Id);
}
else if (feed.SourceFormat == SyndicationFormat.Rss20)
{
Match m = Regex.Match(
item.Summary.Text, @"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");
feedItem.Content = m.Groups[1].ToString();
feedItem.Content = m.Value;
feedItem.Link = item.Links[0].Uri;
}
feedData.Items.Add(feedItem);
}
return feedData;
}
catch (Exception)
{
return null;
}
}
FeedItem.cs
public class FeedItem
{
public string Author { get; set; }
public string Content { get; set; }
public Uri Link { get; set; }
public DateTime PubDate { get; set; }
public string Title { get; set; }
}