From fe2123c04a2d0953501659fb454b74189396885e Mon Sep 17 00:00:00 2001 From: LagradOst Date: Sun, 10 Oct 2021 04:26:18 +0200 Subject: [PATCH] zoro stuff (1/2) --- .../com/lagradost/cloudstream3/MainAPI.kt | 10 ++--- .../animeproviders/AnimeFlickProvider.kt | 3 -- .../animeproviders/AnimePaheProvider.kt | 4 +- .../animeproviders/DubbedAnimeProvider.kt | 13 ------ .../animeproviders/GogoanimeProvider.kt | 12 +++-- .../animeproviders/KawaiifuProvider.kt | 9 ---- .../animeproviders/TenshiProvider.kt | 9 ---- .../WatchCartoonOnlineProvider.kt | 3 -- .../animeproviders/WcoProvider.kt | 13 ++---- .../animeproviders/ZoroProvider.kt | 39 +++++++++++----- .../cloudstream3/ui/search/SearchFragment.kt | 3 +- .../ui/search/SearchResultBuilder.kt | 44 ++++++++++++++----- app/src/main/res/layout/home_result_grid.xml | 3 +- .../main/res/layout/search_result_grid.xml | 33 +++++++------- app/src/main/res/values/colors.xml | 4 +- app/src/main/res/values/strings.xml | 1 + 16 files changed, 97 insertions(+), 106 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 48459479..5e920f60 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -323,12 +323,12 @@ data class AnimeSearchResponse( override val type: TvType, override val posterUrl: String?, - val year: Int?, - - val otherName: String?, + val year: Int? = null, val dubStatus: EnumSet?, - val dubEpisodes: Int?, - val subEpisodes: Int?, + + val otherName: String? = null, + val dubEpisodes: Int? = null, + val subEpisodes: Int? = null, override val id: Int? = null, ) : SearchResponse diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt index 4e178f35..e18dc610 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimeFlickProvider.kt @@ -51,10 +51,7 @@ class AnimeFlickProvider : MainAPI() { getType(title), poster, null, - null, EnumSet.of(DubStatus.Subbed), - null, - null ) }) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt index 31cf060a..83646a82 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/AnimePaheProvider.kt @@ -93,9 +93,9 @@ class AnimePaheProvider : MainAPI() { TvType.Anime, it.snapshot, null, - null, EnumSet.of(DubStatus.Subbed), null, + null, it.episode ) } @@ -159,9 +159,9 @@ class AnimePaheProvider : MainAPI() { TvType.Anime, it.poster, it.year, - null, EnumSet.of(DubStatus.Subbed), null, + null, it.episodes ) }) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt index 51ba09c5..80f22b9a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/DubbedAnimeProvider.kt @@ -11,7 +11,6 @@ import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.getQualityFromName import org.jsoup.Jsoup import java.util.* -import kotlin.collections.ArrayList class DubbedAnimeProvider : MainAPI() { override val mainUrl: String @@ -76,10 +75,7 @@ class DubbedAnimeProvider : MainAPI() { TvType.Anime, poster, null, - null, EnumSet.of(DubStatus.Dubbed), - null, - null ) } } @@ -98,10 +94,7 @@ class DubbedAnimeProvider : MainAPI() { TvType.Anime, poster, null, - null, EnumSet.of(DubStatus.Dubbed), - null, - null ) } } @@ -164,10 +157,7 @@ class DubbedAnimeProvider : MainAPI() { TvType.Anime, img, null, - null, EnumSet.of(DubStatus.Dubbed), - null, - null ) } ) @@ -201,10 +191,7 @@ class DubbedAnimeProvider : MainAPI() { TvType.Anime, img, null, - null, EnumSet.of(DubStatus.Dubbed), - null, - null ) } ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/GogoanimeProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/GogoanimeProvider.kt index 738a30f2..a11d6ae7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/GogoanimeProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/GogoanimeProvider.kt @@ -79,6 +79,7 @@ class GogoanimeProvider : MainAPI() { ).text items.add(HomePageList(i.second, (parseRegex.findAll(html).map { val (link, epNum, title, poster) = it.destructured + val isSub = listOf(1, 3).contains(i.first.toInt()) AnimeSearchResponse( title, link, @@ -86,12 +87,12 @@ class GogoanimeProvider : MainAPI() { TvType.Anime, poster, null, - null, - if (listOf(1, 3).contains(i.first.toInt())) EnumSet.of(DubStatus.Subbed) else EnumSet.of( + if (isSub) EnumSet.of(DubStatus.Subbed) else EnumSet.of( DubStatus.Dubbed ), null, - epNum.toIntOrNull() + if (!isSub) epNum.toIntOrNull() else null, + if (isSub) epNum.toIntOrNull() else null, ) }).toList())) } catch (e: Exception) { @@ -115,12 +116,9 @@ class GogoanimeProvider : MainAPI() { TvType.Anime, it.selectFirst("img").attr("src"), it.selectFirst(".released")?.text()?.split(":")?.getOrNull(1)?.trim()?.toIntOrNull(), - null, if (it.selectFirst(".name").text().contains("Dub")) EnumSet.of(DubStatus.Dubbed) else EnumSet.of( DubStatus.Subbed ), - null, - null ) } @@ -236,7 +234,7 @@ class GogoanimeProvider : MainAPI() { val url = it.attr("href") val extractorLinks = ArrayList() for (api in extractorApis) { - if (url.startsWith(api.mainUrl) ) { + if (url.startsWith(api.mainUrl)) { extractorLinks.addAll(api.getSafeUrl(url) ?: listOf()) break } diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/KawaiifuProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/KawaiifuProvider.kt index e2ed00db..d8de465a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/KawaiifuProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/KawaiifuProvider.kt @@ -37,10 +37,7 @@ class KawaiifuProvider : MainAPI() { TvType.Anime, it.selectFirst("img").attr("src"), it.selectFirst("h4 > a").attr("href").split("-").last().toIntOrNull(), - null, if (title.contains("(DUB)")) EnumSet.of(DubStatus.Dubbed) else EnumSet.of(DubStatus.Subbed), - null, - null ) })) for (section in soup.select(".section")) { @@ -55,10 +52,7 @@ class KawaiifuProvider : MainAPI() { TvType.Anime, ani.selectFirst("img").attr("src"), ani.selectFirst(".vl-chil-date").text().toIntOrNull(), - null, if (animTitle.contains("(DUB)")) EnumSet.of(DubStatus.Dubbed) else EnumSet.of(DubStatus.Subbed), - null, - null ) } items.add(HomePageList(title, anime)) @@ -89,10 +83,7 @@ class KawaiifuProvider : MainAPI() { TvType.Anime, poster, year, - null, if (title.contains("(DUB)")) EnumSet.of(DubStatus.Dubbed) else EnumSet.of(DubStatus.Subbed), - null, - null, ) }) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt index 383b0b26..95d10a37 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/TenshiProvider.kt @@ -66,10 +66,7 @@ class TenshiProvider : MainAPI() { TvType.Anime, it.selectFirst("img").attr("src"), null, - null, EnumSet.of(DubStatus.Subbed), - null, - null ) } items.add(HomePageList(title, anime)) @@ -84,10 +81,7 @@ class TenshiProvider : MainAPI() { TvType.Anime, it.selectFirst("img").attr("src"), null, - null, EnumSet.of(DubStatus.Subbed), - null, - null ) } items.add(HomePageList(title, anime)) @@ -130,10 +124,7 @@ class TenshiProvider : MainAPI() { TvType.Anime, img, null, - null, EnumSet.of(DubStatus.Subbed), - null, - null ) } ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WatchCartoonOnlineProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WatchCartoonOnlineProvider.kt index 54cfd980..958fa6a9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WatchCartoonOnlineProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WatchCartoonOnlineProvider.kt @@ -63,10 +63,7 @@ class WatchCartoonOnlineProvider : MainAPI() { TvType.Anime, poster, null, - null, set, - null, - null ) ) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt index 046f2445..1d80624c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/WcoProvider.kt @@ -1,16 +1,15 @@ package com.lagradost.cloudstream3.animeproviders import com.lagradost.cloudstream3.* -import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.extractors.WcoStream import com.lagradost.cloudstream3.network.get import com.lagradost.cloudstream3.network.post import com.lagradost.cloudstream3.network.text +import com.lagradost.cloudstream3.utils.ExtractorLink import org.json.JSONObject import org.jsoup.Jsoup import org.jsoup.nodes.Document import java.util.* -import kotlin.collections.ArrayList class WcoProvider : MainAPI() { @@ -64,7 +63,7 @@ class WcoProvider : MainAPI() { val poster = filmPoster.selectFirst("> img").attr("data-src") val set: EnumSet = EnumSet.of(if (isDub) DubStatus.Dubbed else DubStatus.Subbed) - AnimeSearchResponse(title, href, this.name, TvType.Anime, poster, null, null, set, null, null) + AnimeSearchResponse(title, href, this.name, TvType.Anime, poster,null, set) } items.add(HomePageList(i.second, results)) } catch (e: Exception) { @@ -107,11 +106,8 @@ class WcoProvider : MainAPI() { TvType.Anime, img, year, - null, EnumSet.of(if (isDub) DubStatus.Dubbed else DubStatus.Subbed), - null, - null - ) + ) } ) } @@ -169,10 +165,7 @@ class WcoProvider : MainAPI() { TvType.Anime, img, year, - null, EnumSet.of(if (isDub) DubStatus.Dubbed else DubStatus.Subbed), - null, - null ) } ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt index 38bd8447..47d0e8cc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/animeproviders/ZoroProvider.kt @@ -56,9 +56,14 @@ class ZoroProvider : MainAPI() { } } - fun Element.toSearchResult(): SearchResponse? { + private fun Element.toSearchResult(): SearchResponse? { val href = fixUrl(this.select("a").attr("href")) val title = this.select("h3.film-name").text() + /*val episodes = this.select("div.fd-infor > span.fdi-item")?.get(1)?.text()?.let { eps -> + // current episode / max episode + val epRegex = Regex("Ep (\\d+)/")//Regex("Ep (\\d+)/(\\d+)") + epRegex.find(eps)?.groupValues?.get(1)?.toIntOrNull() + }*/ if (href.contains("/news/") || title.trim().equals("News", ignoreCase = true)) return null val posterUrl = fixUrl(this.select("img").attr("data-src")) val type = getType(this.select("div.fd-infor > span.fdi-item").text()) @@ -71,9 +76,6 @@ class ZoroProvider : MainAPI() { posterUrl, null, null, - EnumSet.of(DubStatus.Subbed), - null, - null ) } @@ -142,7 +144,25 @@ class ZoroProvider : MainAPI() { return document.select(".flw-item").map { val title = it.selectFirst(".film-detail > .film-name > a")?.attr("title").toString() - val poster = it.selectFirst(".film-poster > img")?.attr("data-src") + val filmPoster = it.selectFirst(".film-poster") + val poster = filmPoster.selectFirst("img")?.attr("data-src") + + val episodes = filmPoster.selectFirst("div.rtl > div.tick-eps")?.text()?.let { eps -> + // current episode / max episode + val epRegex = Regex("Ep (\\d+)/")//Regex("Ep (\\d+)/(\\d+)") + epRegex.find(eps)?.groupValues?.get(1)?.toIntOrNull() + } + val dubsub = filmPoster.selectFirst("div.ltr")?.text() + val dubExist = dubsub?.contains("DUB") ?: false + val subExist = dubsub?.contains("SUB") ?: false || dubsub?.contains("RAW") ?: false + + val set = if (dubExist && subExist) { + EnumSet.of(DubStatus.Dubbed, DubStatus.Subbed) + } else if (dubExist) { + EnumSet.of(DubStatus.Dubbed) + } else { + EnumSet.of(DubStatus.Subbed) + } val tvType = getType(it.selectFirst(".film-detail > .fd-infor > .fdi-item")?.text().toString()) val href = fixUrl(it.selectFirst(".film-name a").attr("href")) @@ -154,15 +174,15 @@ class ZoroProvider : MainAPI() { tvType, poster, null, + set, null, - EnumSet.of(DubStatus.Subbed), - null, - null + if (dubExist) episodes else null, + if (subExist) episodes else null, ) } } - override fun load(url: String): LoadResponse? { + override fun load(url: String): LoadResponse { val html = get(url).text val document = Jsoup.parse(html) @@ -174,7 +194,6 @@ class ZoroProvider : MainAPI() { var japaneseTitle: String? = null var status: ShowStatus? = null - for (info in document.select(".anisc-info > .item.item-title")) { val text = info?.text().toString() when { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt index 793e383f..2acc57dc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt @@ -36,7 +36,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.getGridIsCompact import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard import kotlinx.android.synthetic.main.fragment_search.* -import java.lang.Exception import java.util.concurrent.locks.ReentrantLock class SearchFragment : Fragment() { @@ -44,7 +43,7 @@ class SearchFragment : Fragment() { fun List.filterSearchResponse(): List { return this.filter { response -> if (response is AnimeSearchResponse) { - response.dubStatus?.any { APIRepository.dubStatusActive.contains(it) } ?: false + (response.dubStatus.isNullOrEmpty()) || (response.dubStatus.any { APIRepository.dubStatusActive.contains(it) }) } else { true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt index a45dd11e..3a6f4934 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchResultBuilder.kt @@ -5,10 +5,7 @@ import android.widget.ImageView import android.widget.ProgressBar import android.widget.TextView import androidx.cardview.widget.CardView -import com.lagradost.cloudstream3.AnimeSearchResponse -import com.lagradost.cloudstream3.DubStatus -import com.lagradost.cloudstream3.SearchResponse -import com.lagradost.cloudstream3.isMovieType +import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.utils.AppUtils.getNameFull import com.lagradost.cloudstream3.utils.DataStoreHelper import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual @@ -24,8 +21,9 @@ object SearchResultBuilder { val cardView: ImageView = itemView.imageView val cardText: TextView = itemView.imageText - val textIsDub: View? = itemView.text_is_dub - val textIsSub: View? = itemView.text_is_sub + val textIsDub: TextView? = itemView.text_is_dub + val textIsSub: TextView? = itemView.text_is_sub + println(card.name) val bg: CardView = itemView.backgroundCard @@ -45,7 +43,13 @@ object SearchResultBuilder { cardView.setImage(card.posterUrl) bg.setOnClickListener { - clickCallback.invoke(SearchClickCallback(if(card is DataStoreHelper.ResumeWatchingResult) SEARCH_ACTION_PLAY_FILE else SEARCH_ACTION_LOAD, it, card)) + clickCallback.invoke( + SearchClickCallback( + if (card is DataStoreHelper.ResumeWatchingResult) SEARCH_ACTION_PLAY_FILE else SEARCH_ACTION_LOAD, + it, + card + ) + ) } bg.setOnLongClickListener { @@ -69,16 +73,32 @@ object SearchResultBuilder { } } is AnimeSearchResponse -> { - if (card.dubStatus?.size == 1) { - //search_result_lang?.visibility = View.VISIBLE + if (card.dubStatus != null && card.dubStatus.size > 0) { if (card.dubStatus.contains(DubStatus.Dubbed)) { textIsDub?.visibility = View.VISIBLE - //search_result_lang?.setColorFilter(ContextCompat.getColor(activity, R.color.dubColor)) - } else if (card.dubStatus.contains(DubStatus.Subbed)) { - //search_result_lang?.setColorFilter(ContextCompat.getColor(activity, R.color.subColor)) + } + if (card.dubStatus.contains(DubStatus.Subbed)) { textIsSub?.visibility = View.VISIBLE } } + + textIsDub?.apply { + val dubText = context.getString(R.string.app_dubbed_text) + text = if (card.dubEpisodes != null && card.dubEpisodes > 0) { + context.getString(R.string.app_dub_sub_episode_text_format).format(dubText, card.dubEpisodes) + } else { + dubText + } + } + + textIsSub?.apply { + val subText = context.getString(R.string.app_subbed_text) + text = if (card.subEpisodes != null && card.subEpisodes > 0) { + context.getString(R.string.app_dub_sub_episode_text_format).format(subText, card.subEpisodes) + } else { + subText + } + } } } } diff --git a/app/src/main/res/layout/home_result_grid.xml b/app/src/main/res/layout/home_result_grid.xml index 09db64ec..2afa5ae5 100644 --- a/app/src/main/res/layout/home_result_grid.xml +++ b/app/src/main/res/layout/home_result_grid.xml @@ -123,7 +123,6 @@ android:gravity="center" android:background="@drawable/sub_bg_color" android:layout_width="wrap_content" android:layout_height="wrap_content" - > - + /> diff --git a/app/src/main/res/layout/search_result_grid.xml b/app/src/main/res/layout/search_result_grid.xml index 4f74ae3a..554a288f 100644 --- a/app/src/main/res/layout/search_result_grid.xml +++ b/app/src/main/res/layout/search_result_grid.xml @@ -55,23 +55,6 @@ android:paddingEnd="5dp" android:ellipsize="end" /> - - + #80F53B66 - #F54A3B - #4DF54A3B + #3BF585 + #803BF585 #73FFFFFF #66000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a71f89c9..cfc00ecd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,6 +34,7 @@ -%d %d %d + %s Ep %d Poster