mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-23 19:26:50 +00:00
feat: add SeriesIdLookUpUseCase for episode to series ID mapping and update track preference saving logic
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package hu.bbara.purefin.core.feature.content.episode
|
||||||
|
|
||||||
|
import hu.bbara.purefin.core.data.LocalMediaRepository
|
||||||
|
import java.util.UUID
|
||||||
|
import javax.inject.Inject
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
|
class SeriesIdLookUpUseCase @Inject constructor(
|
||||||
|
private val localMediaRepository: LocalMediaRepository,
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(episodeId: UUID): UUID? {
|
||||||
|
return localMediaRepository.getEpisode(episodeId).first()?.seriesId
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,19 +11,20 @@ import androidx.media3.exoplayer.ExoPlayer
|
|||||||
import dagger.hilt.android.scopes.ViewModelScoped
|
import dagger.hilt.android.scopes.ViewModelScoped
|
||||||
import hu.bbara.purefin.core.data.PlayableMediaRepository
|
import hu.bbara.purefin.core.data.PlayableMediaRepository
|
||||||
import hu.bbara.purefin.core.data.PlaybackReportContext
|
import hu.bbara.purefin.core.data.PlaybackReportContext
|
||||||
|
import hu.bbara.purefin.core.feature.content.episode.SeriesIdLookUpUseCase
|
||||||
import hu.bbara.purefin.core.player.model.MetadataState
|
import hu.bbara.purefin.core.player.model.MetadataState
|
||||||
import hu.bbara.purefin.core.player.model.PlaybackProgressSnapshot
|
import hu.bbara.purefin.core.player.model.PlaybackProgressSnapshot
|
||||||
import hu.bbara.purefin.core.player.model.PlaybackStateSnapshot
|
import hu.bbara.purefin.core.player.model.PlaybackStateSnapshot
|
||||||
import hu.bbara.purefin.core.player.model.SegmentStatus
|
import hu.bbara.purefin.core.player.model.SegmentStatus
|
||||||
import hu.bbara.purefin.core.player.model.TrackOption
|
import hu.bbara.purefin.core.player.model.TrackOption
|
||||||
import hu.bbara.purefin.core.player.model.TrackType
|
import hu.bbara.purefin.core.player.model.TrackType
|
||||||
|
import hu.bbara.purefin.core.player.preference.TrackMatcher
|
||||||
|
import hu.bbara.purefin.core.player.preference.TrackPreferencesRepository
|
||||||
import hu.bbara.purefin.model.AudioTrackProperties
|
import hu.bbara.purefin.model.AudioTrackProperties
|
||||||
import hu.bbara.purefin.model.MediaSegment
|
import hu.bbara.purefin.model.MediaSegment
|
||||||
import hu.bbara.purefin.model.PlayableMedia
|
import hu.bbara.purefin.model.PlayableMedia
|
||||||
import hu.bbara.purefin.model.SegmentType
|
import hu.bbara.purefin.model.SegmentType
|
||||||
import hu.bbara.purefin.model.SubtitleTrackProperties
|
import hu.bbara.purefin.model.SubtitleTrackProperties
|
||||||
import hu.bbara.purefin.core.player.preference.TrackMatcher
|
|
||||||
import hu.bbara.purefin.core.player.preference.TrackPreferencesRepository
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
@@ -52,7 +53,8 @@ class PlayerManager @Inject constructor(
|
|||||||
private val trackMapper: TrackMapper,
|
private val trackMapper: TrackMapper,
|
||||||
private val playableMediaRepository: PlayableMediaRepository,
|
private val playableMediaRepository: PlayableMediaRepository,
|
||||||
private val trackPreferencesRepository: TrackPreferencesRepository,
|
private val trackPreferencesRepository: TrackPreferencesRepository,
|
||||||
private val trackMatcher: TrackMatcher
|
private val trackMatcher: TrackMatcher,
|
||||||
|
private val seriesIdLookUpUseCase: SeriesIdLookUpUseCase
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val SEEK_SETTLE_TOLERANCE_MS = 750L
|
private const val SEEK_SETTLE_TOLERANCE_MS = 750L
|
||||||
@@ -338,6 +340,11 @@ class PlayerManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveTrackPreference(option: TrackOption, mediaId: UUID) {
|
private suspend fun saveTrackPreference(option: TrackOption, mediaId: UUID) {
|
||||||
|
val preferenceMediaId = when (currentPlayableMedia.firstOrNull()) {
|
||||||
|
is PlayableMedia.Episode -> seriesIdLookUpUseCase(mediaId) ?: mediaId
|
||||||
|
else -> mediaId
|
||||||
|
}.toString()
|
||||||
|
|
||||||
when (option.type) {
|
when (option.type) {
|
||||||
TrackType.AUDIO -> {
|
TrackType.AUDIO -> {
|
||||||
val properties = AudioTrackProperties(
|
val properties = AudioTrackProperties(
|
||||||
@@ -345,7 +352,7 @@ class PlayerManager @Inject constructor(
|
|||||||
channelCount = option.channelCount,
|
channelCount = option.channelCount,
|
||||||
label = option.label
|
label = option.label
|
||||||
)
|
)
|
||||||
trackPreferencesRepository.saveAudioPreference(mediaId.toString(), properties)
|
trackPreferencesRepository.saveAudioPreference(preferenceMediaId, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackType.TEXT -> {
|
TrackType.TEXT -> {
|
||||||
@@ -355,7 +362,7 @@ class PlayerManager @Inject constructor(
|
|||||||
label = option.label,
|
label = option.label,
|
||||||
isOff = option.isOff
|
isOff = option.isOff
|
||||||
)
|
)
|
||||||
trackPreferencesRepository.saveSubtitlePreference(mediaId.toString(), properties)
|
trackPreferencesRepository.saveSubtitlePreference(preferenceMediaId, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackType.VIDEO -> {
|
TrackType.VIDEO -> {
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import androidx.media3.common.util.UnstableApi
|
|||||||
import hu.bbara.purefin.core.data.PlayableMediaRepository
|
import hu.bbara.purefin.core.data.PlayableMediaRepository
|
||||||
import hu.bbara.purefin.core.data.PlaybackReportContext
|
import hu.bbara.purefin.core.data.PlaybackReportContext
|
||||||
import hu.bbara.purefin.core.data.UserSessionRepository
|
import hu.bbara.purefin.core.data.UserSessionRepository
|
||||||
|
import hu.bbara.purefin.core.image.ArtworkKind
|
||||||
|
import hu.bbara.purefin.core.image.ImageUrlBuilder
|
||||||
|
import hu.bbara.purefin.core.player.preference.TrackPreferencesRepository
|
||||||
import hu.bbara.purefin.data.jellyfin.client.JellyfinApiClient
|
import hu.bbara.purefin.data.jellyfin.client.JellyfinApiClient
|
||||||
import hu.bbara.purefin.data.jellyfin.playback.JellyfinPlaybackResolver
|
import hu.bbara.purefin.data.jellyfin.playback.JellyfinPlaybackResolver
|
||||||
import hu.bbara.purefin.data.jellyfin.playback.PlaybackDecision
|
import hu.bbara.purefin.data.jellyfin.playback.PlaybackDecision
|
||||||
import hu.bbara.purefin.data.jellyfin.playback.playbackCustomCacheKey
|
import hu.bbara.purefin.data.jellyfin.playback.playbackCustomCacheKey
|
||||||
import hu.bbara.purefin.core.image.ArtworkKind
|
|
||||||
import hu.bbara.purefin.core.image.ImageUrlBuilder
|
|
||||||
import hu.bbara.purefin.model.MediaSegment
|
import hu.bbara.purefin.model.MediaSegment
|
||||||
import hu.bbara.purefin.model.PlayableMedia
|
import hu.bbara.purefin.model.PlayableMedia
|
||||||
import hu.bbara.purefin.model.SegmentType
|
import hu.bbara.purefin.model.SegmentType
|
||||||
import hu.bbara.purefin.core.player.preference.TrackPreferencesRepository
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -48,7 +48,7 @@ class DefaultPlayableMediaRepository @Inject constructor(
|
|||||||
|
|
||||||
val mediaItem = getMediaItem(baseItem, playbackDecision)
|
val mediaItem = getMediaItem(baseItem, playbackDecision)
|
||||||
val resumePositionMs = calculateResumePosition(baseItem, playbackDecision.mediaSource)
|
val resumePositionMs = calculateResumePosition(baseItem, playbackDecision.mediaSource)
|
||||||
val mediaTrackPreferences = trackPreferencesRepository.getMediaPreferences(mediaId.toString()).first()
|
val mediaTrackPreferences = trackPreferencesRepository.getMediaPreferences(baseItem.parentId.toString()).first()
|
||||||
val mediaSegments = getMediaSegments(mediaId)
|
val mediaSegments = getMediaSegments(mediaId)
|
||||||
when (baseItem.type) {
|
when (baseItem.type) {
|
||||||
BaseItemKind.MOVIE -> PlayableMedia.Movie(
|
BaseItemKind.MOVIE -> PlayableMedia.Movie(
|
||||||
|
|||||||
Reference in New Issue
Block a user