Example #1
0
        private async Task <Video> UpdateVideo(Video video, string part, YouTubeService service)
        {
            VideosResource.UpdateRequest request = service.Videos.Update(video, part);
            Video updatedVideo = await request.ExecuteAsync();

            return(updatedVideo);
        }
Example #2
0
        public async Task UpdateVideoMetadataAsync(VideoMetadataModel videoMetadataModel, string chatMessage, CancellationToken cancellationToken)
        {
            _logger.LogTrace($"{GetType()} - BEGIN {nameof(UpdateVideoMetadataAsync)}");

            try
            {
                YouTubeService ytService = await _ytServiceProvider.CreateServiceAsync(cancellationToken);

                string videoId = GetVideoIdFromUrl(videoMetadataModel.VideoUrl);
                if (!string.IsNullOrEmpty(videoId))
                {
                    IEnumerable <VideoCategory> categories = await GetCategoriesAsync(cancellationToken);

                    VideoCategory category = categories.FirstOrDefault(c => c.Snippet.Title == videoMetadataModel.Category);

                    Video video = await GetVideoMetadataInternalAsync(videoId, cancellationToken);

                    video.HydrateFromVideoModel(videoMetadataModel);
                    video.Snippet.CategoryId = category.Id;

                    VideosResource.UpdateRequest req = ytService.Videos.Update(video, new string[] { "snippet", "status" });
                    await req.ExecuteAsync(cancellationToken);

                    if (!string.IsNullOrEmpty(chatMessage))
                    {
                        LiveChatMessage msg = new LiveChatMessage {
                            Snippet = new LiveChatMessageSnippet {
                                LiveChatId         = video.LiveStreamingDetails.ActiveLiveChatId,
                                Type               = "textMessageEvent",
                                TextMessageDetails = new LiveChatTextMessageDetails {
                                    MessageText = chatMessage
                                }
                            }
                        };
                        ytService.LiveChatMessages.Insert(msg, SNIPPET_PART_PARAM);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError("An error occurred while updating video", e);
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Updates the specified video.
        /// </summary>
        /// <param name="video">The video to update</param>
        /// <param name="title">The title to set</param>
        /// <param name="description">The description to set</param>
        /// <param name="categoryId">The category ID to set</param>
        /// <returns>The updated broadcast</returns>
        public async Task <Video> UpdateVideo(Video video, string title = null, string description = null, string categoryId = null)
        {
            Validator.ValidateVariable(video, "video");
            return(await this.YouTubeServiceWrapper(async() =>
            {
                VideosResource.UpdateRequest request = this.connection.GoogleYouTubeService.Videos.Update(new Video()
                {
                    Id = video.Id,
                    Snippet = new VideoSnippet()
                    {
                        Title = title ?? video.Snippet.Title,
                        Description = description ?? video.Snippet.Description,
                        CategoryId = categoryId ?? video.Snippet.CategoryId
                    }
                }, "snippet");
                LogRequest(request);

                Video response = await request.ExecuteAsync();
                LogResponse(request, response);
                return response;
            }));
        }
        public async Task <ActionResult <Video> > Update([Required, FromQuery] string part, [Required, FromBody] Video video)
        {
            if (part is null)
            {
                throw new ArgumentNullException(nameof(part));
            }
            if (video is null)
            {
                throw new ArgumentNullException(nameof(video));
            }

            YouTubeService service = await serviceAccessor.InitializeServiceAsync();

            VideosResource.UpdateRequest request = service.Videos.Update(video, part);

            try {
                Video response = await request.ExecuteAsync();

                return(new ActionResult <Video>(response));
            } catch (GoogleApiException ex) {
                return(StatusCode((int)ex.HttpStatusCode, ex.Message));
            }
        }