mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Add streamable file uploader
This commit is contained in:
parent
1ea3e5a555
commit
55f92ce07f
7 changed files with 326 additions and 161 deletions
|
@ -132,6 +132,8 @@ public enum FileDestination
|
|||
Up1,
|
||||
[Description("Seafile")]
|
||||
Seafile,
|
||||
[Description("Streamable")]
|
||||
Streamable,
|
||||
SharedFolder, // Localized
|
||||
Email, // Localized
|
||||
CustomFileUploader // Localized
|
||||
|
@ -322,4 +324,4 @@ public enum OAuthLoginStatus
|
|||
LoginSuccessful,
|
||||
LoginFailed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
133
ShareX.UploadersLib/FileUploaders/Streamable.cs
Normal file
133
ShareX.UploadersLib/FileUploaders/Streamable.cs
Normal 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; }
|
||||
}
|
||||
}
|
266
ShareX.UploadersLib/Properties/Resources.Designer.cs
generated
266
ShareX.UploadersLib/Properties/Resources.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
|
@ -26,36 +26,36 @@
|
|||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
|
@ -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>
|
||||
</root>
|
||||
<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>
|
||||
|
|
|
@ -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" />
|
||||
|
@ -888,11 +889,11 @@ if not exist APIKeysLocal.cs (
|
|||
type nul > APIKeysLocal.cs
|
||||
)</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -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
|
||||
|
@ -520,4 +526,4 @@ public int GetLocalhostIndex(EDataType dataType)
|
|||
|
||||
#endregion Helper Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -1490,4 +1500,4 @@ public void Dispose()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue