perf: only request stream url when preparing player items

This commit is contained in:
Jarne Demeulemeester 2023-05-13 21:34:05 +02:00
parent 765a31838e
commit b816a2d460
No known key found for this signature in database
GPG key ID: 1E5C6AFBD622E9F5
6 changed files with 11 additions and 9 deletions

View file

@ -43,7 +43,7 @@ class DownloaderImpl(
storageIndex: Int,
): Pair<Long, UiText?> {
try {
val source = jellyfinRepository.getMediaSources(item.id).first { it.id == sourceId }
val source = jellyfinRepository.getMediaSources(item.id, true).first { it.id == sourceId }
val intro = jellyfinRepository.getIntroTimestamps(item.id)
val trickPlayManifest = jellyfinRepository.getTrickPlayManifest(item.id)
val trickPlayData = if (trickPlayManifest != null) {

View file

@ -19,12 +19,13 @@ data class FindroidSource(
suspend fun MediaSourceInfo.toFindroidSource(
jellyfinRepository: JellyfinRepository,
itemId: UUID
itemId: UUID,
includePath: Boolean = false,
): FindroidSource {
val path = when (protocol) {
MediaProtocol.FILE -> {
try {
jellyfinRepository.getStreamUrl(itemId, id.orEmpty())
if (includePath) jellyfinRepository.getStreamUrl(itemId, id.orEmpty()) else ""
} catch (e: Exception) {
""
}

View file

@ -80,7 +80,7 @@ interface JellyfinRepository {
offline: Boolean = false
): List<FindroidEpisode>
suspend fun getMediaSources(itemId: UUID): List<FindroidSource>
suspend fun getMediaSources(itemId: UUID, includePath: Boolean = false): List<FindroidSource>
suspend fun getStreamUrl(itemId: UUID, mediaSourceId: String): String

View file

@ -282,7 +282,7 @@ class JellyfinRepositoryImpl(
}
}
override suspend fun getMediaSources(itemId: UUID): List<FindroidSource> =
override suspend fun getMediaSources(itemId: UUID, includePath: Boolean): List<FindroidSource> =
withContext(Dispatchers.IO) {
val sources = mutableListOf<FindroidSource>()
sources.addAll(
@ -325,7 +325,8 @@ class JellyfinRepositoryImpl(
).content.mediaSources.map {
it.toFindroidSource(
this@JellyfinRepositoryImpl,
itemId
itemId,
includePath,
)
}
)

View file

@ -168,7 +168,7 @@ class JellyfinRepositoryOfflineImpl(
database.getEpisodesBySeasonId(seasonId).map { it.toFindroidEpisode(database, jellyfinApi.userId!!) }
}
override suspend fun getMediaSources(itemId: UUID): List<FindroidSource> =
override suspend fun getMediaSources(itemId: UUID, includePath: Boolean): List<FindroidSource> =
withContext(Dispatchers.IO) {
database.getSources(itemId).map { it.toFindroidSource(database) }
}

View file

@ -137,9 +137,9 @@ class PlayerViewModel @Inject internal constructor(
playbackPosition: Long
): PlayerItem {
val mediaSource = if (mediaSourceIndex == null) {
repository.getMediaSources(id).firstOrNull { it.type == FindroidSourceType.LOCAL } ?: repository.getMediaSources(id)[0]
repository.getMediaSources(id, true).firstOrNull { it.type == FindroidSourceType.LOCAL } ?: repository.getMediaSources(id, true)[0]
} else {
repository.getMediaSources(id)[mediaSourceIndex]
repository.getMediaSources(id, true)[mediaSourceIndex]
}
val externalSubtitles = mediaSource.mediaStreams
.filter { mediaStream ->