public void TestRetrieval() { var simple = new SimpleYouTubeClip("dC1FJBw8uaU", "*****@*****.**", DateTime.Now); simpleChannel.Publish(simple); Assert.AreEqual(1, sink.Messages.Count); var clip = sink.Messages[0]; Assert.AreEqual(new TimeSpan(0, 0, 12), clip.Duration); Assert.AreEqual("foreman.qcif", clip.Title); }
/// <summary> /// Parse one message for YouTube links and publish them on the clip channel /// if found. /// </summary> /// <remarks> /// Currently only supports one link per mail. /// </remarks> private void HandleMessage(MailMessage m) { var match = YouTubeLinkRegex1.Match(MessageAsText(m)); if (!match.Success) match = YouTubeLinkRegex2.Match(MessageAsText(m)); if (match.Success) { var vid = match.Groups["videoid"].Value; var clip = new SimpleYouTubeClip(vid, m.From != null ? m.From.DisplayName : "Unknown Sender", DateTime.Now); Debug.WriteLine("In message '{0}' found: {1}", m.Subject, clip); clipChannel.Publish(clip); } else Debug.WriteLine("Did not find a YouTube link in '" + m.Subject + "'"); }
private void EnrichYouTubeClip(SimpleYouTubeClip simple) { var dataUrl = string.Format("http://gdata.youtube.com/feeds/api/videos/{0}", simple.ID); Debug.WriteLine("Downloading " + dataUrl); using (var wc = new WebClient()) { string xml = wc.DownloadString(dataUrl); StringReader reader = new StringReader(xml); XmlDocument doc = new XmlDocument(); doc.Load(reader); // Get properties from feed var seconds = int.Parse(doc.GetElementsByTagName("yt:duration")[0].Attributes["seconds"].Value); var duration = new TimeSpan(0, 0, seconds); var title = doc.GetElementsByTagName("title")[0].FirstChild.Value; var thumbnailURL = new Uri(doc.GetElementsByTagName("media:thumbnail")[0].Attributes["url"].Value); var rich = RichYouTubeClip.FromSimple(simple, duration, title, thumbnailURL); Debug.WriteLine("YouTube clip enriched. Publishing."); richChannel.Publish(rich); } }
public static RichYouTubeClip FromSimple(SimpleYouTubeClip simple, TimeSpan duration, string title, Uri thumbnailURL) { return new RichYouTubeClip( simple.ID, simple.Submitter, simple.SubmittedTime, duration, title, thumbnailURL); }
private void NewClip(SimpleYouTubeClip clip) { if (DateTime.Now.Hour != 12 || !Enabled) output.Publish(clip); }