private void TranscodeFile(UploadResult result) { StreamableTranscodeResponse transcodeResponse = JsonConvert.DeserializeObject<StreamableTranscodeResponse>(result.Response); if (!string.IsNullOrEmpty(transcodeResponse.Shortcode)) { ProgressManager progress = new ProgressManager(100); if (AllowReportProgress) { OnProgressChanged(progress); } while (!StopUploadRequested) { string statusJson = SendRequest(HttpMethod.GET, URLHelpers.CombineURL(Host, "videos", transcodeResponse.Shortcode)); StreamableStatusResponse response = JsonConvert.DeserializeObject<StreamableStatusResponse>(statusJson); if (response.Status > 2) { result.Errors.Add(response.Message); result.IsSuccess = false; break; } else if (response.Status == 2) { if (AllowReportProgress) { long delta = 100 - progress.Position; progress.UpdateProgress(delta); OnProgressChanged(progress); } result.IsSuccess = true; result.URL = URLHelpers.CombineURL("https://streamable.com", transcodeResponse.Shortcode); break; } if (AllowReportProgress) { long delta = response.Percent - progress.Position; progress.UpdateProgress(delta); OnProgressChanged(progress); } Thread.Sleep(100); } } else { result.Errors.Add("Could not create video"); result.IsSuccess = false; } }
private void TranscodeFile(string key, UploadResult result) { Dictionary<string, string> args = new Dictionary<string, string>(); if (NoResize) args.Add("noResize", "true"); if (IgnoreExisting) args.Add("noMd5", "true"); string url = CreateQuery("https://upload.gfycat.com/transcodeRelease/" + key, args); string transcodeJson = SendRequest(HttpMethod.GET, url); GfycatTranscodeResponse transcodeResponse = JsonConvert.DeserializeObject<GfycatTranscodeResponse>(transcodeJson); if (transcodeResponse.IsOk) { ProgressManager progress = new ProgressManager(10000); if (AllowReportProgress) { OnProgressChanged(progress); } while (!StopUploadRequested) { string statusJson = SendRequest(HttpMethod.GET, "https://upload.gfycat.com/status/" + key); GfycatStatusResponse response = JsonConvert.DeserializeObject<GfycatStatusResponse>(statusJson); if (response.Error != null) { result.Errors.Add(response.Error); result.IsSuccess = false; break; } else if (response.GfyName != null) { result.IsSuccess = true; result.URL = "https://gfycat.com/" + response.GfyName; break; } if (AllowReportProgress && progress.UpdateProgress((progress.Length - progress.Position) / response.Time)) { OnProgressChanged(progress); } Thread.Sleep(100); } } else { result.Errors.Add(transcodeResponse.Error); result.IsSuccess = false; } }
private string Send(Stream stream, Dictionary<string, string> arguments) { client.Connect(url.DnsSafeHost, 80); using (NetworkStream networkStream = client.GetStream()) { networkStream.Write(postMethod, 0, postMethod.Length); networkStream.Write(headerBytes, 0, headerBytes.Length); networkStream.Write(request, 0, request.Length); byte[] buffer = new byte[(int)Math.Min(4096, stream.Length)]; ProgressManager progress = new ProgressManager(); using (stream) { int bytesRead = stream.Read(buffer, 0, buffer.Length); while (bytesRead > 0) { networkStream.Write(buffer, 0, bytesRead); //if (progress.ChangeProgress(stream)) uploader.OnProgressChanged(progress.Progress); bytesRead = stream.Read(buffer, 0, buffer.Length); } } networkStream.Write(requestEnd, 0, requestEnd.Length); using (StreamReader reader = new StreamReader(networkStream)) return reader.ReadToEnd(); } }