Fix my own screwup

This commit is contained in:
Michael Bucari-Tovo 2022-05-26 21:26:56 -06:00
parent 9c20250b0a
commit b2d0ee41f2
3 changed files with 9 additions and 20 deletions

View File

@ -131,18 +131,8 @@ namespace AudibleUtilities
{
if (item.IsEpisodes && importEpisodes)
{
//Helps to distinguish product parrents which have no content
//from children which do have content.
item.Asin = $"SERIES_{item.Asin}";
//Add the parent to the library because it contains the series
//description, series rating, and series cover art which differ
//from the individual episodes' values.
item.Series = new Series[] { new Series { Asin = item.Asin, Sequence = RelationshipToProduct.Parent, Title = item.TitleWithSubtitle } };
//Get child episodes asynchronously and await all at the end
getChildEpisodesTasks.Add(getChildEpisodesAsync(concurrencySemaphore, item));
items.Add(item);
}
else if (!item.IsEpisodes)
items.Add(item);
@ -174,7 +164,7 @@ namespace AudibleUtilities
}
#region episodes and podcasts
private async Task<List<Item>> getChildEpisodesAsync(SemaphoreSlim concurrencySemaphore, Item parent)
{
await concurrencySemaphore.WaitAsync();
@ -189,10 +179,9 @@ namespace AudibleUtilities
{
//The parent is the only episode in the podcase series,
//so the parent is its own child.
var parentJson = parent.ToJson(parent).ToString();
var child = Item.FromJson(parentJson);
child.Asin = child.Asin.Replace("SERIES_", "");
children.Add(child);
parent.Series = new Series[] { new Series { Asin = parent.Asin, Sequence = RelationshipToProduct.Parent, Title = parent.TitleWithSubtitle } };
children.Add(parent);
return children;
}
foreach (var child in children)
@ -254,8 +243,8 @@ namespace AudibleUtilities
{
childrenBatch = await Api.GetCatalogProductsAsync(idBatch, CatalogOptions.ResponseGroupOptions.ALL_OPTIONS);
#if DEBUG
//var childrenBatchDebug = childrenBatch.Select(i => i.ToJson()).Aggregate((a, b) => $"{a}\r\n\r\n{b}");
//System.IO.File.WriteAllText($"children of {parent.Asin}.json", childrenBatchDebug);
//var childrenBatchDebug = childrenBatch.Select(i => i.ToJson()).Aggregate((a, b) => $"{a}\r\n\r\n{b}");
//System.IO.File.WriteAllText($"children of {parent.Asin}.json", childrenBatchDebug);
#endif
}
catch (Exception ex)

View File

@ -109,7 +109,6 @@ namespace LibationWinForms.GridView
=> gridEntries.Series().FirstOrDefault(i => matchSeries.Any(s => s.Series.Name == i.Series));
public static IEnumerable<SeriesEntry> EmptySeries(this IEnumerable<GridEntry> gridEntries)
=> gridEntries.Series().Where(i => i.Children.Count == 0);
public static bool IsEpisodeChild(this LibraryBook lb) => lb.Book.ContentType == ContentType.Episode && lb.Book.SeriesLink is not null && lb.Book.SeriesLink.Any() && lb.Book.SeriesLink.First().Order != AudibleApi.Common.RelationshipToProduct.Parent;
public static bool IsEpisodeParent(this LibraryBook lb) => lb.Book.ContentType == ContentType.Episode && lb.Book.SeriesLink is not null && lb.Book.SeriesLink.Any() && lb.Book.SeriesLink.First().Order == AudibleApi.Common.RelationshipToProduct.Parent;
public static bool IsEpisodeChild(this LibraryBook lb) => lb.Book.ContentType == ContentType.Episode;
}
}

View File

@ -86,7 +86,8 @@ namespace LibationWinForms.GridView
var episodes = dbBooks.Where(b => b.IsEpisodeChild()).ToList();
foreach (var series in episodes.SelectMany(lb => lb.Book.SeriesLink).DistinctBy(s => s.Series))
var allSeries = episodes.SelectMany(lb => lb.Book.SeriesLink.Where(s => !s.Series.AudibleSeriesId.StartsWith("SERIES_"))).DistinctBy(s => s.Series).ToList();
foreach (var series in allSeries)
{
var seriesEntry = new SeriesEntry(series, episodes.Where(lb => lb.Book.SeriesLink.Any(s => s.Series == series.Series)));