Beispiel #1
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public YouTubeService(BaseClientService.Initializer initializer)
     : base(initializer)
 {
     this.activities              = new ActivitiesResource((IClientService)this);
     this.captions                = new CaptionsResource((IClientService)this);
     this.channelBanners          = new ChannelBannersResource((IClientService)this);
     this.channelSections         = new ChannelSectionsResource((IClientService)this);
     this.channels                = new ChannelsResource((IClientService)this);
     this.commentThreads          = new CommentThreadsResource((IClientService)this);
     this.comments                = new CommentsResource((IClientService)this);
     this.guideCategories         = new GuideCategoriesResource((IClientService)this);
     this.i18nLanguages           = new I18nLanguagesResource((IClientService)this);
     this.i18nRegions             = new I18nRegionsResource((IClientService)this);
     this.liveBroadcasts          = new LiveBroadcastsResource((IClientService)this);
     this.liveChatBans            = new LiveChatBansResource((IClientService)this);
     this.liveChatMessages        = new LiveChatMessagesResource((IClientService)this);
     this.liveChatModerators      = new LiveChatModeratorsResource((IClientService)this);
     this.liveStreams             = new LiveStreamsResource((IClientService)this);
     this.playlistItems           = new PlaylistItemsResource((IClientService)this);
     this.playlists               = new PlaylistsResource((IClientService)this);
     this.search                  = new SearchResource((IClientService)this);
     this.sponsors                = new SponsorsResource((IClientService)this);
     this.subscriptions           = new SubscriptionsResource((IClientService)this);
     this.superChatEvents         = new SuperChatEventsResource((IClientService)this);
     this.thumbnails              = new ThumbnailsResource((IClientService)this);
     this.videoAbuseReportReasons = new VideoAbuseReportReasonsResource((IClientService)this);
     this.videoCategories         = new VideoCategoriesResource((IClientService)this);
     this.videos                  = new VideosResource((IClientService)this);
     this.watermarks              = new WatermarksResource((IClientService)this);
 }
Beispiel #2
0
        /// <summary>
        /// Uploads a caption track in draft status that matches the API request parameters.
        /// (captions.insert)
        /// </summary>
        /// <param name="config"></param>
        /// <param name="youtubeService"></param>
        private void UploadCaption(YouTuBotSettings config, YouTubeService youtubeService)
        {
            string captionFile = config.CaptionFile;

            if (!File.Exists(captionFile))
            {
                return;                 //Ignore subtitles file when not found.
            }
            // Add extra information to the caption before uploading.
            var captionObjectDefiningMetadata = new Caption();

            //captionObjectDefiningMetadata.Kind = "youtube#caption";
            captionObjectDefiningMetadata.Snippet          = new CaptionSnippet();
            captionObjectDefiningMetadata.Snippet.VideoId  = config.VideoId;
            captionObjectDefiningMetadata.Snippet.Language = config.CaptionLanguage;
            captionObjectDefiningMetadata.Snippet.Name     = config.CaptionFile;
            //captionObjectDefiningMetadata.Snippet.IsDraft = false;
            //captionObjectDefiningMetadata.Snippet.TrackKind = "standard";

            var capRes = new CaptionsResource(youtubeService);

            var minimumChunkSize = 8 * Google.Apis.Upload.ResumableUpload <int> .MinimumChunkSize;

            using (var mediaContent = new FileStream(captionFile, FileMode.Open))
            {
                var part = "snippet";
                // Create an API request that specifies that the mediaContent object is the caption of the specified video.
                var captionInsertRequest = capRes.Insert(captionObjectDefiningMetadata, part, mediaContent, "*/*");

                captionInsertRequest.ProgressChanged  += captionInsertRequest_ProgressChanged;
                captionInsertRequest.ResponseReceived += captionInsertRequest_ResponseReceived;
                captionInsertRequest.ChunkSize         = minimumChunkSize;
                //captionInsertRequest.Sync = false;

                //var response = await captionInsertRequest.UploadAsync();
                var response = captionInsertRequest.Upload();
            }
        }