private void buttonCheckVideo_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(textBoxVideoLink.Text)) { MessageBox.Show("Please enter a video url"); } dataGridViewYTStats.Rows.Clear(); var yt = new YoutubeVideoAnalytics(); string response = yt.GetVideoAnalytics(textBoxVideoLink.Text); var youtubeAnalytics = JsonConvert.DeserializeObject <YoutubeData>(response);; for (int i = 0; i < youtubeAnalytics.Day.Data.Count; i++) { var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(youtubeAnalytics.Day.Data[i]); dataGridViewYTStats.Rows.Add( dateTime.ToString("MM/dd/yyyy"), youtubeAnalytics.Views.Daily.Data[i], youtubeAnalytics.Views.Cumulative.Data[i], youtubeAnalytics.WatchTime.Daily.Data[i], youtubeAnalytics.WatchTime.Cumulative.Data[i], youtubeAnalytics.Subscribers.Daily.Data[i], youtubeAnalytics.Subscribers.Cumulative.Data[i], youtubeAnalytics.Shares.Daily.Data[i], youtubeAnalytics.Shares.Cumulative.Data[i] ); } }
public void YoutubeVideoAnalyticsTest() { var yt = new YoutubeVideoAnalytics(); string response = yt.GetVideoAnalytics("kSoO2KjVVG4"); Console.WriteLine(response); var youtubeAnalytics = JsonConvert.DeserializeObject <YoutubeData>(response);; for (int i = 0; i < youtubeAnalytics.Day.Data.Count; i++) { Console.WriteLine("Daily:" + youtubeAnalytics.Subscribers.Daily.Data[i]); Console.WriteLine("Cumulative:" + youtubeAnalytics.Subscribers.Cumulative.Data[i]); } Assert.Fail(); }
public void extractVideoIDTest() { var yt = new YoutubeVideoAnalytics(); string[] urls = { "http://youtu.be/XsNHs4EvWs4", "http://www.youtube.com/embed/watch?feature=player_embedded&v=XsNHs4EvWs4", "http://www.youtube.com/embed/watch?v=XsNHs4EvWs4", "http://www.youtube.com/watch?feature=player_embedded&v=XsNHs4EvWs4", "http://www.youtube.com/watch?v=XsNHs4EvWs4", "http://www.youtube.com/v/XsNHs4EvWs4", "www.youtu.be/XsNHs4EvWs4", "youtu.be/XsNHs4EvWs4", "http://www.youtube.com/watch?v=XsNHs4EvWs4&feature=related", "http://www.youtube.com/v/XsNHs4EvWs4?fs=1&rel=0", "http://www.youtube.com/watch/XsNHs4EvWs4", }; foreach (string url in urls) { string id = yt.extractVideoID(url); Assert.AreEqual("XsNHs4EvWs4", id); } }