How To Upload Your Daily Laptop Activity To YouTube By Using Youtube Api And Free Screen Recoder Software

avatar

Hello Friend My Name Is Viraj, By Profession I Am A Full Stack Developer,Today I This Article I Will Demonstrate,

How To Upload Your Daily Laptop Activity To YouTube By Using Youtube Api And Free Screen Recoder Software.

Step 1 :- Create Youtube Api


First Search On Google "google developer console" 

Or 

You Can Use This Link https://console.developers.google.com/apis/dashboard?project=mailsend-1541833980100&angularJsUrl=

See In Figure 1


Then Create A Project 

See In Figure 2


Then Click On Libary

See In Figure 3


Then Click YouTube In The Category And Select YouTube Data API v3 And Enable It.

See In Figure 4


Now Click On Create Credentials And Select OAuth client ID

See In Figure 5


Now Select Application Type Other And Give The Name To It.You Will Get Your Client ID And Client Secret.

See In Figure 6


Just Need To Download The Json Which Will Be Required For Uploading Video


Step 2 :- Create Console Application

First Click On File -> New -> Project And Select Console Application c# Give Name Google.Apis.YouTube.Samples


Add This Two Package


Install-Package Google.Apis.YouTube.v3 -Version 1.43.0.1834

Install-Package Google.Apis.Oauth2.v2 -Version 1.43.0.1602


Create A Folder YouTubeVideoUpload And Add client_secret.json and Name.txt


Code Bellow program.cs


using System;

using System.Diagnostics;

using System.IO;

using System.Reflection;

using System.Threading;

using System.Threading.Tasks;


using Google.Apis.Auth.OAuth2;

using Google.Apis.Services;

using Google.Apis.Upload;

using Google.Apis.Util.Store;

using Google.Apis.YouTube.v3;

using Google.Apis.YouTube.v3.Data;


namespace Google.Apis.YouTube.Samples

{

    /// <summary>

    /// YouTube Data API v3 sample: upload a video.

    /// Relies on the Google APIs Client Library for .NET, v1.7.0 or higher.

    /// See https://developers.google.com/api-client-library/dotnet/get_started

    /// </summary>

    internal class UploadVideo

    {

        [STAThread]

        static void Main(string[] args)

        {

            // create the  process to launch another exe file

            Process[] _proceses = null;

            _proceses = Process.GetProcessesByName("ScreenRecorder");

            foreach (Process proces in _proceses)

            {

                proces.Kill();

            }




            Console.WriteLine("YouTube Data API: Upload Video");

            Console.WriteLine("==============================");


            try

            {

                new UploadVideo().Run().Wait();

            }

            catch (AggregateException ex)

            {

                foreach (var e in ex.InnerExceptions)

                {

                    Console.WriteLine("Error: " + e.Message);

                }

            }


            Console.WriteLine("Press any key to continue...");

            Console.ReadKey();

        }


        private async Task Run()

        {

            UserCredential credential;

            var json = @"C:\YouTubeVideoUpload\client_secret.json";

        

            using (var stream = new FileStream(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

            });


            string fullname = @"C:\YouTubeVideoUpload\Name.txt";

            string UserName = "";

            if (System.IO.File.Exists(fullname))

            {

                using (StreamReader file = new StreamReader(fullname))

                {

                    int counter = 0;

                    string ln;

                    while ((ln = file.ReadLine()) != null)

                    {

                        UserName= UserName+ln;

                        counter++;

                    }

                    file.Close();

                }

            }





            var video = new Video();

            video.Snippet = new VideoSnippet();

            //video.Snippet.Title = "Default Video Title";

            video.Snippet.Title = "User Name : "+ UserName+" Laptop Screen Recording Of Date : "+DateTime.Now;


            //video.Snippet.Description = "Default Video Description";

             video.Snippet.Description = "This Video Is Related To User Name : " + UserName + " Laptop Screen Recording Of Date : " + DateTime.Now;


            //video.Snippet.Tags = new string[] { "tag1", "tag2" };


            video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list

            video.Status = new VideoStatus();


            //video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"


            video.Status.PrivacyStatus = "private"; // or "private" or "public"


            //var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.


            //DirectoryInfo d = new DirectoryInfo(@"C:\Users\BMT17\Documents\Bandicam");//Assuming Test is your Folder


            DirectoryInfo d = new DirectoryInfo(@"C:\Users\BMT17\Videos\List");//Assuming Test is your Folder


        

            FileInfo[] Files = d.GetFiles("*.flv"); //Getting Text files

            //string filePath = @"C:\Users\BMT17\Documents\Bandicam";

            string filePath = @"C:\Users\BMT17\Videos\List";

            foreach (FileInfo file in Files)

            {

                filePath = filePath + @"\" + file.Name;

            }


            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();

            }

        }


        void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)

        {

            switch (progress.Status)

            {

                case UploadStatus.Uploading:

                    Console.WriteLine("{0} bytes sent.", progress.BytesSent);

                    break;


                case UploadStatus.Failed:

                    Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);

                    break;

            }

        }


        void videosInsertRequest_ResponseReceived(Video video)

        {

            Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);


        }

    }

}


Create Exec Of Above Code.


Step 3 : Download Free Screen Recorder And Install It


Download From This Link https://free-screen-recorder.soft112.com/


Step 4 : Now Use Task Shedular To Shedule Task Of Both ScreenRecorder.exe and YoutubeUploadVideo.exe

See In Figure 7


Step 5 : Output

See In Figure 8




0
0
0.000
0 comments