From 77cf88785b7bab5a805639f9dcde622eb46d3ed0 Mon Sep 17 00:00:00 2001 From: rhenwinch Date: Wed, 29 May 2024 22:29:32 +0800 Subject: [PATCH] fix(providers): fix scoped capabilities to create grouped providers In order to fix this, the whole film object is necessary to be passed instead of just the film title, id, etc. to the majority of the methods the provider api class. --- .../provider/DefaultSourceLinksRepository.kt | 5 +- .../data/provider/SourceLinksRepository.kt | 1 + .../provider/SourceLinksProviderUseCase.kt | 1 + .../dialogs/servers/PlayerServersDialog.kt | 9 +- .../tv/player/controls/PlaybackControls.kt | 11 +- .../com/flixclusive/provider/ProviderApi.kt | 14 +- .../provider/testing/BaseProviderTest.kt | 196 ------------------ 7 files changed, 20 insertions(+), 217 deletions(-) delete mode 100644 provider/src/main/kotlin/com/flixclusive/provider/testing/BaseProviderTest.kt diff --git a/data/provider/src/main/kotlin/com/flixclusive/data/provider/DefaultSourceLinksRepository.kt b/data/provider/src/main/kotlin/com/flixclusive/data/provider/DefaultSourceLinksRepository.kt index 69ba1b28e..0ade4a685 100644 --- a/data/provider/src/main/kotlin/com/flixclusive/data/provider/DefaultSourceLinksRepository.kt +++ b/data/provider/src/main/kotlin/com/flixclusive/data/provider/DefaultSourceLinksRepository.kt @@ -24,6 +24,7 @@ class DefaultSourceLinksRepository @Inject constructor( override suspend fun getSourceLinks( mediaId: String, providerApi: ProviderApi, + film: Film, season: Int?, episode: Int?, onLinkLoaded: (SourceLink) -> Unit, @@ -33,6 +34,7 @@ class DefaultSourceLinksRepository @Inject constructor( try { providerApi.getSourceLinks( filmId = mediaId, + film = film, episode = episode, season = season, onLinkLoaded = onLinkLoaded, @@ -70,9 +72,8 @@ class DefaultSourceLinksRepository @Inject constructor( } val searchResponse = providerApi.search( - query = film.title, page = i, - filmType = film.filmType + film = film ) if (searchResponse.results.isEmpty()) diff --git a/data/provider/src/main/kotlin/com/flixclusive/data/provider/SourceLinksRepository.kt b/data/provider/src/main/kotlin/com/flixclusive/data/provider/SourceLinksRepository.kt index ccdb85746..d320533d4 100644 --- a/data/provider/src/main/kotlin/com/flixclusive/data/provider/SourceLinksRepository.kt +++ b/data/provider/src/main/kotlin/com/flixclusive/data/provider/SourceLinksRepository.kt @@ -11,6 +11,7 @@ interface SourceLinksRepository { suspend fun getSourceLinks( mediaId: String, providerApi: ProviderApi, + film: Film, season: Int? = null, episode: Int? = null, onLinkLoaded: (SourceLink) -> Unit, diff --git a/domain/provider/src/main/kotlin/com/flixclusive/domain/provider/SourceLinksProviderUseCase.kt b/domain/provider/src/main/kotlin/com/flixclusive/domain/provider/SourceLinksProviderUseCase.kt index 36adbd639..6610b8621 100644 --- a/domain/provider/src/main/kotlin/com/flixclusive/domain/provider/SourceLinksProviderUseCase.kt +++ b/domain/provider/src/main/kotlin/com/flixclusive/domain/provider/SourceLinksProviderUseCase.kt @@ -288,6 +288,7 @@ class SourceLinksProviderUseCase @Inject constructor( val result = sourceLinksRepository.getSourceLinks( mediaId = mediaIdToUse, + film = film, season = episodeToUse?.season, episode = episodeToUse?.episode, providerApi = provider, diff --git a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/servers/PlayerServersDialog.kt b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/servers/PlayerServersDialog.kt index 5de4337f2..8c249d9a9 100644 --- a/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/servers/PlayerServersDialog.kt +++ b/feature/mobile/player/src/main/java/com/flixclusive/feature/mobile/player/controls/dialogs/servers/PlayerServersDialog.kt @@ -25,6 +25,7 @@ import com.flixclusive.feature.mobile.player.controls.common.ListContentHolder import com.flixclusive.feature.mobile.player.controls.common.PlayerDialogButton import com.flixclusive.model.provider.SourceLink import com.flixclusive.model.provider.Subtitle +import com.flixclusive.model.tmdb.Film import com.flixclusive.provider.ProviderApi import com.flixclusive.provider.dto.FilmInfo import com.flixclusive.provider.dto.SearchResults @@ -108,11 +109,7 @@ private fun PlayerServersDialogPreview() { override val name: String get() = "Provider #$it" - override suspend fun search( - query: String, - page: Int, - filmType: FilmType - ): SearchResults { + override suspend fun search(film: Film, page: Int): SearchResults { TODO("Not yet implemented") } @@ -122,6 +119,7 @@ private fun PlayerServersDialogPreview() { override suspend fun getSourceLinks( filmId: String, + film: Film, season: Int?, episode: Int?, onLinkLoaded: (SourceLink) -> Unit, @@ -129,7 +127,6 @@ private fun PlayerServersDialogPreview() { ) { TODO("Not yet implemented") } - } } diff --git a/feature/tv/player/src/main/kotlin/com/flixclusive/feature/tv/player/controls/PlaybackControls.kt b/feature/tv/player/src/main/kotlin/com/flixclusive/feature/tv/player/controls/PlaybackControls.kt index e6cf576ff..06bbab1b2 100644 --- a/feature/tv/player/src/main/kotlin/com/flixclusive/feature/tv/player/controls/PlaybackControls.kt +++ b/feature/tv/player/src/main/kotlin/com/flixclusive/feature/tv/player/controls/PlaybackControls.kt @@ -59,6 +59,7 @@ import com.flixclusive.model.datastore.AppSettings import com.flixclusive.model.provider.SourceDataState import com.flixclusive.model.provider.SourceLink import com.flixclusive.model.provider.Subtitle +import com.flixclusive.model.tmdb.Film import com.flixclusive.model.tmdb.TMDBEpisode import com.flixclusive.provider.ProviderApi import com.flixclusive.provider.dto.FilmInfo @@ -356,20 +357,17 @@ private fun PlaybackControlsPreview() { override val name: String get() = "Provider #$it" - override suspend fun search( - query: String, - page: Int, - filmType: FilmType - ): SearchResults { + override suspend fun getFilmInfo(filmId: String, filmType: FilmType): FilmInfo { TODO("Not yet implemented") } - override suspend fun getFilmInfo(filmId: String, filmType: FilmType): FilmInfo { + override suspend fun search(film: Film, page: Int): SearchResults { TODO("Not yet implemented") } override suspend fun getSourceLinks( filmId: String, + film: Film, season: Int?, episode: Int?, onLinkLoaded: (SourceLink) -> Unit, @@ -377,7 +375,6 @@ private fun PlaybackControlsPreview() { ) { TODO("Not yet implemented") } - } } diff --git a/provider/src/main/kotlin/com/flixclusive/provider/ProviderApi.kt b/provider/src/main/kotlin/com/flixclusive/provider/ProviderApi.kt index cee1914a8..42423c325 100644 --- a/provider/src/main/kotlin/com/flixclusive/provider/ProviderApi.kt +++ b/provider/src/main/kotlin/com/flixclusive/provider/ProviderApi.kt @@ -5,7 +5,9 @@ import com.flixclusive.core.util.film.FilmType import com.flixclusive.model.provider.SourceLink import com.flixclusive.model.provider.Subtitle import com.flixclusive.model.tmdb.Film +import com.flixclusive.model.tmdb.Movie import com.flixclusive.model.tmdb.TMDBEpisode +import com.flixclusive.model.tmdb.TvShow import com.flixclusive.provider.dto.FilmInfo import com.flixclusive.provider.dto.SearchResults import com.flixclusive.provider.extractor.Extractor @@ -42,20 +44,18 @@ abstract class ProviderApi( /** * Performs a search for films based on the provided query. - * @param query The search query. + * @param film The [Film] object of the film. It could either be a [Movie] or [TvShow]. * @param page The page number for paginated results. Defaults to 1. - * @param filmType The type of film being searched for. * @return a [SearchResults] instance containing the search results. */ abstract suspend fun search( - query: String, + film: Film, page: Int = 1, - filmType: FilmType, ): SearchResults /** * Retrieves detailed information about a film. - * @param filmId The ID of the film. + * @param filmId The ID of the film. The ID must come from the [search] method. * @param filmType The type of film. * @return a [FilmInfo] instance containing the film's information. */ @@ -66,7 +66,8 @@ abstract class ProviderApi( /** * Obtains source links for the provided film, season, and episode. - * @param filmId The ID of the film. + * @param filmId The ID of the film. The ID must come from the [search] method. + * @param film The [Film] object of the film. It could either be a [Movie] or [TvShow]. * @param season The season number. Defaults to null if the film is a movie. * @param episode The episode number. Defaults to null if the film is a movie. * @param onLinkLoaded A callback function invoked when a [SourceLink] is loaded. @@ -74,6 +75,7 @@ abstract class ProviderApi( */ abstract suspend fun getSourceLinks( filmId: String, + film: Film, season: Int? = null, episode: Int? = null, onLinkLoaded: (SourceLink) -> Unit, diff --git a/provider/src/main/kotlin/com/flixclusive/provider/testing/BaseProviderTest.kt b/provider/src/main/kotlin/com/flixclusive/provider/testing/BaseProviderTest.kt deleted file mode 100644 index 5792df6cb..000000000 --- a/provider/src/main/kotlin/com/flixclusive/provider/testing/BaseProviderTest.kt +++ /dev/null @@ -1,196 +0,0 @@ -package com.flixclusive.provider.testing - -import android.util.Base64 -import com.flixclusive.core.util.film.FilmType -import com.flixclusive.model.provider.SourceLink -import com.flixclusive.model.provider.Subtitle -import com.flixclusive.provider.ProviderApi -import com.flixclusive.provider.dto.FilmInfo -import io.mockk.every -import io.mockk.mockkStatic -import kotlinx.coroutines.test.runTest -import org.junit.Assert -import org.junit.Before -import org.junit.Test - -abstract class BaseProviderTest { - lateinit var sourceProviderApi: ProviderApi - - @Before - open fun setUp(): Unit = runTest { - mockkStatic(Base64::class) - every { Base64.encodeToString(any(), any()) } answers { - val byteArray = arg(0) - java.util.Base64.getEncoder().encodeToString(byteArray) - } - every { Base64.encode(any(), any()) } answers { - val byteArray = arg(0).toByteArray() - java.util.Base64.getEncoder().encode(byteArray) - } - every { Base64.decode(any(), any()) } answers { - val byteArray = arg(0).toByteArray() - java.util.Base64.getDecoder().decode(byteArray) - } - every { Base64.decode(any(), any()) } answers { - java.util.Base64.getDecoder().decode(arg(0)) - } - } - - private suspend fun getSourceData( - title: String, - releaseDate: String, - type: FilmType, - season: Int? = null, - episode: Int? = null, - ) { - val response = sourceProviderApi.search( - query = title, - page = 1, - filmType = type - ) - - val filmId = response.results.find { - val releaseDateToUse = if(it.releaseDate == null) { - sourceProviderApi.getFilmInfo( - filmId = it.id!!, - filmType = it.filmType!! - ).yearReleased - } else it.releaseDate - - releaseDateToUse == releaseDate - }?.id - Assert.assertNotNull(filmId) - - val links = mutableSetOf() - val subtitles = mutableSetOf() - sourceProviderApi.getSourceLinks( - filmId = filmId!!, - season = season, - episode = episode, - onLinkLoaded = { - assert(it.url.isNotEmpty()) - links.add(it) - println("SourceLink for $title: $it") - }, - onSubtitleLoaded = { - assert(it.url.isNotEmpty()) - subtitles.add(it) - println("Subtitle for $title: $it") - } - ) - - assert(links.isNotEmpty()) - assert(subtitles.isNotEmpty()) - } - - private suspend fun getFilmInfo( - title: String, - releaseDate: String, - type: FilmType, - ): FilmInfo { - val response = sourceProviderApi.search( - query = title, - page = 1, - filmType = type - ) - - val filmId = response.results.find { - val releaseDateToUse = if(it.releaseDate == null) { - sourceProviderApi.getFilmInfo( - filmId = it.id!!, - filmType = it.filmType!! - ).yearReleased - } else it.releaseDate - - releaseDateToUse == releaseDate - }?.id - Assert.assertNotNull(filmId) - - return sourceProviderApi.getFilmInfo( - filmId = filmId!!, - filmType = type - ) - } - - @Test - open fun search_for_The_Dark_Knight_2008() = runTest { - val title = "The Dark Knight" - val releaseDate = "2008" - val response = sourceProviderApi.search( - query = title, - page = 1, - filmType = FilmType.MOVIE - ) - - assert(response.results.isNotEmpty()) - assert(response.results.any { it.releaseDate == releaseDate }) - } - - @Test - open fun get_source_for_The_Dark_Knight_2008() = runTest { - val title = "The Dark Knight" - val releaseDate = "2008" - - getSourceData( - title = title, - releaseDate = releaseDate, - type = FilmType.MOVIE - ) - } - - @Test - open fun getfor_World_War_Z_2013() = runTest { - val title = "World War Z" - val releaseDate = "2013" - - getSourceData( - title = title, - releaseDate = releaseDate, - type = FilmType.MOVIE - ) - } - - @Test - open fun get_for_When_Evil_Returns_2023() = runTest { - val title = "When Evil Lurks" - val releaseDate = "2023" - - getSourceData( - title = title, - releaseDate = releaseDate, - type = FilmType.MOVIE - ) - } - - @Test - open fun get_for_Silo_2023_tv_show() = runTest { - val title = "Silo" - val releaseDate = "2023" - - val data = getFilmInfo( - title = title, - releaseDate = releaseDate, - type = FilmType.TV_SHOW - ) - - Assert.assertEquals(data.title, title) - assert(data.yearReleased.isNotBlank()) - assert(data.id.isNotEmpty()) - } - - @Test - open fun get_for_Attack_On_Titan_2013_tv_show_S1_E3() = runTest { - val title = "Attack on Titan" - val releaseDate = "2013" - val season = 1 - val episode = 3 - - getSourceData( - title = title, - releaseDate = releaseDate, - type = FilmType.TV_SHOW, - season = season, - episode = episode - ) - } -} \ No newline at end of file