From d2a38b0238d4a6842925980a88c7db247e5c5393 Mon Sep 17 00:00:00 2001 From: grakovne Date: Thu, 12 Dec 2024 00:42:41 +0100 Subject: [PATCH] hide books/podcasts without the audiocontent --- .../common/converter/LibraryPageResponseConverter.kt | 5 +++++ .../library/converter/LibrarySearchItemsConverter.kt | 9 ++++++++- .../channel/audiobookshelf/library/model/BookResponse.kt | 2 +- .../audiobookshelf/library/model/LibraryItemsResponse.kt | 1 + .../podcast/converter/PodcastPageResponseConverter.kt | 5 +++++ .../podcast/converter/PodcastSearchItemsConverter.kt | 5 +++++ .../audiobookshelf/podcast/model/PodcastItemsResponse.kt | 1 + 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt index 5fa2d1cf..c9cfe31d 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/common/converter/LibraryPageResponseConverter.kt @@ -14,6 +14,11 @@ class LibraryPageResponseConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null + val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + if (hasMediaItems.not()) { + return@mapNotNull null + } + Book( id = it.id, title = title, diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt index b9bf747b..b3364393 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/converter/LibrarySearchItemsConverter.kt @@ -9,9 +9,16 @@ import javax.inject.Singleton class LibrarySearchItemsConverter @Inject constructor() { fun apply(response: List) = response .mapNotNull { + val title = it.media.metadata.title ?: return@mapNotNull null + + val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + if (hasMediaItems.not()) { + return@mapNotNull null + } + Book( id = it.id, - title = it.media.metadata.title ?: return@mapNotNull null, + title = title, author = it.media.metadata.authorName, duration = it.media.duration.toInt(), ) diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/BookResponse.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/BookResponse.kt index 30803194..f430473a 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/BookResponse.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/BookResponse.kt @@ -10,7 +10,7 @@ data class BookResponse( data class BookMedia( val metadata: LibraryMetadataResponse, val audioFiles: List?, - val chapters: List?, + val chapters: List? ) data class LibraryMetadataResponse( diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/LibraryItemsResponse.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/LibraryItemsResponse.kt index ad2bab82..f0836ed1 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/LibraryItemsResponse.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/library/model/LibraryItemsResponse.kt @@ -13,6 +13,7 @@ data class LibraryItem( data class Media( val duration: Double, val metadata: LibraryMetadata, + val numAudioFiles: Int? ) data class LibraryMetadata( diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt index 505ec47d..df58b51d 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastPageResponseConverter.kt @@ -14,6 +14,11 @@ class PodcastPageResponseConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null + val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + if (hasMediaItems.not()) { + return@mapNotNull null + } + Book( id = it.id, title = title, diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt index ed790ddf..a3dc04bf 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/converter/PodcastSearchItemsConverter.kt @@ -12,6 +12,11 @@ class PodcastSearchItemsConverter @Inject constructor() { .mapNotNull { val title = it.media.metadata.title ?: return@mapNotNull null + val hasMediaItems = (it.media.numAudioFiles ?: 0) > 0 + if (hasMediaItems.not()) { + return@mapNotNull null + } + Book( id = it.id, title = title, diff --git a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/model/PodcastItemsResponse.kt b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/model/PodcastItemsResponse.kt index 3a5a4214..e9c02d3c 100644 --- a/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/model/PodcastItemsResponse.kt +++ b/app/src/main/java/org/grakovne/lissen/channel/audiobookshelf/podcast/model/PodcastItemsResponse.kt @@ -13,6 +13,7 @@ data class PodcastItem( data class PodcastItemMedia( val duration: Double, val metadata: PodcastMetadata, + val numAudioFiles: Int? ) data class PodcastMetadata(