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,
|
storageIndex: Int,
|
||||||
): Pair<Long, UiText?> {
|
): Pair<Long, UiText?> {
|
||||||
try {
|
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 intro = jellyfinRepository.getIntroTimestamps(item.id)
|
||||||
val trickPlayManifest = jellyfinRepository.getTrickPlayManifest(item.id)
|
val trickPlayManifest = jellyfinRepository.getTrickPlayManifest(item.id)
|
||||||
val trickPlayData = if (trickPlayManifest != null) {
|
val trickPlayData = if (trickPlayManifest != null) {
|
||||||
|
|
|
@ -19,12 +19,13 @@ data class FindroidSource(
|
||||||
|
|
||||||
suspend fun MediaSourceInfo.toFindroidSource(
|
suspend fun MediaSourceInfo.toFindroidSource(
|
||||||
jellyfinRepository: JellyfinRepository,
|
jellyfinRepository: JellyfinRepository,
|
||||||
itemId: UUID
|
itemId: UUID,
|
||||||
|
includePath: Boolean = false,
|
||||||
): FindroidSource {
|
): FindroidSource {
|
||||||
val path = when (protocol) {
|
val path = when (protocol) {
|
||||||
MediaProtocol.FILE -> {
|
MediaProtocol.FILE -> {
|
||||||
try {
|
try {
|
||||||
jellyfinRepository.getStreamUrl(itemId, id.orEmpty())
|
if (includePath) jellyfinRepository.getStreamUrl(itemId, id.orEmpty()) else ""
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ interface JellyfinRepository {
|
||||||
offline: Boolean = false
|
offline: Boolean = false
|
||||||
): List<FindroidEpisode>
|
): 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
|
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) {
|
withContext(Dispatchers.IO) {
|
||||||
val sources = mutableListOf<FindroidSource>()
|
val sources = mutableListOf<FindroidSource>()
|
||||||
sources.addAll(
|
sources.addAll(
|
||||||
|
@ -325,7 +325,8 @@ class JellyfinRepositoryImpl(
|
||||||
).content.mediaSources.map {
|
).content.mediaSources.map {
|
||||||
it.toFindroidSource(
|
it.toFindroidSource(
|
||||||
this@JellyfinRepositoryImpl,
|
this@JellyfinRepositoryImpl,
|
||||||
itemId
|
itemId,
|
||||||
|
includePath,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -168,7 +168,7 @@ class JellyfinRepositoryOfflineImpl(
|
||||||
database.getEpisodesBySeasonId(seasonId).map { it.toFindroidEpisode(database, jellyfinApi.userId!!) }
|
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) {
|
withContext(Dispatchers.IO) {
|
||||||
database.getSources(itemId).map { it.toFindroidSource(database) }
|
database.getSources(itemId).map { it.toFindroidSource(database) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,9 +137,9 @@ class PlayerViewModel @Inject internal constructor(
|
||||||
playbackPosition: Long
|
playbackPosition: Long
|
||||||
): PlayerItem {
|
): PlayerItem {
|
||||||
val mediaSource = if (mediaSourceIndex == null) {
|
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 {
|
} else {
|
||||||
repository.getMediaSources(id)[mediaSourceIndex]
|
repository.getMediaSources(id, true)[mediaSourceIndex]
|
||||||
}
|
}
|
||||||
val externalSubtitles = mediaSource.mediaStreams
|
val externalSubtitles = mediaSource.mediaStreams
|
||||||
.filter { mediaStream ->
|
.filter { mediaStream ->
|
||||||
|
|
Loading…
Reference in a new issue