Skip to content

Commit

Permalink
fix(en/animeflix): Update baseUrl (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky authored Oct 30, 2023
1 parent 65914de commit 1770355
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/en/animeflix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
extName = 'AnimeFlix'
pkgNameSuffix = 'en.animeflix'
extClass = '.AnimeFlix'
extVersionCode = 6
extVersionCode = 7
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand All @@ -21,6 +22,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import org.jsoup.nodes.Document
Expand All @@ -34,7 +36,7 @@ class AnimeFlix : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "AnimeFlix"

override val baseUrl = "https://animeflix.net.in"
override val baseUrl = "https://animeflix.mobi"

override val lang = "en"

Expand Down Expand Up @@ -250,7 +252,13 @@ class AnimeFlix : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
if (url.url.toHttpUrl().encodedPath == "/404") return@runCatching null
val (videos, mediaUrl) = extractVideo(url)
when {
videos.isEmpty() -> extractGDriveLink(mediaUrl, url.quality)
videos.isEmpty() -> {
extractGDriveLink(mediaUrl, url.quality).ifEmpty {
getDirectLink(mediaUrl, "instant", "/mfile/")?.let {
listOf(Video(it, "${url.quality}p - GDrive Instant link", it))
} ?: emptyList()
}
}
else -> videos
}
}.getOrNull()
Expand Down Expand Up @@ -293,15 +301,37 @@ class AnimeFlix : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

Video(
url = decodedLink,
quality = "$quality - CF $type Worker ${index + 1}$size",
quality = "${quality}p - CF $type Worker ${index + 1}$size",
videoUrl = decodedLink,
)
}
}

private fun getDirectLink(url: String, action: String = "direct", newPath: String = "/file/"): String? {
val doc = client.newCall(GET(url, headers)).execute().use { it.asJsoup() }
val script = doc.selectFirst("script:containsData(async function taskaction)")
?.data()
?: return url

val key = script.substringAfter("key\", \"").substringBefore('"')
val form = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("action", action)
.addFormDataPart("key", key)
.addFormDataPart("action_token", "")
.build()

val headers = headersBuilder().set("x-token", url.toHttpUrl().host).build()

val req = client.newCall(POST(url.replace("/file/", newPath), headers, form)).execute()
return runCatching {
json.decodeFromString<DriveLeechDirect>(req.use { it.body.string() }).url
}.getOrNull()
}

private fun extractGDriveLink(mediaUrl: String, quality: String): List<Video> {
val tokenClient = client.newBuilder().addInterceptor(TokenInterceptor()).build()
val response = tokenClient.newCall(GET(mediaUrl)).execute().use { it.asJsoup() }
val neoUrl = getDirectLink(mediaUrl) ?: mediaUrl
val response = client.newCall(GET(neoUrl)).execute().use { it.asJsoup() }
val gdBtn = response.selectFirst("div.card-body a.btn")!!
val gdLink = gdBtn.attr("href")
val sizeMatch = SIZE_REGEX.find(gdBtn.text())
Expand Down Expand Up @@ -345,6 +375,9 @@ class AnimeFlix : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val name: String,
)

@Serializable
data class DriveLeechDirect(val url: String? = null)

// From Dopebox
private inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> =
runBlocking {
Expand Down

This file was deleted.

0 comments on commit 1770355

Please sign in to comment.