From f882ab4afcb64dc6dfbac92decc9f5cb36493d6b Mon Sep 17 00:00:00 2001 From: kl3jvi Date: Mon, 17 Jan 2022 02:30:07 +0100 Subject: [PATCH] fixed!!!! --- .../data/repository/PlayerRepositoryImpl.kt | 7 ++++--- .../domain/repositories/PlayerRepository.kt | 2 +- .../domain/use_cases/GetEpisodeInfoUseCase.kt | 3 +-- .../ui/activities/player/PlayerActivity.kt | 15 ++++++++++++--- .../com/kl3jvi/animity/utils/parser/HtmlParser.kt | 10 +++------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/kl3jvi/animity/data/repository/PlayerRepositoryImpl.kt b/app/src/main/java/com/kl3jvi/animity/data/repository/PlayerRepositoryImpl.kt index f24f64b4..d0604f1b 100644 --- a/app/src/main/java/com/kl3jvi/animity/data/repository/PlayerRepositoryImpl.kt +++ b/app/src/main/java/com/kl3jvi/animity/data/repository/PlayerRepositoryImpl.kt @@ -3,7 +3,6 @@ package com.kl3jvi.animity.data.repository import com.kl3jvi.animity.data.model.EpisodeInfo import com.kl3jvi.animity.data.network.AnimeApiClient import com.kl3jvi.animity.domain.repositories.PlayerRepository -import com.kl3jvi.animity.utils.Constants.Companion.REFERER import com.kl3jvi.animity.utils.parser.HtmlParser import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext @@ -29,9 +28,11 @@ class PlayerRepositoryImpl @Inject constructor( override suspend fun fetchM3u8Url( header: Map, url: String - ): Pair, ArrayList> = + ): ArrayList = withContext(ioDispatcher) { - parser.parseEncryptedUrls(apiClient.fetchM3u8PreProcessor(header = header, url = url).string()) + parser.parseEncryptedUrls( + apiClient.fetchM3u8PreProcessor(header = header, url = url).string() + ) } override suspend fun fetchEncryptedAjaxUrl(header: Map, url: String): String = diff --git a/app/src/main/java/com/kl3jvi/animity/domain/repositories/PlayerRepository.kt b/app/src/main/java/com/kl3jvi/animity/domain/repositories/PlayerRepository.kt index 5f3eb47e..2fa87a28 100644 --- a/app/src/main/java/com/kl3jvi/animity/domain/repositories/PlayerRepository.kt +++ b/app/src/main/java/com/kl3jvi/animity/domain/repositories/PlayerRepository.kt @@ -6,6 +6,6 @@ import com.kl3jvi.animity.utils.parser.HtmlParser interface PlayerRepository { val parser: HtmlParser suspend fun fetchEpisodeMediaUrl(header: Map, url: String): EpisodeInfo - suspend fun fetchM3u8Url(header: Map, url: String):Pair,ArrayList> + suspend fun fetchM3u8Url(header: Map, url: String):ArrayList suspend fun fetchEncryptedAjaxUrl(header: Map, url: String):String } \ No newline at end of file diff --git a/app/src/main/java/com/kl3jvi/animity/domain/use_cases/GetEpisodeInfoUseCase.kt b/app/src/main/java/com/kl3jvi/animity/domain/use_cases/GetEpisodeInfoUseCase.kt index 6c6f4e31..5d2adb55 100644 --- a/app/src/main/java/com/kl3jvi/animity/domain/use_cases/GetEpisodeInfoUseCase.kt +++ b/app/src/main/java/com/kl3jvi/animity/domain/use_cases/GetEpisodeInfoUseCase.kt @@ -31,8 +31,7 @@ class GetEpisodeInfoUseCase @Inject constructor( emit(Resource.Loading()) try { val response = playerRepository.fetchM3u8Url(getNetworkHeader(), url ?: "") - Log.e("respons'ua", response.toString()) - emit(Resource.Success(data = response.first.first())) + emit(Resource.Success(data = response.last())) } catch (e: Exception) { e.printStackTrace() emit(Resource.Error("Couldn't find a Stream for this Anime")) diff --git a/app/src/main/java/com/kl3jvi/animity/ui/activities/player/PlayerActivity.kt b/app/src/main/java/com/kl3jvi/animity/ui/activities/player/PlayerActivity.kt index f920c2c4..a1551156 100644 --- a/app/src/main/java/com/kl3jvi/animity/ui/activities/player/PlayerActivity.kt +++ b/app/src/main/java/com/kl3jvi/animity/ui/activities/player/PlayerActivity.kt @@ -15,6 +15,7 @@ import androidx.core.content.ContextCompat import com.google.android.exoplayer2.* import com.google.android.exoplayer2.audio.AudioAttributes import com.google.android.exoplayer2.source.MediaSource +import com.google.android.exoplayer2.source.ProgressiveMediaSource import com.google.android.exoplayer2.source.hls.HlsMediaSource import com.google.android.exoplayer2.trackselection.DefaultTrackSelector import com.google.android.exoplayer2.trackselection.MappingTrackSelector @@ -237,7 +238,7 @@ class PlayerActivity : AppCompatActivity() { viewBinding.videoView.player = exoPlayer val mdItem = MediaItem.fromUri(videoM3U8Url) val videoSource: MediaSource = - buildMediaSource(mdItem) + buildMediaSource(mdItem,videoM3U8Url) exoPlayer.setMediaSource(videoSource) exoPlayer.playWhenReady = playWhenReady @@ -357,11 +358,19 @@ class PlayerActivity : AppCompatActivity() { } } - private fun buildMediaSource(mediaItem: MediaItem): HlsMediaSource { +// private fun buildMediaSource(mediaItem: MediaItem): HlsMediaSource { +// val dataSourceFactory: DataSource.Factory = getDataSourceFactory() +// return HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem) +// } + + private fun buildMediaSource(mediaItem: MediaItem, url: String): MediaSource { val dataSourceFactory: DataSource.Factory = getDataSourceFactory() - return HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem) + return if (url.contains("m3u8")) + HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem) + else ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem) } + private fun releasePlayer() { player?.run { playbackPosition = this.currentPosition diff --git a/app/src/main/java/com/kl3jvi/animity/utils/parser/HtmlParser.kt b/app/src/main/java/com/kl3jvi/animity/utils/parser/HtmlParser.kt index aef771ef..49ae573e 100644 --- a/app/src/main/java/com/kl3jvi/animity/utils/parser/HtmlParser.kt +++ b/app/src/main/java/com/kl3jvi/animity/utils/parser/HtmlParser.kt @@ -294,23 +294,19 @@ object HtmlParser { ) } - fun parseEncryptedUrls(response: String): Pair, ArrayList> { + fun parseEncryptedUrls(response: String): ArrayList { val urls: ArrayList = ArrayList() - val qualities: ArrayList = ArrayList() var i = 0 val res = JSONObject(response).getJSONArray("source") Log.e("resu,", res.toString()) return try { while (i != res.length() && res.getJSONObject(i).getString("label") != "Auto") { urls.add(res.getJSONObject(i).getString("file")) - qualities.add( - res.getJSONObject(i).getString("label").lowercase(Locale.getDefault()) - .filterNot { it.isWhitespace() }) i++ } - Pair(urls, qualities) + urls } catch (exp: java.lang.NullPointerException) { - Pair(urls, qualities) + urls } } }