Skip to content

Commit

Permalink
chore: Some fixes for pt/doramogo
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed May 31, 2024
1 parent 2a77355 commit e86091a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/pt/doramogo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ apply from: "$rootDir/common.gradle"
dependencies {
implementation(project(':lib:dailymotion-extractor'))
implementation(project(":lib:googledrive-extractor"))
implementation(project(":lib:okru-extractor"))
implementation(project(":lib:playlist-utils"))
implementation("dev.datlag.jsunpacker:jsunpacker:1.0.1")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.lib.dailymotionextractor.DailymotionExtractor
import eu.kanade.tachiyomi.lib.googledriveextractor.GoogleDriveExtractor
import eu.kanade.tachiyomi.lib.okruextractor.OkruExtractor
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.awaitSuccess
import eu.kanade.tachiyomi.util.asJsoup
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
import eu.kanade.tachiyomi.util.parseAs
import kotlinx.serialization.Serializable
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request
import okhttp3.Response
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element

class Doramogo : ParsedAnimeHttpSource() {

override val name = "Doramogo"

override val baseUrl = "https://doramogo.com/"
override val baseUrl = "https://doramogo.com"

override val lang = "pt-BR"

Expand Down Expand Up @@ -77,52 +75,25 @@ class Doramogo : ParsedAnimeHttpSource() {
return AnimesPage(listOf(details), false)
}

@Serializable
data class SearchResponseDto(
val results: List<String>,
val page: Int,
val total_page: Int = 1,
)

private val searchToken by lazy {
client.newCall(GET("$baseUrl/lista-de-animes", headers)).execute()
.asJsoup()
.selectFirst("div.menu_filter_box")!!
.attr("data-secury")
}

override fun getFilterList() = DoramogoFilters.FILTER_LIST

override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val params = DoramogoFilters.getSearchParameters(filters)

val url = "$baseUrl/search/$query".toHttpUrl().newBuilder()
val url = "$baseUrl/search".toHttpUrl().newBuilder()
.addPathSegment(query)
.addIfNotBlank("filter_audio", params.audio)
.addIfNotBlank("filter_genre", params.genre)
.build()
.toString()

return GET(url, headers = headers)
}

override fun searchAnimeParse(response: Response): AnimesPage {
return runCatching {
val data = response.parseAs<SearchResponseDto>()
val animes = data.results.map(Jsoup::parse)
.mapNotNull { it.selectFirst(searchAnimeSelector()) }
.map(::searchAnimeFromElement)
val hasNext = data.total_page > data.page
AnimesPage(animes, hasNext)
}.getOrElse { AnimesPage(emptyList(), false) }
}

override fun searchAnimeSelector() = popularAnimeSelector()

override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)

override fun searchAnimeNextPageSelector(): String? {
throw UnsupportedOperationException()
}
override fun searchAnimeNextPageSelector() = null

// =========================== Anime Details ============================
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
Expand Down Expand Up @@ -152,32 +123,26 @@ class Doramogo : ParsedAnimeHttpSource() {
override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()

val urls = document.select("div.source-box iframe")
.mapNotNull {
it.attr("src")
}
val urls = document.select("div.source-box iframe").map {
it.attr("src")
}

return urls.parallelCatchingFlatMapBlocking { getVideosFromURL(it) }
}

private val dailymotionExtractor by lazy { DailymotionExtractor(client, headers) }
private val doramogoExtractor by lazy { DoramogoExtractor(client, headers) }
private val gdriveExtractor by lazy { GoogleDriveExtractor(client, headers) }
private val okruExtractor by lazy { OkruExtractor(client) }
private val playlistUtils by lazy { PlaylistUtils(client, headers) }
private val doramogoExtractor by lazy { DoramogoExtractor(client, headers) }
private fun getVideosFromURL(url: String): List<Video> {
return when {
"dailymotion" in url -> dailymotionExtractor.videosFromUrl(url)
"ok.ru" in url -> okruExtractor.videosFromUrl(url)

"drive.google.com" in url -> {
// We need to do that bc the googledrive extractor is garbage.
val newUrl = when {
url.contains("uc?id=") -> url
else -> {
val id = url.substringAfter("/d/").substringBefore("/")
"https://drive.google.com/uc?id=$id"
}
}
gdriveExtractor.videosFromUrl(newUrl, "GDrive")
val id = Regex("[\\w-]{28,}").find(url)?.groupValues?.get(0) ?: return emptyList()
gdriveExtractor.videosFromUrl(id, "GDrive")
}

"embedrise.com" in url -> {
Expand All @@ -191,6 +156,23 @@ class Doramogo : ParsedAnimeHttpSource() {
)
}

"streamable.com" in url -> {
val mp4Url = client.newCall(GET(url)).execute()
.asJsoup()
.selectFirst("video")
?.attr("src")
?.let {
if (it.startsWith("//")) {
return@let "https:$it"
}
it
}
?: return emptyList()
listOf<Video>(
Video(mp4Url, "Streamable", mp4Url, headers),
)
}

"/player/" in url -> doramogoExtractor.videosFromUrl(url)

else -> emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object DoramogoFilters {
GenreFilter(),
)

data class FilterSearchParams(
class FilterSearchParams(
val audio: String = "",
val genre: String = "",
)
Expand All @@ -52,7 +52,43 @@ object DoramogoFilters {
)

val GENRES = arrayOf(
Pair("ASMR", "65"),
Pair("Todos", ""),
Pair("Ação", "6"),
Pair("Action & Adventure", "47"),
Pair("Aventura", "50"),
Pair("Business", "70"),
Pair("Chinês", "20"),
Pair("Comédia", "4"),
Pair("Crime", " 18"),
Pair("Documentário", "67"),
Pair("Drama", " 19"),
Pair("Escolar", "0"),
Pair("Esporte", "8"),
Pair("Família", "7"),
Pair("Fantasia", "62"),
Pair("Friendship", "31"),
Pair("Histórico", " 53"),
Pair("Horror", "91"),
Pair("Japan", " 31"),
Pair("Juventude", " 24"),
Pair("Law", "9"),
Pair("LGBTQ", " 35"),
Pair("Life", "42"),
Pair("Médico", "67"),
Pair("Melodrama", " 32"),
Pair("Militar", "8"),
Pair("Mistério", "7 "),
Pair("Música", "14"),
Pair("Política", "84"),
Pair("Psicológico", "7"),
Pair("Reality", "7"),
Pair("Romance", "5"),
Pair("Sci-Fi & Fantasy", "47"),
Pair("Sci-Fi", "23"),
Pair("Soap", "83"),
Pair("Supernatural", "10"),
Pair("Thriller", "35"),
Pair("War & Politics", "67"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.animeextension.pt.doramogo.extractors

import dev.datlag.jsunpacker.JsUnpacker
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Headers
Expand Down

0 comments on commit e86091a

Please sign in to comment.