perf: only request stream url when preparing player items
This commit is contained in:
parent
765a31838e
commit
b816a2d460
6 changed files with 11 additions and 9 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
""
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
@ -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 ->
|
||||
|
|
Loading…
Reference in a new issue