Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed video player and finished anilist app :) #80

Merged
merged 1 commit into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/src/main/graphql/Query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ query AnimeListCollectionQuery(
nextAiringEpisode {
id
airingAt
timeUntilAiring
episode
mediaId
}
Expand Down Expand Up @@ -209,7 +208,7 @@ query FavoritesAnimeQuery($id: Int, $page: Int) {
}
description
nextAiringEpisode {
timeUntilAiring
airingAt
episode
}
}
Expand Down Expand Up @@ -255,14 +254,14 @@ query SearchAnimeQuery(
medium
}
nextAiringEpisode {
timeUntilAiring
airingAt
episode
}
genres
averageScore
meanScore
nextAiringEpisode {
timeUntilAiring
airingAt
episode
}
trailer { id site thumbnail }
Expand Down Expand Up @@ -378,7 +377,7 @@ fragment HomeMedia on Media {
medium
}
nextAiringEpisode {
timeUntilAiring
airingAt
episode
}
bannerImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fun FavoritesAnimeQuery.Data.convert(): List<Media>? {
Media(
idAniList = it?.node?.id ?: 0,
title = MediaTitle(romaji = it?.node?.title?.romaji ?: ""),
coverImage = MediaCoverImage(it?.node?.coverImage?.large ?: ""),
coverImage = MediaCoverImage(large = it?.node?.coverImage?.large ?: ""),
description = it?.node?.description ?: ""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.kl3jvi.animity.data.mapper

import com.kl3jvi.animity.HomeDataQuery
import com.kl3jvi.animity.data.model.ui_models.*

import com.kl3jvi.animity.fragment.HomeMedia


Expand Down Expand Up @@ -54,6 +55,7 @@ private fun HomeMedia?.convert(): Media {
title = MediaTitle(romaji = this?.title?.romaji ?: ""),
type = this?.type,
format = this?.format,
nextAiringEpisode = this?.nextAiringEpisode?.airingAt,
status = this?.status,
description = this?.description ?: "",
startDate = if (this?.startDate?.year != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private fun List<AnimeListCollectionQuery.Entry?>?.convert(): List<Media> {
type = it?.media?.type,
format = it?.media?.format,
status = it?.media?.status,
nextAiringEpisode = it?.media?.nextAiringEpisode?.airingAt,
description = it?.media?.description ?: "",
startDate = if (it?.media?.startDate?.year != null) {
FuzzyDate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.kl3jvi.animity.data.model.ui_models

import android.os.Parcelable
import com.kl3jvi.animity.type.*


import kotlinx.parcelize.Parcelize


Expand Down Expand Up @@ -39,6 +41,7 @@ data class Media(
val type: MediaType? = null,
val format: MediaFormat? = null,
val status: MediaStatus? = null,
val nextAiringEpisode: Int? = null,
val description: String = "",
val startDate: FuzzyDate? = null,
val endDate: FuzzyDate? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ class PlayerRepositoryImpl @Inject constructor(
)
}

override suspend fun fetchEncryptedAjaxUrl(header: Map<String, String>, url: String): String =
override suspend fun fetchEncryptedAjaxUrl(
header: Map<String, String>,
url: String,
id: String
): String =
withContext(ioDispatcher) {
parser.parseEncryptAjax(
apiClient.fetchM3u8Url(
header = header,
url = url
).string()
).string(),
id
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface PlayerRepository {
val parser: HtmlParser
suspend fun fetchEpisodeMediaUrl(header: Map<String, String>, url: String): EpisodeInfo
suspend fun fetchM3u8Url(header: Map<String, String>, url: String):ArrayList<String>
suspend fun fetchEncryptedAjaxUrl(header: Map<String, String>, url: String):String
suspend fun fetchEncryptedAjaxUrl(header: Map<String, String>, url: String,id:String):String
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class GetEpisodeInfoUseCase @Inject constructor(
}.flowOn(ioDispatcher)

//
fun fetchEncryptedAjaxUrl(url: String?) = flow {
fun fetchEncryptedAjaxUrl(url: String?,id:String) = flow {
emit(Resource.Loading())
try {
val response = playerRepository.fetchEncryptedAjaxUrl(getNetworkHeader(), url ?: "")
val response = playerRepository.fetchEncryptedAjaxUrl(getNetworkHeader(), url ?: "",id)
val streamUrl = "${REFERER}encrypt-ajax.php?${response}"
emit(Resource.Success(data = streamUrl))
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class PlayerViewModel @Inject constructor(

val videoUrlLiveData = Transformations.switchMap(_episodeUrl) { url ->
getEpisodeInfoUseCase(url).flatMapLatest { episodeInfo ->
getEpisodeInfoUseCase.fetchEncryptedAjaxUrl(episodeInfo.data?.vidCdnUrl)
val id =
Regex("id=([^&]+)").find(
episodeInfo.data?.vidCdnUrl ?: ""
)?.value?.removePrefix("id=")
getEpisodeInfoUseCase.fetchEncryptedAjaxUrl(episodeInfo.data?.vidCdnUrl, id ?: "")
}.flatMapLatest {
getEpisodeInfoUseCase.fetchM3U8(it.data)
}.asLiveData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.view.View.VISIBLE
import android.widget.PopupMenu
import androidx.annotation.MenuRes
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.navArgs
Expand All @@ -31,6 +30,8 @@ import com.kl3jvi.animity.utils.launchActivity
import com.kl3jvi.animity.utils.setHtmlText
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.ExperimentalCoroutinesApi
import java.text.SimpleDateFormat
import java.util.*

@ExperimentalCoroutinesApi
@AndroidEntryPoint
Expand Down Expand Up @@ -84,7 +85,8 @@ class DetailsFragment : BaseFragment<DetailsViewModel, FragmentDetailsBinding>()
binding.releaseDate.text = info.startDate?.getDate()
binding.status.text = info.status?.name
binding.type.text = info.type?.rawValue

binding.releaseTime.text =
if (info.nextAiringEpisode != null) displayInDayDateTimeFormat(info.nextAiringEpisode) else ""
binding.animeInfoLayout.textOverview.visibility = VISIBLE
binding.releaseDate.visibility = VISIBLE
binding.status.visibility = VISIBLE
Expand All @@ -98,39 +100,12 @@ class DetailsFragment : BaseFragment<DetailsViewModel, FragmentDetailsBinding>()
}
createGenreChips(info.genres)
}

// collectFlow(viewModel.animeInfo) { res ->
// when (res) {
// is Resource.Success -> {
// res.data?.let { info ->
//
// binding.animeInfoLayout.textOverview.visibility = VISIBLE
// binding.releaseDate.visibility = VISIBLE
// binding.status.visibility = VISIBLE
// binding.type.visibility = VISIBLE
// binding.detailsProgress.visibility = GONE
//
// // Check if the type is movie and this makes invisible the listview of the episodes
// showButtonForMovie(info.type == " Movie")
// createGenreChips(info.genre)
// }
// }
// is Resource.Loading -> {
// binding.animeInfoLayout.textOverview.visibility = GONE
// binding.releaseDate.visibility = GONE
// binding.status.visibility = GONE
// binding.type.visibility = GONE
// }
// is Resource.Error -> {
// showSnack(binding.root, res.message)
// }
// null -> {}
// }
// }
}

private fun showButtonForMovie(isMovie: Boolean) {

private fun displayInDayDateTimeFormat(seconds: Int): String {
val dateFormat = SimpleDateFormat("E, dd MMM yyyy, hh:mm a", Locale.getDefault())
val date = Date(seconds * 1000L)
return dateFormat.format(date)
}

private fun createGenreChips(genre: List<Genre>) {
Expand All @@ -156,29 +131,16 @@ class DetailsFragment : BaseFragment<DetailsViewModel, FragmentDetailsBinding>()
}

private fun observeDatabase() {
if (isGuestLogin()) {
viewModel.isOnDatabase.observe(viewLifecycleOwner) {
check = it
if (!check) {
menu[1].setIcon(R.drawable.ic_favorite_uncomplete)
} else {
menu[1].setIcon(R.drawable.ic_favorite_complete)
}
}
} else {
collectFlow(favoritesViewModel.favoriteAniListAnimeList) {
check = it?.any { media ->
media.idAniList == animeDetails.idAniList
} ?: false
if (!check) {
menu[1].setIcon(R.drawable.ic_favorite_uncomplete)
} else {
menu[1].setIcon(R.drawable.ic_favorite_complete)
}
collectFlow(favoritesViewModel.favoriteAniListAnimeList) {
check = it?.any { media ->
media.idAniList == animeDetails.idAniList
} ?: false
if (!check) {
menu[1].setIcon(R.drawable.ic_favorite_uncomplete)
} else {
menu[1].setIcon(R.drawable.ic_favorite_complete)
}
}

binding.setType.isVisible = !isGuestLogin()
binding.setType.setOnClickListener { v ->
showMenu(v, R.menu.popup_menu)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.kl3jvi.animity.databinding.FragmentFavoritesBinding
import com.kl3jvi.animity.favoriteAnime
import com.kl3jvi.animity.ui.activities.main.MainActivity
import com.kl3jvi.animity.ui.base.viewBinding
import com.kl3jvi.animity.utils.NetworkUtils.isConnectedToInternet
import com.kl3jvi.animity.utils.collectFlow
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -82,4 +83,17 @@ class FavoritesFragment : Fragment(R.layout.fragment_favorites) {
(activity as MainActivity?)?.showBottomNavBar()
}
}


override fun onStart() {
super.onStart()
handleNetworkChanges()
}

private fun handleNetworkChanges() {
requireActivity().isConnectedToInternet(viewLifecycleOwner) { isConnected ->
binding.noInternetResult.noInternet.isVisible = !isConnected
binding.favoritesRecycler.isVisible = isConnected
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import com.kl3jvi.animity.vertical

fun EpoxyController.buildHome(homeData: HomeData) {

val (trendingAnime, newAnime, popularAnime, reviews) = homeData
val (trendingAnime, newAnime, movies, reviews) = homeData

listOf(
homeData.newAnime,
homeData.trendingAnime,
homeData.movies
newAnime,
trendingAnime,
movies
).forEachIndexed { index, list ->
title {
id(Uuid.randomUUID().toString())
Expand All @@ -35,7 +35,7 @@ fun EpoxyController.buildHome(homeData: HomeData) {
id(Uuid.randomUUID().toString())
title(Title.values()[3].title)
}
popularAnime.forEach { media ->
movies.forEach { media ->
vertical {
id(Uuid.randomUUID().toString())
animeInfo(media)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun EpoxyController.buildProfile(
profileCard {
id(randomId())
userData?.userData?.let {
bgImage(it.bannerImage.ifEmpty { Constants.DEFAULT_COVER })
backgroundImage(it.bannerImage.ifEmpty { Constants.DEFAULT_COVER })
userData(it)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/kl3jvi/animity/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Constants {
// }

//Gogoanime Secrets
const val GogoSecretkey = "25716538522938396164662278833288"
const val GogoSecretIV = "1285672985238393"
const val GogoSecretkey = "63976882873559819639988080820907"
const val GogoSecretIV = "4770478969418267"
val GogoPadding = byteArrayOf(0x8, 0xe, 0x3, 0x8, 0x9, 0x3, 0x4, 0x9)

fun getSafeString(string: String?) = string.toString()
Expand Down
27 changes: 13 additions & 14 deletions app/src/main/java/com/kl3jvi/animity/utils/parser/HtmlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ object HtmlParser {

private fun decryptAES(encrypted: String, key: String, iv: String): String {
val ix = IvParameterSpec(iv.toByteArray())
val cipher = Cipher.getInstance("AES/CBC/NoPadding")
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
val secretKey = SecretKeySpec(key.toByteArray(Charsets.UTF_8), "AES")
cipher.init(Cipher.DECRYPT_MODE, secretKey, ix)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand All @@ -232,30 +232,29 @@ object HtmlParser {

private fun encryptAes(text: String, key: String, iv: String): String {
val ix = IvParameterSpec(iv.toByteArray())
val cipher = Cipher.getInstance("AES/CBC/NoPadding")
val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
val secretKey = SecretKeySpec(key.toByteArray(), "AES")
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ix)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Base64.getEncoder()
.encodeToString(cipher.doFinal(text.toByteArray() + Constants.GogoPadding))
Base64.getEncoder().encodeToString(cipher.doFinal(text.toByteArray()))
} else {
android.util.Base64.encodeToString(
cipher.doFinal(text.toByteArray() + Constants.GogoPadding),
cipher.doFinal(text.toByteArray()),
android.util.Base64.DEFAULT
)
}
}


fun parseEncryptAjax(response: String): String {
val document = Jsoup.parse(response)
val value2 = document.select("script[data-name='crypto']").attr("data-value")
val decryptKey =
decryptAES(value2, Constants.GogoSecretkey, Constants.GogoSecretIV).replaceAfter(
"&",
""
).removeSuffix("&")
val encrypted = encryptAes(decryptKey, Constants.GogoSecretkey, Constants.GogoSecretIV)
fun parseEncryptAjax(response: String, id: String): String {
// val document = Jsoup.parse(response)
// val value2 = document.select("script[data-name='crypto']").attr("data-value")
// val decryptKey =
// decryptAES(value2, Constants.GogoSecretkey, Constants.GogoSecretIV).replaceAfter(
// "&",
// ""
// ).removeSuffix("&")
val encrypted = encryptAes(id, Constants.GogoSecretkey, Constants.GogoSecretIV)
return "id=$encrypted"
}

Expand Down
Loading