Clean up JellyfinRepositoryImpl
This commit is contained in:
parent
8e3c4a3a37
commit
9a4f846023
2 changed files with 101 additions and 157 deletions
|
@ -10,21 +10,12 @@ import timber.log.Timber
|
|||
import java.util.*
|
||||
|
||||
class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRepository {
|
||||
override suspend fun getUserViews(): List<BaseItemDto> {
|
||||
val views: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
views =
|
||||
jellyfinApi.viewsApi.getUserViews(jellyfinApi.userId!!).content.items ?: emptyList()
|
||||
}
|
||||
return views
|
||||
override suspend fun getUserViews(): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.viewsApi.getUserViews(jellyfinApi.userId!!).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getItem(itemId: UUID): BaseItemDto {
|
||||
val item: BaseItemDto
|
||||
withContext(Dispatchers.IO) {
|
||||
item = jellyfinApi.userLibraryApi.getItem(jellyfinApi.userId!!, itemId).content
|
||||
}
|
||||
return item
|
||||
override suspend fun getItem(itemId: UUID): BaseItemDto = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.userLibraryApi.getItem(jellyfinApi.userId!!, itemId).content
|
||||
}
|
||||
|
||||
override suspend fun getItems(
|
||||
|
@ -33,106 +24,75 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
recursive: Boolean,
|
||||
sortBy: SortBy,
|
||||
sortOrder: SortOrder
|
||||
): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
Timber.d("$sortBy $sortOrder")
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(
|
||||
): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.itemsApi.getItems(
|
||||
jellyfinApi.userId!!,
|
||||
parentId = parentId,
|
||||
includeItemTypes = includeTypes,
|
||||
recursive = recursive,
|
||||
sortBy = listOf(sortBy.SortString),
|
||||
sortOrder = listOf(sortOrder)
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return items
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getPersonItems(
|
||||
personIds: List<UUID>,
|
||||
includeTypes: List<ContentType>?,
|
||||
recursive: Boolean
|
||||
): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(
|
||||
): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.itemsApi.getItems(
|
||||
jellyfinApi.userId!!,
|
||||
personIds = personIds,
|
||||
includeItemTypes = includeTypes?.map { it.type },
|
||||
recursive = recursive
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return items
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getFavoriteItems(): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(
|
||||
override suspend fun getFavoriteItems(): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.itemsApi.getItems(
|
||||
jellyfinApi.userId!!,
|
||||
filters = listOf(ItemFilter.IS_FAVORITE),
|
||||
includeItemTypes = listOf("Movie", "Series", "Episode"),
|
||||
recursive = true
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return items
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getSearchItems(searchQuery: String): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
override suspend fun getSearchItems(searchQuery: String): List<BaseItemDto> =
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.itemsApi.getItems(
|
||||
jellyfinApi.itemsApi.getItems(
|
||||
jellyfinApi.userId!!,
|
||||
searchTerm = searchQuery,
|
||||
includeItemTypes = listOf("Movie", "Series", "Episode"),
|
||||
recursive = true
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return items
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getResumeItems(): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
items =
|
||||
override suspend fun getResumeItems(): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.itemsApi.getResumeItems(
|
||||
jellyfinApi.userId!!,
|
||||
includeItemTypes = listOf("Movie", "Episode"),
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return items
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getLatestMedia(parentId: UUID): List<BaseItemDto> {
|
||||
val items: List<BaseItemDto>
|
||||
override suspend fun getLatestMedia(parentId: UUID): List<BaseItemDto> =
|
||||
withContext(Dispatchers.IO) {
|
||||
items = jellyfinApi.userLibraryApi.getLatestMedia(
|
||||
jellyfinApi.userLibraryApi.getLatestMedia(
|
||||
jellyfinApi.userId!!,
|
||||
parentId = parentId
|
||||
).content
|
||||
}
|
||||
return items
|
||||
|
||||
override suspend fun getSeasons(seriesId: UUID): List<BaseItemDto> =
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.showsApi.getSeasons(seriesId, jellyfinApi.userId!!).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getSeasons(seriesId: UUID): List<BaseItemDto> {
|
||||
val seasons: List<BaseItemDto>
|
||||
override suspend fun getNextUp(seriesId: UUID?): List<BaseItemDto> =
|
||||
withContext(Dispatchers.IO) {
|
||||
seasons = jellyfinApi.showsApi.getSeasons(seriesId, jellyfinApi.userId!!).content.items
|
||||
?: emptyList()
|
||||
}
|
||||
return seasons
|
||||
}
|
||||
|
||||
override suspend fun getNextUp(seriesId: UUID?): List<BaseItemDto> {
|
||||
val nextUpItems: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
nextUpItems = jellyfinApi.showsApi.getNextUp(
|
||||
jellyfinApi.showsApi.getNextUp(
|
||||
jellyfinApi.userId!!,
|
||||
seriesId = seriesId?.toString(),
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return nextUpItems
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getEpisodes(
|
||||
|
@ -140,23 +100,19 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
seasonId: UUID,
|
||||
fields: List<ItemFields>?,
|
||||
startItemId: UUID?
|
||||
): List<BaseItemDto> {
|
||||
val episodes: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
episodes = jellyfinApi.showsApi.getEpisodes(
|
||||
): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.showsApi.getEpisodes(
|
||||
seriesId,
|
||||
jellyfinApi.userId!!,
|
||||
seasonId = seasonId,
|
||||
fields = fields,
|
||||
startItemId = startItemId
|
||||
).content.items ?: emptyList()
|
||||
}
|
||||
return episodes
|
||||
).content.items.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getMediaSources(itemId: UUID): List<MediaSourceInfo> {
|
||||
val mediaSourceInfoList: List<MediaSourceInfo>
|
||||
val mediaInfo by jellyfinApi.mediaInfoApi.getPostedPlaybackInfo(
|
||||
override suspend fun getMediaSources(itemId: UUID): List<MediaSourceInfo> =
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.mediaInfoApi.getPostedPlaybackInfo(
|
||||
itemId, PlaybackInfoDto(
|
||||
userId = jellyfinApi.userId!!,
|
||||
deviceProfile = DeviceProfile(
|
||||
|
@ -188,26 +144,22 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
subtitleStreamIndex = null,
|
||||
maxStreamingBitrate = 1_000_000_000,
|
||||
)
|
||||
)
|
||||
mediaSourceInfoList = mediaInfo.mediaSources ?: emptyList()
|
||||
return mediaSourceInfoList
|
||||
).content.mediaSources.orEmpty()
|
||||
}
|
||||
|
||||
override suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String {
|
||||
var streamUrl = ""
|
||||
override suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String =
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
streamUrl = jellyfinApi.videosApi.getVideoStreamUrl(
|
||||
jellyfinApi.videosApi.getVideoStreamUrl(
|
||||
itemId,
|
||||
static = true,
|
||||
mediaSourceId = mediaSourceId
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
""
|
||||
}
|
||||
}
|
||||
return streamUrl
|
||||
}
|
||||
|
||||
override suspend fun postCapabilities() {
|
||||
Timber.d("Sending capabilities")
|
||||
|
@ -291,13 +243,7 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun getIntros(itemId: UUID): List<BaseItemDto> {
|
||||
val intros: List<BaseItemDto>
|
||||
withContext(Dispatchers.IO) {
|
||||
intros =
|
||||
jellyfinApi.userLibraryApi.getIntros(jellyfinApi.userId!!, itemId).content.items
|
||||
?: emptyList()
|
||||
}
|
||||
return intros
|
||||
override suspend fun getIntros(itemId: UUID): List<BaseItemDto> = withContext(Dispatchers.IO) {
|
||||
jellyfinApi.userLibraryApi.getIntros(jellyfinApi.userId!!, itemId).content.items.orEmpty()
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ class HomeViewModel @Inject internal constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun loadDynamicItems() = withContext(Dispatchers.IO) {
|
||||
private suspend fun loadDynamicItems(): List<Section> {
|
||||
val resumeItems = repository.getResumeItems()
|
||||
val nextUpItems = repository.getNextUp()
|
||||
|
||||
|
@ -88,11 +88,10 @@ class HomeViewModel @Inject internal constructor(
|
|||
)
|
||||
}
|
||||
|
||||
items.map { Section(it) }
|
||||
return items.map { Section(it) }
|
||||
}
|
||||
|
||||
private suspend fun loadViews() = withContext(Dispatchers.IO) {
|
||||
repository
|
||||
private suspend fun loadViews() = repository
|
||||
.getUserViews()
|
||||
.filter { view -> unsupportedCollections().none { it.type == view.collectionType } }
|
||||
.map { view -> view to repository.getLatestMedia(view.id) }
|
||||
|
@ -100,6 +99,5 @@ class HomeViewModel @Inject internal constructor(
|
|||
.map { (view, latest) -> view.toView().apply { items = latest } }
|
||||
.map { ViewItem(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue