Skip to content

Commit

Permalink
Resolved multiples extensions issues (#195)
Browse files Browse the repository at this point in the history
* Resolved multiples extensions issues

* fix(all/anizone): update video parsing logic
  • Loading branch information
Dark25 authored Jan 17, 2025
1 parent 0fa0da1 commit 56d38d4
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/all/anizone/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'AniZone'
extClass = '.AniZone'
extVersionCode = 4
extVersionCode = 5
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.add
import kotlinx.serialization.json.addJsonObject
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.buildJsonObject
Expand Down Expand Up @@ -280,7 +281,6 @@ class AniZone : AnimeHttpSource(), ConfigurableAnimeSource {

return SEpisode.create().apply {
setUrlWithoutDomain(url)
episode_number = url.substringAfterLast("/").toFloat()
name = element.selectFirst("h3")!!.text()
date_upload = element.select("div.flex-row > span").getOrNull(1)
?.text()
Expand All @@ -299,7 +299,10 @@ class AniZone : AnimeHttpSource(), ConfigurableAnimeSource {

override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()
val serverSelects = document.select("select > option[value]")
val serverSelects = document.select("button[wire:click]")
.filter { video ->
video.attr("wire:click").contains("setVideo")
}

val subtitles = document.select("track[kind=subtitles]").map {
Track(it.attr("src"), it.attr("label"))
Expand All @@ -308,20 +311,35 @@ class AniZone : AnimeHttpSource(), ConfigurableAnimeSource {
val m3u8List = mutableListOf(
VideoData(
url = document.selectFirst("media-player")!!.attr("src"),
name = serverSelects.first()!!.text(),
name = serverSelects.first().text(),
subtitles = subtitles,
),
)
snapShots[VIDEO_SNAPSHOT_KEY] = document.getSnapshot()

serverSelects.drop(1).forEach { video ->
val updates = buildJsonObject {
put("videoKey", video.attr("value"))
val regex = "setVideo\\('(\\d+)'\\)".toRegex()
val matchResult = regex.find(video.attr("wire:click"))
val videoId = if (matchResult != null && matchResult.groupValues.size == 1) {
matchResult.groupValues[1]
} else {
"0"
}
val updates = buildJsonObject { }
val calls = buildJsonArray {
add(
buildJsonObject {
put("path", "")
put("method", "setVideo")
putJsonArray("params") {
add(videoId.toInt())
}
},
)
}
val calls = buildJsonArray { }

val doc = client.newCall(
createLivewireReq(VIDEO_SNAPSHOT_KEY, updates, calls, response.request.url.toString()),
createLivewireReq(VIDEO_SNAPSHOT_KEY, updates, calls, response.request.url.encodedPath),
).execute().parseAs<LivewireDto>().getHtml(VIDEO_SNAPSHOT_KEY)

val subs = doc.select("track[kind=subtitles]").map {
Expand Down
2 changes: 1 addition & 1 deletion src/all/missav/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'MissAV'
extClass = '.MissAV'
extVersionCode = 13
extVersionCode = 14
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MissAV : AnimeHttpSource(), ConfigurableAnimeSource {

override val lang = "all"

override val baseUrl = "https://missav.com"
override val baseUrl = "https://missav.ai"

override val supportsLatest = true

Expand Down
4 changes: 2 additions & 2 deletions src/en/animepahe/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ext {
extName = 'AnimePahe'
extClass = '.AnimePahe'
extVersionCode = 27
extVersionCode = 28
}

apply from: "$rootDir/common.gradle"

dependencies {
implementation "dev.datlag.jsunpacker:jsunpacker:1.0.1"
implementation libs.jsunpacker
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import eu.kanade.tachiyomi.util.parseAs
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import okhttp3.Headers
import okhttp3.Request
Expand Down Expand Up @@ -67,16 +64,8 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
* @see episodeListRequest
*/
override fun animeDetailsRequest(anime: SAnime): Request {
val animeId = anime.getId()
// We're using coroutines here to run it inside another thread and
// prevent android.os.NetworkOnMainThreadException when trying to open
// webview or share it.
val session = runBlocking {
withContext(Dispatchers.IO) {
fetchSession(anime.title, animeId)
}
}
return GET("$baseUrl/anime/$session?anime_id=$animeId")
val session = anime.getSession()
return GET("$baseUrl/anime/$session")
}

override fun animeDetailsParse(response: Response): SAnime {
Expand Down Expand Up @@ -106,8 +95,8 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
SAnime.create().apply {
title = anime.title
thumbnail_url = anime.snapshot
val animeId = anime.id
setUrlWithoutDomain("/anime/?anime_id=$animeId")
val sessionId = anime.anime_session
setUrlWithoutDomain("/anime/?session_id=$sessionId")
artist = anime.fansub
}
}
Expand All @@ -124,8 +113,8 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
SAnime.create().apply {
title = anime.title
thumbnail_url = anime.poster
val animeId = anime.id
setUrlWithoutDomain("/anime/?anime_id=$animeId")
val sessionId = anime.session
setUrlWithoutDomain("/anime/?session_id=$sessionId")
}
}
return AnimesPage(animeList, false)
Expand All @@ -146,7 +135,7 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
* @see animeDetailsRequest
*/
override fun episodeListRequest(anime: SAnime): Request {
val session = fetchSession(anime.title, anime.getId())
val session = anime.getSession()
return GET("$baseUrl/api?m=release&id=$session&sort=episode_desc&page=1")
}

Expand Down Expand Up @@ -310,15 +299,6 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
}

// ============================= Utilities ==============================
private fun fetchSession(title: String, animeId: String): String {
return client.newCall(GET("$baseUrl/api?m=search&q=$title"))
.execute()
.body.string()
.substringAfter("\"id\":$animeId")
.substringAfter("\"session\":\"")
.substringBefore("\"")
}

private fun parseStatus(statusString: String): Int {
return when (statusString) {
"Currently Airing" -> SAnime.ONGOING
Expand All @@ -327,7 +307,7 @@ class AnimePahe : ConfigurableAnimeSource, AnimeHttpSource() {
}
}

private fun SAnime.getId() = url.substringAfterLast("?anime_id=").substringBefore("\"")
private fun SAnime.getSession() = url.substringAfterLast("?session_id=").substringBefore("\"")

private fun String.toDate(): Long {
return runCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import okhttp3.FormBody
import okhttp3.Headers
import okhttp3.OkHttpClient
import okhttp3.Response
import kotlin.math.pow

class KwikExtractor(private val client: OkHttpClient) {
private var cookies: String = ""
Expand Down Expand Up @@ -108,52 +107,25 @@ class KwikExtractor(private val client: OkHttpClient) {
}

private fun decrypt(fullString: String, key: String, v1: Int, v2: Int): String {
var r = ""
val keyIndexMap = key.withIndex().associate { it.value to it.index }
val sb = StringBuilder()
var i = 0
val toFind = key[v2]

while (i < fullString.length) {
var s = ""

while (fullString[i] != key[v2]) {
s += fullString[i]
++i
}
var j = 0

while (j < key.length) {
s = s.replace(key[j].toString(), j.toString())
++j
val nextIndex = fullString.indexOf(toFind, i)
val decodedCharStr = buildString {
for (j in i until nextIndex) {
append(keyIndexMap[fullString[j]] ?: -1)
}
}
r += (getString(s, v2).toInt() - v1).toChar()
++i
}
return r
}

private fun getString(content: String, s1: Int): String {
val s2 = 10
val characterMap = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/"
i = nextIndex + 1

val slice2 = characterMap.slice(0 until s2)
var acc: Long = 0

for ((n, i) in content.reversed().withIndex()) {
acc += when (isNumber("$i")) {
true -> "$i".toLong()
false -> 0L
} * s1.toDouble().pow(n.toDouble()).toInt()
val decodedChar = (decodedCharStr.toInt(v2) - v1).toChar()
sb.append(decodedChar)
}

var k = ""

while (acc > 0) {
k = slice2[(acc % s2).toInt()] + k
acc = (acc - (acc % s2)) / s2
}

return when (k != "") {
true -> k
false -> "0"
}
return sb.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ data class LatestAnimeDto(
@SerialName("anime_id")
val id: Int,
val fansub: String,
val anime_session: String,
)

@Serializable
data class SearchResultDto(
val title: String,
val poster: String,
val id: Int,
val session: String,
)

@Serializable
Expand Down
2 changes: 1 addition & 1 deletion src/tr/tranimeizle/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="www.tranimeizle.co"
android:host="www.tranimeizle.top"
android:pathPattern="/anime/..*"
android:scheme="https" />
</intent-filter>
Expand Down
2 changes: 1 addition & 1 deletion src/tr/tranimeizle/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'TR Anime Izle'
extClass = '.TRAnimeIzle'
extVersionCode = 20
extVersionCode = 21
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TRAnimeIzle : ParsedAnimeHttpSource(), ConfigurableAnimeSource {

override val name = "TR Anime Izle"

override val baseUrl = "https://www.tranimeizle.co"
override val baseUrl = "https://www.tranimeizle.top"

override val lang = "tr"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.util.Log
import kotlin.system.exitProcess

/**
* Springboard that accepts https://www.tranimeizle.co/anime/<item> intents
* Springboard that accepts https://www.tranimeizle.top/anime/<item> intents
* and redirects them to the main Aniyomi process.
*/
class TRAnimeIzleUrlActivity : Activity() {
Expand Down

0 comments on commit 56d38d4

Please sign in to comment.