Example #1
0
        static void Main(string[] args)
        {
            var request = new YouTubeRequest(
                new YouTubeRequestSettings(
                    "YouTubeTest",
                    "AI39si4diV_7ebufqI-_h1tCkD_8B36b8pqzFlNUQDKEO0hww8nLrqO7UjsOksWQvcUsEILnK9qJIn12cuQbgf4QhZauyw8s8g"
                    ));
            var feed = request.GetVideoFeed("CGPGrey");

            feed.AutoPaging = true;

            long  total  = 0;
            int   nVids  = 0;
            Video oldest = null;
            Video newest = null;

            foreach (var v in feed.Entries)
            {
                if (oldest == null || ComparePublishDate(v, oldest) < 0)
                {
                    oldest = v;
                }
                if (newest == null || ComparePublishDate(v, newest) > 0)
                {
                    newest = v;
                }
                nVids++;
                int dur = int.Parse(v.Media.Duration.Seconds);
                total += dur;
            }

            var    span = PublishDate(newest).Subtract(PublishDate(oldest));
            double rate = (double)total * 365.25 / span.TotalDays / 3600;
        }
Example #2
0
        ///////////////////////// START OF REQUEST TESTS



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a test on the YouTube factory object</summary>
        //////////////////////////////////////////////////////////////////////
        [Test] public void YouTubeRequestTest()
        {
            Tracing.TraceMsg("Entering YouTubeRequestTest");


            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd);

            YouTubeRequest f = new YouTubeRequest(settings);
            // GetVideoFeed get's you a users video feed
            Feed <Video> feed = f.GetVideoFeed(null);

            // this will get you just the first 25 videos.
            foreach (Video v in feed.Entries)
            {
                Assert.IsTrue(v.AtomEntry != null, "There should be an atomentry");
                Assert.IsTrue(v.Title != null, "There should be a title");
                Assert.IsTrue(v.VideoId != null, "There should be a videoID");
            }

            Feed <Video> sfeed = f.GetStandardFeed(YouTubeQuery.MostPopular);

            int iCountOne = 0;

            // this loop get's you all videos in the mostpopular video feeed
            foreach (Video v in sfeed.Entries)
            {
                Assert.IsTrue(v.AtomEntry != null, "There should be an atomentry");
                Assert.IsTrue(v.Title != null, "There should be a title");
                Assert.IsTrue(v.VideoId != null, "There should be a videoID");
                iCountOne++;
            }
            int iCountTwo = 0;

            sfeed.AutoPaging = true;
            sfeed.Maximum    = 50;

            foreach (Video v in sfeed.Entries)
            {
                Assert.IsTrue(v.AtomEntry != null, "There should be an atomentry");
                Assert.IsTrue(v.Title != null, "There should be a title");
                Assert.IsTrue(v.VideoId != null, "There should be a videoID");
                iCountTwo++;
            }
            Assert.IsTrue(iCountTwo > iCountOne);
        }
Example #3
0
        public List <YoutubeVideo> GetVideoByUserId(int numberToRetrieve, string userId)
        {
            var youTubeRequestSettings = new YouTubeRequestSettings(_applicationName, _developerKey);
            var request = new YouTubeRequest(youTubeRequestSettings);

            youTubeRequestSettings.Maximum = 50;

            var feed = request.GetVideoFeed(_userId);

            var videos = new List <YoutubeVideo>();

            foreach (var item in feed.Entries.ToList())
            {
                videos.Add(item.ToYoutubeVideo());
            }

            return(videos);
        }
Example #4
0
        public List <Video> GetVideoByUserId(string userId)
        {
            var youTubeRequestSettings = new YouTubeRequestSettings(_applicationName, _developerKey);
            var request = new YouTubeRequest(youTubeRequestSettings);

            youTubeRequestSettings.PageSize   = 50;
            youTubeRequestSettings.AutoPaging = true;

            var feed   = request.GetVideoFeed(userId);
            var videos = new List <Video>();

            foreach (Video video in feed.Entries)
            {
                videos.Add(video);
            }

            return(videos);
        }
        void CallYoutube ()
        {
            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            var yreq = new YouTubeRequest (new YouTubeRequestSettings ("MonoTouchSample", "AI39si4v3E6oIYiI60ndCNDqnPP5lCqO28DSvvDPnQt-Mqia5uPz2e4E-gMSBVwHXwyn_LF1tWox4LyM-0YQd2o4i_3GcXxa2Q"));

            var feed = yreq.GetVideoFeed ("xamarinhq");

            feed.Entries.ToList ().ForEach ((video) => {
                data.Add (video.Title);
            }
            );

            InvokeOnMainThread (delegate {
                    
                TableView.ReloadData ();
                UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
            }
            );
        }
Example #6
0
        public void YouTubeYtRatingsDislikeTest()
        {
            Tracing.TraceMsg("Entering YouTubeYtRatingsDislikeTest");
            string videoOwner = "GoogleDevelopers";

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd);

            YouTubeRequest f = new YouTubeRequest(settings);
            // GetVideoFeed gets you a users video feed
            Feed <Video> feed = f.GetVideoFeed(videoOwner);

            // this will get you just the first 25 videos.

            foreach (Video v in feed.Entries)
            {
                YtRating rating = new YtRating(YtRating.Dislike);
                v.YouTubeEntry.YtRating = rating;
                YouTubeEntry ratedEntry = f.Service.Insert(new Uri(v.YouTubeEntry.RatingsLink.ToString()), v.YouTubeEntry);
                Assert.AreEqual(YtRating.Dislike, ratedEntry.YtRating.RatingValue, "YtRating should be equal to dislike");
                break; // we can stop after one
            }
        }
Example #7
0
        public void YouTubePrivateTest()
        {
            Tracing.TraceMsg("Entering YouTubePrivateTest");

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd);

            settings.PageSize   = 15;
            settings.AutoPaging = true;
            YouTubeRequest f = new YouTubeRequest(settings);

            Feed <Video> feed         = f.GetVideoFeed(null);
            Video        privateVideo = null;

            foreach (Video v in feed.Entries)
            {
                if (v.IsDraft == false)
                {
                    v.YouTubeEntry.Private = true;
                    privateVideo           = f.Update(v);
                }
                else
                {
                    // there should be a state as well
                    State s = v.YouTubeEntry.State;
                    Assert.IsNotNull(s, "state should not be null");
                    Assert.IsNotNull(s.Reason, "State.Reason should not be null");
                }
            }

            Assert.IsTrue(privateVideo != null, "we should have one private video");
            Assert.IsTrue(privateVideo.YouTubeEntry.Private, "that video should be private");
            privateVideo.YouTubeEntry.Private = false;

            Video ret = f.Update(privateVideo);

            Assert.IsTrue(ret != null, "we should have one private video");
            Assert.IsTrue(!ret.YouTubeEntry.Private, "that video should be not private");
        }
        public void YouTubePrivateTest()
        {
            Tracing.TraceMsg("Entering YouTubePrivateTest");

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytClient, this.ytDevKey, this.ytUser, this.ytPwd);
            settings.PageSize = 15;
            settings.AutoPaging = true;
            YouTubeRequest f = new YouTubeRequest(settings);

            Feed<Video> feed = f.GetVideoFeed(null);
            Video privateVideo = null; 

            foreach (Video v in feed.Entries)
            {
                if (v.IsDraft==false)
                {
                    v.YouTubeEntry.Private = true;
                    privateVideo = f.Update(v);
                }
                else
                {
                    // there should be a state as well
                    State s = v.YouTubeEntry.State;
                    Assert.IsNotNull(s, "state should not be null");
                    Assert.IsNotNull(s.Reason, "State.Reason should not be null");
                }
            }

            Assert.IsTrue(privateVideo != null, "we should have one private video");
            Assert.IsTrue(privateVideo.YouTubeEntry.Private == true, "that video should be private");
            privateVideo.YouTubeEntry.Private = false;

            Video ret = f.Update(privateVideo);
            Assert.IsTrue(ret != null, "we should have one private video");
            Assert.IsTrue(ret.YouTubeEntry.Private == false, "that video should be not private");
            
        }
        ///////////////////////// START OF REQUEST TESTS 



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs a test on the YouTube factory object</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void YouTubeRequestTest()
        {
            Tracing.TraceMsg("Entering YouTubeRequestTest");


            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytClient, this.ytDevKey, this.ytUser, this.ytPwd);

            YouTubeRequest f = new YouTubeRequest(settings);
            // GetVideoFeed get's you a users video feed
            Feed<Video> feed = f.GetVideoFeed(null);
            // this will get you just the first 25 videos. 
            foreach (Video v in feed.Entries)
            {
                Assert.IsTrue(v.AtomEntry != null, "There should be an atomentry");
                Assert.IsTrue(v.Title != null, "There should be a title");
                Assert.IsTrue(v.VideoId != null, "There should be a videoID");
            }

            Feed<Video> sfeed = f.GetStandardFeed(YouTubeQuery.MostPopular);

            int iCountOne=0; 
            // this loop get's you all videos in the mostpopular video feeed
            foreach (Video v in sfeed.Entries)
            {
                Assert.IsTrue(v.AtomEntry != null, "There should be an atomentry");
                Assert.IsTrue(v.Title != null, "There should be a title");
                Assert.IsTrue(v.VideoId != null, "There should be a videoID");
                iCountOne++; 
            }
            int iCountTwo = 0; 
            sfeed.AutoPaging = true;
            sfeed.Maximum = 50; 

            foreach (Video v in sfeed.Entries)
            {
                Assert.IsTrue(v.AtomEntry != null, "There should be an atomentry");
                Assert.IsTrue(v.Title != null, "There should be a title");
                Assert.IsTrue(v.VideoId != null, "There should be a videoID");
                iCountTwo++; 
            }
            Assert.IsTrue(iCountTwo > iCountOne); 
        }
Example #10
0
        public void YouTubeYtRatingsDislikeTest() {
            Tracing.TraceMsg("Entering YouTubeYtRatingsDislikeTest");
            string videoOwner = "GoogleDevelopers";

            YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd);

            YouTubeRequest f = new YouTubeRequest(settings);
            // GetVideoFeed gets you a users video feed
            Feed<Video> feed = f.GetVideoFeed(videoOwner);
            // this will get you just the first 25 videos.

            foreach (Video v in feed.Entries) {
                YtRating rating = new YtRating(YtRating.Dislike);
                v.YouTubeEntry.YtRating = rating;
                YouTubeEntry ratedEntry = f.Service.Insert(new Uri(v.YouTubeEntry.RatingsLink.ToString()), v.YouTubeEntry);
                Assert.AreEqual(YtRating.Dislike, ratedEntry.YtRating.RatingValue, "YtRating should be equal to dislike");
                break; // we can stop after one
            }
        }