bug fix: if not importing episodes, remember to remove parents from import list

This commit is contained in:
Robert McRackan 2021-09-29 10:00:04 -04:00
parent 1165f81203
commit 22548dc8ae
2 changed files with 11 additions and 9 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>6.1.5.1</Version>
<Version>6.1.6.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -108,7 +108,7 @@ namespace InternalUtilities
public Task<List<Item>> GetLibraryValidatedAsync(LibraryOptions.ResponseGroupOptions responseGroups = LibraryOptions.ResponseGroupOptions.ALL_OPTIONS, bool importEpisodes = true)
{
// 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
// 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 not 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
@ -130,8 +130,7 @@ namespace InternalUtilities
if (!items.Any())
items = await Api.GetAllLibraryItemsAsync(responseGroups);
if (importEpisodes)
await manageEpisodesAsync(items);
await manageEpisodesAsync(items, importEpisodes);
#if DEBUG
//System.IO.File.WriteAllText(library_json, AudibleApi.Common.Converter.ToJson(items));
@ -150,7 +149,7 @@ namespace InternalUtilities
}
#region episodes and podcasts
private async Task manageEpisodesAsync(List<Item> items)
private async Task manageEpisodesAsync(List<Item> items, bool importEpisodes)
{
// add podcasts and episodes to list. If fail, don't let it de-rail the rest of the import
try
@ -171,11 +170,14 @@ namespace InternalUtilities
// also must happen before processing children because children abuses this flag
items.RemoveAll(i => i.IsEpisodes);
if (importEpisodes)
{
// add children
var children = await getEpisodesAsync(parents);
Serilog.Log.Logger.Information($"{children.Count} episodes of shows/podcasts found");
items.AddRange(children);
}
}
catch (Exception ex)
{
Serilog.Log.Logger.Error(ex, "Error adding podcasts and episodes");