Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (AR/Anime4up): fix Videolist #168

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ar/anime4up/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Anime4up'
extClass = '.Anime4Up'
extVersionCode = 64
extVersionCode = 65
}

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

override val name = "Anime4Up"

override val baseUrl = "https://anime4up.cam"
override val baseUrl = "https://anime4up.rest"

override val lang = "ar"

Expand Down Expand Up @@ -136,22 +136,54 @@ class Anime4Up : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
episode_number = name.substringAfterLast(" ").toFloatOrNull() ?: 0F
}

// ============================ Video Links =============================
@Serializable
data class Qualities(
val fhd: Map<String, String> = emptyMap(),
val hd: Map<String, String> = emptyMap(),
val sd: Map<String, String> = emptyMap(),
)

@Serializable
data class WatchServerData(
val name: String,
val link: String,
val order: String,
val icon: Boolean,
)

override fun videoListParse(response: Response): List<Video> {
val base64 = response.asJsoup().selectFirst("input[name=wl]")
val document = response.asJsoup()

// Decode base64 for each quality level
val base64Fhd = document.selectFirst(".WatchServersEmbed form input[name='watch_fhd']")
?.attr("value")
?.let { String(Base64.decode(it, Base64.DEFAULT)) }
?: return emptyList()
?: "[]"

val parsedData = json.decodeFromString<Qualities>(base64)
val streamLinks = with(parsedData) { fhd + hd + sd }
val base64Hd = document.selectFirst(".WatchServersEmbed form input[name='watch_hd']")
?.attr("value")
?.let { String(Base64.decode(it, Base64.DEFAULT)) }
?: "[]"

val base64Sd = document.selectFirst(".WatchServersEmbed form input[name='watch_SD']")
?.attr("value")
?.let { String(Base64.decode(it, Base64.DEFAULT)) }
?: "[]"

// Parse the base64 decoded strings into lists of WatchServerData
val parsedFhd = json.decodeFromString<List<WatchServerData>>(base64Fhd)
val parsedHd = json.decodeFromString<List<WatchServerData>>(base64Hd)
val parsedSd = json.decodeFromString<List<WatchServerData>>(base64Sd)

// Convert to the old Qualities structure
val qualities = Qualities(
fhd = parsedFhd.associate { it.name to it.link },
hd = parsedHd.associate { it.name to it.link },
sd = parsedSd.associate { it.name to it.link },
)

// Use the same logic as the old implementation
val streamLinks = with(qualities) { fhd + hd + sd }

return streamLinks.values.distinct().flatMap(::extractVideos)
}
Expand Down
Loading