From 889d8dc7cacbe9d406fc80420193d900edca065d Mon Sep 17 00:00:00 2001 From: Claudemirovsky <63046606+Claudemirovsky@users.noreply.github.com> Date: Thu, 19 Oct 2023 02:16:38 -0300 Subject: [PATCH 1/3] refactor: General refactoration --- src/de/moflixstream/build.gradle | 8 +- .../de/moflixstream/MoflixStream.kt | 408 +++++++----------- .../de/moflixstream/dto/MoflixStreamDto.kt | 83 ++++ 3 files changed, 250 insertions(+), 249 deletions(-) create mode 100644 src/de/moflixstream/src/eu/kanade/tachiyomi/animeextension/de/moflixstream/dto/MoflixStreamDto.kt diff --git a/src/de/moflixstream/build.gradle b/src/de/moflixstream/build.gradle index 8f53d83f70..e48ef07881 100644 --- a/src/de/moflixstream/build.gradle +++ b/src/de/moflixstream/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlinx-serialization' +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.serialization) +} ext { extName = 'Moflix-Stream' diff --git a/src/de/moflixstream/src/eu/kanade/tachiyomi/animeextension/de/moflixstream/MoflixStream.kt b/src/de/moflixstream/src/eu/kanade/tachiyomi/animeextension/de/moflixstream/MoflixStream.kt index 75c096f8ad..dd8fb67af4 100644 --- a/src/de/moflixstream/src/eu/kanade/tachiyomi/animeextension/de/moflixstream/MoflixStream.kt +++ b/src/de/moflixstream/src/eu/kanade/tachiyomi/animeextension/de/moflixstream/MoflixStream.kt @@ -1,10 +1,15 @@ package eu.kanade.tachiyomi.animeextension.de.moflixstream import android.app.Application -import android.content.SharedPreferences import androidx.preference.ListPreference import androidx.preference.MultiSelectListPreference import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.animeextension.de.moflixstream.dto.AnimeDetailsDto +import eu.kanade.tachiyomi.animeextension.de.moflixstream.dto.EpisodeListDto +import eu.kanade.tachiyomi.animeextension.de.moflixstream.dto.EpisodePageDto +import eu.kanade.tachiyomi.animeextension.de.moflixstream.dto.SearchDto +import eu.kanade.tachiyomi.animeextension.de.moflixstream.dto.SeasonPaginationDto +import eu.kanade.tachiyomi.animeextension.de.moflixstream.dto.VideoResponseDto import eu.kanade.tachiyomi.animeextension.de.moflixstream.extractors.UnpackerExtractor import eu.kanade.tachiyomi.animeextension.de.moflixstream.extractors.VidGuardExtractor import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource @@ -25,11 +30,11 @@ import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.Headers -import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy import kotlin.Exception class MoflixStream : ConfigurableAnimeSource, AnimeHttpSource() { @@ -42,19 +47,21 @@ class MoflixStream : ConfigurableAnimeSource, AnimeHttpSource() { override val supportsLatest = false - override val client: OkHttpClient = network.cloudflareClient + override val client = network.cloudflareClient - private val preferences: SharedPreferences by lazy { + override fun headersBuilder() = super.headersBuilder().add("Referer", "$baseUrl/") + + private val preferences by lazy { Injekt.get().getSharedPreferences("source_$id", 0x0000) } - private val json = Json { - isLenient = true - ignoreUnknownKeys = true - } + private val json: Json by injectLazy() + + private val apiUrl = "$baseUrl/api/v1" + // ============================== Popular =============================== override fun popularAnimeRequest(page: Int): Request = GET( - "$baseUrl/api/v1/channel/345?returnContentOnly=true&restriction=&order=rating:desc&paginate=simple&perPage=50&query=&page=$page", + "$apiUrl/channel/345?returnContentOnly=true&restriction=&order=rating:desc&paginate=simple&perPage=50&query=&page=$page", headers = Headers.headersOf("referer", "$baseUrl/movies?order=rating%3Adesc"), ) @@ -77,268 +84,156 @@ class MoflixStream : ConfigurableAnimeSource, AnimeHttpSource() { val anime = SAnime.create() anime.title = item.jsonObject["name"]!!.jsonPrimitive.content val animeId = item.jsonObject["id"]!!.jsonPrimitive.content - anime.setUrlWithoutDomain("$baseUrl/api/v1/titles/$animeId?load=images,genres,productionCountries,keywords,videos,primaryVideo,seasons,compactCredits") + anime.setUrlWithoutDomain("$apiUrl/titles/$animeId?load=images,genres,productionCountries,keywords,videos,primaryVideo,seasons,compactCredits") anime.thumbnail_url = item.jsonObject["poster"]?.jsonPrimitive?.content ?: item.jsonObject["backdrop"]?.jsonPrimitive?.content animeList.add(anime) } return AnimesPage(animeList, hasNextPage) } - // episodes + // =============================== Latest =============================== + override fun latestUpdatesParse(response: Response) = throw Exception("not Used") - override fun episodeListRequest(anime: SAnime): Request = GET(baseUrl + anime.url, headers = Headers.headersOf("referer", baseUrl)) + override fun latestUpdatesRequest(page: Int) = throw Exception("Not used") - override fun episodeListParse(response: Response): List { - val responseString = response.body.string() - val url = response.request.url.toString() - return parseEpisodeAnimeJson(responseString, url) - } + // =============================== Search =============================== + override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList) = GET( + "$apiUrl/search/$query?query=$query", + headers = Headers.headersOf("referer", "$baseUrl/search/$query"), + ) - private fun parseEpisodeAnimeJson(jsonLine: String?, url: String): List { - val jsonData = jsonLine ?: return emptyList() - val jObject = json.decodeFromString(jsonData) - val episodeList = mutableListOf() - val mId = jObject.jsonObject["title"]!!.jsonObject["id"]!!.jsonPrimitive.content - val season = jObject.jsonObject["seasons"]?.jsonObject - if (season != null) { - val dataArray = season.jsonObject["data"]!!.jsonArray - val next = season.jsonObject["next_page"]?.jsonPrimitive?.content - if (next != null) { - val seNextJsonData = client.newCall(GET("$baseUrl/api/v1/titles/$mId/seasons?perPage=8&query=&page=$next", headers = Headers.headersOf("referer", baseUrl))).execute().body.string() - val seNextJObject = json.decodeFromString(seNextJsonData) - val seasonNext = seNextJObject.jsonObject["pagination"]!!.jsonObject - val dataNextArray = seasonNext.jsonObject["data"]!!.jsonArray - val dataAllArray = dataArray.plus(dataNextArray) - for (item in dataAllArray) { - val id = item.jsonObject["title_id"]!!.jsonPrimitive.content - val num = item.jsonObject["number"]!!.jsonPrimitive.content - val seUrl = "$baseUrl/api/v1/titles/$id/seasons/$num?load=episodes,primaryVideo" - val seJsonData = client.newCall(GET(seUrl, headers = Headers.headersOf("referer", baseUrl))).execute().body.string() - val seJObject = json.decodeFromString(seJsonData) - val epObject = seJObject.jsonObject["episodes"]!!.jsonObject - val epDataArray = epObject.jsonObject["data"]!!.jsonArray.reversed() - for (epItem in epDataArray) { - val episode = SEpisode.create() - val seNum = epItem.jsonObject["season_number"]!!.jsonPrimitive.content - val epNum = epItem.jsonObject["episode_number"]!!.jsonPrimitive.content - episode.name = "Staffel $seNum Folge $epNum : " + epItem.jsonObject["name"]!!.jsonPrimitive.content - episode.episode_number = epNum.toFloat() - val epId = epItem.jsonObject["title_id"]!!.jsonPrimitive.content - episode.setUrlWithoutDomain("$baseUrl/api/v1/titles/$epId/seasons/$seNum/episodes/$epNum?load=videos,compactCredits,primaryVideo") - episodeList.add(episode) - } - } - } else { - for (item in dataArray) { - val id = item.jsonObject["title_id"]!!.jsonPrimitive.content - val num = item.jsonObject["number"]!!.jsonPrimitive.content - val seUrl = "$baseUrl/api/v1/titles/$id/seasons/$num?load=episodes,primaryVideo" - val seJsonData = client.newCall(GET(seUrl, headers = Headers.headersOf("referer", baseUrl))).execute().body.string() - val seJObject = json.decodeFromString(seJsonData) - val epObject = seJObject.jsonObject["episodes"]!!.jsonObject - val epDataArray = epObject.jsonObject["data"]!!.jsonArray.reversed() - for (epItem in epDataArray) { - val episode = SEpisode.create() - val seNum = epItem.jsonObject["season_number"]!!.jsonPrimitive.content - val epNum = epItem.jsonObject["episode_number"]!!.jsonPrimitive.content - episode.name = "Staffel $seNum Folge $epNum : " + epItem.jsonObject["name"]!!.jsonPrimitive.content - episode.episode_number = epNum.toFloat() - val epId = epItem.jsonObject["title_id"]!!.jsonPrimitive.content - episode.setUrlWithoutDomain("$baseUrl/api/v1/titles/$epId/seasons/$seNum/episodes/$epNum?load=videos,compactCredits,primaryVideo") - episodeList.add(episode) - } - } + override fun searchAnimeParse(response: Response): AnimesPage { + val data = response.parseAs() + val animeList = data.results.map { + SAnime.create().apply { + title = it.name + setUrlWithoutDomain("$apiUrl/titles/${it.id}?$ANIME_URL_QUERIES") + thumbnail_url = it.thumbnail } - } else { - val episode = SEpisode.create() - episode.episode_number = 1F - episode.name = "Film" - episode.setUrlWithoutDomain(url) - episodeList.add(episode) } - return episodeList + return AnimesPage(animeList, hasNextPage = false) } - // Video Extractor - - override fun videoListRequest(episode: SEpisode): Request { - return GET(baseUrl + episode.url, headers = Headers.headersOf("referer", baseUrl)) - } + // =========================== Anime Details ============================ + override fun animeDetailsParse(response: Response) = SAnime.create().apply { + val data = response.parseAs().title - override fun videoListParse(response: Response): List