diff --git a/src/en/allanime/src/eu/kanade/tachiyomi/animeextension/en/allanime/AllAnime.kt b/src/en/allanime/src/eu/kanade/tachiyomi/animeextension/en/allanime/AllAnime.kt index b2422ac52..d2ed21ed2 100644 --- a/src/en/allanime/src/eu/kanade/tachiyomi/animeextension/en/allanime/AllAnime.kt +++ b/src/en/allanime/src/eu/kanade/tachiyomi/animeextension/en/allanime/AllAnime.kt @@ -25,7 +25,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.runBlocking -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import okhttp3.OkHttpClient import okhttp3.Request @@ -40,8 +39,7 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { override val name = "AllAnime" - // allanime.to - override val baseUrl by lazy { preferences.getString("preferred_domain", "https://api.allanime.to")!! } + override val baseUrl by lazy { preferences.getString(PREF_DOMAIN_KEY, PREF_DOMAIN_DEFAULT)!! } override val lang = "en" @@ -51,108 +49,6 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { private val json: Json by injectLazy() - private val popularQuery = """ - query( - ${'$'}type: VaildPopularTypeEnumType! - ${'$'}size: Int! - ${'$'}page: Int - ${'$'}dateRange: Int - ) { - queryPopular( - type: ${'$'}type - size: ${'$'}size - dateRange: ${'$'}dateRange - page: ${'$'}page - ) { - total - recommendations { - anyCard { - _id - name - thumbnail - englishName - nativeName - slugTime - } - } - } - } - """.trimIndent().trim() - - private val searchQuery = """ - query( - ${'$'}search: SearchInput - ${'$'}limit: Int - ${'$'}page: Int - ${'$'}translationType: VaildTranslationTypeEnumType - ${'$'}countryOrigin: VaildCountryOriginEnumType - ) { - shows( - search: ${'$'}search - limit: ${'$'}limit - page: ${'$'}page - translationType: ${'$'}translationType - countryOrigin: ${'$'}countryOrigin - ) { - pageInfo { - total - } - edges { - _id - name - thumbnail - englishName - nativeName - slugTime - } - } - } - """.trimIndent().trim() - - private val detailsQuery = """ - query (${'$'}_id: String!) { - show( - _id: ${'$'}_id - ) { - thumbnail - description - type - season - score - genres - status - studios - } - } - """.trimIndent().trim() - - private val episodesQuery = """ - query (${'$'}_id: String!) { - show( - _id: ${'$'}_id - ) { - _id - availableEpisodesDetail - } - } - """.trimIndent().trim() - - private val streamQuery = """ - query( - ${'$'}showId: String!, - ${'$'}translationType: VaildTranslationTypeEnumType!, - ${'$'}episodeString: String! - ) { - episode( - showId: ${'$'}showId - translationType: ${'$'}translationType - episodeString: ${'$'}episodeString - ) { - sourceUrls - } - } - """.trimIndent().trim() - private val preferences: SharedPreferences by lazy { Injekt.get().getSharedPreferences("source_$id", 0x0000) } @@ -160,18 +56,15 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { // ============================== Popular =============================== override fun popularAnimeRequest(page: Int): Request { - val variables = """{"type":"anime","size":26,"dateRange":7,"page":$page}""" - val headers = headers.newBuilder() - .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0") - .build() - return GET("$baseUrl/allanimeapi?variables=$variables&query=$popularQuery", headers = headers) + val variables = """{"type":"anime","size":$PAGE_SIZE,"dateRange":7,"page":$page}""" + return GET("$baseUrl/allanimeapi?variables=$variables&query=$POPULAR_QUERY", headers = headers) } override fun popularAnimeParse(response: Response): AnimesPage { val parsed = json.decodeFromString(response.body.string()) val animeList = mutableListOf() - val titleStyle = preferences.getString("preferred_title_style", "romaji")!! + val titleStyle = preferences.getString(PREF_TITLE_STYLE_KEY, PREF_TITLE_STYLE_DEFAULT)!! parsed.data.queryPopular.recommendations.forEach { if (it.anyCard != null) { @@ -189,17 +82,16 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { } } - return AnimesPage(animeList, animeList.size == 26) + return AnimesPage(animeList, animeList.size == PAGE_SIZE) } // =============================== Latest =============================== override fun latestUpdatesRequest(page: Int): Request { - val variables = """{"search":{"allowAdult":false,"allowUnknown":false},"limit":26,"page":$page,"translationType":"${preferences.getString("preferred_sub", "sub")!!}","countryOrigin":"ALL"}""" - val headers = headers.newBuilder() - .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0") - .build() - return GET("$baseUrl/allanimeapi?variables=$variables&query=$searchQuery", headers = headers) + // Could be lazily loaded along with url, but would require user to restart + val subPref = preferences.getString(PREF_SUB_KEY, PREF_SUB_DEFAULT)!! + val variables = """{"search":{"allowAdult":false,"allowUnknown":false},"limit":$PAGE_SIZE,"page":$page,"translationType":"$subPref","countryOrigin":"ALL"}""" + return GET("$baseUrl/allanimeapi?variables=$variables&query=$SEARCH_QUERY", headers = headers) } override fun latestUpdatesParse(response: Response): AnimesPage { @@ -220,12 +112,10 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request = throw Exception("not used") private fun searchAnimeRequest(page: Int, query: String, filters: AllAnimeFilters.FilterSearchParams): Request { + val subPref = preferences.getString(PREF_SUB_KEY, PREF_SUB_DEFAULT)!! return if (query.isNotEmpty()) { - val variables = """{"search":{"query":"$query","allowAdult":false,"allowUnknown":false},"limit":26,"page":$page,"translationType":"${preferences.getString("preferred_sub", "sub")!!}","countryOrigin":"ALL"}""" - val headers = headers.newBuilder() - .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0") - .build() - GET("$baseUrl/allanimeapi?variables=$variables&query=$searchQuery", headers = headers) + val variables = """{"search":{"query":"$query","allowAdult":false,"allowUnknown":false},"limit":$PAGE_SIZE,"page":$page,"translationType":"$subPref","countryOrigin":"ALL"}""" + GET("$baseUrl/allanimeapi?variables=$variables&query=$SEARCH_QUERY", headers = headers) } else { val seasonString = if (filters.season == "all") "" else ""","season":"${filters.season}"""" val yearString = if (filters.releaseYear == "all") "" else ""","year":${filters.releaseYear}""" @@ -234,12 +124,9 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { val sortByString = if (filters.sortBy == "update") "" else ""","sortBy":"${filters.sortBy}"""" var variables = """{"search":{"allowAdult":false,"allowUnknown":false$seasonString$yearString$genresString$typesString$sortByString""" - variables += """},"limit":26,"page":$page,"translationType":"${preferences.getString("preferred_sub", "sub")!!}","countryOrigin":"${filters.origin}"}""" + variables += """},"limit":$PAGE_SIZE,"page":$page,"translationType":"$subPref","countryOrigin":"${filters.origin}"}""" - val headers = headers.newBuilder() - .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0") - .build() - GET("$baseUrl/allanimeapi?variables=$variables&query=$searchQuery", headers = headers) + GET("$baseUrl/allanimeapi?variables=$variables&query=$SEARCH_QUERY", headers = headers) } } @@ -263,10 +150,7 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { private fun animeDetailsRequestInternal(anime: SAnime): Request { val variables = """{"_id":"${anime.url.split("<&sep>").first()}"}""" - val headers = headers.newBuilder() - .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0") - .build() - return GET("$baseUrl/allanimeapi?variables=$variables&query=$detailsQuery", headers = headers) + return GET("$baseUrl/allanimeapi?variables=$variables&query=$DETAILS_QUERY", headers = headers) } override fun animeDetailsRequest(anime: SAnime): Request { @@ -276,73 +160,53 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { } else { time } - val siteUrl = preferences.getString("preferred_site_domain", "https://allanime.to")!! + val siteUrl = preferences.getString(PREF_SITE_DOMAIN_KEY, PREF_SITE_DOMAIN_DEFAULT)!! return GET("$siteUrl/anime/$id/$slug$slugTime") } private fun animeDetailsParse(response: Response, animeOld: SAnime): SAnime { val show = json.decodeFromString(response.body.string()).data.show - val anime = SAnime.create() - - anime.title = animeOld.title - - anime.description = Jsoup.parse( - show.description?.replace("
", "br2n") ?: "", - ).text().replace("br2n", "\n") + "\n\n" - anime.description += "Type: ${show.type ?: "Unknown"}" - anime.description += "\nAired: ${show.season?.quarter ?: "-"} ${show.season?.year ?: "-"}" - anime.description += "\nScore: ${show.score ?: "-"}★" - - anime.genre = show.genres?.joinToString(separator = ", ") ?: "" - anime.status = parseStatus(show.status) - if (show.studios?.isNotEmpty() == true) { - anime.author = show.studios.first() + return SAnime.create().apply { + title = animeOld.title + genre = show.genres?.joinToString(separator = ", ") ?: "" + status = parseStatus(show.status) + author = show.studios?.firstOrNull() + description = Jsoup.parse( + show.description?.replace("
", "br2n") ?: "", + ).text().replace("br2n", "\n") + + "\n\n" + + "Type: ${show.type ?: "Unknown"}" + + "\nAired: ${show.season?.quarter ?: "-"} ${show.season?.year ?: "-"}" + + "\nScore: ${show.score ?: "-"}★" } - - return anime } // ============================== Episodes ============================== override fun episodeListRequest(anime: SAnime): Request { val variables = """{"_id":"${anime.url.split("<&sep>").first()}"}""" - val headers = headers.newBuilder() - .set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0") - .build() - return GET("$baseUrl/allanimeapi?variables=$variables&query=$episodesQuery", headers = headers) + return GET("$baseUrl/allanimeapi?variables=$variables&query=$EPISODES_QUERY", headers = headers) } override fun episodeListParse(response: Response): List { + val subPref = preferences.getString(PREF_SUB_KEY, PREF_SUB_DEFAULT)!! val medias = json.decodeFromString(response.body.string()) - val episodeList = mutableListOf() - val subOrDub = preferences.getString("preferred_sub", "sub")!! - - if (subOrDub == "sub") { - for (ep in medias.data.show.availableEpisodesDetail.sub!!) { - val episode = SEpisode.create() - episode.episode_number = ep.toFloatOrNull() ?: 0F - val numName = ep.toIntOrNull() ?: (ep.toFloatOrNull() ?: "1") - episode.name = "Episode $numName (sub)" - - val variables = """{"showId":"${medias.data.show._id}","translationType":"sub","episodeString":"$ep"}""" - episode.setUrlWithoutDomain("/allanimeapi?variables=$variables&query=$streamQuery") - episodeList.add(episode) - } + val episodesDetail = if (subPref == "sub") { + medias.data.show.availableEpisodesDetail.sub!! } else { - for (ep in medias.data.show.availableEpisodesDetail.dub!!) { - val episode = SEpisode.create() - episode.episode_number = ep.toFloatOrNull() ?: 0F - val numName = ep.toIntOrNull() ?: (ep.toFloatOrNull() ?: "1") - episode.name = "Episode $numName (dub)" - - val variables = """{"showId":"${medias.data.show._id}","translationType":"dub","episodeString":"$ep"}""" - episode.setUrlWithoutDomain("/allanimeapi?variables=$variables&query=$streamQuery") - episodeList.add(episode) - } + medias.data.show.availableEpisodesDetail.dub!! } - return episodeList + return episodesDetail.map { ep -> + val numName = ep.toIntOrNull() ?: (ep.toFloatOrNull() ?: "1") + val variables = """{"showId":"${medias.data.show._id}","translationType":"$subPref","episodeString":"$ep"}""" + SEpisode.create().apply { + episode_number = ep.toFloatOrNull() ?: 0F + name = "Episode $numName ($subPref)" + setUrlWithoutDomain("/allanimeapi?variables=$variables&query=$STREAMS_QUERY") + } + } } // ============================ Video Links ============================= @@ -355,61 +219,47 @@ class AllAnime : ConfigurableAnimeSource, AnimeHttpSource() { } override fun videoListParse(response: Response): List