/////////////////////////////////////////////////////////////////////////////


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

            YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey);
            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd);
            }

            YouTubeEntry entry = new YouTubeEntry();

            entry.MediaSource = new MediaFileSource(this.resourcePath + "test_movie.mov", "video/quicktime");
            entry.Media = new YouTube.MediaGroup();
            entry.Media.Description = new MediaDescription("This is a test");
            entry.Media.Title = new MediaTitle("Sample upload");
            entry.Media.Keywords = new MediaKeywords("math");

            // entry.Media.Categories

            MediaCategory category = new MediaCategory("Nonprofit");
            category.Attributes["scheme"] = YouTubeService.DefaultCategory;

            entry.Media.Categories.Add(category);

            YouTubeEntry newEntry = service.Upload(this.ytUser, entry);

            Assert.AreEqual(newEntry.Media.Description.Value, entry.Media.Description.Value, "Description should be equal");
            Assert.AreEqual(newEntry.Media.Keywords.Value, entry.Media.Keywords.Value, "Keywords should be equal");


            Rating rating = new Rating();
            rating.Value = 1;
            newEntry.Rating = rating;

            YouTubeEntry ratedEntry = newEntry.Update();
            ratedEntry.Delete();
        }
 protected virtual void VideoAdded(YouTubeEntry video)
 {
     if (OnVideoAdded != null)
     {
         if (video.Rating == null)
         {
             Rating r = new Rating();
             r.NumRaters = 0;
             r.Average = 0;
             video.Rating = r;
         }
         OnVideoAdded(this, video);
     }
 }
예제 #3
0
        public void YouTubeRatingsTest() {
            Tracing.TraceMsg("Entering YouTubeRatingsTest");
            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) {
                Rating rating = new Rating();
                rating.Value = 1;
                v.YouTubeEntry.Rating = rating;
                YouTubeEntry ratedEntry = f.Service.Insert(new Uri(v.YouTubeEntry.RatingsLink.ToString()), v.YouTubeEntry);
                Assert.AreEqual(1, ratedEntry.Rating.Value, "Rating should be equal to 1");
                break; // we can stop after one
            }
        }