2014-06-01 03:04:52 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2016-01-04 04:16:01 +13:00
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
2014-06-01 03:04:52 +12:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-06-01 20:59:37 +12:00
|
|
|
|
// Credits: https://github.com/Dinnerbone
|
|
|
|
|
|
2014-06-01 03:04:52 +12:00
|
|
|
|
using Newtonsoft.Json;
|
2014-12-11 12:19:28 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
|
|
|
|
using ShareX.UploadersLib.HelperClasses;
|
2014-06-01 03:04:52 +12:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2014-06-01 20:59:37 +12:00
|
|
|
|
using System.Threading;
|
2014-06-01 03:04:52 +12:00
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.UploadersLib.FileUploaders
|
2014-06-01 03:04:52 +12:00
|
|
|
|
{
|
|
|
|
|
public class GfycatUploader : FileUploader
|
|
|
|
|
{
|
2014-06-01 20:59:37 +12:00
|
|
|
|
public bool NoResize { get; set; }
|
|
|
|
|
public bool IgnoreExisting { get; set; }
|
|
|
|
|
|
|
|
|
|
public GfycatUploader()
|
2014-06-01 03:04:52 +12:00
|
|
|
|
{
|
2014-06-01 20:59:37 +12:00
|
|
|
|
NoResize = true;
|
|
|
|
|
IgnoreExisting = false;
|
|
|
|
|
}
|
2014-06-01 03:04:52 +12:00
|
|
|
|
|
2014-06-01 20:59:37 +12:00
|
|
|
|
public override UploadResult Upload(Stream stream, string fileName)
|
|
|
|
|
{
|
2014-06-01 03:04:52 +12:00
|
|
|
|
// Magical official values from http://www.reddit.com/r/gfycat/comments/20xbth/any_word_on_allowing_uploading_a_gif_through_the/
|
2014-06-01 20:59:37 +12:00
|
|
|
|
Dictionary<string, string> args = new Dictionary<string, string>();
|
2014-06-01 03:04:52 +12:00
|
|
|
|
args.Add("key", Helpers.GetRandomAlphanumeric(10));
|
|
|
|
|
args.Add("acl", "private");
|
|
|
|
|
args.Add("AWSAccessKeyId", "AKIAIT4VU4B7G2LQYKZQ");
|
|
|
|
|
args.Add("policy", "eyAiZXhwaXJhdGlvbiI6ICIyMDIwLTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICAgICAgICAgICAiY29uZGl0aW9ucyI6IFsKICAgICAgICAgICAgeyJidWNrZXQiOiAiZ2lmYWZmZSJ9LAogICAgICAgICAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAiIl0sCiAgICAgICAgICAgIHsiYWNsIjogInByaXZhdGUifSwKCSAgICB7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6ICIyMDAifSwKICAgICAgICAgICAgWyJzdGFydHMtd2l0aCIsICIkQ29udGVudC1UeXBlIiwgIiJdLAogICAgICAgICAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgNTI0Mjg4MDAwXQogICAgICAgICAgICBdCiAgICAgICAgICB9");
|
|
|
|
|
args.Add("success_action_status", "200");
|
|
|
|
|
args.Add("signature", "mk9t/U/wRN4/uU01mXfeTe2Kcoc=");
|
2014-06-01 20:59:37 +12:00
|
|
|
|
args.Add("Content-Type", Helpers.GetMimeType(fileName));
|
|
|
|
|
|
2014-06-01 03:04:52 +12:00
|
|
|
|
UploadResult result = UploadData(stream, "https://gifaffe.s3.amazonaws.com/", fileName, "file", args);
|
|
|
|
|
|
|
|
|
|
if (!result.IsError)
|
|
|
|
|
{
|
|
|
|
|
TranscodeFile(args["key"], result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TranscodeFile(string key, UploadResult result)
|
|
|
|
|
{
|
2014-06-01 20:59:37 +12:00
|
|
|
|
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);
|
2014-06-01 05:52:18 +12:00
|
|
|
|
GfycatTranscodeResponse transcodeResponse = JsonConvert.DeserializeObject<GfycatTranscodeResponse>(transcodeJson);
|
2014-06-01 03:04:52 +12:00
|
|
|
|
|
2014-06-01 05:52:18 +12:00
|
|
|
|
if (transcodeResponse.IsOk)
|
2014-06-01 03:04:52 +12:00
|
|
|
|
{
|
2014-06-01 05:52:18 +12:00
|
|
|
|
ProgressManager progress = new ProgressManager(10000);
|
2014-06-01 20:59:37 +12:00
|
|
|
|
|
2014-06-01 05:52:18 +12:00
|
|
|
|
if (AllowReportProgress)
|
|
|
|
|
{
|
|
|
|
|
OnProgressChanged(progress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 09:26:00 +12:00
|
|
|
|
while (!StopUploadRequested)
|
2014-06-01 05:52:18 +12:00
|
|
|
|
{
|
|
|
|
|
string statusJson = SendRequest(HttpMethod.GET, "https://upload.gfycat.com/status/" + key);
|
|
|
|
|
GfycatStatusResponse response = JsonConvert.DeserializeObject<GfycatStatusResponse>(statusJson);
|
2014-06-03 03:24:24 +12:00
|
|
|
|
|
2014-06-01 05:52:18 +12:00
|
|
|
|
if (response.Error != null)
|
|
|
|
|
{
|
|
|
|
|
result.Errors.Add(response.Error);
|
|
|
|
|
result.IsSuccess = false;
|
|
|
|
|
break;
|
2014-06-01 20:59:37 +12:00
|
|
|
|
}
|
|
|
|
|
else if (response.GfyName != null)
|
|
|
|
|
{
|
2014-06-01 05:52:18 +12:00
|
|
|
|
result.IsSuccess = true;
|
|
|
|
|
result.URL = "https://gfycat.com/" + response.GfyName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-06-01 20:59:37 +12:00
|
|
|
|
|
|
|
|
|
if (AllowReportProgress && progress.UpdateProgress((progress.Length - progress.Position) / response.Time))
|
2014-06-01 05:52:18 +12:00
|
|
|
|
{
|
2014-06-01 20:59:37 +12:00
|
|
|
|
OnProgressChanged(progress);
|
2014-06-01 05:52:18 +12:00
|
|
|
|
}
|
2014-06-01 20:59:37 +12:00
|
|
|
|
|
|
|
|
|
Thread.Sleep(100);
|
2014-06-01 05:52:18 +12:00
|
|
|
|
}
|
2014-06-01 03:04:52 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-01 05:52:18 +12:00
|
|
|
|
result.Errors.Add(transcodeResponse.Error);
|
2014-06-01 03:04:52 +12:00
|
|
|
|
result.IsSuccess = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class GfycatTranscodeResponse
|
|
|
|
|
{
|
2014-06-01 05:52:18 +12:00
|
|
|
|
public bool IsOk { get; set; }
|
2014-06-01 03:04:52 +12:00
|
|
|
|
public string Error { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 05:52:18 +12:00
|
|
|
|
public class GfycatStatusResponse
|
|
|
|
|
{
|
|
|
|
|
public string Task { get; set; }
|
|
|
|
|
public int Time { get; set; }
|
|
|
|
|
public string GfyName { get; set; }
|
|
|
|
|
public string Error { get; set; }
|
2014-06-01 03:04:52 +12:00
|
|
|
|
}
|
|
|
|
|
}
|