Skip to content

Commit

Permalink
feat(en/aniwave,fmovies): Minor improvements (#2402)
Browse files Browse the repository at this point in the history
* Adds descriptive user-agent for enimax
* Aniwave
  * Don't spam preferences when loading episode list
  * Make lang preference take precedence, helpful for the (very few) cases where sub and dub have different resolutions available
  * Fix video name for filemoon
  • Loading branch information
Secozzi authored Oct 20, 2023
1 parent 86fa5b7 commit d56976e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/en/aniwave/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
extName = 'Aniwave'
pkgNameSuffix = 'en.nineanime'
extClass = '.Aniwave'
extVersionCode = 55
extVersionCode = 56
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
add("Referer", "$baseUrl/")
}.build()

private val markFiller by lazy { preferences.getBoolean(PREF_MARK_FILLERS_KEY, PREF_MARK_FILLERS_DEFAULT) }

// ============================== Popular ===============================

override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/filter?sort=trending&page=$page", refererHeaders)
Expand Down Expand Up @@ -177,7 +179,7 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val dub = if (element.attr("data-dub").toInt().toBoolean()) "Dub" else ""
val softSub = if (SOFTSUB_REGEX.find(title) != null) "SoftSub" else ""

val extraInfo = if (element.hasClass("filler") && preferences.getBoolean(PREF_MARK_FILLERS_KEY, PREF_MARK_FILLERS_DEFAULT)) {
val extraInfo = if (element.hasClass("filler") && markFiller) {
" • Filler Episode"
} else {
""
Expand Down Expand Up @@ -226,7 +228,7 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val hosterSelection = preferences.getStringSet(PREF_HOSTER_KEY, PREF_HOSTER_DEFAULT)!!
val typeSelection = preferences.getStringSet(PREF_TYPE_TOGGLE_KEY, PREF_TYPES_TOGGLE_DEFAULT)!!

return document.select("div.servers > div").parallelMap { elem ->
return document.select("div.servers > div").parallelFlatMap { elem ->
val type = elem.attr("data-type").replaceFirstChar { it.uppercase() }
elem.select("li").mapNotNull { serverElement ->
val serverId = serverElement.attr("data-link-id")
Expand All @@ -237,9 +239,7 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
VideoData(type, serverId, serverName)
}
}
.flatten()
.parallelMap { extractVideo(it, epurl) }
.flatten()
.parallelFlatMap { extractVideo(it, epurl) }
.ifEmpty { throw Exception("Failed to fetch videos") }
}

Expand Down Expand Up @@ -275,7 +275,7 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val embedLink = utils.callEnimax(parsed.result.url, "decrypt")
when (server.serverName) {
"vidplay", "mycloud" -> vidsrcExtractor.videosFromUrl(embedLink, server.serverName, server.type)
"filemoon" -> filemoonExtractor.videosFromUrl(embedLink, "Filemoon - ${server.type}")
"filemoon" -> filemoonExtractor.videosFromUrl(embedLink, "Filemoon - ${server.type} - ")
"streamtape" -> streamtapeExtractor.videoFromUrl(embedLink, "StreamTape - ${server.type}")?.let(::listOf) ?: emptyList()
"mp4upload" -> mp4uploadExtractor.videosFromUrl(embedLink, headers, suffix = " - ${server.type}")
else -> emptyList()
Expand All @@ -295,9 +295,9 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val server = preferences.getString(PREF_SERVER_KEY, PREF_SERVER_DEFAULT)!!

return this.sortedWith(
compareByDescending<Video> { it.quality.contains(quality) }
.thenByDescending { it.quality.contains(server, true) }
.thenByDescending { it.quality.contains(lang) },
compareByDescending<Video> { it.quality.contains(lang) }
.thenByDescending { it.quality.contains(quality) }
.thenByDescending { it.quality.contains(server, true) },
)
}

Expand All @@ -319,6 +319,11 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
map { async(Dispatchers.Default) { f(it) } }.awaitAll()
}

inline fun <A, B> Iterable<A>.parallelFlatMap(crossinline f: suspend (A) -> Iterable<B>): List<B> =
runBlocking {
map { async(Dispatchers.Default) { f(it) } }.awaitAll().flatten()
}

private inline fun <reified T> Response.parseAs(): T {
val responseBody = use { it.body.string() }
return json.decodeFromString(responseBody)
Expand Down Expand Up @@ -442,6 +447,7 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
title = "Mark filler episodes"
setDefaultValue(PREF_MARK_FILLERS_DEFAULT)
setOnPreferenceChangeListener { _, newValue ->
Toast.makeText(screen.context, "Restart Aniyomi to apply new setting.", Toast.LENGTH_LONG).show()
preferences.edit().putBoolean(key, newValue as Boolean).commit()
}
}.also(screen::addPreference)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.animeextension.en.nineanime

import eu.kanade.tachiyomi.AppInfo
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import kotlinx.serialization.json.Json
Expand All @@ -13,6 +14,11 @@ class AniwaveUtils(private val client: OkHttpClient, private val headers: Header

val json: Json by injectLazy()

private val userAgent = Headers.headersOf(
"User-Agent",
"Aniyomi/${AppInfo.getVersionName()} (AniWave)",
)

fun callEnimax(query: String, action: String): String {
return if (action in listOf("rawVizcloud", "rawMcloud")) {
val referer = if (action == "rawVizcloud") "https://vidstream.pro/" else "https://mcloud.to/"
Expand All @@ -27,11 +33,12 @@ class AniwaveUtils(private val client: OkHttpClient, private val headers: Header
POST(
url = "https://9anime.eltik.net/$action?apikey=aniyomi",
body = formBody,
headers = userAgent,
),
).execute().parseAs<RawResponse>().rawURL
} else {
client.newCall(
GET("https://9anime.eltik.net/$action?query=$query&apikey=aniyomi"),
GET("https://9anime.eltik.net/$action?query=$query&apikey=aniyomi", userAgent),
).execute().use {
val body = it.body.string()
when (action) {
Expand Down
2 changes: 1 addition & 1 deletion src/en/fmovies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
extName = 'FMovies'
pkgNameSuffix = 'en.fmovies'
extClass = '.FMovies'
extVersionCode = 12
extVersionCode = 13
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.animeextension.en.fmovies

import eu.kanade.tachiyomi.AppInfo
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import kotlinx.serialization.json.Json
Expand All @@ -15,14 +16,19 @@ class FMoviesHelper(private val client: OkHttpClient, private val headers: Heade

private val json: Json by injectLazy()

private val userAgent = Headers.headersOf(
"User-Agent",
"Aniyomi/${AppInfo.getVersionName()} (FMovies)",
)

fun getVrf(id: String): String {
val url = API_URL.newBuilder().apply {
addPathSegment("fmovies-vrf")
addQueryParameter("query", id)
addQueryParameter("apikey", API_KEY)
}.build().toString()

return client.newCall(GET(url)).execute().parseAs<VrfResponse>().let {
return client.newCall(GET(url, userAgent)).execute().parseAs<VrfResponse>().let {
URLEncoder.encode(it.url, "utf-8")
}
}
Expand All @@ -34,7 +40,7 @@ class FMoviesHelper(private val client: OkHttpClient, private val headers: Heade
addQueryParameter("apikey", API_KEY)
}.build().toString()

return client.newCall(GET(url)).execute().parseAs<VrfResponse>().url
return client.newCall(GET(url, userAgent)).execute().parseAs<VrfResponse>().url
}

fun getVidSrc(query: String, host: String): String {
Expand All @@ -53,7 +59,7 @@ class FMoviesHelper(private val client: OkHttpClient, private val headers: Heade
}.build()

return client.newCall(
POST(url, body = body),
POST(url, body = body, headers = userAgent),
).execute().parseAs<RawResponse>().rawURL
}

Expand Down

0 comments on commit d56976e

Please sign in to comment.