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