string FollowYouTube(string videoID)
{
string url = "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&key=AI39si4LaIHfBlDmxNNRIqZjXYlDgVTmUVa7p8dSE8_bI45a9leskPQKauV7qi-qmAqjf6zjTdhwAfJxOfkxNcYOmloh8B1X9Q";
URL.WebPage page;
try
{
page = URL.FetchURL(url);
}
catch (System.Exception ex)
{
Logger.Write(ex.Message + "\n" + url, Settings.Instance.ErrorFile);
return null;
}
Match titleMatch = Regex.Match(page.Page, @"<title>([^<]+?)</title><content");
if (titleMatch.Success)
{
Match lengthMatch = Regex.Match(page.Page, @"<yt:duration seconds='([0-9]+?)'/>");
Match descriptionMatch = Regex.Match(page.Page, @"<media:description type='plain'>([^<]+?)</media:description>");
string title = HttpUtility.HtmlDecode(titleMatch.Groups[1].Value);
TimeSpan lengthSpan = TimeSpan.FromSeconds( Int32.Parse(lengthMatch.Groups[1].Value) );
string length = (lengthSpan.Hours > 0 ? lengthSpan.Hours.ToString() + ":" : String.Empty);
length += lengthSpan.Minutes.ToString("D2") + ":" + lengthSpan.Seconds.ToString("D2");
string description = URL.StripHTML( HttpUtility.HtmlDecode(descriptionMatch.Groups[1].Value) );
description = StringUtils.ReplaceNewlines(description, " ");
if (description.Length > 150)
description = description.Substring(0, 147) + "...";
return title + " | " + length + " | " + description;
}
return null;
}