Integrate audible API draft 1. incomplete

This commit is contained in:
Robert McRackan 2019-10-21 16:27:28 -04:00
parent 37708bece1
commit cecbea1e9f
30 changed files with 1313 additions and 226 deletions

View file

@ -0,0 +1,113 @@
namespace LibationWinForm.Dialogs.Login
{
partial class AudibleLoginDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.passwordLbl = new System.Windows.Forms.Label();
this.emailLbl = new System.Windows.Forms.Label();
this.passwordTb = new System.Windows.Forms.TextBox();
this.emailTb = new System.Windows.Forms.TextBox();
this.submitBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// passwordLbl
//
this.passwordLbl.AutoSize = true;
this.passwordLbl.Location = new System.Drawing.Point(12, 41);
this.passwordLbl.Name = "passwordLbl";
this.passwordLbl.Size = new System.Drawing.Size(53, 13);
this.passwordLbl.TabIndex = 2;
this.passwordLbl.Text = "Password";
//
// emailLbl
//
this.emailLbl.AutoSize = true;
this.emailLbl.Location = new System.Drawing.Point(12, 15);
this.emailLbl.Name = "emailLbl";
this.emailLbl.Size = new System.Drawing.Size(32, 13);
this.emailLbl.TabIndex = 0;
this.emailLbl.Text = "Email";
//
// passwordTb
//
this.passwordTb.Location = new System.Drawing.Point(71, 38);
this.passwordTb.Name = "passwordTb";
this.passwordTb.PasswordChar = '*';
this.passwordTb.Size = new System.Drawing.Size(200, 20);
this.passwordTb.TabIndex = 3;
//
// emailTb
//
this.emailTb.Location = new System.Drawing.Point(71, 12);
this.emailTb.Name = "emailTb";
this.emailTb.Size = new System.Drawing.Size(200, 20);
this.emailTb.TabIndex = 1;
//
// submitBtn
//
this.submitBtn.Location = new System.Drawing.Point(196, 64);
this.submitBtn.Name = "submitBtn";
this.submitBtn.Size = new System.Drawing.Size(75, 23);
this.submitBtn.TabIndex = 4;
this.submitBtn.Text = "Submit";
this.submitBtn.UseVisualStyleBackColor = true;
this.submitBtn.Click += new System.EventHandler(this.submitBtn_Click);
//
// AudibleLoginDialog
//
this.AcceptButton = this.submitBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(283, 99);
this.Controls.Add(this.submitBtn);
this.Controls.Add(this.passwordLbl);
this.Controls.Add(this.emailLbl);
this.Controls.Add(this.passwordTb);
this.Controls.Add(this.emailTb);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AudibleLoginDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Audible Login";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label passwordLbl;
private System.Windows.Forms.Label emailLbl;
private System.Windows.Forms.TextBox passwordTb;
private System.Windows.Forms.TextBox emailTb;
private System.Windows.Forms.Button submitBtn;
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Windows.Forms;
namespace LibationWinForm.Dialogs.Login
{
public partial class AudibleLoginDialog : Form
{
public string Email { get; private set; }
public string Password { get; private set; }
public AudibleLoginDialog()
{
InitializeComponent();
}
private void submitBtn_Click(object sender, EventArgs e)
{
Email = this.emailTb.Text;
Password = this.passwordTb.Text;
DialogResult = DialogResult.OK;
}
}
}

View file

@ -0,0 +1,103 @@
namespace LibationWinForm.Dialogs.Login
{
partial class CaptchaDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.captchaPb = new System.Windows.Forms.PictureBox();
this.answerTb = new System.Windows.Forms.TextBox();
this.submitBtn = new System.Windows.Forms.Button();
this.answerLbl = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.captchaPb)).BeginInit();
this.SuspendLayout();
//
// captchaPb
//
this.captchaPb.Location = new System.Drawing.Point(12, 12);
this.captchaPb.Name = "captchaPb";
this.captchaPb.Size = new System.Drawing.Size(429, 186);
this.captchaPb.TabIndex = 0;
this.captchaPb.TabStop = false;
//
// answerTb
//
this.answerTb.Location = new System.Drawing.Point(118, 206);
this.answerTb.Name = "answerTb";
this.answerTb.Size = new System.Drawing.Size(100, 20);
this.answerTb.TabIndex = 1;
//
// submitBtn
//
this.submitBtn.Location = new System.Drawing.Point(366, 204);
this.submitBtn.Name = "submitBtn";
this.submitBtn.Size = new System.Drawing.Size(75, 23);
this.submitBtn.TabIndex = 2;
this.submitBtn.Text = "Submit";
this.submitBtn.UseVisualStyleBackColor = true;
this.submitBtn.Click += new System.EventHandler(this.submitBtn_Click);
//
// answerLbl
//
this.answerLbl.AutoSize = true;
this.answerLbl.Location = new System.Drawing.Point(12, 209);
this.answerLbl.Name = "answerLbl";
this.answerLbl.Size = new System.Drawing.Size(100, 13);
this.answerLbl.TabIndex = 0;
this.answerLbl.Text = "CAPTCHA answer: ";
//
// CaptchaDialog
//
this.AcceptButton = this.submitBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(453, 239);
this.Controls.Add(this.answerLbl);
this.Controls.Add(this.submitBtn);
this.Controls.Add(this.answerTb);
this.Controls.Add(this.captchaPb);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CaptchaDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "CAPTCHA";
((System.ComponentModel.ISupportInitialize)(this.captchaPb)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox captchaPb;
private System.Windows.Forms.TextBox answerTb;
private System.Windows.Forms.Button submitBtn;
private System.Windows.Forms.Label answerLbl;
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace LibationWinForm.Dialogs.Login
{
public partial class CaptchaDialog : Form
{
public string Answer { get; private set; }
private MemoryStream ms { get; }
private Image image { get; }
public CaptchaDialog(byte[] captchaImage)
{
InitializeComponent();
this.FormClosed += (_, __) => { ms?.Dispose(); image?.Dispose(); };
ms = new MemoryStream(captchaImage);
image = Image.FromStream(ms);
this.captchaPb.Image = image;
var h1 = captchaPb.Height;
var w1 = captchaPb.Width;
var h2 = captchaPb.Image.Height;
var w2 = captchaPb.Image.Width;
}
private void submitBtn_Click(object sender, EventArgs e)
{
Answer = this.answerTb.Text;
DialogResult = DialogResult.OK;
}
}
}

View file

@ -0,0 +1,32 @@
using System;
using LibationWinForm.Dialogs.Login;
namespace LibationWinForm.Login
{
public class WinformResponder : AudibleApiDomainService.IAudibleApiResponder
{
public string Get2faCode()
{
using var dialog = new _2faCodeDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
return dialog.Code;
return null;
}
public string GetCaptchaAnswer(byte[] captchaImage)
{
using var dialog = new CaptchaDialog(captchaImage);
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
return dialog.Answer;
return null;
}
public (string email, string password) GetLogin()
{
using var dialog = new AudibleLoginDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
return (dialog.Email, dialog.Password);
return (null, null);
}
}
}

View file

@ -0,0 +1,90 @@
namespace LibationWinForm.Dialogs.Login
{
partial class _2faCodeDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.submitBtn = new System.Windows.Forms.Button();
this.codeTb = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// submitBtn
//
this.submitBtn.Location = new System.Drawing.Point(15, 51);
this.submitBtn.Name = "SaveBtn";
this.submitBtn.Size = new System.Drawing.Size(79, 23);
this.submitBtn.TabIndex = 1;
this.submitBtn.Text = "Submit";
this.submitBtn.UseVisualStyleBackColor = true;
this.submitBtn.Click += new System.EventHandler(this.submitBtn_Click);
//
// codeTb
//
this.codeTb.Location = new System.Drawing.Point(15, 25);
this.codeTb.Name = "newTagsTb";
this.codeTb.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.codeTb.Size = new System.Drawing.Size(79, 20);
this.codeTb.TabIndex = 0;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(82, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Enter 2FA Code";
//
// _2faCodeDialog
//
this.AcceptButton = this.submitBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(106, 86);
this.Controls.Add(this.label1);
this.Controls.Add(this.codeTb);
this.Controls.Add(this.submitBtn);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "_2faCodeDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "2FA Code";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button submitBtn;
private System.Windows.Forms.TextBox codeTb;
private System.Windows.Forms.Label label1;
}
}

View file

@ -0,0 +1,21 @@
using System;
using System.Windows.Forms;
namespace LibationWinForm.Dialogs.Login
{
public partial class _2faCodeDialog : Form
{
public string Code { get; private set; }
public _2faCodeDialog()
{
InitializeComponent();
}
private void submitBtn_Click(object sender, EventArgs e)
{
Code = this.codeTb.Text;
DialogResult = DialogResult.OK;
}
}
}

View file

@ -358,8 +358,11 @@ namespace LibationWinForm
private async void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e)
{
// audible api
//var client = new AudibleApiDomainService.AudibleApiLibationClient(config.);
//await client.ImportLibraryAsync();
var settings = new AudibleApiDomainService.Settings(config);
var responder = new Login.WinformResponder();
var client = await AudibleApiDomainService.AudibleApiLibationClient.CreateClientAsync(settings, responder);
var testResult = await client.TestGetLibraryAsync();
await client.ImportLibraryAsync();
// scrape
await indexDialog(new ScanLibraryDialog());