Ejemplo n.º 1
0
        internal override void Run()
        {
            LOGGER.Info($"Changing video details for video '{Video.Title}'");

            progress = 0;

            var request = HttpWebRequestCreator.CreateWithAuthHeader("https://www.googleapis.com/youtube/v3/videos?part=snippet,status", "PUT", Account.GetActiveToken());

            request.ContentType = "application/json";

            SerializableYoutubeVideo resource = SerializableYoutubeVideo.Create(Video);
            var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(resource));

            var response = WebService.Communicate(request, bytes);

            Status.QuotaReached = QuotaProblemHandler.IsQuotaLimitReached(response);

            if (!Status.QuotaReached)
            {
                LOGGER.Info($"Video details for video '{Video.Title}' were successfully changed");

                FinishedSuccessful = true;
                progress           = 100;
            }

            OnStepFinished();
        }
Ejemplo n.º 2
0
        private string InitializeUploadOnYoutube()
        {
            var    ytVideo = SerializableYoutubeVideo.Create(Video);
            string content = JsonConvert.SerializeObject(ytVideo);
            var    bytes   = Encoding.UTF8.GetBytes(content);

            var request = HttpWebRequestCreator.CreateWithAuthHeader(
                $"https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable"
                + $"&autoLevels={Video.AutoLevels}&notifySubscribers={Video.NotifySubscribers}"
                + $"&stabilize={Video.Stabilize}&part=snippet,status,contentDetails",
                "POST",
                Account.GetActiveToken());

            request.Headers.Add("Slug", Path.GetFileName(new string(Video.File.Name.Where(c => Convert.ToInt32(c) < 128).ToArray())));
            request.Headers.Add($"x-upload-content-length: {Video.File.Length}");
            request.Headers.Add($"x-upload-content-type: {MimeMapping.GetMimeMapping(Video.File.Name)}");

            request.ContentLength = bytes.Length;
            request.ContentType   = "application/json; charset=utf-8";

            return(WebService.Communicate(request, bytes, "Location"));
        }