Skip to content

Commit

Permalink
refactoring code and adding encrypted video cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
kl3jvi committed Jan 11, 2022
1 parent e1390bd commit 890417a
Show file tree
Hide file tree
Showing 22 changed files with 251 additions and 99 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ plugins {
}

android {
compileSdk 31
compileSdk 32
defaultConfig {
applicationId "com.kl3jvi.animity"
minSdk 21
targetSdk 31
targetSdk 32
versionCode 5
versionName "1.0.3"
archivesBaseName = "Animity-v$versionName"
Expand Down Expand Up @@ -145,6 +145,6 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

def paging_version = "3.1.0"
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
implementation 'org.apache.commons:commons-text:1.7'

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class EpisodeInfo(
var vidCdnUrl: String? = null,
var nextEpisodeUrl: String? = null,
var previousEpisodeUrl: String? = null
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ class AnimeApiClient @Inject constructor(

suspend fun fetchSearchData(header: Map<String, String>, keyword: String, page: Int) =
animeService.fetchSearchData(header, keyword, page)

suspend fun fetchM3u8PreProcessor(header: Map<String, String>, url: String) =
animeService.fetchM3u8PreProcessor(header, url)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ interface AnimeService {
@Url url: String
): ResponseBody

@GET
@Headers("X-Requested-With:XMLHttpRequest")
suspend fun fetchM3u8PreProcessor(
@HeaderMap header: Map<String, String>,
@Url url: String
): ResponseBody

@GET(Constants.EPISODE_LOAD_URL)
suspend fun fetchEpisodeList(
@HeaderMap header: Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,36 @@ import com.kl3jvi.animity.data.model.EpisodeReleaseModel
import com.kl3jvi.animity.data.network.AnimeApiClient
import com.kl3jvi.animity.domain.repositories.DetailsRepository
import com.kl3jvi.animity.utils.parser.HtmlParser
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
@Suppress("BlockingMethodInNonBlockingContext")
class DetailsRepositoryImpl @Inject constructor(
private val apiClient: AnimeApiClient
private val apiClient: AnimeApiClient,
private val ioDispatcher: CoroutineDispatcher
) : DetailsRepository {
override val parser: HtmlParser
get() = HtmlParser

override suspend fun fetchAnimeInfo(
header: Map<String, String>,
episodeUrl: String
): AnimeInfoModel {
return parser.parseAnimeInfo(apiClient.fetchAnimeInfo(header, episodeUrl).string())
): AnimeInfoModel = withContext(ioDispatcher) {
parser.parseAnimeInfo(
apiClient.fetchAnimeInfo(header = header, episodeUrl = episodeUrl).string()
)
}

override suspend fun fetchEpisodeList(
header: Map<String, String>,
id: String,
endEpisode: String,
alias: String
): ArrayList<EpisodeModel> {
return parser.fetchEpisodeList(
): List<EpisodeModel> = withContext(ioDispatcher) {
parser.fetchEpisodeList(
apiClient.fetchEpisodeList(
header = header,
id = id,
Expand All @@ -40,6 +46,9 @@ class DetailsRepositoryImpl @Inject constructor(
}

override suspend fun fetchEpisodeTimeRelease(episodeUrl: String): EpisodeReleaseModel =
parser.fetchEpisodeReleaseTime(apiClient.fetchEpisodeTimeRelease(episodeUrl).string())

withContext(ioDispatcher) {
parser.fetchEpisodeReleaseTime(
apiClient.fetchEpisodeTimeRelease(episodeUrl = episodeUrl).string()
)
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
package com.kl3jvi.animity.data.repository

import com.kl3jvi.animity.domain.repositories.HomeRepository
import com.kl3jvi.animity.data.model.AnimeMetaModel
import com.kl3jvi.animity.data.network.AnimeApiClient
import com.kl3jvi.animity.domain.repositories.HomeRepository
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_MOVIE
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_POPULAR_ANIME
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_RECENT_SUB
import com.kl3jvi.animity.utils.parser.HtmlParser
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class HomeRepositoryImpl @Inject constructor(private val apiClient: AnimeApiClient) :
HomeRepository {
@Suppress("BlockingMethodInNonBlockingContext")
class HomeRepositoryImpl @Inject constructor(
private val apiClient: AnimeApiClient,
private val ioDispatcher: CoroutineDispatcher
) : HomeRepository {
override val parser: HtmlParser
get() = HtmlParser

override suspend fun fetchRecentSubOrDub(
header: Map<String, String>,
page: Int,
type: Int
): ArrayList<AnimeMetaModel> {
return parser.parseRecentSubOrDub(
apiClient.fetchRecentSubOrDub(header, page, type).string(), TYPE_RECENT_SUB
): List<AnimeMetaModel> = withContext(ioDispatcher) {
parser.parseRecentSubOrDub(
apiClient.fetchRecentSubOrDub(header = header, page = page, type = type).string(),
TYPE_RECENT_SUB
)
}

override suspend fun fetchPopularFromAjax(
header: Map<String, String>,
page: Int
): ArrayList<AnimeMetaModel> {
return parser.parsePopular(apiClient.fetchPopularFromAjax(header, page).string(), TYPE_POPULAR_ANIME)
): List<AnimeMetaModel> = withContext(ioDispatcher) {
parser.parsePopular(
apiClient.fetchPopularFromAjax(header = header, page = page).string(),
TYPE_POPULAR_ANIME
)
}

override suspend fun fetchNewSeason(
header: Map<String, String>,
page: Int
): ArrayList<AnimeMetaModel> {
return parser.parseMovie(apiClient.fetchNewSeason(header, page).string(),TYPE_MOVIE)
): List<AnimeMetaModel> = withContext(ioDispatcher) {
parser.parseMovie(
apiClient.fetchNewSeason(header = header, page = page).string(),
TYPE_MOVIE
)
}

override suspend fun fetchMovies(
header: Map<String, String>,
page: Int
): ArrayList<AnimeMetaModel> {
return parser.parseMovie(apiClient.fetchMovies(header, page).string(),TYPE_MOVIE)
): List<AnimeMetaModel> = withContext(ioDispatcher) {
parser.parseMovie(apiClient.fetchMovies(header = header, page = page).string(), TYPE_MOVIE)
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
package com.kl3jvi.animity.data.repository

import com.kl3jvi.animity.domain.repositories.PlayerRepository
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.parser.HtmlParser
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
@Suppress("BlockingMethodInNonBlockingContext")
class PlayerRepositoryImpl @Inject constructor(
private val apiClient: AnimeApiClient
private val apiClient: AnimeApiClient,
private val ioDispatcher: CoroutineDispatcher
) : PlayerRepository {
override val parser: HtmlParser
get() = HtmlParser

override suspend fun fetchEpisodeMediaUrl(
header: Map<String, String>,
url: String
): EpisodeInfo {
return parser.parseMediaUrl(apiClient.fetchEpisodeMediaUrl(header, url).string())
): EpisodeInfo = withContext(ioDispatcher) {
parser.parseMediaUrl(apiClient.fetchEpisodeMediaUrl(header = header, url = url).string())
}

override suspend fun fetchM3u8Url(header: Map<String, String>, url: String): String {
return parser.parseM3U8Url(apiClient.fetchM3u8Url(header, url).string())?:""
}

override suspend fun fetchM3u8Url(header: Map<String, String>, url: String): String =
withContext(ioDispatcher) {
parser.parseEncryptAjax(apiClient.fetchM3u8Url(header = header, url = url).string()) ?: ""
}

override suspend fun fetchEncryptedAjaxUrl(header: Map<String, String>, url: String): String =
withContext(ioDispatcher) {
parser.parseEncryptAjax(
apiClient.fetchM3u8PreProcessor(header = header, url = url).string()
)
}

}

Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.kl3jvi.animity.data.repository

import com.kl3jvi.animity.domain.repositories.SearchRepository
import com.kl3jvi.animity.data.model.AnimeMetaModel
import com.kl3jvi.animity.data.network.AnimeApiClient
import com.kl3jvi.animity.domain.repositories.SearchRepository
import com.kl3jvi.animity.utils.Constants.Companion.TYPE_SEARCH
import com.kl3jvi.animity.utils.parser.HtmlParser
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
@Suppress("BlockingMethodInNonBlockingContext")
class SearchRepositoryImpl @Inject constructor(
private val apiClient: AnimeApiClient
private val apiClient: AnimeApiClient,
private val ioDispatcher: CoroutineDispatcher
) : SearchRepository {
override val parser: HtmlParser
get() = HtmlParser
Expand All @@ -19,9 +23,13 @@ class SearchRepositoryImpl @Inject constructor(
header: Map<String, String>,
keyword: String,
page: Int
): ArrayList<AnimeMetaModel> {
return parser.parseMovie(
apiClient.fetchSearchData(header, keyword, page).string(),
): List<AnimeMetaModel> = withContext(ioDispatcher) {
parser.parseMovie(
apiClient.fetchSearchData(
header = header,
keyword = keyword,
page = page
).string(),
TYPE_SEARCH
)
}
Expand Down
21 changes: 13 additions & 8 deletions app/src/main/java/com/kl3jvi/animity/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,45 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.CoroutineDispatcher

@Module
@InstallIn(ViewModelComponent::class)
object RepositoryModule {
@Provides
@ViewModelScoped
fun provideDetailsRepository(
apiClient: AnimeApiClient
apiClient: AnimeApiClient,
ioDispatcher: CoroutineDispatcher
): DetailsRepository {
return DetailsRepositoryImpl(apiClient)
return DetailsRepositoryImpl(apiClient, ioDispatcher)
}

@Provides
@ViewModelScoped
fun provideHomeRepository(
apiClient: AnimeApiClient
apiClient: AnimeApiClient,
ioDispatcher: CoroutineDispatcher
): HomeRepository {
return HomeRepositoryImpl(apiClient)
return HomeRepositoryImpl(apiClient, ioDispatcher)
}

@Provides
@ViewModelScoped
fun provideSearchRepository(
apiClient: AnimeApiClient
apiClient: AnimeApiClient,
ioDispatcher: CoroutineDispatcher
): SearchRepository {
return SearchRepositoryImpl(apiClient)
return SearchRepositoryImpl(apiClient, ioDispatcher)
}

@Provides
@ViewModelScoped
fun providePlayerRepository(
apiClient: AnimeApiClient
apiClient: AnimeApiClient,
ioDispatcher: CoroutineDispatcher
): PlayerRepository {
return PlayerRepositoryImpl(apiClient)
return PlayerRepositoryImpl(apiClient, ioDispatcher)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface DetailsRepository {
id: String,
endEpisode: String,
alias: String
): ArrayList<EpisodeModel>
): List<EpisodeModel>

suspend fun fetchEpisodeTimeRelease(episodeUrl: String): EpisodeReleaseModel
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ interface HomeRepository {
header: Map<String, String>,
page: Int,
type: Int
): ArrayList<AnimeMetaModel>
): List<AnimeMetaModel>

suspend fun fetchPopularFromAjax(
header: Map<String, String>,
page: Int
): ArrayList<AnimeMetaModel>
): List<AnimeMetaModel>

suspend fun fetchNewSeason(header: Map<String, String>, page: Int): ArrayList<AnimeMetaModel>
suspend fun fetchMovies(header: Map<String, String>, page: Int): ArrayList<AnimeMetaModel>
suspend fun fetchNewSeason(header: Map<String, String>, page: Int): List<AnimeMetaModel>
suspend fun fetchMovies(header: Map<String, String>, page: Int): List<AnimeMetaModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +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):String
suspend fun fetchEncryptedAjaxUrl(header: Map<String, String>, url: String):String
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface SearchRepository {
header: Map<String, String>,
keyword: String,
page: Int
): ArrayList<AnimeMetaModel>
): List<AnimeMetaModel>
}
Loading

0 comments on commit 890417a

Please sign in to comment.