Search code examples
c#audioyoutube-apiyoutube-data-api

Youtube API upload video and add audio from the free library (C#)


What I want to do is , after uploading the video , I want to add audio to the video from the free audio that you can add in the creator studio. I can do it manually by editing the video and go to the audio section but i want that the software will do it. this is my code now for uploading video to youtube:

UserCredential credential;
        using (var stream = new FileStream("client_id.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                // This OAuth 2.0 access scope allows an application to upload files to the
                // authenticated user's YouTube channel, but doesn't allow other types of access.
                new[] { YouTubeService.Scope.YoutubeUpload },
                "user",
                CancellationToken.None
            );
        }

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
        });

        var video = new Video();
        video.Snippet = new VideoSnippet();
        video.Snippet.Title = "title";
        video.Snippet.Description = "description";
        video.Snippet.Tags = new string[]{"tags"};
        video.Snippet.CategoryId = "22"; 
        video.Status = new VideoStatus();
        video.Status.PrivacyStatus = "public"; 
        var filePath = "video.avi"

        using (var fileStream = new FileStream(filePath, FileMode.Open))
        {
            var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
            videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
            videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

            await videosInsertRequest.UploadAsync();
        }

I just need to add audio to the uploaded youtube from the creator studio programmatically. help is appreciated.


Solution

  • There is no such method from the Youtube API. You can see the supported methods in the Videos reference.

    Update: The method is available here YouTube > Data API > Reference > Videos: insert