如何使用链接youtube下载内容

时间:2013-03-19 15:58:34

标签: c# windows-8

我正在开发一个Windows 8应用程序,它从博客(wordpress RSS)下载内容。内容是标题和youtube的链接。我该如何进行下载?

此应用程序需要一个功能来下载博客内容(帖子),链接yt和标题(我正在尝试dictonary,但app添加不同的标题和链接。)

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; }    
}

0 个答案:

没有答案