Compare commits

..

46 Commits
v3.0 ... v3.0.3

Author SHA1 Message Date
Robert McRackan
e319326c30 Switch to SQLite 2019-11-15 16:34:16 -05:00
Robert McRackan
5474446f62 Minor stablizing changes before the switch to sqlite 2019-11-15 15:58:21 -05:00
Robert McRackan
d53a617bc8 Download logic in DownloadPdf should look more like DownloadBook. Extract common d/l pattern to base class 2019-11-15 12:50:00 -05:00
Robert McRackan
9076fae6f6 - add retry logic to library get
- UI bug fix when no library yet
- publishing related xml added to data and UI projects
- 'how to publish' notes
2019-11-14 14:17:20 -05:00
Robert McRackan
5d4a97cdc4 Download PDF included with backup book. Update README 2019-11-13 11:24:38 -05:00
Robert McRackan
bbe745f487 'download book' now includes pdf 2019-11-13 11:20:37 -05:00
Robert McRackan
47360c036d Pre-beta: picture storage should be more responsive if on disk 2019-11-13 11:11:00 -05:00
Robert McRackan
e69df2abbc Pre-beta: BackupBook now includes downloading pdf. This replaces the need for throttling pdf downloads 2019-11-13 09:49:23 -05:00
Robert McRackan
88d49acdad Pre-beta: image download throttling 2019-11-13 08:37:57 -05:00
Robert McRackan
01a914c390 streamline indexing ui workflow 2019-11-12 12:54:54 -05:00
Robert McRackan
0b42b8ee49 Re-index if search engine files get deleted 2019-11-11 16:16:17 -05:00
Robert McRackan
c598576683 - Change name LibationWinForm.exe => Libation.exe
- lots of pre-beta bug fixes
2019-11-11 11:03:38 -05:00
Robert McRackan
b126eed028 update readme search sample images 2019-11-07 14:41:25 -05:00
rmcrackan
3020a116cf Update README.md
add Filters to readme
2019-11-07 13:43:17 -05:00
Robert McRackan
88b9ea2f2d Merge branch 'master' of https://github.com/rmcrackan/Libation 2019-11-07 13:43:02 -05:00
Robert McRackan
159c04c4b1 add readme image 2019-11-07 13:42:53 -05:00
rmcrackan
fad0f021ed Update README.md
format readme searches
2019-11-07 13:27:22 -05:00
rmcrackan
52f21dcab1 Update README.md 2019-11-07 13:26:01 -05:00
Robert McRackan
a6b89ca4c5 Merge branch 'master' of https://github.com/rmcrackan/Libation 2019-11-07 13:25:20 -05:00
Robert McRackan
650c00cf66 add readme images 2019-11-07 13:24:48 -05:00
rmcrackan
089edf934e Update README.md 2019-11-07 11:25:06 -05:00
rmcrackan
efe2b19e24 Update README.md
add Search to readme
2019-11-07 11:22:50 -05:00
Robert McRackan
c41dc9a6db add readme img.s 2019-11-07 11:15:42 -05:00
Robert McRackan
707cb78dbc Merge branch 'master' of https://github.com/rmcrackan/Libation 2019-11-07 11:06:48 -05:00
Robert McRackan
fc0d97d8e7 add readme img 2019-11-07 11:06:44 -05:00
rmcrackan
1494a15a6e Update README.md
readme formatting
2019-11-07 09:12:39 -05:00
rmcrackan
ac0de2a05e Update README.md
manually add table of contents
2019-11-07 09:10:50 -05:00
rmcrackan
3cc80b6a24 Update README.md
add tags to readme
2019-11-06 22:43:50 -05:00
Robert McRackan
38b04be6ba Merge branch 'master' of https://github.com/rmcrackan/Libation 2019-11-06 22:38:27 -05:00
Robert McRackan
0c52d443b2 more readme images 2019-11-06 22:37:54 -05:00
rmcrackan
aa0ebac50e Update README.md
Added book and pdf download instructions
2019-11-06 22:03:40 -05:00
Robert McRackan
debebf6ee0 update readme images 2019-11-06 22:02:54 -05:00
Robert McRackan
9034288e7c updated screenshots 2019-11-06 16:58:35 -05:00
Robert McRackan
19ee02ced4 Merge branch 'master' of https://github.com/rmcrackan/Libation 2019-11-06 16:53:43 -05:00
Robert McRackan
33723d7412 new screenshots 2019-11-06 16:53:39 -05:00
rmcrackan
a01a67e34a Update README.md
Add import instructions to readme
2019-11-06 15:16:34 -05:00
Robert McRackan
ecdb510513 add files for github readme 2019-11-06 15:10:45 -05:00
Robert McRackan
0b08bb3c4a Display settings wizard on first run 2019-11-06 13:30:23 -05:00
Robert McRackan
22e5dbf83d blank grid if no products 2019-11-06 09:01:57 -05:00
Robert McRackan
3b33648267 Merge branch 'master' of https://github.com/rmcrackan/Libation 2019-11-06 08:40:37 -05:00
Robert McRackan
8709518cd7 hide lucene debug search string 2019-11-06 08:40:32 -05:00
rmcrackan
3da1dff4d8 Update README 2019-11-05 22:15:20 -05:00
Robert McRackan
6aa544b322 Minor changes 2019-11-05 21:48:02 -05:00
Robert McRackan
bd993b4e4d Removed "legacy inAudible wire-up code" 2019-11-05 13:47:56 -05:00
Robert McRackan
4f7b66d64e Legacy inAudible wire-up code is still present but is commented out. All future check-ins are not guaranteed to have inAudible wire-up code 2019-11-05 13:45:19 -05:00
Robert McRackan
df90fc5361 All scraping code removed 2019-11-05 13:42:11 -05:00
165 changed files with 1580 additions and 6592 deletions

View File

@@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using AudibleApi;
using DataLayer;
using DtoImporterService;
using InternalUtilities;
namespace ApplicationServices
{
public static class LibraryCommands
{
public static async Task<(int totalCount, int newCount)> IndexLibraryAsync(ILoginCallback callback)
{
var audibleApiActions = new AudibleApiActions();
var items = await audibleApiActions.GetAllLibraryItemsAsync(callback);
var totalCount = items.Count;
var libImporter = new LibraryImporter();
var newCount = await Task.Run(() => libImporter.Import(items));
await Task.Run(() => SearchEngineCommands.FullReIndex());
return (totalCount, newCount);
}
public static int IndexChangedTags(Book book)
{
// update disconnected entity
using var context = LibationContext.Create();
context.Update(book);
var qtyChanges = context.SaveChanges();
// this part is tags-specific
if (qtyChanges > 0)
SearchEngineCommands.UpdateBookTags(book);
return qtyChanges;
}
}
}

View File

@@ -1,25 +0,0 @@
using System;
using System.Threading.Tasks;
using AudibleApi;
using DtoImporterService;
using InternalUtilities;
namespace ApplicationService
{
public class LibraryIndexer
{
public async Task<(int totalCount, int newCount)> IndexAsync(ILoginCallback callback)
{
var audibleApiActions = new AudibleApiActions();
var items = await audibleApiActions.GetAllLibraryItemsAsync(callback);
var totalCount = items.Count;
var libImporter = new LibraryImporter();
var newCount = await Task.Run(() => libImporter.Import(items));
await SearchEngineActions.FullReIndexAsync();
return (totalCount, newCount);
}
}
}

View File

@@ -1,26 +0,0 @@
using System.Threading.Tasks;
using DataLayer;
namespace ApplicationService
{
public static class SearchEngineActions
{
public static async Task FullReIndexAsync()
{
var engine = new LibationSearchEngine.SearchEngine();
await engine.CreateNewIndexAsync().ConfigureAwait(false);
}
public static void UpdateBookTags(Book book)
{
var engine = new LibationSearchEngine.SearchEngine();
engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags);
}
public static async Task ProductReIndexAsync(string productId)
{
var engine = new LibationSearchEngine.SearchEngine();
await engine.UpdateBookAsync(productId).ConfigureAwait(false);
}
}
}

View File

@@ -0,0 +1,43 @@
using System.Threading.Tasks;
using DataLayer;
using LibationSearchEngine;
namespace ApplicationServices
{
public static class SearchEngineCommands
{
public static void FullReIndex()
{
var engine = new SearchEngine();
engine.CreateNewIndex();
}
public static SearchResultSet Search(string searchString)
{
var engine = new SearchEngine();
try
{
return engine.Search(searchString);
}
catch (System.IO.FileNotFoundException)
{
FullReIndex();
return engine.Search(searchString);
}
}
public static void UpdateBookTags(Book book)
{
var engine = new SearchEngine();
try
{
engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags);
}
catch (System.IO.FileNotFoundException)
{
FullReIndex();
engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags);
}
}
}
}

View File

@@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FileManager\FileManager.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,66 +0,0 @@
using System;
using System.Linq;
using Dinah.Core;
namespace AudibleDotCom
{
public enum AudiblePageType
{
ProductDetails = 1,
Library = 2
}
public static class AudiblePageExt
{
public static AudiblePage GetAudiblePageRobust(this AudiblePageType audiblePage) => AudiblePage.FromPageType(audiblePage);
}
public abstract partial class AudiblePage : Enumeration<AudiblePage>
{
// useful for generic classes:
// public abstract class PageScraper<T> where T : AudiblePageRobust {
// public AudiblePage AudiblePage => AudiblePageRobust.GetAudiblePageFromType(typeof(T));
public static AudiblePageType GetAudiblePageFromType(Type audiblePageRobustType)
=> (AudiblePageType)GetAll().Single(t => t.GetType() == audiblePageRobustType).Id;
public AudiblePageType AudiblePageType { get; }
protected AudiblePage(AudiblePageType audiblePage, string abbreviation) : base((int)audiblePage, abbreviation) => AudiblePageType = audiblePage;
public static AudiblePage FromPageType(AudiblePageType audiblePage) => FromValue((int)audiblePage);
/// <summary>For pages which need a param, the param is marked with {0}</summary>
protected abstract string Url { get; }
public string GetUrl(string id) => string.Format(Url, id);
public string Abbreviation => DisplayName;
}
public abstract partial class AudiblePage : Enumeration<AudiblePage>
{
public static AudiblePage Library { get; } = LibraryPage.Instance;
public class LibraryPage : AudiblePage
{
#region singleton stuff
public static LibraryPage Instance { get; } = new LibraryPage();
static LibraryPage() { }
private LibraryPage() : base(AudiblePageType.Library, "LIB") { }
#endregion
protected override string Url => "http://www.audible.com/lib";
}
}
public abstract partial class AudiblePage : Enumeration<AudiblePage>
{
public static AudiblePage Product { get; } = ProductDetailPage.Instance;
public class ProductDetailPage : AudiblePage
{
#region singleton stuff
public static ProductDetailPage Instance { get; } = new ProductDetailPage();
static ProductDetailPage() { }
private ProductDetailPage() : base(AudiblePageType.ProductDetails, "PD") { }
#endregion
protected override string Url => "http://www.audible.com/pd/{0}";
}
}
}

View File

@@ -1,43 +0,0 @@
using FileManager;
namespace AudibleDotCom
{
public class AudiblePageSource
{
public AudiblePageType AudiblePage { get; }
public string Source { get; }
public string PageId { get; }
public AudiblePageSource(AudiblePageType audiblePage, string source, string pageId)
{
AudiblePage = audiblePage;
Source = source;
PageId = pageId;
}
/// <summary>declawed allows local file to safely be reloaded in chrome
/// NOTE ABOUT DECLAWED FILES
/// making them safer also breaks functionality
/// eg: previously hidden parts become visible. this changes how selenium can parse pages.
/// hidden elements don't expose .Text property</summary>
public AudiblePageSource Declawed() => new AudiblePageSource(AudiblePage, FileUtility.Declaw(Source), PageId);
public string Serialized() => $"<!-- |{AudiblePage.GetAudiblePageRobust().Abbreviation}|{(PageId ?? "").Trim()}| -->\r\n" + Source;
public static AudiblePageSource Deserialize(string serializedSource)
{
var endOfLine1 = serializedSource.IndexOf('\n');
var parameters = serializedSource
.Substring(0, endOfLine1)
.Split('|');
var abbrev = parameters[1];
var pageId = parameters[2];
var source = serializedSource.Substring(endOfLine1 + 1);
var audiblePage = AudibleDotCom.AudiblePage.FromDisplayName(abbrev).AudiblePageType;
return new AudiblePageSource(audiblePage, source, pageId);
}
}
}

View File

@@ -1,23 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Selenium.Support" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AudibleDotCom\AudibleDotCom.csproj" />
<ProjectReference Include="..\CookieMonster\CookieMonster.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="chromedriver.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -1,184 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AudibleDotCom;
using Dinah.Core.Humanizer;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
namespace AudibleDotComAutomation
{
/// <summary>browser manipulation. web driver access
/// browser operators. create and store web driver, browser navigation which can vary depending on whether anon or auth'd
///
/// this base class: is online. no auth. used for most pages. retain no chrome cookies</summary>
public abstract class SeleniumRetriever : IPageRetriever
{
#region // chrome driver details
/*
HIDING CHROME CONSOLE WINDOW
hiding chrome console window has proven to cause more headaches than it solves. here's how to do it though:
// can also use CreateDefaultService() overloads to specify driver path and/or file name
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
return new ChromeDriver(chromeDriverService, options);
HEADLESS CHROME
this WOULD be how to do headless. but amazon/audible are far too tricksy about their changes and anti-scraping measures
which renders 'headless' mode useless
var options = new ChromeOptions();
options.AddArgument("--headless");
SPECIFYING DRIVER LOCATION
if continues to have trouble finding driver:
var driver = new ChromeDriver(@"C:\my\path\to\chromedriver\directory");
var chromeDriverService = ChromeDriverService.CreateDefaultService(@"C:\my\path\to\chromedriver\directory");
*/
#endregion
protected IWebDriver Driver { get; }
Humanizer humanizer { get; } = new Humanizer();
protected SeleniumRetriever()
{
Driver = new ChromeDriver(ctorCreateChromeOptions());
}
/// <summary>no auth. retain no chrome cookies</summary>
protected virtual ChromeOptions ctorCreateChromeOptions() => new ChromeOptions();
protected async Task AudibleLinkClickAsync(IWebElement element)
{
// EACH CALL to audible should have a small random wait to reduce chances of scrape detection
await humanizer.Wait();
await Task.Run(() => Driver.Click(element));
await waitForSpinnerAsync();
// sometimes these clicks just take a while. add a few more seconds
await Task.Delay(5000);
}
By spinnerLocator { get; } = By.Id("library-main-overlay");
private async Task waitForSpinnerAsync()
{
// if loading overlay w/spinner exists: pause, wait for it to end
await Task.Delay(100);
if (Driver.FindElements(spinnerLocator).Count > 0)
new WebDriverWait(Driver, TimeSpan.FromSeconds(60))
.Until(ExpectedConditions.InvisibilityOfElementLocated(spinnerLocator));
}
private bool isFirstRun = true;
protected virtual async Task FirstRunAsync()
{
// load with no beginning wait. then wait 7 seconds to allow for page flicker. it usually happens after ~5 seconds. can happen irrespective of login state
await Task.Run(() => Driver.Navigate().GoToUrl("http://www.audible.com/"));
await Task.Delay(7000);
}
public async Task<IEnumerable<AudiblePageSource>> GetPageSourcesAsync(AudiblePageType audiblePage, string pageId = null)
{
if (isFirstRun)
{
await FirstRunAsync();
isFirstRun = false;
}
await initFirstPageAsync(audiblePage, pageId);
return await processUrl(audiblePage, pageId);
}
private async Task initFirstPageAsync(AudiblePageType audiblePage, string pageId)
{
// EACH CALL to audible should have a small random wait to reduce chances of scrape detection
await humanizer.Wait();
var url = audiblePage.GetAudiblePageRobust().GetUrl(pageId);
await Task.Run(() => Driver.Navigate().GoToUrl(url));
await waitForSpinnerAsync();
}
private async Task<IEnumerable<AudiblePageSource>> processUrl(AudiblePageType audiblePage, string pageId)
{
var pageSources = new List<AudiblePageSource>();
do
{
pageSources.Add(new AudiblePageSource(audiblePage, Driver.PageSource, pageId));
}
while (await hasMorePagesAsync());
return pageSources;
}
#region has more pages
/// <summary>if no more pages, return false. else, navigate to next page and return true</summary>
private async Task<bool> hasMorePagesAsync()
{
var next = //old_hasMorePages() ??
new_hasMorePages();
if (next == null)
return false;
await AudibleLinkClickAsync(next);
return true;
}
private IWebElement old_hasMorePages()
{
var parentElements = Driver.FindElements(By.ClassName("adbl-page-next"));
if (parentElements.Count == 0)
return null;
var childElements = parentElements[0].FindElements(By.LinkText("NEXT"));
if (childElements.Count != 1)
return null;
return childElements[0];
}
// ~ oct 2017
private IWebElement new_hasMorePages()
{
// get all active/enabled navigation links
var pageNavLinks = Driver.FindElements(By.ClassName("library-load-page"));
if (pageNavLinks.Count == 0)
return null;
// get only the right chevron if active.
// note: there are also right chevrons which are not for wish list navigation which is why we first filter by library-load-page
var nextLink = pageNavLinks
.Where(p => p.FindElements(By.ClassName("bc-icon-chevron-right")).Count > 0)
.ToList(); // cut-off delayed execution
if (nextLink.Count == 0)
return null;
return nextLink.Single().FindElement(By.TagName("button"));
}
#endregion
#region IDisposable pattern
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && Driver != null)
{
// Quit() does cleanup AND disposes
Driver.Quit();
}
}
#endregion
}
}

View File

@@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
namespace AudibleDotComAutomation
{
/// <summary>for user collections: lib, WL</summary>
public abstract class AuthSeleniumRetriever : SeleniumRetriever
{
protected bool IsLoggedIn => GetListenerPageLink() != null;
// needed?
protected AuthSeleniumRetriever() : base() { }
protected IWebElement GetListenerPageLink()
{
var listenerPageElement = Driver.FindElements(By.XPath("//a[contains(@href, '/review-by-author')]"));
if (listenerPageElement.Count > 0)
return listenerPageElement[0];
return null;
}
}
}

View File

@@ -1,130 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using AudibleDotCom;
using CookieMonster;
using Dinah.Core;
using Dinah.Core.Humanizer;
namespace AudibleDotComAutomation
{
public class BrowserlessRetriever : IPageRetriever
{
Humanizer humanizer { get; } = new Humanizer();
public async Task<IEnumerable<AudiblePageSource>> GetPageSourcesAsync(AudiblePageType audiblePage, string pageId = null)
{
switch (audiblePage)
{
case AudiblePageType.Library: return await getLibraryPageSourcesAsync();
default: throw new NotImplementedException();
}
}
private async Task<IEnumerable<AudiblePageSource>> getLibraryPageSourcesAsync()
{
var collection = new List<AudiblePageSource>();
var cookies = await getAudibleCookiesAsync();
var currPageNum = 1;
bool hasMorePages;
do
{
// EACH CALL to audible should have a small random wait to reduce chances of scrape detection
await humanizer.Wait();
var html = await getLibraryPageAsync(cookies, currPageNum);
var pageSource = new AudiblePageSource(AudiblePageType.Library, html, null);
collection.Add(pageSource);
hasMorePages = getHasMorePages(pageSource.Source);
currPageNum++;
} while (hasMorePages);
return collection;
}
private static async Task<CookieContainer> getAudibleCookiesAsync()
{
var liveCookies = await CookiesHelper.GetLiveCookieValuesAsync();
var audibleCookies = liveCookies.Where(c
=> c.Domain.ContainsInsensitive("audible.com")
|| c.Domain.ContainsInsensitive("adbl")
|| c.Domain.ContainsInsensitive("amazon.com"))
.ToList();
var cookies = new CookieContainer();
foreach (var c in audibleCookies)
cookies.Add(new Cookie(c.Name, c.Value, "/", c.Domain));
return cookies;
}
private static bool getHasMorePages(string html)
{
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
// final page, invalid page:
// <span class="bc-button
// bc-button-secondary
// nextButton
// bc-button-disabled">
// only page: ???
// has more pages:
// <span class="bc-button
// bc-button-secondary
// refinementFormButton
// nextButton">
var next_active_link = doc
.DocumentNode
.Descendants()
.FirstOrDefault(n =>
n.HasClass("nextButton") &&
!n.HasClass("bc-button-disabled"));
return next_active_link != null;
}
private static async Task<string> getLibraryPageAsync(CookieContainer cookies, int pageNum)
{
#region // POST example (from 2017 ajax)
// var destination = "https://www.audible.com/lib-ajax";
// var webRequest = (HttpWebRequest)WebRequest.Create(destination);
// webRequest.Method = "POST";
// webRequest.Accept = "*/*";
// webRequest.AllowAutoRedirect = false;
// webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
// webRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
// webRequest.Credentials = null;
//
// webRequest.CookieContainer = new CookieContainer();
// webRequest.CookieContainer.Add(cookies.GetCookies(new Uri(destination)));
//
// var postData = $"progType=all&timeFilter=all&itemsPerPage={itemsPerPage}&searchTerm=&searchType=&sortColumn=&sortType=down&page={pageNum}&mode=normal&subId=&subTitle=";
// var data = Encoding.UTF8.GetBytes(postData);
// webRequest.ContentLength = data.Length;
// using var dataStream = webRequest.GetRequestStream();
// dataStream.Write(data, 0, data.Length);
#endregion
var destination = "https://" + $"www.audible.com/lib?purchaseDateFilter=all&programFilter=all&sortBy=PURCHASE_DATE.dsc&page={pageNum}";
var webRequest = (HttpWebRequest)WebRequest.Create(destination);
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";
webRequest.CookieContainer = new CookieContainer();
webRequest.CookieContainer.Add(cookies.GetCookies(new Uri(destination)));
var webResponse = await webRequest.GetResponseAsync();
return new StreamReader(webResponse.GetResponseStream()).ReadToEnd();
}
public void Dispose() { }
}
}

View File

@@ -1,75 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace AudibleDotComAutomation
{
/// <summary>online. get auth by logging in with provided username and password
/// retain no chrome cookies. enter user + pw login</summary>
public class ManualLoginSeleniumRetriever : AuthSeleniumRetriever
{
string _username;
string _password;
public ManualLoginSeleniumRetriever(string username, string password) : base()
{
_username = username;
_password = password;
}
protected override async Task FirstRunAsync()
{
await base.FirstRunAsync();
// can't extract this into AuthSeleniumRetriever ctor. can't use username/pw until prev ctors are complete
// click login link
await AudibleLinkClickAsync(getLoginLink());
// wait until login page loads
new WebDriverWait(Driver, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementIsVisible(By.Id("ap_email")));
// insert credentials
Driver
.FindElement(By.Id("ap_email"))
.SendKeys(_username);
Driver
.FindElement(By.Id("ap_password"))
.SendKeys(_password);
// submit
var submitElement
= Driver.FindElements(By.Id("signInSubmit")).FirstOrDefault()
?? Driver.FindElement(By.Id("signInSubmit-input"));
await AudibleLinkClickAsync(submitElement);
// wait until audible page loads
new WebDriverWait(Driver, TimeSpan.FromSeconds(60))
.Until(d => GetListenerPageLink());
if (!IsLoggedIn)
throw new Exception("not logged in");
}
private IWebElement getLoginLink()
{
{
var loginLinkElements1 = Driver.FindElements(By.XPath("//a[contains(@href, '/signin')]"));
if (loginLinkElements1.Any())
return loginLinkElements1[0];
}
//
// ADD ADDITIONAL ACCEPTABLE PATTERNS HERE
//
//{
// var loginLinkElements2 = Driver.FindElements(By.XPath("//a[contains(@href, '/signin')]"));
// if (loginLinkElements2.Any())
// return loginLinkElements2[0];
//}
throw new NotFoundException("Cannot locate login link");
}
}
}

View File

@@ -1,38 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Chrome;
namespace AudibleDotComAutomation
{
/// <summary>online. load auth, cookies etc from user data</summary>
public class UserDataSeleniumRetriever : AuthSeleniumRetriever
{
public UserDataSeleniumRetriever() : base()
{
// can't extract this into AuthSeleniumRetriever ctor. can't use username/pw until prev ctors are complete
if (!IsLoggedIn)
throw new Exception("not logged in");
}
/// <summary>Use current user data/chrome cookies. DO NOT use if chrome is already open</summary>
protected override ChromeOptions ctorCreateChromeOptions()
{
var options = base.ctorCreateChromeOptions();
// load user data incl cookies. default on windows:
// %LOCALAPPDATA%\Google\Chrome\User Data
// C:\Users\username\AppData\Local\Google\Chrome\User Data
var chromeDefaultWindowsUserDataDir = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Google",
"Chrome",
"User Data");
options.AddArguments($"user-data-dir={chromeDefaultWindowsUserDataDir}");
return options;
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AudibleDotCom;
namespace AudibleDotComAutomation
{
public interface IPageRetriever : IDisposable
{
Task<IEnumerable<AudiblePageSource>> GetPageSourcesAsync(AudiblePageType audiblePage, string pageId = null);
}
}

View File

@@ -1,115 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
namespace AudibleDotComAutomation.Examples
{
public class SeleniumExamples
{
public IWebDriver Driver { get; set; }
IWebElement GetListenerPageLink()
{
var listenerPageElement = Driver.FindElements(By.XPath("//a[contains(@href, '/review-by-author')]"));
if (listenerPageElement.Count > 0)
return listenerPageElement[0];
return null;
}
void wait_examples()
{
new WebDriverWait(Driver, TimeSpan.FromSeconds(60))
.Until(ExpectedConditions.ElementIsVisible(By.Id("mast-member-acct-name")));
new WebDriverWait(Driver, TimeSpan.FromSeconds(60))
.Until(d => GetListenerPageLink());
// https://stackoverflow.com/questions/21339339/how-to-add-custom-expectedconditions-for-selenium
new WebDriverWait(Driver, TimeSpan.FromSeconds(60))
.Until((d) =>
{
// could be refactored into OR, AND per the java selenium library
// check 1
var e1 = Driver.FindElements(By.Id("mast-member-acct-name"));
if (e1.Count > 0)
return e1[0];
// check 2
var e2 = Driver.FindElements(By.Id("header-account-info-0"));
if (e2.Count > 0)
return e2[0];
return null;
});
}
void XPath_examples()
{
// <tr>
// <td>1</td>
// <td>2</td>
// </tr>
// <tr>
// <td>3</td>
// <td>4</td>
// </tr>
ReadOnlyCollection<IWebElement> all_tr = Driver.FindElements(By.XPath("/tr"));
IWebElement first_tr = Driver.FindElement(By.XPath("/tr"));
IWebElement second_tr = Driver.FindElement(By.XPath("/tr[2]"));
// beginning with a single / starts from root
IWebElement ERROR_not_at_root = Driver.FindElement(By.XPath("/td"));
// 2 slashes searches all, NOT just descendants
IWebElement td1 = Driver.FindElement(By.XPath("//td"));
// 2 slashes still searches all, NOT just descendants
IWebElement still_td1 = first_tr.FindElement(By.XPath("//td"));
// dot operator starts from current node specified by first_tr
// single slash: immediate descendant
IWebElement td3 = first_tr.FindElement(By.XPath(
".//td"));
// double slash: descendant at any depth
IWebElement td3_also = first_tr.FindElement(By.XPath(
"./td"));
// <input type="hidden" name="asin" value="ABCD1234">
IWebElement find_anywhere_in_doc = first_tr.FindElement(By.XPath(
"//input[@name='asin']"));
IWebElement find_in_subsection = first_tr.FindElement(By.XPath(
".//input[@name='asin']"));
// search entire page. useful for:
// - RulesLocator to find something that only appears once on the page
// - non-list pages. eg: product details
var onePerPageRules = new RuleFamily
{
RowsLocator = By.XPath("/*"), // search entire page
Rules = new RuleSet {
(row, productItem) => productItem.CustomerId = row.FindElement(By.XPath("//input[@name='cust_id']")).GetValue(),
(row, productItem) => productItem.UserName = row.FindElement(By.XPath("//input[@name='user_name']")).GetValue()
}
};
// - applying conditionals to entire page
var ruleFamily = new RuleFamily
{
RowsLocator = By.XPath("//*[starts-with(@id,'adbl-library-content-row-')]"),
// Rules = getRuleSet()
};
}
#region Rules classes stubs
public class RuleFamily { public By RowsLocator; public IRuleClass Rules; }
public interface IRuleClass { }
public class RuleSet : IRuleClass, IEnumerable<IRuleClass>
{
public void Add(IRuleClass ruleClass) { }
public void Add(RuleAction action) { }
public IEnumerator<IRuleClass> GetEnumerator() => throw new NotImplementedException();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
public delegate void RuleAction(IWebElement row, ProductItem productItem);
public class ProductItem { public string CustomerId; public string UserName; }
#endregion
}
}

View File

@@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
namespace AudibleDotComAutomation
{
public static class IWebElementExt
{
// allows getting Text from elements even if hidden
// this only works on visible elements: webElement.Text
// http://yizeng.me/2014/04/08/get-text-from-hidden-elements-using-selenium-webdriver/#c-sharp
//
public static string GetText(this IWebElement webElement) => webElement.GetAttribute("textContent");
public static string GetValue(this IWebElement webElement) => webElement.GetAttribute("value");
}
public static class IWebDriverExt
{
/// <summary>Use this instead of element.Click() to ensure that the element is clicked even if it's not currently scrolled into view</summary>
public static void Click(this IWebDriver driver, IWebElement element)
{
// from: https://stackoverflow.com/questions/12035023/selenium-webdriver-cant-click-on-a-link-outside-the-page
//// this works but isn't really the same
//element.SendKeys(Keys.Enter);
//// didn't work for me
//new Actions(driver)
// .MoveToElement(element)
// .Click()
// .Build()
// .Perform();
driver.ScrollIntoView(element);
element.Click();
}
public static void ScrollIntoView(this IWebDriver driver, IWebElement element)
=> ((IJavaScriptExecutor)driver).ExecuteScript($"window.scroll({element.Location.X}, {element.Location.Y})");
}
}

View File

Binary file not shown.

View File

@@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.112" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileManager\FileManager.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using FileManager;
namespace CookieMonster
{
internal class Chrome : IBrowser
{
public async Task<IEnumerable<CookieValue>> GetAllCookiesAsync()
{
var col = new List<CookieValue>();
var strPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Google\Chrome\User Data\Default\Cookies");
if (!FileUtility.FileExists(strPath))
return col;
//
// IF WE GET AN ERROR HERE
// then add a reference to sqlite core in the project which is ultimately calling this.
// a project which directly references CookieMonster doesn't need to also ref sqlite.
// however, for any further number of abstractions, the project needs to directly ref sqlite.
// eg: this will not work unless the winforms proj adds sqlite to ref.s:
// LibationWinForm > AudibleDotComAutomation > CookieMonster
//
using var conn = new SQLiteConnection("Data Source=" + strPath + ";pooling=false");
using var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT host_key, name, value, encrypted_value, last_access_utc, expires_utc FROM cookies;";
conn.Open();
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
while (reader.Read())
{
var host_key = reader.GetString(0);
var name = reader.GetString(1);
var value = reader.GetString(2);
var last_access_utc = reader.GetInt64(4);
var expires_utc = reader.GetInt64(5);
// https://stackoverflow.com/a/25874366
if (string.IsNullOrWhiteSpace(value))
{
var encrypted_value = (byte[])reader[3];
var decodedData = System.Security.Cryptography.ProtectedData.Unprotect(encrypted_value, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);
value = Encoding.ASCII.GetString(decodedData);
}
try
{
// if something goes wrong in this step (eg: a cookie has an invalid filetime), then just skip this cookie
col.Add(new CookieValue { Browser = "chrome", Domain = host_key, Name = name, Value = value, LastAccess = chromeTimeToDateTimeUtc(last_access_utc), Expires = chromeTimeToDateTimeUtc(expires_utc) });
}
catch { }
}
return col;
}
// Chrome uses 1601-01-01 00:00:00 UTC as the epoch (ie the starting point for the millisecond time counter).
// this is the same as "FILETIME" in Win32 except FILETIME uses 100ns ticks instead of ms.
private static DateTime chromeTimeToDateTimeUtc(long time) => DateTime.SpecifyKind(DateTime.FromFileTime(time * 10), DateTimeKind.Utc);
}
}

View File

@@ -1,61 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Threading.Tasks;
using FileManager;
namespace CookieMonster
{
internal class FireFox : IBrowser
{
public async Task<IEnumerable<CookieValue>> GetAllCookiesAsync()
{
var col = new List<CookieValue>();
string strPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Mozilla\Firefox\Profiles");
if (!FileUtility.FileExists(strPath))
return col;
var dirs = new DirectoryInfo(strPath).GetDirectories("*.default");
if (dirs.Length != 1)
return col;
strPath = Path.Combine(strPath, dirs[0].Name, "cookies.sqlite");
if (!FileUtility.FileExists(strPath))
return col;
// First copy the cookie jar so that we can read the cookies from unlocked copy while FireFox is running
var strTemp = strPath + ".temp";
File.Copy(strPath, strTemp, true);
// Now open the temporary cookie jar and extract Value from the cookie if we find it.
using var conn = new SQLiteConnection("Data Source=" + strTemp + ";pooling=false");
using var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT host, name, value, lastAccessed, expiry FROM moz_cookies; ";
conn.Open();
using var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false);
while (reader.Read())
{
var host_key = reader.GetString(0);
var name = reader.GetString(1);
var value = reader.GetString(2);
var lastAccessed = reader.GetInt32(3);
var expiry = reader.GetInt32(4);
col.Add(new CookieValue { Browser = "firefox", Domain = host_key, Name = name, Value = value, LastAccess = lastAccessedToDateTime(lastAccessed), Expires = expiryToDateTime(expiry) });
}
if (FileUtility.FileExists(strTemp))
File.Delete(strTemp);
return col;
}
// time is in microseconds since unix epoch
private static DateTime lastAccessedToDateTime(int time) => new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(time);
// time is in normal seconds since unix epoch
private static DateTime expiryToDateTime(int time) => new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).AddSeconds(time);
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace CookieMonster
{
internal interface IBrowser
{
Task<IEnumerable<CookieValue>> GetAllCookiesAsync();
}
}

View File

@@ -1,87 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CookieMonster
{
internal class InternetExplorer : IBrowser
{
public async Task<IEnumerable<CookieValue>> GetAllCookiesAsync()
{
// real locations of Windows Cookies folders
//
// Windows 7:
// C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies
// C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies\Low
//
// Windows 8, Windows 8.1, Windows 10:
// C:\Users\username\AppData\Local\Microsoft\Windows\INetCookies
// C:\Users\username\AppData\Local\Microsoft\Windows\INetCookies\Low
var strPath = Environment.GetFolderPath(Environment.SpecialFolder.Cookies);
var col = (await getIECookiesAsync(strPath).ConfigureAwait(false)).ToList();
col = col.Concat(await getIECookiesAsync(Path.Combine(strPath, "Low"))).ToList();
return col;
}
private static async Task<IEnumerable<CookieValue>> getIECookiesAsync(string strPath)
{
var cookies = new List<CookieValue>();
var files = await Task.Run(() => Directory.EnumerateFiles(strPath, "*.txt"));
foreach (string path in files)
{
var cookiesInFile = new List<CookieValue>();
var cookieLines = File.ReadAllLines(path);
CookieValue currCookieVal = null;
for (var i = 0; i < cookieLines.Length; i++)
{
var line = cookieLines[i];
// IE cookie format
// 0 Cookie name
// 1 Cookie value
// 2 Host / path for the web server setting the cookie
// 3 Flags
// 4 Expiration time (low int)
// 5 Expiration time (high int)
// 6 Creation time (low int)
// 7 Creation time (high int)
// 8 Record delimiter == "*"
var pos = i % 9;
long expLoTemp = 0;
long creatLoTemp = 0;
if (pos == 0)
{
currCookieVal = new CookieValue { Browser = "ie", Name = line };
cookiesInFile.Add(currCookieVal);
}
else if (pos == 1)
currCookieVal.Value = line;
else if (pos == 2)
currCookieVal.Domain = line;
else if (pos == 4)
expLoTemp = Int64.Parse(line);
else if (pos == 5)
currCookieVal.Expires = LoHiToDateTime(expLoTemp, Int64.Parse(line));
else if (pos == 6)
creatLoTemp = Int64.Parse(line);
else if (pos == 7)
currCookieVal.LastAccess = LoHiToDateTime(creatLoTemp, Int64.Parse(line));
}
cookies.AddRange(cookiesInFile);
}
return cookies;
}
private static DateTime LoHiToDateTime(long lo, long hi) => DateTime.FromFileTimeUtc(((hi << 32) + lo));
}
}

View File

@@ -1,32 +0,0 @@
using System;
namespace CookieMonster
{
public class CookieValue
{
public string Browser { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public string Domain { get; set; }
public DateTime LastAccess { get; set; }
public DateTime Expires { get; set; }
public bool IsValid
{
get
{
// sanity check. datetimes are stored weird in each cookie type. make sure i haven't converted these incredibly wrong.
// some early conversion attempts produced years like 42, 1955, 4033
var _5yearsPast = DateTime.UtcNow.AddYears(-5);
if (LastAccess < _5yearsPast || LastAccess > DateTime.UtcNow)
return false;
// don't check expiry. some sites are setting stupid values for year. eg: 9999
return true;
}
}
public bool HasExpired => Expires < DateTime.UtcNow;
}
}

View File

@@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dinah.Core.Collections.Generic;
namespace CookieMonster
{
public static class CookiesHelper
{
internal static IEnumerable<IBrowser> GetBrowsers()
=> AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => typeof(IBrowser).IsAssignableFrom(p) && !p.IsAbstract && !p.IsInterface)
.Select(t => Activator.CreateInstance(t) as IBrowser)
.ToList();
/// <summary>all. including expired</summary>
public static async Task<IEnumerable<CookieValue>> GetAllCookieValuesAsync()
{
//// foreach{await} runs in serial
//var allCookies = new List<CookieValue>();
//foreach (var b in GetBrowsers())
//{
// var browserCookies = await b.GetAllCookiesAsync().ConfigureAwait(false);
// allCookies.AddRange(browserCookies);
//}
//// WhenAll runs in parallel
// this 1st step LOOKS like a bug which runs each method until completion. However, since we don't use await, it's actually returning a Task. That resulting task is awaited asynchronously
var browserTasks = GetBrowsers().Select(b => b.GetAllCookiesAsync());
var results = await Task.WhenAll(browserTasks).ConfigureAwait(false);
var allCookies = results.SelectMany(a => a).ToList();
if (allCookies.Any(c => !c.IsValid))
throw new Exception("some date time was converted way too far");
foreach (var c in allCookies)
c.Domain = c.Domain.TrimEnd('/');
// for each domain+name, only keep the 1 with the most recent access
var sortedCookies = allCookies
.OrderByDescending(c => c.LastAccess)
.DistinctBy(c => new { c.Domain, c.Name })
.ToList();
return sortedCookies;
}
/// <summary>not expired</summary>
public static async Task<IEnumerable<CookieValue>> GetLiveCookieValuesAsync()
=> (await GetAllCookieValuesAsync().ConfigureAwait(false))
.Where(c => !c.HasExpired)
.ToList();
}
}

View File

@@ -32,6 +32,7 @@
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>

View File

@@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DataLayer.Migrations
{
[DbContext(typeof(LibationContext))]
[Migration("20191007202808_UpgradeToCore3")]
partial class UpgradeToCore3
[Migration("20191115193402_Fresh")]
partial class Fresh
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@@ -40,9 +40,6 @@ namespace DataLayer.Migrations
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<bool>("HasBookDetails")
.HasColumnType("bit");
b.Property<bool>("IsAbridged")
.HasColumnType("bit");
@@ -148,9 +145,6 @@ namespace DataLayer.Migrations
b.Property<DateTime>("DateAdded")
.HasColumnType("datetime2");
b.Property<string>("DownloadBookLink")
.HasColumnType("nvarchar(max)");
b.HasKey("BookId");
b.ToTable("Library");

View File

@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace DataLayer.Migrations
{
public partial class UpgradeToCore3 : Migration
public partial class Fresh : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@@ -67,7 +67,6 @@ namespace DataLayer.Migrations
Description = table.Column<string>(nullable: true),
LengthInMinutes = table.Column<int>(nullable: false),
PictureId = table.Column<string>(nullable: true),
HasBookDetails = table.Column<bool>(nullable: false),
IsAbridged = table.Column<bool>(nullable: false),
DatePublished = table.Column<DateTime>(nullable: true),
CategoryId = table.Column<int>(nullable: false),
@@ -117,8 +116,7 @@ namespace DataLayer.Migrations
columns: table => new
{
BookId = table.Column<int>(nullable: false),
DateAdded = table.Column<DateTime>(nullable: false),
DownloadBookLink = table.Column<string>(nullable: true)
DateAdded = table.Column<DateTime>(nullable: false)
},
constraints: table =>
{

View File

@@ -38,9 +38,6 @@ namespace DataLayer.Migrations
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<bool>("HasBookDetails")
.HasColumnType("bit");
b.Property<bool>("IsAbridged")
.HasColumnType("bit");
@@ -146,9 +143,6 @@ namespace DataLayer.Migrations
b.Property<DateTime>("DateAdded")
.HasColumnType("datetime2");
b.Property<string>("DownloadBookLink")
.HasColumnType("nvarchar(max)");
b.HasKey("BookId");
b.ToTable("Library");

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
namespace DataLayer
{
public static class RemoveOrphansCommand
{
public static int RemoveOrphans(this LibationContext context)
=> context.Database.ExecuteSqlRaw(@"
delete c
from Contributors c
left join BookContributor bc on c.ContributorId = bc.ContributorId
left join Books b on bc.BookId = b.BookId
where bc.ContributorId is null
");
}
}

View File

@@ -30,7 +30,6 @@ namespace DataLayer
public string PictureId { get; set; }
// book details
public bool HasBookDetails { get; private set; }
public bool IsAbridged { get; private set; }
public DateTime? DatePublished { get; private set; }
@@ -231,8 +230,6 @@ namespace DataLayer
// don't overwrite with default values
IsAbridged |= isAbridged;
DatePublished = datePublished ?? DatePublished;
HasBookDetails = true;
}
public void UpdateCategory(Category category, DbContext context = null)

View File

@@ -10,18 +10,12 @@ namespace DataLayer
public DateTime DateAdded { get; private set; }
/// <summary>For downloading AAX file</summary>
public string DownloadBookLink { get; private set; }
private LibraryBook() { }
public LibraryBook(Book book, DateTime dateAdded
, string downloadBookLink = null
)
public LibraryBook(Book book, DateTime dateAdded)
{
ArgumentValidator.EnsureNotNull(book, nameof(book));
Book = book;
DateAdded = dateAdded;
DownloadBookLink = downloadBookLink;
}
}
}

View File

@@ -6,6 +6,9 @@ namespace DataLayer
public class LibationContextFactory : DesignTimeDbContextFactoryBase<LibationContext>
{
protected override LibationContext CreateNewInstance(DbContextOptions<LibationContext> options) => new LibationContext(options);
protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder.UseSqlServer(connectionString);
protected override void UseDatabaseEngine(DbContextOptionsBuilder optionsBuilder, string connectionString) => optionsBuilder
//.UseSqlServer
.UseSqlite
(connectionString);
}
}

View File

@@ -8,14 +8,6 @@ namespace DataLayer
{
public static class BookQueries
{
public static int BooksWithoutDetailsCount()
{
using var context = LibationContext.Create();
return context
.Books
.Count(b => !b.HasBookDetails);
}
public static Book GetBook_Flat_NoTracking(string productId)
{
using var context = LibationContext.Create();

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DataLayer.Utilities
{
public static class LocalDatabaseInfo
{
public static List<string> GetLocalDBInstances()
{
// Start the child process.
using var p = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = "cmd.exe",
Arguments = "/C sqllocaldb info",
CreateNoWindow = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
}
};
p.Start();
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
// if LocalDb is not installed then it will return that 'sqllocaldb' is not recognized as an internal or external command operable program or batch file
return string.IsNullOrWhiteSpace(output) || output.Contains("not recognized")
? new List<string>()
: output
.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)
.Select(i => i.Trim())
.Where(i => !string.IsNullOrEmpty(i))
.ToList();
}
}
}

View File

@@ -1,6 +1,5 @@
HOW TO CREATE: EF CORE PROJECT
==============================
easiest with .NET Core but there's also a work-around for .NET Standard
example is for sqlite but the same works with MsSql
@@ -26,7 +25,6 @@ set project "Set as StartUp Project"
Tools >> Nuget Package Manager >> Package Manager Console
default project: Examples\SQLite_NETCore2_0
note: in EFCore, Enable-Migrations is no longer used. start with add-migration
PM> add-migration InitialCreate
PM> Update-Database

View File

@@ -1,55 +0,0 @@
proposed extensible schema to generalize beyond audible
problems
0) reeks of premature optimization
- i'm currently only doing audible audiobooks. this adds several layers of abstraction for the sake of possible expansion
- there's a good chance that supporting another platform may not conform to this schema, in which case i'd have done this for nothing. genres are one likely pain point
- libation is currently single-user. hopefully the below would suffice for adding users, but if i'm wrong it might be all pain and no gain
1) very thorough == very complex
2) there are some books which would still be difficult to taxonimize
- joy of cooking. has become more of a brand
- the bible. has different versions that aren't just editions
- dictionary. authored by a publisher
3) "books" vs "editions" is a confusing problem waiting to happen
[AIPK=auto increm PK]
(libation) users [AIPK id, name, join date]
audible users [AIPK id, AUDIBLE-PK username]
libation audible users [PK user id, PK audible user id -- cluster PK across all FKs]
- potential danger in multi-user environment. wouldn't want one libation user getting access to a different libation user's audible info
contributors [AIPK id, name]. prev people. incl publishers
audible authors [PK/FK contributor id, AUDIBLE-PK author id]
roles [AIPK id, name]. seeded: author, narrator, publisher. could expand (eg: translator, editor) without each needing a new table
books [AIPK id, title, desc]
book contributors [FK book id, FK contributor id, FK role id, order -- cluster PK across all FKs]
- likely only authors
editions [AIPK id, FK book id, title]. could expand to include year, is first edition, is abridged
- reasons for optional different title: "Ender's Game: Special 20th Anniversary Edition", "Harry Potter and the Sorcerer's Stone" vs "Harry Potter and the Philosopher's Stone" vs "Harry Potter y la piedra filosofal", "Midnight Riot" vs "Rivers of London"
edition contributors [FK edition id, FK contributor id, FK role id, order -- cluster PK across all FKs]
- likely everything except authors. eg narrators, publisher
audiobooks [PK/FK edition id, lengthInMinutes]
- could expand to other formats by adding other similar tables. eg: print with #pages and isbn, ebook with mb
audible origins [AIPK id, name]. seeded: library. detail. json. series
audible books [PK/FK edition id, AUDIBLE-PK product id, picture id, sku, 3 ratings, audible category id, audible origin id]
- could expand to other vendors by adding other similar tables
audible user ratings [PK/FK edition id, audible user id, 3 ratings]
audible supplements [AIPK id, FK edition id, download url]
- pdfs only. although book download info could be the same format, they're substantially different and subject to change
audible book downloads [PK/FK edition id, audible user id, bookdownloadlink]
pictures [AIPK id, FK edition id, filename (xyz.jpg -- not incl path)]
audible categories [AIPK id, AUDIBLE-PK category id, name, parent]. may only nest 1 deep
(libation) library [FK libation user id, FK edition id, date added -- cluster PK across all FKs]
(libation) user defined [FK libation user id, FK edition id, tagsRaw (, notes...) -- cluster PK across all FKs]
- there's no reason to restrict tags to library items, so don't combine/link this table with library
series [AIPK id, name]
audible series [FK series id, AUDIBLE-PK series id/asin, audible origin id]
- could also include a 'name' field for what audible calls this series
series books [FK series id, FK book id (NOT edition id), index -- cluster PK across all FKs]
- "index" not "order". display this number; don't just put in this sequence
- index is float instead of int to allow for in-between books. eg 2.5
- if only using "editions" (ie: getting rid of the "books" table), to show 2 editions as the same book in a series, give them the same index
(libation) user shelves [AIPK id, FK libation user id, name, desc]
- custom shelf. similar to library but very different in philosophy. likely different in evolving details
(libation) shelf books [AIPK id, FK user shelf id, date added, order]
- technically, it's no violation to list a book more than once so use AIPK

View File

@@ -1,76 +0,0 @@
ignore for now:
authorProperties [PK/FK contributor id, AUDIBLE-PK author id]
notes in Contributor.cs for later refactoring
c# enum only, not their own tables:
roles [AIPK id, name]. seeded: author, narrator, publisher. could expand (eg: translator, editor) without each needing a new table
origins [AIPK id, name]. seeded: library. detail. json. series
-- begin SCHEMA ---------------------------------------------------------------------------------------------------------------------
any audible keys should be indexed
SCHEMA
======
contributors [AIPK id, name]. people and publishers
books [AIPK id, AUDIBLE-PK product id, title, desc, lengthInMinutes, picture id, 3 ratings, category id, origin id]
- product instances. each edition and version is discrete: unique and disconnected from different editions of the same book
- on book re-import
update:
update book origin and series origin with the new source type
overwrite simple fields
invoke complex contributor updates
details page gets
un/abridged
release date
language
publisher
series info incl name
categories
if new == series: ignore. do update series info. do not update book info
else if old == json: update (incl if new == json)
else if old == library && new == detail: update
else: ignore
book contributors [FK book id, FK contributor id, FK role id, order -- cluster PK across all FKs]
supplements [AIPK id, FK book id, download url]
categories [AIPK id, AUDIBLE-PK category id, name, parent]. may only nest 1 deep
user defined [PK/FK book id, 3 ratings, tagsRaw]
series [AIPK id, AUDIBLE-PK series id/asin, name, origin id]
series books [FK series id, FK book id, index -- cluster PK across all FKs]
- "index" not "order". display this number; don't just put in this sequence
- index is float instead of int to allow for in-between books. eg 2.5
- to show 2 editions as the same book in a series, give them the same index
- re-import using series page, there will need to be a re-eval of import logic
library [PK/FK book id, date added, bookdownloadlink]
-- end SCHEMA ---------------------------------------------------------------------------------------------------------------------
-- begin SIMPLIFIED DDD ---------------------------------------------------------------------------------------------------------------------
combine domain and persistence (C(r)UD). no repository pattern. encapsulated in domain objects; direct calls to EF Core
https://www.thereformedprogrammer.net/creating-domain-driven-design-entity-classes-with-entity-framework-core/
// pattern for x-to-many
public void AddReview(int numStars, DbContext context = null)
{
if (_reviews != null) _reviews.Add(new Review(numStars));
else if (context == null) throw new Exception("need context");
else if (context.Entry(this).IsKeySet) context.Add(new Review(numStars, BookId));
else throw new Exception("Could not add");
}
// pattern for optional one-to-one
MyPropClass MyProps { get; private set; }
public void AddMyProps(string s, int i, DbContext context = null)
{
// avoid a trip to the db
if (MyProps != null) { MyProps.Update(s, i); return; }
if (BookId == 0) { MyProps = new MyPropClass(s, i); return; }
if (context == null) throw new Exception("need context");
// per Jon P Smith, this single trip to db loads the property if there is one
// note: .Reference() is for single object references. for collections use .Collection()
context.Entry(this).Reference(s => s.MyProps).Load();
if (MyProps != null) MyProps.Update(s, i);
else MyProps = new MyPropClass(s, i);
}
repository reads are 'query object'-like extension methods
https://www.thereformedprogrammer.net/is-the-repository-pattern-useful-with-entity-framework-core/#1-query-objects-a-way-to-isolate-and-hide-database-read-code
-- and SIMPLIFIED DDD ---------------------------------------------------------------------------------------------------------------------

View File

@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"LibationContext": "Server=(LocalDb)\\MSSQLLocalDB;Database=DataLayer.LibationContext;Integrated Security=true;",
"LibationContext_sqlserver": "Server=(LocalDb)\\MSSQLLocalDB;Database=DataLayer.LibationContext;Integrated Security=true;",
"LibationContext": "Data Source=LibationContext.db;Foreign Keys=False;",
"// on windows sqlite paths accept windows and/or unix slashes": "",
"MyTestContext": "Data Source=%DESKTOP%/sample.db"

View File

@@ -28,10 +28,7 @@ namespace DtoImporterService
{
var libraryBook = new LibraryBook(
context.Books.Local.Single(b => b.AudibleProductId == newItem.ProductId),
newItem.DateAdded
// needed for scraping
//,FileManager.FileUtility.RestoreDeclawed(newLibraryDTO.DownloadBookLink)
);
newItem.DateAdded);
context.Library.Add(libraryBook);
}

View File

@@ -5,10 +5,11 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Dinah.Core\Dinah.Core\Dinah.Core.csproj" />
<ProjectReference Include="..\AaxDecrypter\AaxDecrypter.csproj" />
<ProjectReference Include="..\ApplicationService\ApplicationService.csproj" />
<ProjectReference Include="..\AudibleDotComAutomation\AudibleDotComAutomation.csproj" />
<ProjectReference Include="..\ApplicationServices\ApplicationServices.csproj" />
<ProjectReference Include="..\DataLayer\DataLayer.csproj" />
<ProjectReference Include="..\FileManager\FileManager.csproj" />
<ProjectReference Include="..\InternalUtilities\InternalUtilities.csproj" />
</ItemGroup>

View File

@@ -0,0 +1,76 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.ErrorHandling;
using FileManager;
namespace FileLiberator
{
/// <summary>
/// Download DRM book and decrypt audiobook files
///
/// Processes:
/// Download: download aax file: the DRM encrypted audiobook
/// Decrypt: remove DRM encryption from audiobook. Store final book
/// Backup: perform all steps (downloaded, decrypt) still needed to get final book
/// </summary>
public class BackupBook : IProcessable
{
public event EventHandler<string> Begin;
public event EventHandler<string> StatusUpdate;
public event EventHandler<string> Completed;
public DownloadBook DownloadBook { get; } = new DownloadBook();
public DecryptBook DecryptBook { get; } = new DecryptBook();
public DownloadPdf DownloadPdf { get; } = new DownloadPdf();
// ValidateAsync() doesn't need UI context
public async Task<bool> ValidateAsync(LibraryBook libraryBook)
=> await validateAsync_ConfigureAwaitFalse(libraryBook.Book.AudibleProductId).ConfigureAwait(false);
private async Task<bool> validateAsync_ConfigureAwaitFalse(string productId)
=> !await AudibleFileStorage.Audio.ExistsAsync(productId);
// do NOT use ConfigureAwait(false) on ProcessAsync()
// often calls events which prints to forms in the UI context
public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
{
var productId = libraryBook.Book.AudibleProductId;
var displayMessage = $"[{productId}] {libraryBook.Book.Title}";
Begin?.Invoke(this, displayMessage);
try
{
{
var statusHandler = await processAsync(libraryBook, AudibleFileStorage.AAX, DownloadBook);
if (statusHandler.HasErrors)
return statusHandler;
}
{
var statusHandler = await processAsync(libraryBook, AudibleFileStorage.Audio, DecryptBook);
if (statusHandler.HasErrors)
return statusHandler;
}
{
var statusHandler = await processAsync(libraryBook, AudibleFileStorage.PDF, DownloadPdf);
if (statusHandler.HasErrors)
return statusHandler;
}
return new StatusHandler();
}
finally
{
Completed?.Invoke(this, displayMessage);
}
}
private static async Task<StatusHandler> processAsync(LibraryBook libraryBook, AudibleFileStorage afs, IProcessable processable)
=> !await afs.ExistsAsync(libraryBook.Book.AudibleProductId)
? await processable.ProcessAsync(libraryBook)
: new StatusHandler();
}
}

View File

@@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AaxDecrypter;
using DataLayer;
using Dinah.Core;
using Dinah.Core.ErrorHandling;
using FileManager;
namespace FileLiberator
{
/// <summary>
/// Decrypt audiobook files
///
/// Processes:
/// Download: download aax file: the DRM encrypted audiobook
/// Decrypt: remove DRM encryption from audiobook. Store final book
/// Backup: perform all steps (downloaded, decrypt) still needed to get final book
/// </summary>
public class DecryptBook : IDecryptable
{
public event EventHandler<string> Begin;
public event EventHandler<string> StatusUpdate;
public event EventHandler<string> DecryptBegin;
public event EventHandler<string> TitleDiscovered;
public event EventHandler<string> AuthorsDiscovered;
public event EventHandler<string> NarratorsDiscovered;
public event EventHandler<byte[]> CoverImageFilepathDiscovered;
public event EventHandler<int> UpdateProgress;
public event EventHandler<string> DecryptCompleted;
public event EventHandler<string> Completed;
// ValidateAsync() doesn't need UI context
public async Task<bool> ValidateAsync(LibraryBook libraryBook)
=> await validateAsync_ConfigureAwaitFalse(libraryBook.Book.AudibleProductId).ConfigureAwait(false);
private async Task<bool> validateAsync_ConfigureAwaitFalse(string productId)
=> await AudibleFileStorage.AAX.ExistsAsync(productId)
&& !await AudibleFileStorage.Audio.ExistsAsync(productId);
// do NOT use ConfigureAwait(false) on ProcessAsync()
// often calls events which prints to forms in the UI context
public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
{
var displayMessage = $"[{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}";
Begin?.Invoke(this, displayMessage);
try
{
var aaxFilename = await AudibleFileStorage.AAX.GetAsync(libraryBook.Book.AudibleProductId);
if (aaxFilename == null)
return new StatusHandler { "aaxFilename parameter is null" };
if (!FileUtility.FileExists(aaxFilename))
return new StatusHandler { $"Cannot find AAX file: {aaxFilename}" };
if (await AudibleFileStorage.Audio.ExistsAsync(libraryBook.Book.AudibleProductId))
return new StatusHandler { "Cannot find decrypt. Final audio file already exists" };
var proposedOutputFile = Path.Combine(AudibleFileStorage.DecryptInProgress, $"[{libraryBook.Book.AudibleProductId}].m4b");
var outputAudioFilename = await aaxToM4bConverterDecrypt(proposedOutputFile, aaxFilename);
// decrypt failed
if (outputAudioFilename == null)
return new StatusHandler { "Decrypt failed" };
moveFilesToBooksDir(libraryBook.Book, outputAudioFilename);
Dinah.Core.IO.FileExt.SafeDelete(aaxFilename);
var statusHandler = new StatusHandler();
var finalAudioExists = await AudibleFileStorage.Audio.ExistsAsync(libraryBook.Book.AudibleProductId);
if (!finalAudioExists)
statusHandler.AddError("Cannot find final audio file after decryption");
return statusHandler;
}
finally
{
Completed?.Invoke(this, displayMessage);
}
}
private async Task<string> aaxToM4bConverterDecrypt(string proposedOutputFile, string aaxFilename)
{
DecryptBegin?.Invoke(this, $"Begin decrypting {aaxFilename}");
try
{
var converter = await AaxToM4bConverter.CreateAsync(aaxFilename, Configuration.Instance.DecryptKey);
converter.AppName = "Libation";
TitleDiscovered?.Invoke(this, converter.tags.title);
AuthorsDiscovered?.Invoke(this, converter.tags.author);
NarratorsDiscovered?.Invoke(this, converter.tags.narrator);
CoverImageFilepathDiscovered?.Invoke(this, converter.coverBytes);
converter.SetOutputFilename(proposedOutputFile);
converter.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress);
// REAL WORK DONE HERE
var success = await Task.Run(() => converter.Run());
if (!success)
{
Console.WriteLine("decrypt failed");
return null;
}
Configuration.Instance.DecryptKey = converter.decryptKey;
return converter.outputFileName;
}
finally
{
DecryptCompleted?.Invoke(this, $"Completed decrypting {aaxFilename}");
}
}
private static void moveFilesToBooksDir(Book product, string outputAudioFilename)
{
// files are: temp path\author\[asin].ext
var m4bDir = new FileInfo(outputAudioFilename).Directory;
var files = m4bDir
.EnumerateFiles()
.Where(f => f.Name.ContainsInsensitive(product.AudibleProductId))
.ToList();
// create final directory. move each file into it. MOVE AUDIO FILE LAST
// new dir: safetitle_limit50char + " [" + productId + "]"
// to prevent the paths from getting too long, we don't need after the 1st ":" for the folder
var underscoreIndex = product.Title.IndexOf(':');
var titleDir = (underscoreIndex < 4) ? product.Title : product.Title.Substring(0, underscoreIndex);
var finalDir = FileUtility.GetValidFilename(AudibleFileStorage.BooksDirectory, titleDir, null, product.AudibleProductId);
Directory.CreateDirectory(finalDir);
// move audio files to the end of the collection so these files are moved last
var musicFiles = files.Where(f => AudibleFileStorage.Audio.IsFileTypeMatch(f));
files = files
.Except(musicFiles)
.Concat(musicFiles)
.ToList();
var musicFileExt = musicFiles
.Select(f => f.Extension)
.Distinct()
.Single()
.Trim('.');
foreach (var f in files)
{
var dest = AudibleFileStorage.Audio.IsFileTypeMatch(f)
// audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext
? FileUtility.GetValidFilename(finalDir, product.Title, musicFileExt, product.AudibleProductId)
// non-audio filename: safetitle_limit50char + " [" + productId + "][" + audio_ext +"]." + non_audio_ext
: FileUtility.GetValidFilename(finalDir, product.Title, f.Extension, product.AudibleProductId, musicFileExt);
File.Move(f.FullName, dest);
}
}
}
}

View File

@@ -0,0 +1,66 @@
using System;
using System.IO;
using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.ErrorHandling;
using FileManager;
namespace FileLiberator
{
/// <summary>
/// Download DRM book
///
/// Processes:
/// Download: download aax file: the DRM encrypted audiobook
/// Decrypt: remove DRM encryption from audiobook. Store final book
/// Backup: perform all steps (downloaded, decrypt) still needed to get final book
/// </summary>
public class DownloadBook : DownloadableBase
{
public override async Task<bool> ValidateAsync(LibraryBook libraryBook)
=> !await AudibleFileStorage.Audio.ExistsAsync(libraryBook.Book.AudibleProductId)
&& !await AudibleFileStorage.AAX.ExistsAsync(libraryBook.Book.AudibleProductId);
public override async Task<StatusHandler> ProcessItemAsync(LibraryBook libraryBook)
{
var tempAaxFilename = getDownloadPath(libraryBook);
var actualFilePath = await downloadBookAsync(libraryBook, tempAaxFilename);
moveBook(libraryBook, actualFilePath);
return await verifyDownloadAsync(libraryBook);
}
private static string getDownloadPath(LibraryBook libraryBook)
=> FileUtility.GetValidFilename(
AudibleFileStorage.DownloadsInProgress,
libraryBook.Book.Title,
"aax",
libraryBook.Book.AudibleProductId);
private async Task<string> downloadBookAsync(LibraryBook libraryBook, string tempAaxFilename)
{
var api = await AudibleApi.EzApiCreator.GetApiAsync(AudibleApiStorage.IdentityTokensFile);
var actualFilePath = await PerformDownloadAsync(
tempAaxFilename,
(p) => api.DownloadAaxWorkaroundAsync(libraryBook.Book.AudibleProductId, tempAaxFilename, p));
return actualFilePath;
}
private void moveBook(LibraryBook libraryBook, string actualFilePath)
{
var newAaxFilename = FileUtility.GetValidFilename(
AudibleFileStorage.DownloadsFinal,
libraryBook.Book.Title,
"aax",
libraryBook.Book.AudibleProductId);
File.Move(actualFilePath, newAaxFilename);
Invoke_StatusUpdate($"Successfully downloaded. Moved to: {newAaxFilename}");
}
private static async Task<StatusHandler> verifyDownloadAsync(LibraryBook libraryBook)
=> !await AudibleFileStorage.AAX.ExistsAsync(libraryBook.Book.AudibleProductId)
? new StatusHandler { "Downloaded AAX file cannot be found" }
: new StatusHandler();
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.ErrorHandling;
using Dinah.Core.Net.Http;
using FileManager;
namespace FileLiberator
{
public class DownloadPdf : DownloadableBase
{
public override async Task<bool> ValidateAsync(LibraryBook libraryBook)
{
if (string.IsNullOrWhiteSpace(getdownloadUrl(libraryBook)))
return false;
return !await AudibleFileStorage.PDF.ExistsAsync(libraryBook.Book.AudibleProductId);
}
private static string getdownloadUrl(LibraryBook libraryBook)
=> libraryBook?.Book?.Supplements?.FirstOrDefault()?.Url;
public override async Task<StatusHandler> ProcessItemAsync(LibraryBook libraryBook)
{
var proposedDownloadFilePath = await getProposedDownloadFilePathAsync(libraryBook);
await downloadPdfAsync(libraryBook, proposedDownloadFilePath);
return await verifyDownloadAsync(libraryBook);
}
private static async Task<string> getProposedDownloadFilePathAsync(LibraryBook libraryBook)
{
// if audio file exists, get it's dir. else return base Book dir
var destinationDir =
// this is safe b/c GetDirectoryName(null) == null
Path.GetDirectoryName(await AudibleFileStorage.Audio.GetAsync(libraryBook.Book.AudibleProductId))
?? AudibleFileStorage.PDF.StorageDirectory;
return Path.Combine(destinationDir, Path.GetFileName(getdownloadUrl(libraryBook)));
}
private async Task downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath)
{
var client = new HttpClient();
var actualDownloadedFilePath = await PerformDownloadAsync(
proposedDownloadFilePath,
(p) => client.DownloadFileAsync(getdownloadUrl(libraryBook), proposedDownloadFilePath, p));
}
private static async Task<StatusHandler> verifyDownloadAsync(LibraryBook libraryBook)
=> !await AudibleFileStorage.PDF.ExistsAsync(libraryBook.Book.AudibleProductId)
? new StatusHandler { "Downloaded PDF cannot be found" }
: new StatusHandler();
}
}

View File

@@ -0,0 +1,63 @@
using System;
using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.ErrorHandling;
using Dinah.Core.Net.Http;
namespace FileLiberator
{
public abstract class DownloadableBase : IDownloadable
{
public event EventHandler<string> Begin;
public event EventHandler<string> Completed;
public event EventHandler<string> DownloadBegin;
public event EventHandler<DownloadProgress> DownloadProgressChanged;
public event EventHandler<string> DownloadCompleted;
public event EventHandler<string> StatusUpdate;
protected void Invoke_StatusUpdate(string message) => StatusUpdate?.Invoke(this, message);
public abstract Task<bool> ValidateAsync(LibraryBook libraryBook);
public abstract Task<StatusHandler> ProcessItemAsync(LibraryBook libraryBook);
// do NOT use ConfigureAwait(false) on ProcessAsync()
// often calls events which prints to forms in the UI context
public async Task<StatusHandler> ProcessAsync(LibraryBook libraryBook)
{
var displayMessage = $"[{libraryBook.Book.AudibleProductId}] {libraryBook.Book.Title}";
Begin?.Invoke(this, displayMessage);
try
{
return await ProcessItemAsync(libraryBook);
}
finally
{
Completed?.Invoke(this, displayMessage);
}
}
protected async Task<string> PerformDownloadAsync(string proposedDownloadFilePath, Func<Progress<DownloadProgress>, Task<string>> func)
{
var progress = new Progress<DownloadProgress>();
progress.ProgressChanged += (_, e) => DownloadProgressChanged?.Invoke(this, e);
DownloadBegin?.Invoke(this, proposedDownloadFilePath);
try
{
var result = await func(progress);
StatusUpdate?.Invoke(this, result);
return result;
}
finally
{
DownloadCompleted?.Invoke(this, proposedDownloadFilePath);
}
}
}
}

View File

@@ -1,6 +1,6 @@
using System;
namespace ScrapingDomainServices
namespace FileLiberator
{
public interface IDecryptable : IProcessable
{

View File

@@ -1,6 +1,6 @@
using System;
namespace ScrapingDomainServices
namespace FileLiberator
{
public interface IDownloadable : IProcessable
{

View File

@@ -3,7 +3,7 @@ using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.ErrorHandling;
namespace ScrapingDomainServices
namespace FileLiberator
{
public interface IProcessable
{

View File

@@ -1,10 +1,9 @@
using System;
using System.Threading.Tasks;
using DataLayer;
using Dinah.Core.Collections.Generic;
using Dinah.Core.ErrorHandling;
namespace ScrapingDomainServices
namespace FileLiberator
{
public static class IProcessableExt
{
@@ -23,16 +22,14 @@ namespace ScrapingDomainServices
if (libraryBook == null)
return null;
var status = await processable.ProcessAsync(libraryBook);
// this should never happen. check anyway. ProcessFirstValidAsync returning null is the signal that we're done. we can't let another IProcessable accidentally send this commans
var status = await processable.ProcessAsync(libraryBook);
if (status == null)
throw new Exception("Processable should never return a null status");
return status;
}
// i'd love to turn this into Task<IEnumerable<LibraryBook>>
// since enumeration is a blocking operation, this won't be possible until
// 2019's C# 8 async streams, aka async enumerables, aka async iterators: https://blogs.msdn.microsoft.com/dotnet/2018/11/12/building-c-8-0/
public static async Task<LibraryBook> GetNextValidAsync(this IProcessable processable)
{
var libraryBooks = LibraryQueries.GetLibrary_Flat_NoTracking();
@@ -43,12 +40,5 @@ namespace ScrapingDomainServices
return null;
}
public static async Task<StatusHandler> ProcessValidateLibraryBookAsync(this IProcessable processable, LibraryBook libraryBook)
{
if (!await processable.ValidateAsync(libraryBook))
return new StatusHandler { "Validation failed" };
return await processable.ProcessAsync(libraryBook);
}
}
}

View File

@@ -4,6 +4,7 @@ namespace FileManager
{
public static class AudibleApiStorage
{
// not customizable. don't move to config
public static string IdentityTokensFile => Path.Combine(Configuration.Instance.LibationFiles, "IdentityTokens.json");
}
}

View File

@@ -29,8 +29,10 @@ namespace FileManager
[".aac"] = FileType.Audio,
[".mp4"] = FileType.Audio,
[".m4a"] = FileType.Audio,
[".ogg"] = FileType.Audio,
[".flac"] = FileType.Audio,
[".aax"] = FileType.AAX,
[".aax"] = FileType.AAX,
[".pdf"] = FileType.PDF,
[".zip"] = FileType.PDF,

View File

@@ -38,7 +38,7 @@ namespace FileManager
[Description("Location of the configuration file where these settings are saved. Please do not edit this file directly while Libation is running.")]
public string Filepath { get; }
[Description("Your user-specific key used to decrypt your audible files (*.aax) into audio files you can use anywhere (*.m4b)")]
[Description("[Advanced. Leave alone in most cases.] Your user-specific key used to decrypt your audible files (*.aax) into audio files you can use anywhere (*.m4b)")]
public string DecryptKey
{
get => persistentDictionary[nameof(DecryptKey)];

View File

@@ -27,13 +27,6 @@ namespace FileManager
return File.Exists(path);
}
/// <param name="proposedPath">acceptable inputs:
/// example.txt
/// C:\Users\username\Desktop\example.txt</param>
/// <returns>Returns full name and path of unused filename. including (#)</returns>
public static string GetValidFilename(string proposedPath)
=> GetValidFilename(Path.GetDirectoryName(proposedPath), Path.GetFileNameWithoutExtension(proposedPath), Path.GetExtension(proposedPath));
public static string GetValidFilename(string dirFullPath, string filename, string extension, params string[] metadataSuffixes)
{
if (string.IsNullOrWhiteSpace(dirFullPath))
@@ -77,25 +70,5 @@ namespace FileManager
property = property.Replace(ch.ToString(), "");
return property;
}
public static string Declaw(string str)
=> str
.Replace("<script", "<sxcript")
.Replace(".net", ".nxet")
.Replace(".com", ".cxom")
.Replace("<link", "<lxink")
.Replace("http", "hxttp");
public static string RestoreDeclawed(string str)
=> str
?.Replace("<sxcript", "<script")
.Replace(".nxet", ".net")
.Replace(".cxom", ".com")
.Replace("<lxink", "<link")
.Replace("hxttp", "http");
public static string TitleCompressed(string title)
=> new string(title
.Where(c => (char.IsLetterOrDigit(c)))
.ToArray());
}
}

View File

@@ -2,77 +2,108 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
namespace FileManager
{
/// <summary>
/// Files are small. Entire file is read from disk every time. No volitile storage. Paths are well known
/// </summary>
public enum PictureSize { _80x80, _300x300, _500x500 }
public struct PictureDefinition
{
public string PictureId { get; }
public PictureSize Size { get; }
public PictureDefinition(string pictureId, PictureSize pictureSize)
{
PictureId = pictureId;
Size = pictureSize;
}
}
public static class PictureStorage
{
public enum PictureSize { _80x80, _300x300, _500x500 }
// not customizable. don't move to config
private static string ImagesDirectory { get; }
= new DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectory("Images").FullName;
private static string getPath(string pictureId, PictureSize size)
=> Path.Combine(ImagesDirectory, $"{pictureId}{size}.jpg");
private static string getPath(PictureDefinition def)
=> Path.Combine(ImagesDirectory, $"{def.PictureId}{def.Size}.jpg");
public static byte[] GetImage(string pictureId, PictureSize size)
{
var path = getPath(pictureId, size);
if (!FileUtility.FileExists(path))
DownloadImages(pictureId);
private static System.Timers.Timer timer { get; }
static PictureStorage()
{
timer = new System.Timers.Timer(700)
{
AutoReset = true,
Enabled = true
};
timer.Elapsed += (_, __) => timerDownload();
}
return File.ReadAllBytes(path);
}
private static Dictionary<PictureDefinition, byte[]> cache { get; } = new Dictionary<PictureDefinition, byte[]>();
public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def)
{
if (!cache.ContainsKey(def))
{
var path = getPath(def);
cache[def]
= FileUtility.FileExists(path)
? File.ReadAllBytes(path)
: null;
}
return (cache[def] == null, cache[def] ?? getDefaultImage(def.Size));
}
public static void DownloadImages(string pictureId)
{
var path80 = getPath(pictureId, PictureSize._80x80);
var path300 = getPath(pictureId, PictureSize._300x300);
var path500 = getPath(pictureId, PictureSize._500x500);
private static Dictionary<PictureSize, byte[]> defaultImages { get; } = new Dictionary<PictureSize, byte[]>();
public static void SetDefaultImage(PictureSize pictureSize, byte[] bytes)
=> defaultImages[pictureSize] = bytes;
private static byte[] getDefaultImage(PictureSize size)
=> defaultImages.ContainsKey(size)
? defaultImages[size]
: new byte[0];
int retry = 0;
do
{
try
{
using var webClient = new System.Net.WebClient();
// download any that don't exist
{
if (!FileUtility.FileExists(path80))
{
var bytes = webClient.DownloadData(
"https://images-na.ssl-images-amazon.com/images/I/" + pictureId + "._SL80_.jpg");
File.WriteAllBytes(path80, bytes);
}
}
// necessary to avoid IO errors. ReadAllBytes and WriteAllBytes can conflict in some cases, esp when debugging
private static bool isProcessing;
private static void timerDownload()
{
// must live outside try-catch, else 'finally' can reset another thread's lock
if (isProcessing)
return;
{
if (!FileUtility.FileExists(path300))
{
var bytes = webClient.DownloadData(
"https://images-na.ssl-images-amazon.com/images/I/" + pictureId + "._SL300_.jpg");
File.WriteAllBytes(path300, bytes);
}
}
try
{
isProcessing = true;
{
if (!FileUtility.FileExists(path500))
{
var bytes = webClient.DownloadData(
"https://m.media-amazon.com/images/I/" + pictureId + "._SL500_.jpg");
File.WriteAllBytes(path500, bytes);
}
}
var def = cache
.Where(kvp => kvp.Value is null)
.Select(kvp => kvp.Key)
// 80x80 should be 1st since it's enum value == 0
.OrderBy(d => d.PictureId)
.FirstOrDefault();
break;
}
catch { retry++; }
}
while (retry < 3);
}
}
// no more null entries. all requsted images are cached
if (string.IsNullOrWhiteSpace(def.PictureId))
return;
var bytes = downloadBytes(def);
saveFile(def, bytes);
cache[def] = bytes;
}
finally
{
isProcessing = false;
}
}
private static HttpClient imageDownloadClient { get; } = new HttpClient();
private static byte[] downloadBytes(PictureDefinition def)
{
var sz = def.Size.ToString().Split('x')[1];
return imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result;
}
private static void saveFile(PictureDefinition def, byte[] bytes)
{
var path = getPath(def);
File.WriteAllBytes(path, bytes);
}
}
}

View File

@@ -1,68 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace FileManager
{
public static class WebpageStorage
{
// not customizable. don't move to config
private static string PagesDirectory { get; }
= new DirectoryInfo(Configuration.Instance.LibationFiles).CreateSubdirectory("Pages").FullName;
private static string BookDetailsDirectory { get; }
= new DirectoryInfo(PagesDirectory).CreateSubdirectory("Book Details").FullName;
public static string GetLibraryBatchName() => "Library_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
public static string SavePageToBatch(string contents, string batchName, string extension)
{
var batch_dir = Path.Combine(PagesDirectory, batchName);
Directory.CreateDirectory(batch_dir);
var file = Path.Combine(batch_dir, batchName + '.' + extension.Trim('.'));
var filename = FileUtility.GetValidFilename(file);
File.WriteAllText(filename, contents);
return filename;
}
public static List<FileInfo> GetJsonFiles(DirectoryInfo libDir)
=> libDir == null
? new List<FileInfo>()
: Directory
.EnumerateFiles(libDir.FullName, "*.json")
.Select(f => new FileInfo(f))
.ToList();
public static DirectoryInfo GetMostRecentLibraryDir()
{
var dir = Directory
.EnumerateDirectories(PagesDirectory, "Library_*")
.OrderBy(a => a)
.LastOrDefault();
if (string.IsNullOrWhiteSpace(dir))
return null;
return new DirectoryInfo(dir);
}
public static FileInfo GetBookDetailHtmFileInfo(string productId)
{
var path = Path.Combine(BookDetailsDirectory, $"BookDetail-{productId}.htm");
return new FileInfo(path);
}
public static FileInfo GetBookDetailJsonFileInfo(string productId)
{
var path = Path.Combine(BookDetailsDirectory, $"BookDetail-{productId}.json");
return new FileInfo(path);
}
public static FileInfo SaveBookDetailsToHtm(string productId, string contents)
{
var fi = GetBookDetailHtmFileInfo(productId);
File.WriteAllText(fi.FullName, contents);
return fi;
}
}
}

View File

@@ -4,9 +4,13 @@
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Polly" Version="7.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\audible api\AudibleApi\AudibleApi\AudibleApi.csproj" />
<ProjectReference Include="..\Scraping\Scraping.csproj" />
<ProjectReference Include="..\FileManager\FileManager.csproj" />
</ItemGroup>
</Project>

View File

@@ -5,26 +5,25 @@ using System.Threading.Tasks;
using AudibleApi;
using AudibleApiDTOs;
using FileManager;
using Polly;
using Polly.Retry;
namespace InternalUtilities
{
public class AudibleApiActions
{
private AsyncRetryPolicy policy { get; }
= Policy.Handle<Exception>()
// 2 retries == 3 total
.RetryAsync(2);
public async Task<List<Item>> GetAllLibraryItemsAsync(ILoginCallback callback)
{
// bug on audible's side. the 1st time after a long absence, a query to get library will return without titles or authors. a subsequent identical query will be successful. this is true whether or tokens are refreshed
// worse, this 1st dummy call doesn't seem to help:
// var page = await api.GetLibraryAsync(new AudibleApi.LibraryOptions { NumberOfResultPerPage = 1, PageNumber = 1, PurchasedAfter = DateTime.Now.AddYears(-20), ResponseGroups = AudibleApi.LibraryOptions.ResponseGroupOptions.ALL_OPTIONS });
// i don't want to incur the cost of making a full dummy call every time because it fails sometimes
try
{
return await getItemsAsync(callback);
}
catch
{
return await getItemsAsync(callback);
}
return await policy.ExecuteAsync(() => getItemsAsync(callback));
}
private async Task<List<Item>> getItemsAsync(ILoginCallback callback)
@@ -33,7 +32,7 @@ namespace InternalUtilities
var items = await AudibleApiExtensions.GetAllLibraryItemsAsync(api);
// remove episode parents
items.RemoveAll(i => i.Episodes);
items.RemoveAll(i => i.IsEpisodes);
#region // episode handling. doesn't quite work
// // add individual/children episodes
@@ -46,7 +45,7 @@ namespace InternalUtilities
// foreach (var childId in childIds)
// {
// var bookResult = await api.GetLibraryBookAsync(childId, AudibleApi.LibraryOptions.ResponseGroupOptions.ALL_OPTIONS);
// var bookItem = AudibleApiDTOs.LibraryApiV10.FromJson(bookResult.ToString()).Item;
// var bookItem = AudibleApiDTOs.LibraryDtoV10.FromJson(bookResult.ToString()).Item;
// items.Add(bookItem);
// }
#endregion

View File

@@ -28,7 +28,7 @@ namespace InternalUtilities
});
// important! use this convert method
var libResult = LibraryApiV10.FromJson(page.ToString());
var libResult = LibraryDtoV10.FromJson(page.ToString());
if (!libResult.Items.Any())
break;

View File

@@ -1,51 +0,0 @@
using System.IO;
using AudibleDotCom;
using FileManager;
using Newtonsoft.Json;
namespace InternalUtilities
{
public static partial class DataConverter
{
// also need: htm file => PageSource
public static AudiblePageSource HtmFile_2_AudiblePageSource(string htmFilepath)
{
var htmContentsDeclawed = File.ReadAllText(htmFilepath);
var htmContents = FileUtility.RestoreDeclawed(htmContentsDeclawed);
return AudiblePageSource.Deserialize(htmContents);
}
public static FileInfo Value_2_JsonFile(object value, string jsonFilepath)
{
var json = JsonConvert.SerializeObject(value, Formatting.Indented);
File.WriteAllText(jsonFilepath, json);
return new FileInfo(jsonFilepath);
}
/// <summary>AudiblePageSource => declawed htm file</summary>
/// <returns>path of htm file</returns>
public static FileInfo AudiblePageSource_2_HtmFile_Batch(AudiblePageSource audiblePageSource, string batchName)
{
var source = audiblePageSource.Declawed().Serialized();
var htmFile = WebpageStorage.SavePageToBatch(source, batchName, "htm");
return new FileInfo(htmFile);
}
/// <summary>AudiblePageSource => declawed htm file</summary>
/// <returns>path of htm file</returns>
public static FileInfo AudiblePageSource_2_HtmFile_Product(AudiblePageSource audiblePageSource)
{
if (audiblePageSource.AudiblePage == AudiblePageType.ProductDetails)
{
var source = audiblePageSource.Declawed().Serialized();
var htmFile = WebpageStorage.SaveBookDetailsToHtm(audiblePageSource.PageId, source);
return htmFile;
}
throw new System.NotImplementedException();
}
}
}

View File

@@ -7,7 +7,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Items", "_Solutio
ProjectSection(SolutionItems) = preProject
__TODO.txt = __TODO.txt
_DB_NOTES.txt = _DB_NOTES.txt
lucenenet source code.txt = lucenenet source code.txt
REFERENCE.txt = REFERENCE.txt
EndProjectSection
EndProject
@@ -27,15 +26,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileManager", "FileManager\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataLayer", "DataLayer\DataLayer.csproj", "{59A10DF3-63EC-43F1-A3BF-4000CFA118D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AudibleDotCom", "AudibleDotCom\AudibleDotCom.csproj", "{4ABB61D3-4959-4F09-883A-9EDC8CE473FB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Scraping", "Scraping\Scraping.csproj", "{C2C89551-44FD-41E4-80D3-69AF8CE3F174}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AudibleDotComAutomation", "AudibleDotComAutomation\AudibleDotComAutomation.csproj", "{4CDE10DD-60EC-4CCA-99D1-75224A201C89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CookieMonster", "CookieMonster\CookieMonster.csproj", "{7BD02E29-3430-4D06-88D2-5CECEE9ABD01}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScrapingDomainServices", "ScrapingDomainServices\ScrapingDomainServices.csproj", "{393B5B27-D15C-4F77-9457-FA14BA8F3C73}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileLiberator", "FileLiberator\FileLiberator.csproj", "{393B5B27-D15C-4F77-9457-FA14BA8F3C73}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InternalUtilities", "InternalUtilities\InternalUtilities.csproj", "{06882742-27A6-4347-97D9-56162CEC9C11}"
EndProject
@@ -69,10 +60,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "inAudibleLite", "_Demos\inA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.Core", "..\Dinah.Core\Dinah.Core\Dinah.Core.csproj", "{9E951521-2587-4FC6-AD26-FAA9179FB6C4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.Core.Drawing", "..\Dinah.Core\Dinah.Core.Drawing\Dinah.Core.Drawing.csproj", "{2CAAD73E-E2F9-4888-B04A-3F3803DABDAE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.Core.Windows.Forms", "..\Dinah.Core\Dinah.Core.Windows.Forms\Dinah.Core.Windows.Forms.csproj", "{1306F62D-CDAC-4269-982A-2EED51F0E318}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.EntityFrameworkCore", "..\Dinah.Core\Dinah.EntityFrameworkCore\Dinah.EntityFrameworkCore.csproj", "{1255D9BA-CE6E-42E4-A253-6376540B9661}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LuceneNet303r2", "..\LuceneNet303r2\LuceneNet303r2\LuceneNet303r2.csproj", "{35803735-B669-4090-9681-CC7F7FABDC71}"
@@ -89,6 +76,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AudibleApiClientExample", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationServices", "ApplicationServices\ApplicationServices.csproj", "{B95650EA-25F0-449E-BA5D-99126BC5D730}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.Core.WindowsDesktop", "..\Dinah.Core\Dinah.Core.WindowsDesktop\Dinah.Core.WindowsDesktop.csproj", "{059CE32C-9AD6-45E9-A166-790DFFB0B730}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsDesktopUtilities", "WindowsDesktopUtilities\WindowsDesktopUtilities.csproj", "{E7EFD64D-6630-4426-B09C-B6862A92E3FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -107,22 +98,6 @@ Global
{59A10DF3-63EC-43F1-A3BF-4000CFA118D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59A10DF3-63EC-43F1-A3BF-4000CFA118D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59A10DF3-63EC-43F1-A3BF-4000CFA118D2}.Release|Any CPU.Build.0 = Release|Any CPU
{4ABB61D3-4959-4F09-883A-9EDC8CE473FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4ABB61D3-4959-4F09-883A-9EDC8CE473FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4ABB61D3-4959-4F09-883A-9EDC8CE473FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ABB61D3-4959-4F09-883A-9EDC8CE473FB}.Release|Any CPU.Build.0 = Release|Any CPU
{C2C89551-44FD-41E4-80D3-69AF8CE3F174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2C89551-44FD-41E4-80D3-69AF8CE3F174}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2C89551-44FD-41E4-80D3-69AF8CE3F174}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2C89551-44FD-41E4-80D3-69AF8CE3F174}.Release|Any CPU.Build.0 = Release|Any CPU
{4CDE10DD-60EC-4CCA-99D1-75224A201C89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CDE10DD-60EC-4CCA-99D1-75224A201C89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CDE10DD-60EC-4CCA-99D1-75224A201C89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CDE10DD-60EC-4CCA-99D1-75224A201C89}.Release|Any CPU.Build.0 = Release|Any CPU
{7BD02E29-3430-4D06-88D2-5CECEE9ABD01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BD02E29-3430-4D06-88D2-5CECEE9ABD01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BD02E29-3430-4D06-88D2-5CECEE9ABD01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BD02E29-3430-4D06-88D2-5CECEE9ABD01}.Release|Any CPU.Build.0 = Release|Any CPU
{393B5B27-D15C-4F77-9457-FA14BA8F3C73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{393B5B27-D15C-4F77-9457-FA14BA8F3C73}.Debug|Any CPU.Build.0 = Debug|Any CPU
{393B5B27-D15C-4F77-9457-FA14BA8F3C73}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -179,14 +154,6 @@ Global
{9E951521-2587-4FC6-AD26-FAA9179FB6C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E951521-2587-4FC6-AD26-FAA9179FB6C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E951521-2587-4FC6-AD26-FAA9179FB6C4}.Release|Any CPU.Build.0 = Release|Any CPU
{2CAAD73E-E2F9-4888-B04A-3F3803DABDAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CAAD73E-E2F9-4888-B04A-3F3803DABDAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CAAD73E-E2F9-4888-B04A-3F3803DABDAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CAAD73E-E2F9-4888-B04A-3F3803DABDAE}.Release|Any CPU.Build.0 = Release|Any CPU
{1306F62D-CDAC-4269-982A-2EED51F0E318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1306F62D-CDAC-4269-982A-2EED51F0E318}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1306F62D-CDAC-4269-982A-2EED51F0E318}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1306F62D-CDAC-4269-982A-2EED51F0E318}.Release|Any CPU.Build.0 = Release|Any CPU
{1255D9BA-CE6E-42E4-A253-6376540B9661}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1255D9BA-CE6E-42E4-A253-6376540B9661}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1255D9BA-CE6E-42E4-A253-6376540B9661}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -219,6 +186,14 @@ Global
{B95650EA-25F0-449E-BA5D-99126BC5D730}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B95650EA-25F0-449E-BA5D-99126BC5D730}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B95650EA-25F0-449E-BA5D-99126BC5D730}.Release|Any CPU.Build.0 = Release|Any CPU
{059CE32C-9AD6-45E9-A166-790DFFB0B730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{059CE32C-9AD6-45E9-A166-790DFFB0B730}.Debug|Any CPU.Build.0 = Debug|Any CPU
{059CE32C-9AD6-45E9-A166-790DFFB0B730}.Release|Any CPU.ActiveCfg = Release|Any CPU
{059CE32C-9AD6-45E9-A166-790DFFB0B730}.Release|Any CPU.Build.0 = Release|Any CPU
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7EFD64D-6630-4426-B09C-B6862A92E3FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -227,10 +202,6 @@ Global
{8BD8E012-F44F-4EE2-A234-D66C14D5FE4B} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{1AE65B61-9C05-4C80-ABFF-48F16E22FDF1} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{59A10DF3-63EC-43F1-A3BF-4000CFA118D2} = {751093DD-5DBA-463E-ADBE-E05FAFB6983E}
{4ABB61D3-4959-4F09-883A-9EDC8CE473FB} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{C2C89551-44FD-41E4-80D3-69AF8CE3F174} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{4CDE10DD-60EC-4CCA-99D1-75224A201C89} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{7BD02E29-3430-4D06-88D2-5CECEE9ABD01} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{393B5B27-D15C-4F77-9457-FA14BA8F3C73} = {41CDCC73-9B81-49DD-9570-C54406E852AF}
{06882742-27A6-4347-97D9-56162CEC9C11} = {F0CBB7A7-D3FB-41FF-8F47-CF3F6A592249}
{2E1F5DB4-40CC-4804-A893-5DCE0193E598} = {41CDCC73-9B81-49DD-9570-C54406E852AF}
@@ -245,8 +216,6 @@ Global
{DF72740C-900A-45DA-A3A6-4DDD68F286F2} = {F61184E7-2426-4A13-ACEF-5689928E2CE2}
{74D02251-898E-4CAF-80C7-801820622903} = {F61184E7-2426-4A13-ACEF-5689928E2CE2}
{9E951521-2587-4FC6-AD26-FAA9179FB6C4} = {43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}
{2CAAD73E-E2F9-4888-B04A-3F3803DABDAE} = {43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}
{1306F62D-CDAC-4269-982A-2EED51F0E318} = {43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}
{1255D9BA-CE6E-42E4-A253-6376540B9661} = {43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}
{35803735-B669-4090-9681-CC7F7FABDC71} = {7FBBB086-0807-4998-85BF-6D1A49C8AD05}
{5A7681A5-60D9-480B-9AC7-63E0812A2548} = {38E6C6D9-963A-4C5B-89F4-F2F14885ADFD}
@@ -255,6 +224,8 @@ Global
{6069D7F6-BEA0-4917-AFD4-4EB680CB0EDD} = {38E6C6D9-963A-4C5B-89F4-F2F14885ADFD}
{282EEE16-F569-47E1-992F-C6DB8AEC7AA6} = {F61184E7-2426-4A13-ACEF-5689928E2CE2}
{B95650EA-25F0-449E-BA5D-99126BC5D730} = {41CDCC73-9B81-49DD-9570-C54406E852AF}
{059CE32C-9AD6-45E9-A166-790DFFB0B730} = {43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}
{E7EFD64D-6630-4426-B09C-B6862A92E3FD} = {F0CBB7A7-D3FB-41FF-8F47-CF3F6A592249}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {615E00ED-BAEF-4E8E-A92A-9B82D87942A9}

View File

@@ -160,8 +160,7 @@ namespace LibationSearchEngine
private Directory getIndex() => FSDirectory.Open(SearchEngineDirectory);
public async Task CreateNewIndexAsync() => await Task.Run(() => createNewIndex(true));
private void createNewIndex(bool overwrite)
public void CreateNewIndex(bool overwrite = true)
{
// 300 products
// 1st run after app is started: 400ms
@@ -231,8 +230,8 @@ namespace LibationSearchEngine
return doc;
}
public async Task UpdateBookAsync(string productId) => await Task.Run(() => updateBook(productId));
private void updateBook(string productId)
/// <summary>Long running. Use await Task.Run(() => UpdateBook(productId))</summary>
public void UpdateBook(string productId)
{
var libraryBook = LibraryQueries.GetLibraryBook_Flat_NoTracking(productId);
var term = new Term(_ID_, productId);

View File

@@ -5,16 +5,17 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>libation.ico</ApplicationIcon>
<AssemblyName>Libation</AssemblyName>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\audible api\AudibleApi\AudibleApi\AudibleApi.csproj" />
<ProjectReference Include="..\..\Dinah.Core\Dinah.Core.Drawing\Dinah.Core.Drawing.csproj" />
<ProjectReference Include="..\..\Dinah.Core\Dinah.Core.Windows.Forms\Dinah.Core.Windows.Forms.csproj" />
<ProjectReference Include="..\ApplicationService\ApplicationService.csproj" />
<ProjectReference Include="..\DtoImporterService\DtoImporterService.csproj" />
<ProjectReference Include="..\LibationSearchEngine\LibationSearchEngine.csproj" />
<ProjectReference Include="..\ScrapingDomainServices\ScrapingDomainServices.csproj" />
<ProjectReference Include="..\FileLiberator\FileLiberator.csproj" />
<ProjectReference Include="..\WindowsDesktopUtilities\WindowsDesktopUtilities.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -60,6 +60,36 @@ namespace LibationWinForm.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap default_cover_300x300 {
get {
object obj = ResourceManager.GetObject("default_cover_300x300", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap default_cover_500x500 {
get {
object obj = ResourceManager.GetObject("default_cover_500x500", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap default_cover_80x80 {
get {
object obj = ResourceManager.GetObject("default_cover_80x80", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -118,6 +118,15 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="default_cover_300x300" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\img-coverart-prod-unavailable_300x300.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="default_cover_500x500" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\img-coverart-prod-unavailable_500x500.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="default_cover_80x80" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\img-coverart-prod-unavailable_80x80.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="edit_tags_25x25" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\edit-tags-25x25.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -56,10 +56,10 @@ namespace LibationWinForm.BookLiberation
=> bookInfoLbl.UIThread(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}");
public void SetCoverImage(byte[] coverBytes)
=> pictureBox1.UIThread(() => pictureBox1.Image = ImageConverter.GetPictureFromBytes(coverBytes));
=> pictureBox1.UIThread(() => pictureBox1.Image = ImageReader.ToImage(coverBytes));
public void AppendError(Exception ex) => AppendText("ERROR: " + ex.Message);
public void AppendText(string text) =>
public static void AppendError(Exception ex) => AppendText("ERROR: " + ex.Message);
public static void AppendText(string text) =>
// redirected to log textbox
Console.WriteLine($"{DateTime.Now} {text}")
//logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}"))

View File

@@ -1,129 +0,0 @@
namespace LibationWinForm.BookLiberation
{
partial class NoLongerAvailableForm
{
/// <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.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.missingBtn = new System.Windows.Forms.Button();
this.abortBtn = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// 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(174, 39);
this.label1.TabIndex = 0;
this.label1.Text = "Book details download failed.\r\n{0} may be no longer available.\r\nVerify the book i" +
"s still available here";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(15, 51);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(384, 20);
this.textBox1.TabIndex = 1;
//
// missingBtn
//
this.missingBtn.Location = new System.Drawing.Point(324, 77);
this.missingBtn.Name = "missingBtn";
this.missingBtn.Size = new System.Drawing.Size(75, 23);
this.missingBtn.TabIndex = 3;
this.missingBtn.Text = "Missing";
this.missingBtn.UseVisualStyleBackColor = true;
this.missingBtn.Click += new System.EventHandler(this.missingBtn_Click);
//
// abortBtn
//
this.abortBtn.Location = new System.Drawing.Point(324, 126);
this.abortBtn.Name = "abortBtn";
this.abortBtn.Size = new System.Drawing.Size(75, 23);
this.abortBtn.TabIndex = 5;
this.abortBtn.Text = "Abort";
this.abortBtn.UseVisualStyleBackColor = true;
this.abortBtn.Click += new System.EventHandler(this.abortBtn_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 74);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(306, 26);
this.label2.TabIndex = 2;
this.label2.Text = "If the book is not available, click here to mark it as missing\r\nNo further book d" +
"etails download will be attempted for this book";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 123);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(204, 26);
this.label3.TabIndex = 4;
this.label3.Text = "If the book is actually available, click here\r\nto abort and try again later";
//
// NoLongerAvailableForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(411, 161);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.abortBtn);
this.Controls.Add(this.missingBtn);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "NoLongerAvailableForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "No Longer Available";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button missingBtn;
private System.Windows.Forms.Button abortBtn;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
}
}

View File

@@ -1,28 +0,0 @@
using System;
using System.Windows.Forms;
using ScrapingDomainServices;
namespace LibationWinForm.BookLiberation
{
public partial class NoLongerAvailableForm : Form
{
public ScrapeBookDetails.NoLongerAvailableEnum EnumResult { get; private set; }
public NoLongerAvailableForm(string title, string url) : this()
{
this.Text += ": " + title;
this.label1.Text = string.Format(this.label1.Text, title);
this.textBox1.Text = url;
}
public NoLongerAvailableForm() => InitializeComponent();
private void missingBtn_Click(object sender, EventArgs e) => complete(ScrapeBookDetails.NoLongerAvailableEnum.MarkAsMissing);
private void abortBtn_Click(object sender, EventArgs e) => complete(ScrapeBookDetails.NoLongerAvailableEnum.Abort);
private void complete(ScrapeBookDetails.NoLongerAvailableEnum nlaEnum)
{
EnumResult = nlaEnum;
Close();
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
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
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<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
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
mimetype set.
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
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: 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
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -3,7 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DataLayer;
using ScrapingDomainServices;
using Dinah.Core.ErrorHandling;
using FileLiberator;
namespace LibationWinForm.BookLiberation
{
@@ -22,13 +23,20 @@ namespace LibationWinForm.BookLiberation
return;
var backupBook = new BackupBook();
backupBook.Download.Completed += SetBackupCountsAsync;
backupBook.Decrypt.Completed += SetBackupCountsAsync;
await backupBook.ProcessValidateLibraryBookAsync(libraryBook);
}
backupBook.DownloadBook.Completed += SetBackupCountsAsync;
backupBook.DecryptBook.Completed += SetBackupCountsAsync;
await ProcessValidateLibraryBookAsync(backupBook, libraryBook);
}
// Download First Book (Download encrypted/DRM file)
async Task DownloadFirstBookAsync()
static async Task<StatusHandler> ProcessValidateLibraryBookAsync(IProcessable processable, LibraryBook libraryBook)
{
if (!await processable.ValidateAsync(libraryBook))
return new StatusHandler { "Validation failed" };
return await processable.ProcessAsync(libraryBook);
}
// Download First Book (Download encrypted/DRM file)
async Task DownloadFirstBookAsync()
{
var downloadBook = ProcessorAutomationController.GetWiredUpDownloadBook();
downloadBook.Completed += SetBackupCountsAsync;
@@ -47,8 +55,8 @@ namespace LibationWinForm.BookLiberation
async Task BackupFirstBookAsync()
{
var backupBook = ProcessorAutomationController.GetWiredUpBackupBook();
backupBook.Download.Completed += SetBackupCountsAsync;
backupBook.Decrypt.Completed += SetBackupCountsAsync;
backupBook.DownloadBook.Completed += SetBackupCountsAsync;
backupBook.DecryptBook.Completed += SetBackupCountsAsync;
await backupBook.ProcessFirstValidAsync();
}

View File

@@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using ScrapingDomainServices;
using FileLiberator;
namespace LibationWinForm.BookLiberation
{
@@ -16,10 +16,11 @@ namespace LibationWinForm.BookLiberation
{
var backupBook = new BackupBook();
backupBook.Download.Begin += (_, __) => wireUpDownloadable(backupBook.Download);
backupBook.Decrypt.Begin += (_, __) => wireUpDecryptable(backupBook.Decrypt);
backupBook.DownloadBook.Begin += (_, __) => wireUpDownloadable(backupBook.DownloadBook);
backupBook.DecryptBook.Begin += (_, __) => wireUpDecryptable(backupBook.DecryptBook);
backupBook.DownloadPdf.Begin += (_, __) => wireUpDecryptable(backupBook.DecryptBook);
return backupBook;
return backupBook;
}
public static DecryptBook GetWiredUpDecryptBook()
{
@@ -39,21 +40,6 @@ namespace LibationWinForm.BookLiberation
downloadPdf.Begin += (_, __) => wireUpDownloadable(downloadPdf);
return downloadPdf;
}
public static ScrapeBookDetails GetWiredUpScrapeBookDetails()
{
var scrapeBookDetails = new ScrapeBookDetails();
scrapeBookDetails.Begin += (_, __) => wireUpDownloadable(scrapeBookDetails);
scrapeBookDetails.NoLongerAvailableAction = noLongerAvailableUI;
return scrapeBookDetails;
}
static ScrapeBookDetails.NoLongerAvailableEnum noLongerAvailableUI(string title, string url)
{
var nla = new NoLongerAvailableForm(title, url);
nla.ShowDialog();
return nla.EnumResult;
}
// subscribed to Begin event because a new form should be created+processed+closed on each iteration
private static void wireUpDownloadable(IDownloadable downloadable)
@@ -206,34 +192,43 @@ namespace LibationWinForm.BookLiberation
#endregion
#region define how model actions will affect form behavior
void downloadBegin(object _, string str) => automatedBackupsForm.AppendText("DownloadStep_Begin: " + str);
void downloadBookBegin(object _, string str) => automatedBackupsForm.AppendText("DownloadStep_Begin: " + str);
void statusUpdate(object _, string str) => automatedBackupsForm.AppendText("- " + str);
void downloadCompleted(object _, string str) => automatedBackupsForm.AppendText("DownloadStep_Completed: " + str);
void decryptBegin(object _, string str) => automatedBackupsForm.AppendText("DecryptStep_Begin: " + str);
void downloadBookCompleted(object _, string str) => automatedBackupsForm.AppendText("DownloadStep_Completed: " + str);
void decryptBookBegin(object _, string str) => automatedBackupsForm.AppendText("DecryptStep_Begin: " + str);
// extra line after book is completely finished
void decryptCompleted(object _, string str) => automatedBackupsForm.AppendText("DecryptStep_Completed: " + str + Environment.NewLine);
#endregion
void decryptBookCompleted(object _, string str) => automatedBackupsForm.AppendText("DecryptStep_Completed: " + str + Environment.NewLine);
void downloadPdfBegin(object _, string str) => automatedBackupsForm.AppendText("PdfStep_Begin: " + str);
// extra line after book is completely finished
void downloadPdfCompleted(object _, string str) => automatedBackupsForm.AppendText("PdfStep_Completed: " + str + Environment.NewLine);
#endregion
#region subscribe new form to model's events
backupBook.Download.Begin += downloadBegin;
backupBook.Download.StatusUpdate += statusUpdate;
backupBook.Download.Completed += downloadCompleted;
backupBook.Decrypt.Begin += decryptBegin;
backupBook.Decrypt.StatusUpdate += statusUpdate;
backupBook.Decrypt.Completed += decryptCompleted;
#endregion
#region subscribe new form to model's events
backupBook.DownloadBook.Begin += downloadBookBegin;
backupBook.DownloadBook.StatusUpdate += statusUpdate;
backupBook.DownloadBook.Completed += downloadBookCompleted;
backupBook.DecryptBook.Begin += decryptBookBegin;
backupBook.DecryptBook.StatusUpdate += statusUpdate;
backupBook.DecryptBook.Completed += decryptBookCompleted;
backupBook.DownloadPdf.Begin += downloadPdfBegin;
backupBook.DownloadPdf.StatusUpdate += statusUpdate;
backupBook.DownloadPdf.Completed += downloadPdfCompleted;
#endregion
#region when form closes, unsubscribe from model's events
// unsubscribe so disposed forms aren't still trying to receive notifications
automatedBackupsForm.FormClosing += (_, __) =>
#region when form closes, unsubscribe from model's events
// unsubscribe so disposed forms aren't still trying to receive notifications
automatedBackupsForm.FormClosing += (_, __) =>
{
backupBook.Download.Begin -= downloadBegin;
backupBook.Download.StatusUpdate -= statusUpdate;
backupBook.Download.Completed -= downloadCompleted;
backupBook.Decrypt.Begin -= decryptBegin;
backupBook.Decrypt.StatusUpdate -= statusUpdate;
backupBook.Decrypt.Completed -= decryptCompleted;
};
backupBook.DownloadBook.Begin -= downloadBookBegin;
backupBook.DownloadBook.StatusUpdate -= statusUpdate;
backupBook.DownloadBook.Completed -= downloadBookCompleted;
backupBook.DecryptBook.Begin -= decryptBookBegin;
backupBook.DecryptBook.StatusUpdate -= statusUpdate;
backupBook.DecryptBook.Completed -= decryptBookCompleted;
backupBook.DownloadPdf.Begin -= downloadPdfBegin;
backupBook.DownloadPdf.StatusUpdate -= statusUpdate;
backupBook.DownloadPdf.Completed -= downloadPdfCompleted;
};
#endregion
await runBackupLoop(backupBook, automatedBackupsForm);

View File

@@ -1,8 +0,0 @@
namespace LibationWinForm
{
public interface IIndexLibraryDialog : IRunnableDialog
{
int TotalBooksProcessed { get; }
int NewBooksAdded { get; }
}
}

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LibationWinForm
{
public interface IRunnableDialog : IValidatable
{
IButtonControl AcceptButton { get; set; }
Control.ControlCollection Controls { get; }
Task DoMainWorkAsync();
string SuccessMessage { get; }
DialogResult ShowDialog();
DialogResult DialogResult { get; set; }
void Close();
}
}

View File

@@ -1,96 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dinah.Core.Windows.Forms;
namespace LibationWinForm
{
public static class IRunnableDialogExt
{
public static DialogResult RunDialog(this IRunnableDialog dialog)
{
// hook up runner before dialog.ShowDialog for all
var acceptButton = (ButtonBase)dialog.AcceptButton;
acceptButton.Click += acceptButton_Click;
return dialog.ShowDialog();
}
// running/workflow logic is in IndexDialogRunner.Run()
private static async void acceptButton_Click(object sender, EventArgs e)
{
var form = ((Control)sender).FindForm();
var iRunnableDialog = form as IRunnableDialog;
try
{
await iRunnableDialog.Run();
}
catch (Exception ex)
{
throw new Exception("Did the database get created correctly? Including seed data. Eg: Update-Database", ex);
}
}
public static async Task Run(this IRunnableDialog dialog)
{
// validate children
// OfType<T>() -- skips items which aren't of the required type
// Cast<T>() -- throws an exception
var errorStrings = dialog
// get children
.Controls
.GetControlListRecursive()
.OfType<IValidatable>()
// and self
.Append(dialog)
// validate. get errors
.Select(c => c.StringBasedValidate())
// ignore successes
.Where(e => e != null);
if (errorStrings.Any())
{
MessageBox.Show(errorStrings.Aggregate((a, b) => a + "\r\n" + b));
return;
}
// get top level controls only. If Enabled, disable and push on stack
var disabledStack = disable(dialog);
// lazy-man's async. also violates the intent of async/await.
// use here for now simply for UI responsiveness
await dialog.DoMainWorkAsync().ConfigureAwait(true);
// after running, unwind and re-enable
enable(disabledStack);
MessageBox.Show(dialog.SuccessMessage);
dialog.DialogResult = DialogResult.OK;
dialog.Close();
}
static Stack<Control> disable(IRunnableDialog dialog)
{
var disableStack = new Stack<Control>();
foreach (Control ctrl in dialog.Controls)
{
if (ctrl.Enabled)
{
disableStack.Push(ctrl);
ctrl.Enabled = false;
}
}
return disableStack;
}
static void enable(Stack<Control> disabledStack)
{
while (disabledStack.Count > 0)
{
var ctrl = disabledStack.Pop();
ctrl.Enabled = true;
}
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibationWinForm
{
public interface IValidatable
{
// forms has a framework for ValidateChildren and ErrorProvider.s
// i don't feel like setting it up right now. doing this instead
string StringBasedValidate();
}
}

View File

@@ -1,78 +0,0 @@
namespace LibationWinForm
{
partial class ScanLibraryDialog
{
/// <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.websiteProcessorControl1 = new LibationWinForm.WebsiteProcessorControl();
this.BeginScanBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// websiteProcessorControl1
//
this.websiteProcessorControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.websiteProcessorControl1.Location = new System.Drawing.Point(12, 12);
this.websiteProcessorControl1.Name = "websiteProcessorControl1";
this.websiteProcessorControl1.Size = new System.Drawing.Size(324, 137);
this.websiteProcessorControl1.TabIndex = 0;
//
// BeginScanBtn
//
this.BeginScanBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.BeginScanBtn.Location = new System.Drawing.Point(12, 155);
this.BeginScanBtn.Name = "BeginScanBtn";
this.BeginScanBtn.Size = new System.Drawing.Size(324, 23);
this.BeginScanBtn.TabIndex = 1;
this.BeginScanBtn.Text = "BEGIN SCAN";
this.BeginScanBtn.UseVisualStyleBackColor = true;
//
// ScanLibraryDialog
//
this.AcceptButton = this.BeginScanBtn;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(348, 190);
this.Controls.Add(this.BeginScanBtn);
this.Controls.Add(this.websiteProcessorControl1);
this.Name = "ScanLibraryDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Scan Library";
this.ResumeLayout(false);
}
#endregion
private WebsiteProcessorControl websiteProcessorControl1;
private System.Windows.Forms.Button BeginScanBtn;
}
}

View File

@@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dinah.Core;
using ScrapingDomainServices;
namespace LibationWinForm
{
public partial class ScanLibraryDialog : Form, IIndexLibraryDialog
{
public ScanLibraryDialog()
{
InitializeComponent();
}
public string StringBasedValidate() => null;
List<string> successMessages { get; } = new List<string>();
public string SuccessMessage => string.Join("\r\n", successMessages);
public int NewBooksAdded { get; private set; }
public int TotalBooksProcessed { get; private set; }
public async Task DoMainWorkAsync()
{
using var pageRetriever = websiteProcessorControl1.GetPageRetriever();
var jsonFilepaths = await DownloadLibrary.DownloadLibraryAsync(pageRetriever).ConfigureAwait(false);
successMessages.Add($"Downloaded {"library page".PluralizeWithCount(jsonFilepaths.Count)}");
(TotalBooksProcessed, NewBooksAdded) = await Indexer
.IndexLibraryAsync(jsonFilepaths)
.ConfigureAwait(false);
successMessages.Add($"Total processed: {TotalBooksProcessed}");
successMessages.Add($"New: {NewBooksAdded}");
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
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
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<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
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
mimetype set.
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
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: 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
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -1,161 +0,0 @@
namespace LibationWinForm
{
partial class WebsiteProcessorControl
{
/// <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 Component 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.AuthGb = new System.Windows.Forms.GroupBox();
this.AuthRb_Browserless = new System.Windows.Forms.RadioButton();
this.AuthRb_UseCanonicalChrome = new System.Windows.Forms.RadioButton();
this.label3 = new System.Windows.Forms.Label();
this.AuthRb_ManualLogin = new System.Windows.Forms.RadioButton();
this.label2 = new System.Windows.Forms.Label();
this.PasswordTb = new System.Windows.Forms.TextBox();
this.UsernameTb = new System.Windows.Forms.TextBox();
this.AuthGb.SuspendLayout();
this.SuspendLayout();
//
// AuthGb
//
this.AuthGb.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.AuthGb.Controls.Add(this.AuthRb_Browserless);
this.AuthGb.Controls.Add(this.AuthRb_UseCanonicalChrome);
this.AuthGb.Controls.Add(this.label3);
this.AuthGb.Controls.Add(this.AuthRb_ManualLogin);
this.AuthGb.Controls.Add(this.label2);
this.AuthGb.Controls.Add(this.PasswordTb);
this.AuthGb.Controls.Add(this.UsernameTb);
this.AuthGb.Location = new System.Drawing.Point(0, 0);
this.AuthGb.Name = "AuthGb";
this.AuthGb.Size = new System.Drawing.Size(324, 137);
this.AuthGb.TabIndex = 1;
this.AuthGb.TabStop = false;
this.AuthGb.Text = "Authentication";
//
// AuthRb_Browserless
//
this.AuthRb_Browserless.AutoSize = true;
this.AuthRb_Browserless.Checked = true;
this.AuthRb_Browserless.Location = new System.Drawing.Point(6, 19);
this.AuthRb_Browserless.Name = "AuthRb_Browserless";
this.AuthRb_Browserless.Size = new System.Drawing.Size(143, 17);
this.AuthRb_Browserless.TabIndex = 0;
this.AuthRb_Browserless.TabStop = true;
this.AuthRb_Browserless.Text = "Browserless with cookies";
this.AuthRb_Browserless.UseVisualStyleBackColor = true;
//
// AuthRb_UseCanonicalChrome
//
this.AuthRb_UseCanonicalChrome.AutoSize = true;
this.AuthRb_UseCanonicalChrome.Location = new System.Drawing.Point(6, 114);
this.AuthRb_UseCanonicalChrome.Name = "AuthRb_UseCanonicalChrome";
this.AuthRb_UseCanonicalChrome.Size = new System.Drawing.Size(216, 17);
this.AuthRb_UseCanonicalChrome.TabIndex = 6;
this.AuthRb_UseCanonicalChrome.Text = "Use Canonical Chrome. SEE WARNING";
this.AuthRb_UseCanonicalChrome.UseVisualStyleBackColor = true;
this.AuthRb_UseCanonicalChrome.CheckedChanged += new System.EventHandler(this.AuthRb_UseCanonicalChrome_CheckedChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(27, 91);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(53, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Password";
//
// AuthRb_ManualLogin
//
this.AuthRb_ManualLogin.AutoSize = true;
this.AuthRb_ManualLogin.Location = new System.Drawing.Point(6, 42);
this.AuthRb_ManualLogin.Name = "AuthRb_ManualLogin";
this.AuthRb_ManualLogin.Size = new System.Drawing.Size(89, 17);
this.AuthRb_ManualLogin.TabIndex = 1;
this.AuthRb_ManualLogin.Text = "Manual Login";
this.AuthRb_ManualLogin.UseVisualStyleBackColor = true;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(27, 65);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Username/Email";
//
// PasswordTb
//
this.PasswordTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.PasswordTb.Location = new System.Drawing.Point(118, 88);
this.PasswordTb.Name = "PasswordTb";
this.PasswordTb.PasswordChar = '*';
this.PasswordTb.Size = new System.Drawing.Size(200, 20);
this.PasswordTb.TabIndex = 5;
this.PasswordTb.TextChanged += new System.EventHandler(this.UserIsEnteringLoginInfo);
this.PasswordTb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.UsernamePasswordTb_KeyPress);
this.PasswordTb.MouseUp += new System.Windows.Forms.MouseEventHandler(this.UserIsEnteringLoginInfo);
//
// UsernameTb
//
this.UsernameTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.UsernameTb.Location = new System.Drawing.Point(118, 62);
this.UsernameTb.Name = "UsernameTb";
this.UsernameTb.Size = new System.Drawing.Size(200, 20);
this.UsernameTb.TabIndex = 3;
this.UsernameTb.TextChanged += new System.EventHandler(this.UserIsEnteringLoginInfo);
this.UsernameTb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.UsernamePasswordTb_KeyPress);
this.UsernameTb.MouseUp += new System.Windows.Forms.MouseEventHandler(this.UserIsEnteringLoginInfo);
//
// WebsiteProcessorControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.AuthGb);
this.Name = "WebsiteProcessorControl";
this.Size = new System.Drawing.Size(324, 137);
this.AuthGb.ResumeLayout(false);
this.AuthGb.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox AuthGb;
private System.Windows.Forms.RadioButton AuthRb_UseCanonicalChrome;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RadioButton AuthRb_ManualLogin;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox PasswordTb;
private System.Windows.Forms.TextBox UsernameTb;
private System.Windows.Forms.RadioButton AuthRb_Browserless;
}
}

View File

@@ -1,47 +0,0 @@
using System;
using System.Windows.Forms;
using AudibleDotComAutomation;
namespace LibationWinForm
{
public partial class WebsiteProcessorControl : UserControl, IValidatable
{
public event EventHandler<KeyPressEventArgs> KeyPressSubmit;
public WebsiteProcessorControl()
{
InitializeComponent();
}
public IPageRetriever GetPageRetriever()
=> AuthRb_UseCanonicalChrome.Checked ? new UserDataSeleniumRetriever()
: AuthRb_Browserless.Checked ? (IPageRetriever)new BrowserlessRetriever()
: new ManualLoginSeleniumRetriever(UsernameTb.Text, PasswordTb.Text);
public string StringBasedValidate()
{
if (AuthRb_ManualLogin.Checked && (string.IsNullOrWhiteSpace(UsernameTb.Text) || string.IsNullOrWhiteSpace(PasswordTb.Text)))
return "must fill in username and password";
return null;
}
private void UsernamePasswordTb_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
KeyPressSubmit?.Invoke(sender, e);
// call your method for action on enter
e.Handled = true; // suppress default handling
}
}
private void UserIsEnteringLoginInfo(object sender, EventArgs e) => AuthRb_ManualLogin.Checked = true;
private void AuthRb_UseCanonicalChrome_CheckedChanged(object sender, EventArgs e)
{
if (AuthRb_UseCanonicalChrome.Checked)
MessageBox.Show(@"A canonical version of Chrome will be used including User Data, cookies. etc. Selenium chromedriver won't launch URL if another Chrome instance is open");
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
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
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<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
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
mimetype set.
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
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: 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
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -51,7 +51,6 @@
this.MinimizeBox = false;
this.Name = "IndexLibraryDialog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Scan Library";
this.ResumeLayout(false);

View File

@@ -1,43 +1,24 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using ApplicationService;
using System.Windows.Forms;
using ApplicationServices;
namespace LibationWinForm
{
public partial class IndexLibraryDialog : Form, IIndexLibraryDialog
public partial class IndexLibraryDialog : Form
{
public IndexLibraryDialog()
{
InitializeComponent();
var btn = new Button();
AcceptButton = btn;
btn.Location = new System.Drawing.Point(this.Size.Width + 10, 0);
// required for FindForm() to work
this.Controls.Add(btn);
this.Shown += (_, __) => AcceptButton.PerformClick();
}
public string StringBasedValidate() => null;
List<string> successMessages { get; } = new List<string>();
public string SuccessMessage => string.Join("\r\n", successMessages);
public int NewBooksAdded { get; private set; }
public int TotalBooksProcessed { get; private set; }
public async Task DoMainWorkAsync()
public IndexLibraryDialog()
{
var callback = new Login.WinformResponder();
var refresher = new LibraryIndexer();
(TotalBooksProcessed, NewBooksAdded) = await refresher.IndexAsync(callback);
InitializeComponent();
this.Shown += IndexLibraryDialog_Shown;
}
successMessages.Add($"Total processed: {TotalBooksProcessed}");
successMessages.Add($"New: {NewBooksAdded}");
private async void IndexLibraryDialog_Shown(object sender, System.EventArgs e)
{
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(new Login.WinformResponder());
this.Close();
}
}
}

View File

@@ -205,7 +205,7 @@
//
// libationFilesMyDocsRb
//
this.libationFilesMyDocsRb.AutoSize = true;
this.libationFilesMyDocsRb.AutoSize = true;
this.libationFilesMyDocsRb.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.libationFilesMyDocsRb.Location = new System.Drawing.Point(9, 68);
this.libationFilesMyDocsRb.Name = "libationFilesMyDocsRb";

View File

@@ -1,110 +1,117 @@
using FileManager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dinah.Core;
using FileManager;
namespace LibationWinForm
{
public partial class SettingsDialog : Form
{
Configuration config { get; } = Configuration.Instance;
Func<string, string> desc { get; } = Configuration.GetDescription;
string exeRoot { get; }
string myDocs { get; }
public partial class SettingsDialog : Form
{
Configuration config { get; } = Configuration.Instance;
Func<string, string> desc { get; } = Configuration.GetDescription;
string exeRoot { get; }
string myDocs { get; }
public SettingsDialog()
{
InitializeComponent();
audibleLocaleCb.SelectedIndex = 0;
bool isFirstLoad;
public SettingsDialog()
{
InitializeComponent();
this.libationFilesCustomTb.TextChanged += (_, __) =>
{
if (!string.IsNullOrWhiteSpace(libationFilesCustomTb.Text))
this.libationFilesCustomRb.Checked = true;
};
exeRoot = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Exe.FileLocationOnDisk), "Libation"));
myDocs = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Libation"));
}
myDocs = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Libation"));
}
private void SettingsDialog_Load(object sender, EventArgs e)
{
this.settingsFileTb.Text = config.Filepath;
this.settingsFileDescLbl.Text = desc(nameof(config.Filepath));
private void SettingsDialog_Load(object sender, EventArgs e)
{
isFirstLoad = string.IsNullOrWhiteSpace(config.Books);
this.decryptKeyTb.Text = config.DecryptKey;
this.decryptKeyDescLbl.Text = desc(nameof(config.DecryptKey));
this.settingsFileTb.Text = config.Filepath;
this.settingsFileDescLbl.Text = desc(nameof(config.Filepath));
this.booksLocationTb.Text = config.Books;
this.booksLocationDescLbl.Text = desc(nameof(config.Books));
this.decryptKeyTb.Text = config.DecryptKey;
this.decryptKeyDescLbl.Text = desc(nameof(config.DecryptKey));
this.audibleLocaleCb.Text = config.LocaleCountryCode;
this.booksLocationTb.Text
= !string.IsNullOrWhiteSpace(config.Books)
? config.Books
: Path.GetDirectoryName(Exe.FileLocationOnDisk);
this.booksLocationDescLbl.Text = desc(nameof(config.Books));
libationFilesDescLbl.Text = desc(nameof(config.LibationFiles));
this.libationFilesRootRb.Text = "In the same folder that Libation is running from\r\n" + exeRoot;
this.libationFilesMyDocsRb.Text = "In My Documents\r\n" + myDocs;
if (config.LibationFiles == exeRoot)
libationFilesRootRb.Checked = true;
else if (config.LibationFiles == myDocs)
libationFilesMyDocsRb.Checked = true;
else
{
libationFilesCustomRb.Checked = true;
libationFilesCustomTb.Text = config.LibationFiles;
}
this.audibleLocaleCb.Text
= !string.IsNullOrWhiteSpace(config.LocaleCountryCode)
? config.LocaleCountryCode
: "us";
this.downloadsInProgressDescLbl.Text = desc(nameof(config.DownloadsInProgressEnum));
var winTempDownloadsInProgress = Path.Combine(config.WinTemp, "DownloadsInProgress");
this.downloadsInProgressWinTempRb.Text = "In your Windows temporary folder\r\n" + winTempDownloadsInProgress;
switch (config.DownloadsInProgressEnum)
{
case "LibationFiles":
downloadsInProgressLibationFilesRb.Checked = true;
break;
case "WinTemp":
default:
downloadsInProgressWinTempRb.Checked = true;
break;
}
libationFilesDescLbl.Text = desc(nameof(config.LibationFiles));
this.libationFilesRootRb.Text = "In the same folder that Libation is running from\r\n" + exeRoot;
this.libationFilesMyDocsRb.Text = "In My Documents\r\n" + myDocs;
if (config.LibationFiles == exeRoot)
libationFilesRootRb.Checked = true;
else if (config.LibationFiles == myDocs)
libationFilesMyDocsRb.Checked = true;
else
{
libationFilesCustomRb.Checked = true;
libationFilesCustomTb.Text = config.LibationFiles;
}
this.decryptInProgressDescLbl.Text = desc(nameof(config.DecryptInProgressEnum));
var winTempDecryptInProgress = Path.Combine(config.WinTemp, "DecryptInProgress");
this.decryptInProgressWinTempRb.Text = "In your Windows temporary folder\r\n" + winTempDecryptInProgress;
switch (config.DecryptInProgressEnum)
{
case "LibationFiles":
decryptInProgressLibationFilesRb.Checked = true;
break;
case "WinTemp":
default:
decryptInProgressWinTempRb.Checked = true;
break;
}
this.downloadsInProgressDescLbl.Text = desc(nameof(config.DownloadsInProgressEnum));
var winTempDownloadsInProgress = Path.Combine(config.WinTemp, "DownloadsInProgress");
this.downloadsInProgressWinTempRb.Text = "In your Windows temporary folder\r\n" + winTempDownloadsInProgress;
switch (config.DownloadsInProgressEnum)
{
case "LibationFiles":
downloadsInProgressLibationFilesRb.Checked = true;
break;
case "WinTemp":
default:
downloadsInProgressWinTempRb.Checked = true;
break;
}
this.decryptInProgressDescLbl.Text = desc(nameof(config.DecryptInProgressEnum));
var winTempDecryptInProgress = Path.Combine(config.WinTemp, "DecryptInProgress");
this.decryptInProgressWinTempRb.Text = "In your Windows temporary folder\r\n" + winTempDecryptInProgress;
switch (config.DecryptInProgressEnum)
{
case "LibationFiles":
decryptInProgressLibationFilesRb.Checked = true;
break;
case "WinTemp":
default:
decryptInProgressWinTempRb.Checked = true;
break;
}
libationFiles_Changed(this, null);
}
}
private void libationFiles_Changed(object sender, EventArgs e)
{
var libationFilesDir
= libationFilesRootRb.Checked ? exeRoot
: libationFilesMyDocsRb.Checked ? myDocs
: libationFilesCustomTb.Text;
private void libationFiles_Changed(object sender, EventArgs e)
{
var libationFilesDir
= libationFilesRootRb.Checked ? exeRoot
: libationFilesMyDocsRb.Checked ? myDocs
: libationFilesCustomTb.Text;
var downloadsInProgress = Path.Combine(libationFilesDir, "DownloadsInProgress");
this.downloadsInProgressLibationFilesRb.Text = $"In your Libation Files (ie: program-created files)\r\n{downloadsInProgress}";
var downloadsInProgress = Path.Combine(libationFilesDir, "DownloadsInProgress");
this.downloadsInProgressLibationFilesRb.Text = $"In your Libation Files (ie: program-created files)\r\n{downloadsInProgress}";
var decryptInProgress = Path.Combine(libationFilesDir, "DecryptInProgress");
this.decryptInProgressLibationFilesRb.Text = $"In your Libation Files (ie: program-created files)\r\n{decryptInProgress}";
}
var decryptInProgress = Path.Combine(libationFilesDir, "DecryptInProgress");
this.decryptInProgressLibationFilesRb.Text = $"In your Libation Files (ie: program-created files)\r\n{decryptInProgress}";
}
private void booksLocationSearchBtn_Click(object sender, EventArgs e) => selectFolder("Search for books location", this.booksLocationTb);
private void booksLocationSearchBtn_Click(object sender, EventArgs e) => selectFolder("Search for books location", this.booksLocationTb);
private void libationFilesCustomBtn_Click(object sender, EventArgs e) => selectFolder("Search for Libation Files location", this.libationFilesCustomTb);
private static void selectFolder(string desc, TextBox textbox)
private static void selectFolder(string desc, TextBox textbox)
{
using var dialog = new FolderBrowserDialog { Description = desc, SelectedPath = "" };
dialog.ShowDialog();
@@ -143,7 +150,7 @@ namespace LibationWinForm
config.DownloadsInProgressEnum = downloadsInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp";
config.DecryptInProgressEnum = decryptInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp";
if (pathsChanged)
if (!isFirstLoad && pathsChanged)
{
var shutdownResult = MessageBox.Show(
"You have changed a file path important for this program. All files will remain in their original location; nothing will be moved. It is highly recommended that you restart this program so these changes are handled correctly."
@@ -164,5 +171,5 @@ namespace LibationWinForm
}
private void cancelBtn_Click(object sender, EventArgs e) => this.Close();
}
}
}

View File

@@ -34,10 +34,8 @@
this.filterBtn = new System.Windows.Forms.Button();
this.filterSearchTb = new System.Windows.Forms.TextBox();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.indexToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.scanLibraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reimportMostRecentLibraryScanToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.beginImportingBookDetailsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.liberateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.beginBookBackupsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.beginPdfBackupsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -100,7 +98,7 @@
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.indexToolStripMenuItem,
this.importToolStripMenuItem,
this.liberateToolStripMenuItem,
this.quickFiltersToolStripMenuItem,
this.settingsToolStripMenuItem});
@@ -110,38 +108,21 @@
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// indexToolStripMenuItem
// importToolStripMenuItem
//
this.indexToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.scanLibraryToolStripMenuItem,
this.reimportMostRecentLibraryScanToolStripMenuItem,
this.beginImportingBookDetailsToolStripMenuItem});
this.indexToolStripMenuItem.Name = "indexToolStripMenuItem";
this.indexToolStripMenuItem.Size = new System.Drawing.Size(47, 20);
this.indexToolStripMenuItem.Text = "&Index";
this.indexToolStripMenuItem.DropDownOpening += new System.EventHandler(this.indexToolStripMenuItem_DropDownOpening);
this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.scanLibraryToolStripMenuItem});
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20);
this.importToolStripMenuItem.Text = "&Import";
//
// scanLibraryToolStripMenuItem
//
this.scanLibraryToolStripMenuItem.Name = "scanLibraryToolStripMenuItem";
this.scanLibraryToolStripMenuItem.Size = new System.Drawing.Size(277, 22);
this.scanLibraryToolStripMenuItem.Text = "Scan &Library...";
this.scanLibraryToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.scanLibraryToolStripMenuItem.Text = "Scan &Library";
this.scanLibraryToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryToolStripMenuItem_Click);
//
// reimportMostRecentLibraryScanToolStripMenuItem
//
this.reimportMostRecentLibraryScanToolStripMenuItem.Name = "reimportMostRecentLibraryScanToolStripMenuItem";
this.reimportMostRecentLibraryScanToolStripMenuItem.Size = new System.Drawing.Size(277, 22);
this.reimportMostRecentLibraryScanToolStripMenuItem.Text = "Re-&import most recent library scan: {0}";
this.reimportMostRecentLibraryScanToolStripMenuItem.Click += new System.EventHandler(this.reimportMostRecentLibraryScanToolStripMenuItem_Click);
//
// beginImportingBookDetailsToolStripMenuItem
//
this.beginImportingBookDetailsToolStripMenuItem.Name = "beginImportingBookDetailsToolStripMenuItem";
this.beginImportingBookDetailsToolStripMenuItem.Size = new System.Drawing.Size(277, 22);
this.beginImportingBookDetailsToolStripMenuItem.Text = "Begin importing book details: {0}";
this.beginImportingBookDetailsToolStripMenuItem.Click += new System.EventHandler(this.beginImportingBookDetailsToolStripMenuItem_Click);
//
// liberateToolStripMenuItem
//
this.liberateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -154,16 +135,16 @@
// beginBookBackupsToolStripMenuItem
//
this.beginBookBackupsToolStripMenuItem.Name = "beginBookBackupsToolStripMenuItem";
this.beginBookBackupsToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.beginBookBackupsToolStripMenuItem.Text = "Begin &Book Backups: {0}";
this.beginBookBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginBookBackupsToolStripMenuItem_Click);
this.beginBookBackupsToolStripMenuItem.Size = new System.Drawing.Size(248, 22);
this.beginBookBackupsToolStripMenuItem.Text = "Begin &Book and PDF Backups: {0}";
this.beginBookBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginBookBackupsToolStripMenuItem_Click);
//
// beginPdfBackupsToolStripMenuItem
//
this.beginPdfBackupsToolStripMenuItem.Name = "beginPdfBackupsToolStripMenuItem";
this.beginPdfBackupsToolStripMenuItem.Size = new System.Drawing.Size(201, 22);
this.beginPdfBackupsToolStripMenuItem.Text = "Begin &PDF Backups: {0}";
this.beginPdfBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginPdfBackupsToolStripMenuItem_Click);
this.beginPdfBackupsToolStripMenuItem.Size = new System.Drawing.Size(248, 22);
this.beginPdfBackupsToolStripMenuItem.Text = "Begin &PDF Only Backups: {0}";
this.beginPdfBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginPdfBackupsToolStripMenuItem_Click);
//
// quickFiltersToolStripMenuItem
//
@@ -277,7 +258,7 @@
#endregion
private System.Windows.Forms.Panel gridPanel;
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem indexToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel springLbl;
private System.Windows.Forms.ToolStripStatusLabel visibleCountLbl;
@@ -291,8 +272,6 @@
private System.Windows.Forms.Button filterHelpBtn;
private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem scanLibraryToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem reimportMostRecentLibraryScanToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem beginImportingBookDetailsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem quickFiltersToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem firstFilterIsDefaultToolStripMenuItem;
private System.Windows.Forms.Button addFilterBtn;

View File

@@ -6,9 +6,9 @@ using System.Windows.Forms;
using DataLayer;
using Dinah.Core;
using Dinah.Core.Collections.Generic;
using Dinah.Core.Drawing;
using Dinah.Core.Windows.Forms;
using FileManager;
using ScrapingDomainServices;
namespace LibationWinForm
{
@@ -21,9 +21,6 @@ namespace LibationWinForm
private string pdfsCountsLbl_Format { get; }
private string visibleCountLbl_Format { get; }
private string reimportMostRecentLibraryScanToolStripMenuItem_format { get; }
private string beginImportingBookDetailsToolStripMenuItem_format { get; }
private string beginBookBackupsToolStripMenuItem_format { get; }
private string beginPdfBackupsToolStripMenuItem_format { get; }
@@ -36,19 +33,24 @@ namespace LibationWinForm
pdfsCountsLbl_Format = pdfsCountsLbl.Text;
visibleCountLbl_Format = visibleCountLbl.Text;
reimportMostRecentLibraryScanToolStripMenuItem_format = reimportMostRecentLibraryScanToolStripMenuItem.Text;
beginImportingBookDetailsToolStripMenuItem_format = beginImportingBookDetailsToolStripMenuItem.Text;
beginBookBackupsToolStripMenuItem_format = beginBookBackupsToolStripMenuItem.Text;
beginBookBackupsToolStripMenuItem_format = beginBookBackupsToolStripMenuItem.Text;
beginPdfBackupsToolStripMenuItem_format = beginPdfBackupsToolStripMenuItem.Text;
}
private async void Form1_Load(object sender, EventArgs e)
{
// call static ctor. There are bad race conditions if static ctor is first executed when we're running in parallel in setBackupCountsAsync()
var foo = FilePathCache.JsonFile;
{
// call static ctor. There are bad race conditions if static ctor is first executed when we're running in parallel in setBackupCountsAsync()
var foo = FilePathCache.JsonFile;
reloadGrid();
// load default/missing cover images. this will also initiate the background image downloader
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format));
PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format));
setVisibleCount(null, 0);
reloadGrid();
// also applies filter. ONLY call AFTER loading grid
loadInitialQuickFilterState();
@@ -61,18 +63,47 @@ namespace LibationWinForm
}
}
#region bottom: qty books visible
public void SetVisibleCount(int qty, string str = null)
#region reload grid
bool isProcessingGridSelect = false;
private void reloadGrid()
{
visibleCountLbl.Text = string.Format(visibleCountLbl_Format, qty);
// suppressed filter while init'ing UI
var prev_isProcessingGridSelect = isProcessingGridSelect;
isProcessingGridSelect = true;
setGrid();
isProcessingGridSelect = prev_isProcessingGridSelect;
if (!string.IsNullOrWhiteSpace(str))
visibleCountLbl.Text += " | " + str;
// UI init complete. now we can apply filter
doFilter(lastGoodFilter);
}
#endregion
#region bottom: backup counts
private async Task setBackupCountsAsync()
ProductsGrid currProductsGrid;
private void setGrid()
{
SuspendLayout();
{
if (currProductsGrid != null)
{
gridPanel.Controls.Remove(currProductsGrid);
currProductsGrid.VisibleCountChanged -= setVisibleCount;
currProductsGrid.Dispose();
}
currProductsGrid = new ProductsGrid { Dock = DockStyle.Fill };
currProductsGrid.VisibleCountChanged += setVisibleCount;
gridPanel.Controls.Add(currProductsGrid);
currProductsGrid.Display();
}
ResumeLayout();
}
#endregion
#region bottom: qty books visible
private void setVisibleCount(object _, int qty) => visibleCountLbl.Text = string.Format(visibleCountLbl_Format, qty);
#endregion
#region bottom: backup counts
private async Task setBackupCountsAsync()
{
var books = LibraryQueries.GetLibrary_Flat_NoTracking()
.Select(sp => sp.Book)
@@ -122,7 +153,7 @@ namespace LibationWinForm
// update bottom numbers
var pending = noProgress + downloadedOnly;
var text
= !results.Any() ? "No books. Begin by indexing your library"
= !results.Any() ? "No books. Begin by importing your library"
: pending > 0 ? string.Format(backupsCountsLbl_Format, noProgress, downloadedOnly, fullyBackedUp)
: $"All {"book".PluralizeWithCount(fullyBackedUp)} backed up";
statusStrip1.UIThread(() => backupsCountsLbl.Text = text);
@@ -179,41 +210,8 @@ namespace LibationWinForm
}
#endregion
#region reload grid
bool isProcessingGridSelect = false;
private void reloadGrid()
{
// suppressed filter while init'ing UI
var prev_isProcessingGridSelect = isProcessingGridSelect;
isProcessingGridSelect = true;
setGrid();
isProcessingGridSelect = prev_isProcessingGridSelect;
// UI init complete. now we can apply filter
doFilter(lastGoodFilter);
}
ProductsGrid currProductsGrid;
private void setGrid()
{
SuspendLayout();
{
if (currProductsGrid != null)
{
gridPanel.Controls.Remove(currProductsGrid);
currProductsGrid.Dispose();
}
currProductsGrid = new ProductsGrid(this) { Dock = DockStyle.Fill };
gridPanel.Controls.Add(currProductsGrid);
currProductsGrid.Display();
}
ResumeLayout();
}
#endregion
#region filter
private void filterHelpBtn_Click(object sender, EventArgs e) => new Dialogs.SearchSyntaxDialog().ShowDialog();
#region filter
private void filterHelpBtn_Click(object sender, EventArgs e) => new Dialogs.SearchSyntaxDialog().ShowDialog();
private void AddFilterBtn_Click(object sender, EventArgs e)
{
@@ -254,166 +252,41 @@ namespace LibationWinForm
MessageBox.Show($"Bad filter string:\r\n\r\n{ex.Message}", "Bad filter string", MessageBoxButtons.OK, MessageBoxIcon.Error);
// re-apply last good filter
filterSearchTb.Text = lastGoodFilter;
doFilter();
doFilter(lastGoodFilter);
}
}
#endregion
#region index menu
//
// IMPORTANT
//
// IRunnableDialog.Run() extension method contains work flow
//
#region // example code: chaining multiple dialogs
public class MyDialog1 : IRunnableDialog
{
public IEnumerable<string> Files;
public IButtonControl AcceptButton { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public Control.ControlCollection Controls => throw new NotImplementedException();
public string SuccessMessage => throw new NotImplementedException();
public DialogResult DialogResult { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public void Close() => throw new NotImplementedException();
public Task DoMainWorkAsync() => throw new NotImplementedException();
public DialogResult ShowDialog() => throw new NotImplementedException();
public string StringBasedValidate() => throw new NotImplementedException();
}
public class MyDialog2 : Form, IIndexLibraryDialog
{
public MyDialog2(IEnumerable<string> files) { }
Button BeginFileImportBtn = new Button();
public void Begin() => BeginFileImportBtn.PerformClick();
public int TotalBooksProcessed => throw new NotImplementedException();
public int NewBooksAdded => throw new NotImplementedException();
public string SuccessMessage => throw new NotImplementedException();
public Task DoMainWorkAsync() => throw new NotImplementedException();
public string StringBasedValidate() => throw new NotImplementedException();
}
private async void downloadPagesToFile(object sender, EventArgs e)
{
var dialog1 = new MyDialog1();
if (dialog1.RunDialog() != DialogResult.OK || !dialog1.Files.Any())
return;
if (MessageBox.Show("Index from these files?", "Index?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
var dialog2 = new MyDialog2(dialog1.Files);
dialog2.Shown += (_, __) => dialog2.Begin();
await indexDialog(dialog2);
}
}
#endregion
private void indexToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
#region label: Re-import most recent library scan
{
var libDir = WebpageStorage.GetMostRecentLibraryDir();
if (libDir == null)
{
reimportMostRecentLibraryScanToolStripMenuItem.Enabled = false;
reimportMostRecentLibraryScanToolStripMenuItem.Text = string.Format(reimportMostRecentLibraryScanToolStripMenuItem_format, "No previous scans");
}
else
{
reimportMostRecentLibraryScanToolStripMenuItem.Enabled = true;
var now = DateTime.Now;
var span = now - libDir.CreationTime;
var ago
// less than 1 min
= (int)span.TotalSeconds < 60 ? $"{(int)span.TotalSeconds} sec ago"
// less than 1 hr
: (int)span.TotalMinutes < 60 ? $"{(int)span.TotalMinutes} min ago"
// today. eg: 4:25 PM
: now.Date == libDir.CreationTime.Date ? libDir.CreationTime.ToString("h:mm tt")
// else date and time
: libDir.CreationTime.ToString("MM/dd/yyyy h:mm tt");
reimportMostRecentLibraryScanToolStripMenuItem.Text = string.Format(reimportMostRecentLibraryScanToolStripMenuItem_format, ago);
}
}
#endregion
#region label: Begin importing book details
{
var noDetails = BookQueries.BooksWithoutDetailsCount();
if (noDetails == 0)
{
beginImportingBookDetailsToolStripMenuItem.Enabled = false;
beginImportingBookDetailsToolStripMenuItem.Text = string.Format(beginImportingBookDetailsToolStripMenuItem_format, "No books without details");
}
else
{
beginImportingBookDetailsToolStripMenuItem.Enabled = true;
beginImportingBookDetailsToolStripMenuItem.Text = string.Format(beginImportingBookDetailsToolStripMenuItem_format, $"{noDetails} remaining");
}
}
#endregion
}
#endregion
#region index menu
private async void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e)
{
// legacy/scraping method
//await indexDialog(new ScanLibraryDialog());
// new/api method
await indexDialog(new IndexLibraryDialog());
using var dialog = new IndexLibraryDialog();
dialog.ShowDialog();
var totalProcessed = dialog.TotalBooksProcessed;
var newAdded = dialog.NewBooksAdded;
MessageBox.Show($"Total processed: {totalProcessed}\r\nNew: {newAdded}");
// update backup counts if we have new library items
if (newAdded > 0)
await setBackupCountsAsync();
if (totalProcessed > 0)
reloadGrid();
}
#endregion
private async void reimportMostRecentLibraryScanToolStripMenuItem_Click(object sender, EventArgs e)
{
// DO NOT ConfigureAwait(false)
// this would result in index() => reloadGrid() => setGrid() => "gridPanel.Controls.Remove(currProductsGrid);"
// throwing 'Cross-thread operation not valid: Control 'ProductsGrid' accessed from a thread other than the thread it was created on.'
var (TotalBooksProcessed, NewBooksAdded) = await Indexer.IndexLibraryAsync(WebpageStorage.GetMostRecentLibraryDir());
MessageBox.Show($"Total processed: {TotalBooksProcessed}\r\nNew: {NewBooksAdded}");
await indexComplete(TotalBooksProcessed, NewBooksAdded);
}
private async Task indexDialog(IIndexLibraryDialog dialog)
{
if (!dialog.RunDialog().In(DialogResult.Abort, DialogResult.Cancel, DialogResult.None))
await indexComplete(dialog.TotalBooksProcessed, dialog.NewBooksAdded);
}
private async Task indexComplete(int totalBooksProcessed, int newBooksAdded)
{
// update backup counts if we have new library items
if (newBooksAdded > 0)
await setBackupCountsAsync();
// skip reload if:
// - no grid is loaded
// - none indexed
if (currProductsGrid == null || totalBooksProcessed == 0)
return;
reloadGrid();
}
private void updateGridRow(object _, string productId) => currProductsGrid?.UpdateRow(productId);
private async void beginImportingBookDetailsToolStripMenuItem_Click(object sender, EventArgs e)
{
var scrapeBookDetails = BookLiberation.ProcessorAutomationController.GetWiredUpScrapeBookDetails();
scrapeBookDetails.BookSuccessfullyImported += updateGridRow;
await BookLiberation.ProcessorAutomationController.RunAutomaticDownload(scrapeBookDetails);
}
#endregion
#region liberate menu
private async void setBackupCountsAsync(object _, string __) => await setBackupCountsAsync();
#region liberate menu
private async void setBackupCountsAsync(object _, string __) => await setBackupCountsAsync();
private async void beginBookBackupsToolStripMenuItem_Click(object sender, EventArgs e)
{
var backupBook = BookLiberation.ProcessorAutomationController.GetWiredUpBackupBook();
backupBook.Download.Completed += setBackupCountsAsync;
backupBook.Decrypt.Completed += setBackupCountsAsync;
await BookLiberation.ProcessorAutomationController.RunAutomaticBackup(backupBook);
backupBook.DownloadBook.Completed += setBackupCountsAsync;
backupBook.DecryptBook.Completed += setBackupCountsAsync;
backupBook.DownloadPdf.Completed += setBackupCountsAsync;
await BookLiberation.ProcessorAutomationController.RunAutomaticBackup(backupBook);
}
private async void beginPdfBackupsToolStripMenuItem_Click(object sender, EventArgs e)

View File

@@ -37,9 +37,7 @@ namespace LibationWinForm
public bool TryGetFormatted(string key, out string value) => formatReplacements.TryGetValue(key, out value);
public Image Cover =>
Dinah.Core.Drawing.ImageConverter.GetPictureFromBytes(
FileManager.PictureStorage.GetImage(book.PictureId, FileManager.PictureStorage.PictureSize._80x80)
);
WindowsDesktopUtilities.WinAudibleImageServer.GetImage(book.PictureId, FileManager.PictureSize._80x80);
public string Title
{

View File

@@ -2,9 +2,10 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Dinah.Core.DataBinding;
using ApplicationServices;
using DataLayer;
using Dinah.Core.Collections.Generic;
using Dinah.Core.DataBinding;
namespace LibationWinForm
{
@@ -22,13 +23,11 @@ namespace LibationWinForm
// - click on Data Sources > ProductItem. drowdown: DataGridView
// - drag/drop ProductItem on design surface
public partial class ProductsGrid : UserControl
{
private DataGridView dataGridView;
{
public event EventHandler<int> VisibleCountChanged;
private Form1 parent;
private DataGridView dataGridView;
// this is a simple ctor for loading library and wish list. can expand later for other options. eg: overload ctor
public ProductsGrid(Form1 parent) : this() => this.parent = parent;
public ProductsGrid() => InitializeComponent();
private bool hasBeenDisplayed = false;
@@ -54,7 +53,7 @@ namespace LibationWinForm
dataGridView.CellFormatting += replaceFormatted;
dataGridView.CellFormatting += hiddenFormatting;
// sorting breaks filters. must reapply filters after sorting
dataGridView.Sorted += (_, __) => Filter();
dataGridView.Sorted += (_, __) => filter();
{ // add tag buttons
var editUserTagsButton = new DataGridViewButtonColumn { HeaderText = "Edit Tags" };
@@ -92,6 +91,15 @@ namespace LibationWinForm
// transform into sorted GridEntry.s BEFORE binding
//
var lib = LibraryQueries.GetLibrary_Flat_NoTracking();
// if no data. hide all columns. return
if (!lib.Any())
{
for (var i = dataGridView.ColumnCount - 1; i >= 0; i--)
dataGridView.Columns.RemoveAt(i);
return;
}
var orderedGridEntries = lib
.Select(lb => new GridEntry(lb)).ToList()
// default load order
@@ -107,36 +115,10 @@ namespace LibationWinForm
//
gridEntryBindingSource.DataSource = orderedGridEntries.ToSortableBindingList();
//
// AFTER BINDING, BEFORE FILTERING
//
// now that we have data, remove/hide text columns with blank data. don't search image and button columns.
// simplifies the interface in general. also distinuishes library from wish list etc w/o explicit filters.
// must be AFTER BINDING, BEFORE FILTERING because we don't want to remove rows when valid data is simply not visible due to filtering.
for (var c = dataGridView.ColumnCount - 1; c >= 0; c--)
{
if (!(dataGridView.Columns[c] is DataGridViewTextBoxColumn textCol))
continue;
bool hasData = false;
for (var r = 0; r < dataGridView.RowCount; r++)
{
var value = dataGridView[c, r].Value;
if (value != null && value.ToString() != "")
{
hasData = true;
break;
}
}
if (!hasData)
dataGridView.Columns.Remove(textCol);
}
//
// FILTER
//
Filter();
filter();
}
private void paintEditTag_TextAndImage(object sender, DataGridViewCellPaintingEventArgs e)
@@ -201,14 +183,14 @@ namespace LibationWinForm
// needed to update text colors
dataGridView.InvalidateRow(e.RowIndex);
Filter();
filter();
}
private static int saveChangedTags(Book book, string newTags)
{
book.UserDefinedItem.Tags = newTags;
var qtyChanges = ScrapingDomainServices.Indexer.IndexChangedTags(book);
var qtyChanges = LibraryCommands.IndexChangedTags(book);
return qtyChanges;
}
@@ -249,12 +231,15 @@ namespace LibationWinForm
#region filter
string _filterSearchString;
public void Filter() => Filter(_filterSearchString);
private void filter() => Filter(_filterSearchString);
public void Filter(string searchString)
{
_filterSearchString = searchString;
var searchResults = new LibationSearchEngine.SearchEngine().Search(searchString);
if (dataGridView.Rows.Count == 0)
return;
var searchResults = SearchEngineCommands.Search(searchString);
var productIds = searchResults.Docs.Select(d => d.ProductId).ToList();
// https://stackoverflow.com/a/18942430
@@ -265,10 +250,9 @@ namespace LibationWinForm
dataGridView.Rows[r].Visible = productIds.Contains(getGridEntry(r).GetBook().AudibleProductId);
}
currencyManager.ResumeBinding();
VisibleCountChanged?.Invoke(this, dataGridView.Rows.Cast<DataGridViewRow>().Count(r => r.Visible));
// after applying filters, display new visible count
parent.SetVisibleCount(dataGridView.Rows.Cast<DataGridViewRow>().Count(r => r.Visible), searchResults.SearchString);
var luceneSearchString_debug = searchResults.SearchString;
}
#endregion

View File

@@ -1,22 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LibationWinForm
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!createSettings())
return;
Application.Run(new Form1());
}
private static bool createSettings()
{
if (!string.IsNullOrWhiteSpace(FileManager.Configuration.Instance.Books))
return true;
var welcomeText = @"
This appears to be your first time using Libation. Welcome.
Please fill in a few settings on the following page. You can also change these settings later.
After you make your selections, get started by importing your library.
Go to Import > Scan Library
".Trim();
MessageBox.Show(welcomeText, "Welcom to Libation", MessageBoxButtons.OK);
var dialogResult = new SettingsDialog().ShowDialog();
if (dialogResult != DialogResult.OK)
{
MessageBox.Show("Initial set up cancelled.", "Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
}
}

186
README.md
View File

@@ -1,14 +1,180 @@
# Libation
Libation: Liberate your Library
# Libation: Liberate your Library
Audible audiobook manager
# Table of Contents
1. [Audible audiobook manager](#audible-audiobook-manager)
- [The good](#the-good)
- [The bad](#the-bad)
- [The ugly](#the-ugly)
2. [Getting started](#getting-started)
- [Import your library](#import-your-library)
- [Download your books -- DRM-free!](#download-your-books----drm-free)
- [Download PDF attachments](#download-pdf-attachments)
- [Details of downloaded files](#details-of-downloaded-files)
3. [Searching and filtering](#searching-and-filtering)
- [Tags](#tags)
- [Searches](#searches)
- [Search examples](#search-examples)
- [Filters](#filters)
## Audible audiobook manager
### The good
* Import library from audible, including cover art
* Download and remove DRM from all books
* Download accompanying PDFs
* Add tags to books for better organization
* Powerful advanced search built on the Lucene search engine
* Customizable saved filters for common searches
* Open source
* Tested on US Audible only. Should theoretically also work for Canada, UK, Germany, and France
<a name="theBad"/>
### The bad
* Download
* Decrypt. Remove DRM
* Organize
* Advanced search
* Tags
* Open-source
* Windows only
* Several known speed/performance issues
* Made by a programmer, not a designer so the goals are function rather than beauty. And it shows
Current version is functional but is built around a fragile scraping engine. The next version will replace this part with API calls which will make it significantly more robust.
### The ugly
* Documentation? Yer lookin' at it
* This is a single-developer personal passion project. Support, response, updates, enhancements, bug fixes etc are as my free time allows
* I have a full-time job, a life, and a finite attention span. Therefore a lot of time can potentially go by with no improvements of any kind
Disclaimer: I've made every good-faith effort to include nothing insecure, malicious, anti-privacy, or destructive. That said: use at your own risk.
I made this for myself and I want to share it with the great programming and audible/audiobook communiites which have been so generous with their time and help.
## Getting started
### Import your library
Select Import > Scan Library:
![Import step 1](images/Import1.png)
You'll see this window while it's scanning:
![Import step 2](images/Import2.png)
Success! We see how many new titles are imported:
![Import step 3](images/Import3.png)
### Download your books -- DRM-free!
Automatically download some or all of your audible books. This shows you how much of your library is not yet downloaded and decrypted:
![Liberate book step 1](images/LiberateBook1.png)
Select Liberate > Begin Book Backups
![Liberate book step 2](images/LiberateBook2.png)
First the original book with DRM is downloaded
![Liberate book step 3](images/LiberateBook3.png)
Then it's decrypted so you can use it on any device you choose. The very first time you decrypt a book, this step will take a while. Every other book will go much faster. The first time, Libation has to figure out the special decryption key which allows your personal books to be unlocked.
![Liberate book step 4](images/LiberateBook4.png)
And voila! If you have multiple books not yet liberated, Libation will automatically move on to the next.
![Liberate book step 5](images/LiberateBook5.png)
### Download PDF attachments
For books which include PDF downloads, Libation can download these for you as well and will attempt to store them with the book. "Book backup" will already download an available PDF. This additional option is useful when Audible adds a PDF to your book after you've already backed it up.
![PDF download step 1](images/PdfDownload1.png)
Select Liberate > Begin PDF Backups
![PDF download step 2](images/PdfDownload2.png)
The downloads work just like with books, only with no additional decryption needed.
![PDF download step 3](images/PdfDownload3.png)
Ta da!
![PDF download step 4](images/PdfDownload4.png)
### Details of downloaded files
![Post download](images/PostDownload.png)
When you set up Libation, you'll specify a Books directory. Libation looks inside that directory and all subdirectories to look for files or folders with each library book's audible id. This way, organization is completely up to you. When you download + decrypt a book, you get several files
* .m4b: your audiobook in m4b format. This is the most pure version of your audiobook and retains the highest quality. Now that it's decrypted, you can play it on any audio player and put it on any device. If you'd like, you can also use 3rd party tools to turn it into an mp3. The freedom to do what you want with your files was the original inspiration for Libation.
* .cue: this is a file which logs where chapter breaks occur. Many tools are able to use this if you want to split your book into files along chapter lines.
* .nfo: This is just some general info about the book and includes some technical stats about the audiofile.
## Searching and filtering
### Tags
To add tags to a title, click the tags button
![Tags step 1](images/Tags1.png)
Add as many tags as you'd like. Tags are separated by a space. Each tag can contain letters, numbers, and underscores
![Tags step 2](images/Tags2.png)
Tags are saved non-case specific for easy search. There is one special tag "hidden" which will also grey-out the book
![Tags step 3](images/Tags3.png)
To edit tags, just click the button again.
### Searches
Libation's advanced searching is built on the powerful Lucene search engine. Simple searches are effortless and powerful searches are simple. To search, just type and click Filter or press enter
* Type anything in the search box to search common fields: title, authors, narrators, and the book's audible id
* Use Lucene's "Query Parser Syntax" for advanced searching.
* Easy tutorial: http://www.lucenetutorial.com/lucene-query-syntax.html
* Full official guide: https://lucene.apache.org/core/2_9_4/queryparsersyntax.html
* Tons of search fields, specific to audiobooks
* Synonyms so you don't have to memorize magic words. Eg: author and author**s** will both work
* Click [?] button for a full list of search fields and synonyms ![Filter options](images/FilterOptions.png)
* Search by tag like \[this\]
* When tags have an underscore you can use part of the tag. This is useful for quick categories. The below examples make this more clear.
### Search examples
Search for anything with the word potter
![Search example: potter](images/SearchExamplePotter.png)
If you only want to see Harry Potter
![Search example: "harry potter"](images/SearchExampleHarryPotter.png)
If you only want to see potter except for Harry Potter
![Search example: "potter NOT harry"](images/SearchExamplePotterNotHarry.png)
Only books written by Neil Gaiman where he also narrates his own book. (If you don't include AND, you'll see everything written by Neil Gaiman and also all books in your library which are self-narrated.)
![Search example: author:gaiman AND authornarrated](images/SearchExampleGaimanAuthorNarrated.png)
I tagged autobiographies as auto_bio and biographies written by someone else as bio. I can get only autobiographies with \[auto_bio\] or get both by searching \[bio\]
![Search example: \[bio\]](images/SearchExampleBio.png)
![Search example: \[auto_bio\]](images/SearchExampleAutoBio.png)
### Filters
If you have a search you want to save, click Add To Quick Filters to save it in your Quick Filters list. To use it again, select it from the Quick Filters list.
To edit this list go to Quick Filters > Edit quick filters. Here you can re-order the list, delete filters, double-click a filter to edit it, or double-click the bottom blank box to add a new filter.
Check "Quick Filters > Start Libation with 1st filter Default" to have your top filter automatically applied when Libation starts. In this top example, I want to always start without these: at books I've tagged hidden, books I've tagged as free_audible_originals, and books which I have rated.
![default filters](images/FiltersDefault.png)

View File

@@ -1,5 +1,34 @@
-- begin LEGACY CODE ---------------------------------------------------------------------------------------------------------------------
-- end LEGACY CODE ---------------------------------------------------------------------------------------------------------------------
-- begin VERSIONING ---------------------------------------------------------------------------------------------------------------------
https://github.com/rmcrackan/Libation/releases
v3.0.3 : Switch to SQLite
v3.0.2 : Final using LocalDB
v3.0.1 : Legacy inAudible wire-up code is still present but is commented out. All future check-ins are not guaranteed to have inAudible wire-up code
v3.0 : This version is fully powered by the Audible API. Legacy scraping code is still present but is commented out. All future check-ins are not guaranteed to have any scraping code
-- end VERSIONING ---------------------------------------------------------------------------------------------------------------------
-- begin HOW TO PUBLISH ---------------------------------------------------------------------------------------------------------------------
OPTION 1: UI
rt-clk project > Publish...
click Publish
OPTION 2: cmd line
change dir to folder containing project
cd C:\[full...path]\Libation\LibationWinForm
this will use the parameters specified in csproj
dotnet publish -c Release
OPTION 3: cmd line, custom
open csproj
remove: PublishTrimmed, PublishReadyToRun, PublishSingleFile, RuntimeIdentifier
run customized publish. examples:
publish all platforms
dotnet publish -c Release
publish win64 platform only
dotnet publish -r win-x64 -c Release
publish win64 platform, single-file
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true
-- end HOW TO PUBLISH ---------------------------------------------------------------------------------------------------------------------
-- begin AUDIBLE DETAILS ---------------------------------------------------------------------------------------------------------------------
alternate book id (eg BK_RAND_006061) is called 'sku' , 'sku_lite' , 'prod_id' , 'product_id' in different parts of the site

View File

@@ -1,11 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AudibleDotCom\AudibleDotCom.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AudibleDotCom;
using Dinah.Core;
using DTOs;
using Scraping.BookDetail;
using Scraping.Library;
namespace Scraping
{
public static class AudibleScraper
{
public static List<LibraryDTO> ScrapeLibrarySources(params AudiblePageSource[] pageSources)
{
if (pageSources == null || !pageSources.Any())
return new List<LibraryDTO>();
if (pageSources.Select(ps => ps.AudiblePage).Distinct().Single() != AudiblePageType.Library)
throw new Exception("only Library items allowed");
return pageSources.SelectMany(s => scrapeLibraryPageSource(s)).ToList();
}
private static List<LibraryDTO> scrapeLibraryPageSource(AudiblePageSource pageSource)
=> new LibraryScraper(pageSource)
.ScrapeCurrentPage()
// ScrapeCurrentPage() is long running. do not taunt delayed execution
.ToList();
public static BookDetailDTO ScrapeBookDetailsSource(AudiblePageSource pageSource)
{
ArgumentValidator.EnsureNotNull(pageSource, nameof(pageSource));
if (pageSource.AudiblePage != AudiblePageType.ProductDetails)
throw new Exception("only Product Details items allowed");
try
{
return new BookDetailScraper(pageSource).ScrapePage();
}
catch (Exception ex)
{
throw;
}
}
}
}

View File

@@ -1,175 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AudibleDotCom;
using Dinah.Core;
using DTOs;
using Newtonsoft.Json.Linq;
using Scraping.Selectors;
namespace Scraping.BookDetail
{
static class NewtonsoftExt
{
public static string GetDecodedTokenString(this JToken jToken) => System.Net.WebUtility.HtmlDecode(((string)jToken).Trim());
}
internal class BookDetailScraper
{
private AudiblePageSource source { get; }
private WebElement docRoot { get; }
public BookDetailScraper(AudiblePageSource pageSource)
{
source = pageSource;
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(source.Source);
docRoot = new WebElement(doc.DocumentNode);
}
static RuleFamilyBD ruleFamily { get; } = new RuleFamilyBD
{
RowsLocator = By.XPath("/*"),
Rules = new RuleSetBD
{
parseJson,
parseSeries
}
};
public BookDetailDTO ScrapePage()
{
//debug//var sw = System.Diagnostics.Stopwatch.StartNew();
var returnBookDetailDto = new BookDetailDTO { ProductId = source.PageId };
var wholePage = ruleFamily.GetRows(docRoot).Single();
ruleFamily.Rules.Run(wholePage, returnBookDetailDto);
//debug//sw.Stop(); var ms = sw.ElapsedMilliseconds;
return returnBookDetailDto;
}
static void parseJson(WebElement row, BookDetailDTO productItem)
{
// structured data is in the 2nd of the 3 json embedded sections <script type="application/ld+json">
var ldJson = row
.FindElements(By.XPath("//script[@type='application/ld+json']"))
[1]
// use InnerText NOT webElement.Text
// .Text decodes which will break json if it contains &quot;
// eg: "foo &quot; bar" => "foo " bar"
.Node.InnerText;
var jsonArray = JArray.Parse(ldJson);
var json0 = jsonArray[0] as JObject;
//// ways to enumerate properties
//foreach (var kvp in json0) Console.WriteLine(kvp.Key);
//foreach (var prop in json0.Properties()) Console.WriteLine(prop.Name);
var properties = json0.Properties().Select(p => p.Name).ToList();
// mandatory
productItem.Title = json0["name"].GetDecodedTokenString();
productItem.Description = json0["description"].GetDecodedTokenString();
productItem.Publisher = json0["publisher"].GetDecodedTokenString();
productItem.DatePublished = DateTime.Parse(json0["datePublished"].GetDecodedTokenString());
// optional
if (properties.Contains("abridged"))
productItem.IsAbridged = Convert.ToBoolean(json0["abridged"].GetDecodedTokenString());
// not all books have narrators
if (properties.Contains("readBy"))
foreach (var narrator in json0["readBy"])
productItem.Narrators.Add(narrator["name"].GetDecodedTokenString());
var json1 = jsonArray[1]["itemListElement"];
foreach (var element in json1)
{
var item = element["item"];
var id = item["@id"].GetDecodedTokenString();
if (!id.ContainsInsensitive("/cat/"))
continue;
var categoryId = id.Split('?')[0].Split('/').Last();
var categoryName = item["name"].GetDecodedTokenString();
productItem.Categories.Add((categoryId, categoryName));
}
}
static void parseSeries(WebElement row, BookDetailDTO productItem)
{
var element = row.FindElements(By.ClassName("seriesLabel")).SingleOrDefault();
if (element == null)
return;
var currEntry = new SeriesEntry();
var children = element.Node.ChildNodes;
// skip 0. It's just the label "Series:"
for (var i = 1; i < children.Count; i++)
{
var c = children[i];
// if contains html: // series name and id. begin new entry
// new book entry
if (c.HasChildNodes)
{
string seriesId = null;
var href = c.Attributes["href"].Value;
var h2 = href.Split('?')[1];
var h3 = h2.Split('&');
foreach (var h in h3)
{
var h4 = h.Split('=');
if (h4[0].EqualsInsensitive("asin"))
{
seriesId = h4[1];
break;
}
}
if (seriesId == null)
{
// try this format instead
if (href.StartsWithInsensitive("/series/"))
{
// href
// /series/The-Interdependency-Audiobooks/B06XKNK664?pf_rd_p=52918805-f7fc-40f4-a76b-cf1c79f7d10a&pf_rd_r=GV7000W2BM97V9Z35ZQD&ref=a_pd_The-Co_c1_series_1
var mainUrl = href.Split('?')[0];
// mainUrl
// /series/The-Interdependency-Audiobooks/B06XKNK664
var urlAsin = mainUrl.Split('/').Last();
// sanity check
if (urlAsin.StartsWithInsensitive("B") && urlAsin.Length == "B07CM5ZDJL".Length)
seriesId = urlAsin;
}
}
if (seriesId == null)
throw new Exception("series id not found");
currEntry = new SeriesEntry { SeriesId = seriesId, SeriesName = c.FirstChild.InnerText };
productItem.Series.Add(currEntry);
}
// else: is the index in prev series. not all books have an index
else
{
var indexString = c.InnerText
.ToLower()
.Replace("book", "")
.Replace(",", "")
.Trim();
if (float.TryParse(indexString, out float index))
currEntry.Index = index;
}
}
}
}
}

View File

@@ -1,27 +0,0 @@
using System;
using Scraping.Rules;
using Scraping.Selectors;
using DTO = DTOs.BookDetailDTO;
namespace Scraping.BookDetail
{
/// <summary>not the same as LocatedRuleSet. IRuleClass only acts upon 1 product item at a time. RuleFamily returns many product items</summary>
internal class RuleFamilyBD : RuleFamily<DTO> { }
internal interface IRuleClassBD : IRuleClass<DTO> { }
internal class BasicRuleBD : BasicRule<DTO>, IRuleClassBD
{
public BasicRuleBD() : base() { }
public BasicRuleBD(Action<WebElement, DTO> action) : base(action) { }
}
internal class RuleSetBD : RuleSet<DTO>, IRuleClassBD { }
/// <summary>LocatedRuleSet loops through found items. When it's 0 or 1, LocatedRuleSet is an easy way to parse only if exists</summary>
internal class LocatedRuleSetBD : LocatedRuleSet<DTO>, IRuleClassBD
{
public LocatedRuleSetBD(By elementsLocator) : base(elementsLocator) { }
}
}

View File

@@ -1,38 +0,0 @@
using System;
using System.Collections.Generic;
namespace DTOs
{
public class SeriesEntry
{
public string SeriesId;
public string SeriesName;
public float? Index;
}
public class BookDetailDTO
{
public string ProductId { get; set; }
/// <summary>DEBUG only</summary>
public string Title { get; set; }
/// <summary>UNUSED: currently unused: desc from book-details is better desc in lib, but book-details also contains html tags</summary>
public string Description { get; set; }
public bool IsAbridged { get; set; }
// order matters: don't use hashtable/dictionary
public List<string> Narrators { get; } = new List<string>();
public string Publisher { get; set; }
public DateTime DatePublished { get; set; }
// order matters: don't use hashtable/dictionary
public List<(string categoryId, string categoryName)> Categories { get; } = new List<(string categoryId, string categoryName)>();
public List<SeriesEntry> Series { get; } = new List<SeriesEntry>();
public override string ToString() => $"[{ProductId}] {Title}";
}
}

View File

@@ -1,49 +0,0 @@
using System;
using System.Collections.Generic;
namespace DTOs
{
public class LibraryDTO
{
//
// must initialize optional collections
//
public string ProductId { get; set; }
public string Title { get; set; }
/// <summary>Whether this product is episodic. These will not have a book download link or personal library ratings</summary>
public bool IsEpisodes { get; set; }
// order matters. do not use a hashtable/dictionary
public List<(string authorName, string authorId)> Authors { get; set; } = new List<(string name, string id)>();
public string[] Narrators { get; set; } = new string[0];
public int LengthInMinutes { get; set; }
public string Description { get; set; }
public string PictureId { get; set; }
/// <summary>Key: Id. Value: Name</summary>
public Dictionary<string, string> Series { get; } = new Dictionary<string, string>();
// aggregate community ratings for this product
public float Product_OverallStars { get; set; }
public float Product_PerformanceStars { get; set; }
public float Product_StoryStars { get; set; }
// my personal user ratings for this product (only products i own. ie: in library)
public int MyUserRating_Overall { get; set; }
public int MyUserRating_Performance { get; set; }
public int MyUserRating_Story { get; set; }
public List<string> SupplementUrls { get; set; } = new List<string>();
public DateTime DateAdded { get; set; }
public string DownloadBookLink { get; set; }
public override string ToString() => $"[{ProductId}] {Title}";
}
}

Some files were not shown because too many files have changed in this diff Show More