Changes to ImageShack Uploader

This commit is contained in:
mcored 2014-01-12 18:17:09 +08:00
parent e9b6a26d65
commit 05d5e0548d
7 changed files with 175 additions and 47 deletions

View file

@ -138,7 +138,7 @@ public enum HotkeyType
ActiveMonitor, ActiveMonitor,
[Description("Capture rectangle region")] [Description("Capture rectangle region")]
RectangleRegion, RectangleRegion,
[Description("Capture rectangle region with window")] [Description("Capture rectangle region or window")]
WindowRectangle, WindowRectangle,
[Description("Capture rounded rectangle region")] [Description("Capture rounded rectangle region")]
RoundedRectangleRegion, RoundedRectangleRegion,

View file

@ -552,8 +552,13 @@ public UploadResult UploadImage(Stream stream, string fileName)
switch (Info.TaskSettings.ImageDestination) switch (Info.TaskSettings.ImageDestination)
{ {
case ImageDestination.ImageShack: case ImageDestination.ImageShack:
imageUploader = new ImageShackUploader(ApiKeys.ImageShackKey, Program.UploadersConfig.ImageShackAccountType, imageUploader = new ImageShackUploader(ApiKeys.ImageShackKey, new ImageShackOptions()
Program.UploadersConfig.ImageShackRegistrationCode) {
user = Program.UploadersConfig.ImageShackUsername,
password = Program.UploadersConfig.ImageShackPassword,
remember_me = true,
set_cookies = true
}, null)
{ {
IsPublic = Program.UploadersConfig.ImageShackShowImagesInPublic IsPublic = Program.UploadersConfig.ImageShackShowImagesInPublic
}; };

View file

@ -40,9 +40,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
#region Image uploaders #region Image uploaders
// ImageShack // ImageShack
public string ImageShackPassword = string.Empty;
public AccountType ImageShackAccountType = AccountType.Anonymous;
public string ImageShackRegistrationCode = string.Empty;
public string ImageShackUsername = string.Empty; public string ImageShackUsername = string.Empty;
public bool ImageShackShowImagesInPublic = false; public bool ImageShackShowImagesInPublic = false;
@ -265,7 +263,7 @@ public bool IsActive(ImageDestination destination)
switch (destination) switch (destination)
{ {
case ImageDestination.ImageShack: case ImageDestination.ImageShack:
return ImageShackAccountType == AccountType.Anonymous || !string.IsNullOrEmpty(ImageShackRegistrationCode); return !string.IsNullOrEmpty(ImageShackPassword);
case ImageDestination.TinyPic: case ImageDestination.TinyPic:
return TinyPicAccountType == AccountType.Anonymous || !string.IsNullOrEmpty(TinyPicRegistrationCode); return TinyPicAccountType == AccountType.Anonymous || !string.IsNullOrEmpty(TinyPicRegistrationCode);
case ImageDestination.Imgur: case ImageDestination.Imgur:

View file

@ -41,7 +41,7 @@ private void InitializeComponent()
this.lblImageShackUsername = new System.Windows.Forms.Label(); this.lblImageShackUsername = new System.Windows.Forms.Label();
this.btnImageShackOpenRegistrationCode = new System.Windows.Forms.Button(); this.btnImageShackOpenRegistrationCode = new System.Windows.Forms.Button();
this.txtImageShackUsername = new System.Windows.Forms.TextBox(); this.txtImageShackUsername = new System.Windows.Forms.TextBox();
this.txtImageShackRegistrationCode = new System.Windows.Forms.TextBox(); this.txtImageShackPassword = new System.Windows.Forms.TextBox();
this.lblImageShackRegistrationCode = new System.Windows.Forms.Label(); this.lblImageShackRegistrationCode = new System.Windows.Forms.Label();
this.tpTinyPic = new System.Windows.Forms.TabPage(); this.tpTinyPic = new System.Windows.Forms.TabPage();
this.atcTinyPicAccountType = new UploadersLib.GUI.AccountTypeControl(); this.atcTinyPicAccountType = new UploadersLib.GUI.AccountTypeControl();
@ -439,7 +439,7 @@ private void InitializeComponent()
this.tpImageShack.Controls.Add(this.lblImageShackUsername); this.tpImageShack.Controls.Add(this.lblImageShackUsername);
this.tpImageShack.Controls.Add(this.btnImageShackOpenRegistrationCode); this.tpImageShack.Controls.Add(this.btnImageShackOpenRegistrationCode);
this.tpImageShack.Controls.Add(this.txtImageShackUsername); this.tpImageShack.Controls.Add(this.txtImageShackUsername);
this.tpImageShack.Controls.Add(this.txtImageShackRegistrationCode); this.tpImageShack.Controls.Add(this.txtImageShackPassword);
this.tpImageShack.Controls.Add(this.lblImageShackRegistrationCode); this.tpImageShack.Controls.Add(this.lblImageShackRegistrationCode);
this.tpImageShack.Location = new System.Drawing.Point(4, 22); this.tpImageShack.Location = new System.Drawing.Point(4, 22);
this.tpImageShack.Name = "tpImageShack"; this.tpImageShack.Name = "tpImageShack";
@ -456,7 +456,6 @@ private void InitializeComponent()
this.atcImageShackAccountType.SelectedAccountType = UploadersLib.AccountType.Anonymous; this.atcImageShackAccountType.SelectedAccountType = UploadersLib.AccountType.Anonymous;
this.atcImageShackAccountType.Size = new System.Drawing.Size(272, 29); this.atcImageShackAccountType.Size = new System.Drawing.Size(272, 29);
this.atcImageShackAccountType.TabIndex = 0; this.atcImageShackAccountType.TabIndex = 0;
this.atcImageShackAccountType.AccountTypeChanged += new UploadersLib.GUI.AccountTypeControl.AccountTypeChangedEventHandler(this.atcImageShackAccountType_AccountTypeChanged);
// //
// btnImageShackOpenPublicProfile // btnImageShackOpenPublicProfile
// //
@ -492,11 +491,11 @@ private void InitializeComponent()
// lblImageShackUsername // lblImageShackUsername
// //
this.lblImageShackUsername.AutoSize = true; this.lblImageShackUsername.AutoSize = true;
this.lblImageShackUsername.Location = new System.Drawing.Point(16, 112); this.lblImageShackUsername.Location = new System.Drawing.Point(16, 56);
this.lblImageShackUsername.Name = "lblImageShackUsername"; this.lblImageShackUsername.Name = "lblImageShackUsername";
this.lblImageShackUsername.Size = new System.Drawing.Size(246, 13); this.lblImageShackUsername.Size = new System.Drawing.Size(55, 13);
this.lblImageShackUsername.TabIndex = 3; this.lblImageShackUsername.TabIndex = 3;
this.lblImageShackUsername.Text = "Username (To be able to open public profile page):"; this.lblImageShackUsername.Text = "Username";
// //
// btnImageShackOpenRegistrationCode // btnImageShackOpenRegistrationCode
// //
@ -510,28 +509,29 @@ private void InitializeComponent()
// //
// txtImageShackUsername // txtImageShackUsername
// //
this.txtImageShackUsername.Location = new System.Drawing.Point(16, 136); this.txtImageShackUsername.Location = new System.Drawing.Point(16, 80);
this.txtImageShackUsername.Name = "txtImageShackUsername"; this.txtImageShackUsername.Name = "txtImageShackUsername";
this.txtImageShackUsername.Size = new System.Drawing.Size(392, 20); this.txtImageShackUsername.Size = new System.Drawing.Size(392, 20);
this.txtImageShackUsername.TabIndex = 4; this.txtImageShackUsername.TabIndex = 4;
this.txtImageShackUsername.TextChanged += new System.EventHandler(this.txtImageShackUsername_TextChanged); this.txtImageShackUsername.TextChanged += new System.EventHandler(this.txtImageShackUsername_TextChanged);
// //
// txtImageShackRegistrationCode // txtImageShackPassword
// //
this.txtImageShackRegistrationCode.Location = new System.Drawing.Point(16, 80); this.txtImageShackPassword.Location = new System.Drawing.Point(16, 136);
this.txtImageShackRegistrationCode.Name = "txtImageShackRegistrationCode"; this.txtImageShackPassword.Name = "txtImageShackPassword";
this.txtImageShackRegistrationCode.Size = new System.Drawing.Size(392, 20); this.txtImageShackPassword.PasswordChar = '*';
this.txtImageShackRegistrationCode.TabIndex = 2; this.txtImageShackPassword.Size = new System.Drawing.Size(392, 20);
this.txtImageShackRegistrationCode.TextChanged += new System.EventHandler(this.txtImageShackRegistrationCode_TextChanged); this.txtImageShackPassword.TabIndex = 2;
this.txtImageShackPassword.TextChanged += new System.EventHandler(this.txtImageShackRegistrationCode_TextChanged);
// //
// lblImageShackRegistrationCode // lblImageShackRegistrationCode
// //
this.lblImageShackRegistrationCode.AutoSize = true; this.lblImageShackRegistrationCode.AutoSize = true;
this.lblImageShackRegistrationCode.Location = new System.Drawing.Point(16, 56); this.lblImageShackRegistrationCode.Location = new System.Drawing.Point(16, 112);
this.lblImageShackRegistrationCode.Name = "lblImageShackRegistrationCode"; this.lblImageShackRegistrationCode.Name = "lblImageShackRegistrationCode";
this.lblImageShackRegistrationCode.Size = new System.Drawing.Size(93, 13); this.lblImageShackRegistrationCode.Size = new System.Drawing.Size(56, 13);
this.lblImageShackRegistrationCode.TabIndex = 1; this.lblImageShackRegistrationCode.TabIndex = 1;
this.lblImageShackRegistrationCode.Text = "Registration code:"; this.lblImageShackRegistrationCode.Text = "Password:";
// //
// tpTinyPic // tpTinyPic
// //
@ -666,7 +666,6 @@ private void InitializeComponent()
// //
// oauth2Imgur // oauth2Imgur
// //
this.oauth2Imgur.IsRefreshable = true;
this.oauth2Imgur.Location = new System.Drawing.Point(464, 16); this.oauth2Imgur.Location = new System.Drawing.Point(464, 16);
this.oauth2Imgur.LoginStatus = false; this.oauth2Imgur.LoginStatus = false;
this.oauth2Imgur.Name = "oauth2Imgur"; this.oauth2Imgur.Name = "oauth2Imgur";
@ -1242,7 +1241,6 @@ private void InitializeComponent()
// //
// oauth2Picasa // oauth2Picasa
// //
this.oauth2Picasa.IsRefreshable = true;
this.oauth2Picasa.Location = new System.Drawing.Point(16, 16); this.oauth2Picasa.Location = new System.Drawing.Point(16, 16);
this.oauth2Picasa.LoginStatus = false; this.oauth2Picasa.LoginStatus = false;
this.oauth2Picasa.Name = "oauth2Picasa"; this.oauth2Picasa.Name = "oauth2Picasa";
@ -2277,7 +2275,6 @@ private void InitializeComponent()
// //
// oAuthJira // oAuthJira
// //
this.oAuthJira.IsRefreshable = true;
this.oAuthJira.Location = new System.Drawing.Point(473, 13); this.oAuthJira.Location = new System.Drawing.Point(473, 13);
this.oAuthJira.LoginStatus = false; this.oAuthJira.LoginStatus = false;
this.oAuthJira.Name = "oAuthJira"; this.oAuthJira.Name = "oAuthJira";
@ -2301,7 +2298,6 @@ private void InitializeComponent()
// //
// oauth2GoogleDrive // oauth2GoogleDrive
// //
this.oauth2GoogleDrive.IsRefreshable = true;
this.oauth2GoogleDrive.Location = new System.Drawing.Point(16, 16); this.oauth2GoogleDrive.Location = new System.Drawing.Point(16, 16);
this.oauth2GoogleDrive.LoginStatus = false; this.oauth2GoogleDrive.LoginStatus = false;
this.oauth2GoogleDrive.Name = "oauth2GoogleDrive"; this.oauth2GoogleDrive.Name = "oauth2GoogleDrive";
@ -2801,7 +2797,6 @@ private void InitializeComponent()
// //
// oauth2GoogleURLShortener // oauth2GoogleURLShortener
// //
this.oauth2GoogleURLShortener.IsRefreshable = true;
this.oauth2GoogleURLShortener.Location = new System.Drawing.Point(16, 56); this.oauth2GoogleURLShortener.Location = new System.Drawing.Point(16, 56);
this.oauth2GoogleURLShortener.LoginStatus = false; this.oauth2GoogleURLShortener.LoginStatus = false;
this.oauth2GoogleURLShortener.Name = "oauth2GoogleURLShortener"; this.oauth2GoogleURLShortener.Name = "oauth2GoogleURLShortener";
@ -3632,7 +3627,7 @@ private void InitializeComponent()
internal System.Windows.Forms.Label lblImageShackUsername; internal System.Windows.Forms.Label lblImageShackUsername;
internal System.Windows.Forms.Button btnImageShackOpenRegistrationCode; internal System.Windows.Forms.Button btnImageShackOpenRegistrationCode;
internal System.Windows.Forms.TextBox txtImageShackUsername; internal System.Windows.Forms.TextBox txtImageShackUsername;
internal System.Windows.Forms.TextBox txtImageShackRegistrationCode; internal System.Windows.Forms.TextBox txtImageShackPassword;
internal System.Windows.Forms.Label lblImageShackRegistrationCode; internal System.Windows.Forms.Label lblImageShackRegistrationCode;
internal System.Windows.Forms.Button btnTinyPicOpenMyImages; internal System.Windows.Forms.Button btnTinyPicOpenMyImages;
internal System.Windows.Forms.CheckBox cbTinyPicRememberUsernamePassword; internal System.Windows.Forms.CheckBox cbTinyPicRememberUsernamePassword;

View file

@ -69,14 +69,9 @@ private void UploadersConfigForm_Resize(object sender, EventArgs e)
#region ImageShack #region ImageShack
private void atcImageShackAccountType_AccountTypeChanged(AccountType accountType)
{
Config.ImageShackAccountType = accountType;
}
private void txtImageShackRegistrationCode_TextChanged(object sender, EventArgs e) private void txtImageShackRegistrationCode_TextChanged(object sender, EventArgs e)
{ {
Config.ImageShackRegistrationCode = txtImageShackRegistrationCode.Text; Config.ImageShackPassword = txtImageShackPassword.Text;
} }
private void txtImageShackUsername_TextChanged(object sender, EventArgs e) private void txtImageShackUsername_TextChanged(object sender, EventArgs e)

View file

@ -129,8 +129,7 @@ public void LoadSettings(UploadersConfig uploadersConfig)
// ImageShack // ImageShack
atcImageShackAccountType.SelectedAccountType = Config.ImageShackAccountType; txtImageShackPassword.Text = Config.ImageShackPassword;
txtImageShackRegistrationCode.Text = Config.ImageShackRegistrationCode;
txtImageShackUsername.Text = Config.ImageShackUsername; txtImageShackUsername.Text = Config.ImageShackUsername;
cbImageShackIsPublic.Checked = Config.ImageShackShowImagesInPublic; cbImageShackIsPublic.Checked = Config.ImageShackShowImagesInPublic;

View file

@ -24,25 +24,59 @@
#endregion License Information (GPL v3) #endregion License Information (GPL v3)
using HelpersLib; using HelpersLib;
using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Web;
using UploadersLib.HelperClasses; using UploadersLib.HelperClasses;
namespace UploadersLib.ImageUploaders namespace UploadersLib.ImageUploaders
{ {
public sealed class ImageShackUploader : ImageUploader public sealed class ImageShackUploader : ImageUploader
{ {
public AccountType AccountType { get; private set; } private const string URLAPI = "https://api.imageshack.us/v1/";
private const string URLAccessToken = URLAPI + "user/login";
private const string URLUpload = URLAPI + "images";
public bool IsPublic { get; set; } public bool IsPublic { get; set; }
private string DeveloperKey { get; set; } private string DeveloperKey { get; set; }
private string RegistrationCode { get; set; } public ImageShackOptions Config { get; set; }
public OAuth2Info AuthInfo { get; private set; }
public ImageShackUploader(string developerKey, AccountType accountType = AccountType.Anonymous, string registrationCode = null) public ImageShackUploader(string developerKey, ImageShackOptions config, OAuth2Info auth)
{ {
DeveloperKey = developerKey; DeveloperKey = developerKey;
AccountType = accountType; Config = config;
RegistrationCode = registrationCode; AuthInfo = auth;
if (!string.IsNullOrEmpty(config.RegistrationCode))
{
GetAccessToken(config);
}
}
public bool GetAccessToken(ImageShackOptions config)
{
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("user", config.user);
args.Add("password", config.password);
args.Add("set_cookies", config.set_cookies.ToString());
args.Add("remember_me", config.remember_me.ToString());
string response = SendPostRequest(URLAccessToken, args);
if (!string.IsNullOrEmpty(response))
{
ImageShackLoginResponse resp = JsonConvert.DeserializeObject<ImageShackLoginResponse>(response);
if (resp != null && resp.result != null && !string.IsNullOrEmpty(resp.result.auth_token))
{
config.RegistrationCode = resp.result.auth_token;
return true;
}
}
return false;
} }
public override UploadResult Upload(Stream stream, string fileName) public override UploadResult Upload(Stream stream, string fileName)
@ -51,20 +85,122 @@ public override UploadResult Upload(Stream stream, string fileName)
arguments.Add("key", DeveloperKey); arguments.Add("key", DeveloperKey);
arguments.Add("public", IsPublic ? "yes" : "no"); arguments.Add("public", IsPublic ? "yes" : "no");
if (AccountType == AccountType.User && !string.IsNullOrEmpty(RegistrationCode)) if (!string.IsNullOrEmpty(Config.RegistrationCode))
{ {
arguments.Add("cookie", RegistrationCode); arguments.Add("cookie", Config.RegistrationCode);
} }
UploadResult result = UploadData(stream, "http://www.imageshack.us/upload_api.php", fileName, "fileupload", arguments); UploadResult result = UploadData(stream, URLUpload, fileName, "fileupload", arguments);
if (!string.IsNullOrEmpty(result.Response)) if (!string.IsNullOrEmpty(result.Response))
{ {
result.URL = Helpers.GetXMLValue(result.Response, "image_link"); ImageShackUploadResponse resp = JsonConvert.DeserializeObject<ImageShackUploadResponse>(result.Response);
result.ThumbnailURL = Helpers.GetXMLValue(result.Response, "thumb_link"); if (resp != null && resp.result != null && resp.result.images.Count > 0)
{
result.URL = "http://" + resp.result.images[0].direct_link;
result.ThumbnailURL = string.Format("http://imagizer.imageshack.us/v2/{0}x{1}q90/{2}/{3}",
256, 0, resp.result.images[0].server, resp.result.images[0].filename);
}
} }
return result; return result;
} }
public class ImageShackLoginResponse
{
public bool success { get; set; }
public int process_time { get; set; }
public ImageShackLogin result { get; set; }
}
public class ImageShackLogin
{
public string auth_token { get; set; }
public int user_id { get; set; }
public string email { get; set; }
public string username { get; set; }
public ImageShackeUserAvatar avatar { get; set; }
public string membership { get; set; }
public string membership_item_number { get; set; }
public string membership_cookie { get; set; }
}
public class ImageShackUser
{
public bool is_owner { get; set; }
public int cache_version { get; set; }
public string username { get; set; }
public string description { get; set; }
public int creation_date { get; set; }
public string location { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public ImageShackeUserAvatar Avatar { get; set; }
}
public class ImageShackeUserAvatar
{
public int image_id { get; set; }
public int server { get; set; }
public string filename { get; set; }
}
public class ImageShackUploadResponse
{
public bool success { get; set; }
public int process_time { get; set; }
public ImageShackUploadResult result { get; set; }
}
public class ImageShackUploadResult
{
public int max_filesize { get; set; }
public int space_limit { get; set; }
public int space_used { get; set; }
public int space_left { get; set; }
public int passed { get; set; }
public int failed { get; set; }
public int total { get; set; }
public List<ImageShackImage> images { get; set; }
}
public class ImageShackImage
{
public int id { get; set; }
public int server { get; set; }
public int bucket { get; set; }
public string lp_hash { get; set; }
public string filename { get; set; }
public string original_filename { get; set; }
public string direct_link { get; set; }
public object title { get; set; }
public object description { get; set; }
public List<string> tags { get; set; }
public int likes { get; set; }
public bool liked { get; set; }
public int views { get; set; }
public int comments_count { get; set; }
public bool comments_disabled { get; set; }
public int filter { get; set; }
public int filesize { get; set; }
public int creation_date { get; set; }
public int width { get; set; }
public int height { get; set; }
public bool @public { get; set; }
public bool is_owner { get; set; }
public ImageShackUser owner { get; set; }
public List<ImageShackImage> next_images { get; set; }
public List<ImageShackImage> prev_images { get; set; }
public object related_images { get; set; }
}
}
public class ImageShackOptions
{
public string user { get; set; }
public string password { get; set; }
public bool set_cookies { get; set; }
public bool remember_me { get; set; }
public string RegistrationCode { get; set; }
} }
} }