예제 #1
0
        public string UploadVideo(FileInfo path, string name, Guid guid, Action <int> percentageUpdate)
        {
            var video = new Video();

            video.Snippet       = new VideoSnippet();
            video.Snippet.Title = name;
            //video.Snippet.Description = info.Guid.ToString(); //maybe description will be
            //video.Snippet.Tags = new string[] { "tag1", "tag2" }; //maybe tags will be
            video.Snippet.CategoryId  = "22";
            video.Snippet.Description = YoutubeClip.GuidMarker(guid);
            video.Status = new VideoStatus();
            video.Status.PrivacyStatus = "public";
            var filePath = path.FullName;

            fileSize = path.Length;                   //нужно для расчета прогресса
            this.percentageUpdate = percentageUpdate; //"обновлятель" свойства

            string result = null;

            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                var videosInsertRequest = service.Videos.Insert(video, "snippet,status", fileStream, "video/*");
                videosInsertRequest.ProgressChanged  += OnProgressChanged;
                videosInsertRequest.ResponseReceived += v => { result = v.Id; };
                videosInsertRequest.UploadAsync().RunSync();
            }
            return(result);
        }
예제 #2
0
        public void TestPrefix(string prefix, string result)
        {
            var clip = new YoutubeClip {
                Name = prefix + result
            };

            Assert.AreEqual(result, clip.GetProperName());
        }
예제 #3
0
        public void TestGuidDeletion(string before, string after, Guid guid)
        {
            var clip = new YoutubeClip {
                Description = before + "\n" + YoutubeClip.GuidMarker(guid) + "\n" + after
            };

            clip.UpdateGuid(null);
            Assert.AreEqual(before + "\n\n" + after, clip.Description);
        }
예제 #4
0
 public void UpdateVideoThumbnail(YoutubeClip clip, FileInfo image)
 {
     // Create an API request that specifies that the mediaContent
     // object is the thumbnail of the specified video.
     using (var stream = File.Open(image.FullName, FileMode.Open))
     {
         var thumbnailSet = service.Thumbnails.Set(clip.Id, stream, "image/png");
         thumbnailSet.Upload();
     }
 }
예제 #5
0
        public void TestGuidReplacement(string before, string after, Guid guid1, Guid guid2)
        {
            var clip = new YoutubeClip {
                Description = before + "\n" + YoutubeClip.GuidMarker(guid1) + "\n" + after
            };

            clip.UpdateGuid(guid2);
            var expected = before + "\n" + YoutubeClip.GuidMarker(guid2) + "\n" + after;

            Assert.AreEqual(expected, clip.Description);
        }
예제 #6
0
        public void TestGuidAddition(string desc, Guid guid)
        {
            var clip = new YoutubeClip {
                Description = desc
            };

            clip.UpdateGuid(guid);
            string expected = desc + "\n" + "[GUID: " + guid + "]";

            Assert.AreEqual(expected, clip.Description);
        }
예제 #7
0
        public void UpdateVideo(YoutubeClip clip)
        {
            var listRq = service.Videos.List("snippet");

            listRq.Id = clip.Id;
            var video = listRq.Execute().Items[0];

            video.Snippet.Title       = clip.Name;
            video.Snippet.Description = clip.Description;
            video.Snippet.Tags        = null;
            service.Videos.Update(video, "snippet").Execute();
        }