Add streamable file uploader

This commit is contained in:
lucas 2015-12-01 13:02:06 -05:00
parent 1ea3e5a555
commit 55f92ce07f
7 changed files with 326 additions and 161 deletions

View file

@ -132,6 +132,8 @@ public enum FileDestination
Up1,
[Description("Seafile")]
Seafile,
[Description("Streamable")]
Streamable,
SharedFolder, // Localized
Email, // Localized
CustomFileUploader // Localized

View file

@ -0,0 +1,133 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2015 ShareX Team
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)
using Newtonsoft.Json;
using ShareX.HelpersLib;
using ShareX.UploadersLib.HelperClasses;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Threading;
namespace ShareX.UploadersLib.FileUploaders
{
public class Streamable : FileUploader
{
const string Host = "https://api.streamable.com";
string Email;
string Password;
public Streamable(string email, string password)
{
Email = email;
Password = password;
}
public override UploadResult Upload(Stream stream, string fileName)
{
Dictionary<string, string> args = new Dictionary<string, string>();
NameValueCollection headers = new NameValueCollection();
if (Email != "" && Password != "") {
headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(Email + ":" + Password)));
}
UploadResult result = UploadData(stream, Host + "/upload", fileName, "file", args, headers);
TranscodeFile(result);
return result;
}
private void GetShortcode()
{
}
private void TranscodeFile(UploadResult result)
{
StreamableTranscodeResponse transcodeResponse = JsonConvert.DeserializeObject<StreamableTranscodeResponse>(result.Response);
if (transcodeResponse.Shortcode != null)
{
ProgressManager progress = new ProgressManager(100);
if (AllowReportProgress)
{
OnProgressChanged(progress);
}
while (!StopUploadRequested)
{
string statusJson = SendRequest(HttpMethod.GET, 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 = "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;
}
}
}
public class StreamableTranscodeResponse
{
public string Shortcode { get; set; }
public int Status { get; set; }
}
public class StreamableStatusResponse
{
public int Status { get; set; }
public string Message { get; set; }
public long Percent { get; set; }
}
}

View file

@ -876,6 +876,16 @@ internal static System.Drawing.Bitmap Seafile {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon Streamable {
get {
object obj = ResourceManager.GetObject("Streamable", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View file

@ -482,4 +482,7 @@ Created folders:</value>
<data name="Seafile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\Seafile.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Streamable" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\Streamable.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -136,6 +136,7 @@
<Compile Include="FileUploaders\Mega.cs" />
<Compile Include="FileUploaders\OneDrive.cs" />
<Compile Include="FileUploaders\Seafile.cs" />
<Compile Include="FileUploaders\Streamable.cs" />
<Compile Include="FileUploaders\OwnCloud.cs" />
<Compile Include="FileUploaders\Pomf.cs" />
<Compile Include="FileUploaders\PomfUploader.cs" />

View file

@ -269,6 +269,12 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public string SeafileAccInfoEmail = "";
public string SeafileAccInfoUsage = "";
// Streamable
public string StreamableUsername = "";
public string StreamablePassword = "";
public bool StreamableAnonymous = true;
#endregion File uploaders
#region URL shorteners

View file

@ -1120,6 +1120,16 @@ public UploadResult UploadFile(Stream stream, string fileName)
IgnoreInvalidCert = Program.UploadersConfig.SeafileIgnoreInvalidCert
};
break;
case FileDestination.Streamable:
string user = "";
string password = "";
if (!Program.UploadersConfig.StreamableAnonymous) {
user = Program.UploadersConfig.StreamableUsername;
password = Program.UploadersConfig.StreamablePassword;
}
fileUploader = new Streamable(user, password);
break;
}
if (fileUploader != null)