Various updates...
MODIFY
XRayBuilder.Core/src/DataSources/Amazon/IAmazonClient.cs
XRayBuilder.Core/src/DataSources/Amazon/IAmazonClient.cs
@@ -17,5 +17,7 @@ public interface IAmazonClient
Task<AuthorSearchResults> SearchAuthor(string author, string TLD, CancellationToken cancellationToken, bool enableLog = true);
Task<BookInfo> SearchBook(string title, string author, string TLD, CancellationToken cancellationToken);
IAsyncEnumerable<BookInfo> EnhanceBookInfos(IEnumerable<BookInfo> books, CancellationToken cancellationToken);
+ [CanBeNull]
+ Task<BookInfo> GetBookByAsin(string asin, string tld, CancellationToken cancellationToken);
}
}
\ No newline at end of file

MODIFY
XRayBuilder.Core/src/DataSources/Secondary/SecondarySourceGoodreads.cs
XRayBuilder.Core/src/DataSources/Secondary/SecondarySourceGoodreads.cs
@@ -153,20 +153,20 @@ public override async Task<SeriesInfo> GetSeriesInfoAsync(string dataUrl, Cancel
var seriesHtmlDoc = await _httpClient.GetPageAsync(series.Url, cancellationToken);
- seriesNode = seriesHtmlDoc.DocumentNode.SelectSingleNode("//div[contains(@class, 'responsiveSeriesHeader__subtitle')]");
- match = Regex.Match(seriesNode?.InnerText ?? "", @"([0-9]+) (?:primary )?works?");
- if (match.Success)
- series.Total = int.Parse(match.Groups[1].Value);
-
- var positionInt = (int)Convert.ToDouble(series.Position, CultureInfo.InvariantCulture.NumberFormat);
- var totalInt = (int)Convert.ToDouble(series.Total, CultureInfo.InvariantCulture.NumberFormat);
-
var bookNodes = seriesHtmlDoc.DocumentNode.SelectNodes("//div[@itemtype='http://schema.org/Book']");
if (bookNodes == null)
return series;
- var prevSearch = series.Position.Contains(".")
- ? $"book {positionInt}"
- : $"book {positionInt - 1}";
+
+ series.Total = bookNodes
+ .Select(node => node.PreviousSibling)
+ .Count(node => Regex.IsMatch(node?.InnerText.ToUpper() ?? "", @"^BOOK ([0-9]+)$"));
+
+ if (series.Total == 0)
+ return series;
+
+ var positionInt = (int)Convert.ToDouble(series.Position, CultureInfo.InvariantCulture.NumberFormat);
+
+ var prevSearch = $"book {positionInt - 1}";
var nextSearch = $"book {positionInt + 1}";
async Task<BookInfo> ParseSeriesBook(HtmlNode bookNode)
@@ -201,7 +201,7 @@ async Task<BookInfo> ParseSeriesBook(HtmlNode bookNode)
else if (bookIndexText == nextSearch)
series.Next = await ParseSeriesBook(bookNode);
- if (series.Previous != null && (series.Next != null || positionInt == totalInt))
+ if (series.Previous != null && (series.Next != null || positionInt == series.Total))
break; // next and prev found or prev found and latest in series
}

MODIFY
XRayBuilder.Core/src/Extras/AuthorProfile/AuthorProfileGenerator.cs
XRayBuilder.Core/src/Extras/AuthorProfile/AuthorProfileGenerator.cs
@@ -61,6 +61,11 @@ public async Task<Response> GenerateAsync(Request request, Func<string, bool> ed
if (searchResults == null)
return null; // Already logged error in search function
+ // Filter out any results that are the same title but not the same asin
+ searchResults.Books = searchResults.Books
+ .Where(book => !book.Title.ToLower().Contains(request.Book.Title.ToLower()) && book.Asin != request.Book.Asin)
+ .ToArray();
+
var authorAsin = searchResults.Asin;
//todo re-implement saving in a nicer way

MODIFY
XRayBuilder.Core/src/Extras/EndActions/EndActionsArtifactService.cs
XRayBuilder.Core/src/Extras/EndActions/EndActionsArtifactService.cs
@@ -96,12 +96,18 @@ public string GenerateNew(Request request)
endActions.Data.AuthorRecs = new Recs
{
Class = "featuredRecommendationList",
- Recommendations = request.AuthorOtherBooks.Select(bk => Extensions.BookInfoToBook(bk, true)).ToArray()
+ Recommendations = request.AuthorOtherBooks
+ .Select(bk => Extensions.BookInfoToBook(bk, true))
+ .ToArray()
};
+
endActions.Data.CustomersWhoBoughtRecs = new Recs
{
Class = "featuredRecommendationList",
- Recommendations = request.CustomerAlsoBought.Select(bk => Extensions.BookInfoToBook(bk, true)).ToArray()
+ Recommendations = request.CustomerAlsoBought
+ .Where(b => request.AuthorOtherBooks.All(a => a.Asin != b.Asin && !b.Title.ToLower().Contains(a.Title.ToLower())))
+ .Select(bk => Extensions.BookInfoToBook(bk, true))
+ .ToArray()
};
try

MODIFY
XRayBuilder.Core/src/Extras/EndActions/EndActionsDataGenerator.cs
XRayBuilder.Core/src/Extras/EndActions/EndActionsDataGenerator.cs
@@ -139,7 +139,7 @@ string ReadDesc(string file)
: Enumerable.Empty<BookInfo>();
}).Where(list => list != null)
.Distinct()
- .Where(book => book.Title != curBook.Title && book.Asin != curBook.Asin)
+ .Where(book => !book.Title.ToLower().Contains(curBook.Title.ToLower()) && book.Asin != curBook.Asin && !_invalidBookTitleRegex.IsMatch(curBook.Title))
.ToArray();
if (settings.UseNewVersion && relatedBooks.Any())
@@ -362,7 +362,11 @@ async Task<BookInfo> FromApOrSearch(BookInfo book, CancellationToken ct)
{
_logger.Log($"Series URL: {curBook.Series.Url}");
if (!string.IsNullOrEmpty(curBook.Series.Name))
- _logger.Log($"This is book {curBook.Series.Position} of {curBook.Series.Total} in the {curBook.Series.Name} series");
+ {
+ _logger.Log((int) Convert.ToDouble(curBook.Series.Position) == curBook.Series.Total
+ ? $"This is the latest book in the {curBook.Series.Name} series."
+ : $"This is book {curBook.Series.Position} of {curBook.Series.Total} in the {curBook.Series.Name} series.");
+ }
if (curBook.Series.Previous != null)
_logger.Log($"Preceded by: {curBook.Series.Previous.Title}");
if (curBook.Series.Next != null)

MODIFY
XRayBuilder.Core/src/Libraries/Logging/Logger.cs
XRayBuilder.Core/src/Libraries/Logging/Logger.cs
@@ -31,7 +31,7 @@ public sealed class ConsoleLogger : ILogger
public void Log(string message, LogLevel level = LogLevel.Info)
{
- Console.WriteLine($"{level}: {message}");
+ Console.WriteLine($@"{level}: {message}");
LogEvent?.Invoke(new LogEventArgs
{
Message = message,

MODIFY
XRayBuilder/src/UI/frmAbout.designer.cs
XRayBuilder/src/UI/frmAbout.designer.cs
@@ -123,7 +123,7 @@ private void InitializeComponent()
this.lblDescription.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblDescription.Location = new System.Drawing.Point(159, 156);
this.lblDescription.Name = "lblDescription";
- this.lblDescription.Size = new System.Drawing.Size(270, 70);
+ this.lblDescription.Size = new System.Drawing.Size(334, 70);
this.lblDescription.TabIndex = 23;
this.lblDescription.Text = "Description";
//

MODIFY
XRayBuilder/src/UI/frmMain.cs
XRayBuilder/src/UI/frmMain.cs
@@ -847,7 +847,10 @@ private void Form1_Load(object sender, EventArgs e)
if (_settings.outDir == "")
_settings.outDir = $@"{Environment.CurrentDirectory}\out";
- txtGoodreads.Text = _settings.Goodreads;
+ txtGoodreads.Text = !File.Exists(txtMobi.Text)
+ ? ""
+ : _settings.Goodreads;
+
if (_settings.buildSource == "Goodreads")
{
rdoGoodreads.Checked = true;
@@ -911,9 +914,10 @@ private void SetSelectedDatasource()
private void SetDatasourceLink(string url)
{
+ txtDatasource.Visible = true;
if (string.IsNullOrEmpty(url))
{
- txtDatasource.Text = "";
+ txtDatasource.Text = "Search datasource...";
return;
}
@@ -922,7 +926,6 @@ private void SetDatasourceLink(string url)
if (!matchId.Success)
return;
_tooltip.SetToolTip(txtDatasource, url);
- txtDatasource.Visible = true;
txtDatasource.Text = matchId.Groups[2].Value;
}
@@ -986,14 +989,40 @@ private void rdoSource_CheckedChanged(object sender, EventArgs e)
SetDatasourceLabels();
}
- private async void txtMobi_TextChanged(object sender, EventArgs e)
+ private void ClearInterface(bool bookOpened)
{
- if (txtMobi.Text == "" || !File.Exists(txtMobi.Text))
- return;
+ if (!bookOpened)
+ {
+ // todo centralized name (should the app name be localized?)
+ Text = "X-Ray Builder GUI";
+ txtMobi.Text = "";
+ txtOutput.Clear();
+ }
+ else
+ Text = $"X-Ray Builder GUI - {txtMobi.Text}";
+
txtGoodreads.Text = "";
- txtDatasource.Text = "";
+ pbCover.Image = Resources.missing_cover;
+ txtTitle.Text = "";
+ txtAuthor.Text = "";
+ txtAsin.Text = "";
+ // todo another copy
+ txtDatasource.Text = "Search datasource...";
prgBar.Value = 0;
_openedMetadata = null;
+ CheckFiles("","","","","","");
+ }
+
+ private async void txtMobi_TextChanged(object sender, EventArgs e)
+ {
+ if (txtMobi.Text == "" || !File.Exists(txtMobi.Text))
+ {
+ ClearInterface(false);
+ return;
+ }
+ ClearInterface(true);
+
+ ToggleInterface(false);
using var metadata = await GetAndValidateMetadataAsync(txtMobi.Text, false, _cancelTokens.Token);
if (metadata == null)
@@ -1021,8 +1050,19 @@ private async void txtMobi_TextChanged(object sender, EventArgs e)
btnOneClick.Enabled = metadata.XRaySupported;
btnUnpack.Enabled = metadata.RawMlSupported;
- // todo centralized name (should the app name be localized?)
- Text = $"X-Ray Builder GUI - {txtMobi.Text}";
+ //TODO: Check ASIN matches selected Amazon region.
+ //try
+ //{
+ // _logger.Log(@$"Checking if this ASIN matches a book available on Amazon{_settings.amazonTLD}...");
+ // var localBookResult = await _amazonClient.SearchBook(metadata.Title, metadata.Author, _settings.amazonTLD, _cancelTokens.Token);
+ // _logger.Log(localBookResult.Asin == metadata.Asin
+ // ? $@"Successfully found a matching book: {localBookResult.Title}!"
+ // : $"Warning: {localBookResult.Title} by {localBookResult.Author} was found, but the ASIN does not match for your selected Amazon region!\n\rURL: {localBookResult.AmazonUrl}");
+ //}
+ //catch (Exception)
+ //{
+ // // Ignored
+ //}
try
{
@@ -1038,6 +1078,7 @@ private async void txtMobi_TextChanged(object sender, EventArgs e)
{
// Ignored
}
+ ToggleInterface(true);
}
private async void tmiAuthorProfile_Click(object sender, EventArgs e)
@@ -1341,6 +1382,7 @@ private void txtGoodreads_TextChanged(object sender, EventArgs e)
private void pbCover_Click(object sender, EventArgs e)
{
+ if (_openedMetadata == null) return;
using var frmBook = _diContainer.GetInstance<frmBookInfo>();
frmBook.Setup(_openedMetadata, (Image) pbCover.Image.Clone(), new frmBookInfo.DialogData(txtGoodreads.Text, "", "", _settings.buildSource));
frmBook.ShowDialog();

MODIFY
XRayBuilder/src/UI/frmSettings.Designer.cs
XRayBuilder/src/UI/frmSettings.Designer.cs
@@ -807,9 +807,11 @@ private void InitializeComponent()
//
// cmbRegion
//
+ this.cmbRegion.DropDownHeight = 162;
this.cmbRegion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbRegion.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cmbRegion.FormattingEnabled = true;
+ this.cmbRegion.IntegralHeight = false;
this.cmbRegion.Location = new System.Drawing.Point(106, 116);
this.cmbRegion.Name = "cmbRegion";
this.cmbRegion.Size = new System.Drawing.Size(138, 23);

Various updates...