Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        private void WaitForTranscode(string name, UploadResult result)
        {
            ProgressManager progress = new ProgressManager(10000);

            progress.CustomProgressText = "Gfycat encoding...";
            OnProgressChanged(progress);

            int iterations = 0;

            while (!StopUploadRequested)
            {
                string statusJson             = SendRequest(HttpMethod.GET, URL_API_STATUS + name);
                GfycatStatusResponse response = JsonConvert.DeserializeObject <GfycatStatusResponse>(statusJson);

                if (response.Error != null)
                {
                    Errors.Add(response.Error);
                    result.IsSuccess = false;
                    break;
                }
                else if (response.Task.Equals("error", StringComparison.InvariantCultureIgnoreCase))
                {
                    Errors.Add(response.Description);
                    result.IsSuccess = false;
                    break;
                }
                else if (response.GfyName != null)
                {
                    result.IsSuccess = true;
                    result.URL       = "https://gfycat.com/" + response.GfyName;
                    break;
                }
                else if ((response.Task.Equals("NotFoundo", StringComparison.InvariantCultureIgnoreCase) ||
                          response.Task.Equals("NotFound", StringComparison.InvariantCultureIgnoreCase)) && iterations > 5)
                {
                    Errors.Add("Gfy not found");
                    result.IsSuccess = false;
                    break;
                }

                if (progress.UpdateProgress((progress.Length - progress.Position) / response.Time))
                {
                    OnProgressChanged(progress);
                }

                iterations++;
                Thread.Sleep(500);
            }

            progress.CustomProgressText = "";
            OnProgressChanged(progress);
        }
Esempio n. 3
0
        private void WaitForTranscode(string name, UploadResult result)
        {
            ProgressManager progress = new ProgressManager(10000);

            if (AllowReportProgress)
            {
                OnProgressChanged(progress);
            }

            int iterations = 0;

            while (!StopUploadRequested)
            {
                string statusJson             = SendRequest(HttpMethod.GET, URL_API_STATUS + name);
                GfycatStatusResponse response = JsonConvert.DeserializeObject <GfycatStatusResponse>(statusJson);

                if (response.Error != null)
                {
                    Errors.Add(response.Error);
                    result.IsSuccess = false;
                    break;
                }
                else if (response.GfyName != null)
                {
                    result.IsSuccess = true;
                    result.URL       = "https://gfycat.com/" + response.GfyName;
                    break;
                }
                else if (response.Task == "NotFound" && iterations > 10)
                {
                    Errors.Add("Gfy not found");
                    result.IsSuccess = false;
                    break;
                }

                if (AllowReportProgress && progress.UpdateProgress((progress.Length - progress.Position) / response.Time))
                {
                    OnProgressChanged(progress);
                }

                Thread.Sleep(100);
                iterations++;
            }
        }