Fix End Actions not calculating reading time from curBook.PageCount.
Refactor reading time to a function.
Ignore zero or null popular highlights.
Dispose preview forms so text is rest on next display.
MODIFY
XRayBuilder.Core/src/DataSources/Secondary/SecondarySourceGoodreads.cs
XRayBuilder.Core/src/DataSources/Secondary/SecondarySourceGoodreads.cs
@@ -250,35 +250,13 @@ public override async Task<bool> GetPageCountAsync(BookInfo curBook, Cancellatio
var minutes = int.Parse(match.Groups[1].Value, NumberStyles.AllowThousands) * 1.098507462686567;
var span = TimeSpan.FromMinutes(minutes);
-
- var d = PluralUtil.Pluralize($"{span.Days:day}");
- var h = PluralUtil.Pluralize($"{span.Hours:hour}");
- var m = PluralUtil.Pluralize($"{span.Minutes:minute}");
var p = match.Groups["pages"].Value;
curBook.PageCount = int.Parse(p, NumberStyles.AllowThousands, CultureInfo.InvariantCulture);
curBook.ReadingHours = span.Hours;
curBook.ReadingMinutes = span.Minutes;
- // todo clean up this section
- if (span.Days > 1)
- {
- _logger.Log($"Typical time to read: {d}, {h}, and {m} ({p} pages)");
- return true;
- }
-
- if (span.Hours > 1)
- {
- _logger.Log($"Typical time to read: {h}, and {m} ({p} pages)");
- return true;
- }
-
- if (span.Minutes <= 1)
- {
- _logger.Log($"Typical time to read: {m} ({p} pages)");
- return true;
- }
-
+ _logger.Log(Functions.GetReadingTime(curBook));
return true;
}

MODIFY
XRayBuilder.Core/src/DataSources/Secondary/SecondarySourceShelfari.cs
XRayBuilder.Core/src/DataSources/Secondary/SecondarySourceShelfari.cs
using HtmlAgilityPack;
using JetBrains.Annotations;
using XRayBuilder.Core.DataSources.Secondary.Model;
+using XRayBuilder.Core.Libraries;
using XRayBuilder.Core.Libraries.Http;
using XRayBuilder.Core.Libraries.Logging;
using XRayBuilder.Core.Libraries.Progress;
@@ -107,10 +108,10 @@ public override async Task<bool> GetPageCountAsync(BookInfo curBook, Cancellatio
{
var minutes = int.Parse(match1.Groups[1].Value, NumberStyles.AllowThousands) * 1.098507462686567;
var span = TimeSpan.FromMinutes(minutes);
- _logger.Log(string.Format("Typical time to read: {0} hours and {1} minutes ({2} pages)", span.Hours, span.Minutes, match1.Groups[1].Value));
curBook.PageCount = int.Parse(match1.Groups[1].Value);
curBook.ReadingHours = span.Hours;
curBook.ReadingMinutes = span.Minutes;
+ _logger.Log(Functions.GetReadingTime(curBook));
return true;
}
return false;

MODIFY
XRayBuilder.Core/src/Extras/Artifacts/StartActions.cs
XRayBuilder.Core/src/Extras/Artifacts/StartActions.cs
@@ -316,7 +316,7 @@ public sealed class DataJson
[JsonProperty("welcomeText")]
public WelcomeText WelcomeText { get; set; }
- [JsonProperty("popularHighlightsText")]
+ [JsonProperty("popularHighlightsText", NullValueHandling = NullValueHandling.Ignore)]
public PopularHighlightsText PopularHighlightsText { get; set; }
[JsonProperty("grokShelfInfo")]

MODIFY
XRayBuilder.Core/src/Extras/EndActions/EndActionsDataGenerator.cs
XRayBuilder.Core/src/Extras/EndActions/EndActionsDataGenerator.cs
@@ -383,6 +383,9 @@ async Task<BookInfo> FromApOrSearch(BookInfo book, CancellationToken ct)
}
try
+ {
+ var readingTimeFromPageCount = Functions.GetReadingTime(curBook);
+ if (string.IsNullOrEmpty(readingTimeFromPageCount))
{
if (!await dataSource.GetPageCountAsync(curBook, cancellationToken))
{
@@ -399,6 +402,9 @@ async Task<BookInfo> FromApOrSearch(BookInfo book, CancellationToken ct)
_logger.Log($"No page count found on {dataSource.Name} or in metadata");
}
}
+ else
+ _logger.Log(readingTimeFromPageCount);
+ }
catch (Exception ex)
{
_logger.Log($"An error occurred while searching for or estimating the page count: {ex.Message}\r\n{ex.StackTrace}");

MODIFY
XRayBuilder.Core/src/Extras/StartActions/StartActionsArtifactService.cs
XRayBuilder.Core/src/Extras/StartActions/StartActionsArtifactService.cs
@@ -70,8 +70,15 @@ public Artifacts.StartActions GenerateStartActions(BookInfo curBook, AuthorProfi
}
};
startActions.Data.AuthorSubscriptions = startActions.Data.FollowSubscriptions;
- startActions.Data.PopularHighlightsText.LocalizedText.Replace("%NUMPASSAGES%", $"{curBook.NotableClips?.Count ?? 0}");
- startActions.Data.PopularHighlightsText.LocalizedText.Replace("%NUMHIGHLIGHTS%", $"{curBook.NotableClips?.Sum(c => c.Likes) ?? 0}");
+ if (curBook.NotableClips == null || curBook.NotableClips?.Count == 0)
+ {
+ startActions.Data.PopularHighlightsText = null;
+ }
+ else
+ {
+ startActions.Data.PopularHighlightsText.LocalizedText.Replace("%NUMPASSAGES%", $"{curBook.NotableClips?.Count}");
+ startActions.Data.PopularHighlightsText.LocalizedText.Replace("%NUMHIGHLIGHTS%", $"{curBook.NotableClips?.Sum(c => c.Likes)}");
+ }
startActions.Data.GrokShelfInfo.Asin = curBook.Asin;
startActions.Data.GrokShelfInfo.IsAutoshelvingEnabled = true;

MODIFY
XRayBuilder.Core/src/Libraries/Functions.cs
XRayBuilder.Core/src/Libraries/Functions.cs
using System.Text.RegularExpressions;
using HtmlAgilityPack;
using JetBrains.Annotations;
+using XRayBuilder.Core.Libraries.Language.Pluralization;
using XRayBuilder.Core.Model;
namespace XRayBuilder.Core.Libraries
@@ -75,6 +76,26 @@ public static string TimeStamp()
return $"Running X-Ray Builder GUI v{version}. Log started on {date} at {time}.\r\n";
}
+ public static string GetReadingTime(BookInfo bookInfo)
+ {
+ if (bookInfo.PageCount == 0)
+ return null;
+
+ var minutes = bookInfo.PageCount * 1.098507462686567;
+ var span = TimeSpan.FromMinutes(minutes);
+
+ var d = PluralUtil.Pluralize($"{span.Days:day}");
+ var h = PluralUtil.Pluralize($"{span.Hours:hour}");
+ var m = PluralUtil.Pluralize($"{span.Minutes:minute}");
+ var p = bookInfo.PageCount;
+
+ bookInfo.ReadingHours = span.Hours;
+ bookInfo.ReadingMinutes = span.Minutes;
+
+ var formatted = $"Typical time to read: {(span.Days > 1 ? $"{d}, " : string.Empty)}{(span.Hours > 1 ? $"{h}" : string.Empty)}{(span.Hours > 1 ? " and " : ", ")}{(span.Minutes > 1 ? $"{m}" : string.Empty)} ({p} pages)";
+ return formatted.StartsWith(", ") ? formatted.Substring(2, formatted.Length) : formatted;
+ }
+
public static string GetPageCount(string rawMl, BookInfo bookInfo)
{
string output;
@@ -113,8 +134,7 @@ public static string GetPageCount(string rawMl, BookInfo bookInfo)
bookInfo.PageCount = pageCount;
bookInfo.ReadingHours = span.Hours;
bookInfo.ReadingMinutes = span.Minutes;
- output = $"Typical time to read: {span.Hours} hours and {span.Minutes} minutes ({bookInfo.PageCount} pages)";
- return output;
+ return GetReadingTime(bookInfo);
}
public static void RunNotepad(string filename)

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewAP.Designer.cs
XRayBuilder/src/UI/Preview/frmPreviewAP.Designer.cs
@@ -118,7 +118,7 @@ private void InitializeComponent()
//
// frmPreviewAP
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(657, 556);
this.Controls.Add(this.dgvOtherBooks);
@@ -136,6 +136,7 @@ private void InitializeComponent()
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Abouth [author]";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmPreviewAP_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.pbAuthorImage)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dgvOtherBooks)).EndInit();
this.ResumeLayout(false);

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewAP.cs
XRayBuilder/src/UI/Preview/frmPreviewAP.cs
@@ -52,5 +52,10 @@ public new void ShowDialog()
{
base.ShowDialog();
}
+
+ private void frmPreviewAP_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ Dispose();
+ }
}
}

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewEA.Designer.cs
XRayBuilder/src/UI/Preview/frmPreviewEA.Designer.cs
@@ -128,7 +128,7 @@ private void InitializeComponent()
this.lblFollowAuthor.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblFollowAuthor.Location = new System.Drawing.Point(13, 78);
this.lblFollowAuthor.Name = "lblFollowAuthor";
- this.lblFollowAuthor.Size = new System.Drawing.Size(132, 20);
+ this.lblFollowAuthor.Size = new System.Drawing.Size(102, 15);
this.lblFollowAuthor.TabIndex = 79;
this.lblFollowAuthor.Text = "Follow the Author";
this.lblFollowAuthor.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -168,7 +168,7 @@ private void InitializeComponent()
this.lblYourRating.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblYourRating.Location = new System.Drawing.Point(13, 12);
this.lblYourRating.Name = "lblYourRating";
- this.lblYourRating.Size = new System.Drawing.Size(171, 20);
+ this.lblYourRating.Size = new System.Drawing.Size(133, 15);
this.lblYourRating.TabIndex = 75;
this.lblYourRating.Text = "Your Rating on Amazon";
this.lblYourRating.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -205,7 +205,7 @@ private void InitializeComponent()
this.lblCustomersWhoBoughtRecs.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblCustomersWhoBoughtRecs.Location = new System.Drawing.Point(13, 228);
this.lblCustomersWhoBoughtRecs.Name = "lblCustomersWhoBoughtRecs";
- this.lblCustomersWhoBoughtRecs.Size = new System.Drawing.Size(319, 20);
+ this.lblCustomersWhoBoughtRecs.Size = new System.Drawing.Size(249, 15);
this.lblCustomersWhoBoughtRecs.TabIndex = 71;
this.lblCustomersWhoBoughtRecs.Text = "Customers who bought this book also bought";
this.lblCustomersWhoBoughtRecs.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -236,7 +236,7 @@ private void InitializeComponent()
this.lblNextInSeries.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblNextInSeries.Location = new System.Drawing.Point(408, 12);
this.lblNextInSeries.Name = "lblNextInSeries";
- this.lblNextInSeries.Size = new System.Drawing.Size(101, 20);
+ this.lblNextInSeries.Size = new System.Drawing.Size(77, 15);
this.lblNextInSeries.TabIndex = 68;
this.lblNextInSeries.Text = "Next in series";
this.lblNextInSeries.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -253,7 +253,7 @@ private void InitializeComponent()
//
// frmPreviewEA
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(809, 482);
this.Controls.Add(this.pictureBox2);
@@ -284,6 +284,7 @@ private void InitializeComponent()
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Before You Go...";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmPreviewEA_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbAuthor)).EndInit();

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewEA.cs
XRayBuilder/src/UI/Preview/frmPreviewEA.cs
@@ -158,5 +158,10 @@ private void btnFollow_Click(object sender, EventArgs e)
if (string.IsNullOrEmpty(_authorUrl)) return;
Process.Start(_authorUrl);
}
+
+ private void frmPreviewEA_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ Dispose();
+ }
}
}
\ No newline at end of file

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewSA.Designer.cs
XRayBuilder/src/UI/Preview/frmPreviewSA.Designer.cs
@@ -101,7 +101,7 @@ private void InitializeComponent()
this.lblHighlightsCount.Name = "lblHighlightsCount";
this.lblHighlightsCount.Size = new System.Drawing.Size(415, 15);
this.lblHighlightsCount.TabIndex = 77;
- this.lblHighlightsCount.Text = "No popular highlight information available";
+ this.lblHighlightsCount.Text = "n passages have been highlighten n times";
//
// lblBiography
//
@@ -378,6 +378,7 @@ private void InitializeComponent()
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "About This Book";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmPreviewSA_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbRating)).EndInit();

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewXR.Designer.cs
XRayBuilder/src/UI/Preview/frmPreviewXR.Designer.cs
@@ -95,7 +95,7 @@ private void InitializeComponent()
this.tbTerms.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.tbTerms.Name = "tbTerms";
this.tbTerms.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.tbTerms.Size = new System.Drawing.Size(496, 602);
+ this.tbTerms.Size = new System.Drawing.Size(496, 579);
this.tbTerms.TabIndex = 2;
this.tbTerms.Text = "TERMS";
this.tbTerms.UseVisualStyleBackColor = true;
@@ -107,7 +107,7 @@ private void InitializeComponent()
this.pTerms.Location = new System.Drawing.Point(4, 5);
this.pTerms.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.pTerms.Name = "pTerms";
- this.pTerms.Size = new System.Drawing.Size(488, 592);
+ this.pTerms.Size = new System.Drawing.Size(488, 569);
this.pTerms.TabIndex = 0;
//
// flpTerms
@@ -116,12 +116,12 @@ private void InitializeComponent()
this.flpTerms.Dock = System.Windows.Forms.DockStyle.Fill;
this.flpTerms.Location = new System.Drawing.Point(0, 0);
this.flpTerms.Name = "flpTerms";
- this.flpTerms.Size = new System.Drawing.Size(488, 592);
+ this.flpTerms.Size = new System.Drawing.Size(488, 569);
this.flpTerms.TabIndex = 2;
//
// frmPreviewXR
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(508, 625);
this.Controls.Add(this.tcXray);
@@ -134,6 +134,7 @@ private void InitializeComponent()
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "X-Ray";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmPreviewXR_FormClosing);
this.tcXray.ResumeLayout(false);
this.tpPeople.ResumeLayout(false);
this.pPeople.ResumeLayout(false);

MODIFY
XRayBuilder/src/UI/Preview/frmPreviewXR.cs
XRayBuilder/src/UI/Preview/frmPreviewXR.cs
@@ -60,5 +60,10 @@ private void flpPeople_Scroll(object sender, ScrollEventArgs e)
{
flpPeople.VerticalScroll.Value = e.NewValue;
}
+
+ private void frmPreviewXR_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ Dispose();
+ }
}
}

Fix End Actions not calculating reading time from curBook.PageCount.
Refactor reading time to a function.
Ignore zero or null popular highlights.
Dispose preview forms so text is rest on next display.