diff --git a/Source/AudibleUtilities/ApiExtended.cs b/Source/AudibleUtilities/ApiExtended.cs index 1cb31a28..2a14de01 100644 --- a/Source/AudibleUtilities/ApiExtended.cs +++ b/Source/AudibleUtilities/ApiExtended.cs @@ -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> 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) diff --git a/Source/LibationWinForms/GridView/GridEntry.cs b/Source/LibationWinForms/GridView/GridEntry.cs index 63c1a7c1..4b1a614c 100644 --- a/Source/LibationWinForms/GridView/GridEntry.cs +++ b/Source/LibationWinForms/GridView/GridEntry.cs @@ -109,7 +109,6 @@ namespace LibationWinForms.GridView => gridEntries.Series().FirstOrDefault(i => matchSeries.Any(s => s.Series.Name == i.Series)); public static IEnumerable EmptySeries(this IEnumerable 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; } } diff --git a/Source/LibationWinForms/GridView/ProductsGrid.cs b/Source/LibationWinForms/GridView/ProductsGrid.cs index f158c8e9..24dafc73 100644 --- a/Source/LibationWinForms/GridView/ProductsGrid.cs +++ b/Source/LibationWinForms/GridView/ProductsGrid.cs @@ -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)));