Skip to content

Commit

Permalink
Fix(Multi) Mult-extensions fixed (#208)
Browse files Browse the repository at this point in the history
* Fix(Multi) Mult-extensions fixed

* fix ktlink

* fix ktlink
  • Loading branch information
Dark25 authored Jan 26, 2025
1 parent 76b3dd7 commit a7fc7bd
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 326 deletions.
2 changes: 1 addition & 1 deletion src/en/aniplay/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ext {
extName = 'AniPlay'
extClass = '.AniPlay'
themePkg = 'anilist'
overrideVersionCode = 9
overrideVersionCode = 10
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.util.parallelFlatMap
import eu.kanade.tachiyomi.util.parseAs
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request
Expand Down Expand Up @@ -245,60 +246,18 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource {
val responseString = response.body.string()
val sourcesString = extractSourcesList(responseString) ?: return emptyList()
Log.i("AniPlay", "${extra.source} $language -> $sourcesString")

when (extra.source.lowercase()) {
"yuki" -> {
val data = sourcesString.parseAs<VideoSourceResponseYuki>()
return processEpisodeDataYuki(
EpisodeDataYuki(
source = extra.source,
language = language,
response = data,
),
)
}
else -> {
val data = sourcesString.parseAs<VideoSourceResponse>()
return processEpisodeData(
EpisodeData(
source = extra.source,
language = language,
response = data,
),
)
}
}
}

private fun processEpisodeDataYuki(episodeData: EpisodeDataYuki): List<Video> {
val defaultSource = episodeData.response.sources?.firstOrNull()

if (defaultSource == null) {
Log.e("AniPlay", "defaultSource is null (${episodeData.response})")
return emptyList()
}

val subtitles = episodeData.response.tracks
?.filter { it.kind?.lowercase() == "captions" }
?.map { Track(it.file, it.label ?: "Unknown") }
?: emptyList()

val serverName = getServerName(episodeData.source)
val typeName = getTypeName(episodeData.language).let {
if (it == "Sub" && subtitles.isNotEmpty()) "SoftSub" else it
}

try {
return playlistUtils.extractFromHls(
playlistUrl = defaultSource.url,
videoNameGen = { quality -> "$serverName - $quality - $typeName" },
subtitleList = subtitles,
return processEpisodeData(
EpisodeData(
source = extra.source,
language = language,
response = sourcesString.parseAs<VideoSourceResponse>(),
),
)
} catch (e: Exception) {
Log.e("AniPlay", "processEpisodeDataYuki extractFromHls Error (\"$serverName - $typeName\"): $e")
Log.e("AniPlay", "processEpisodeData Error (\"${extra.source} - $language\"): $e")
return emptyList()
}

return emptyList()
}

private fun processEpisodeData(episodeData: EpisodeData): List<Video> {
Expand All @@ -308,7 +267,12 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource {

val subtitles = episodeData.response.subtitles
?.filter { it.lang?.lowercase() != "thumbnails" }
?.map { Track(it.url, it.lang ?: "Unk") }
?.map {
Track(
it.url ?: throw Exception("episodeData.response.subtitles.url is null ($it)"),
it.lang ?: "Unk",
)
}
?: emptyList()

val serverName = getServerName(episodeData.source)
Expand All @@ -318,11 +282,29 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource {
}

try {
return playlistUtils.extractFromHls(
playlistUrl = defaultSource.url,
videoNameGen = { quality -> "$serverName - $quality - $typeName" },
subtitleList = subtitles,
)
if (episodeData.response.headers != null && episodeData.response.headers.Referer?.startsWith(
"https://",
) == true
) {
return playlistUtils.extractFromHls(
playlistUrl = defaultSource.url,
videoNameGen = { quality -> "$serverName - $quality - $typeName" },
subtitleList = subtitles,
masterHeadersGen = { baseHeaders: Headers, _: String ->
baseHeaders.newBuilder().apply {
set("Accept", "*/*")
set("Origin", baseUrl)
set("Referer", episodeData.response.headers.Referer)
}.build()
},
)
} else {
return playlistUtils.extractFromHls(
playlistUrl = defaultSource.url,
videoNameGen = { quality -> "$serverName - $quality - $typeName" },
subtitleList = subtitles,
)
}
} catch (e: Exception) {
Log.e("AniPlay", "processEpisodeData extractFromHls Error (\"$serverName - $typeName\"): $e")
}
Expand Down Expand Up @@ -508,8 +490,8 @@ class AniPlay : AniListAnimeHttpSource(), ConfigurableAnimeSource {
private const val PREF_DOMAIN_DEFAULT = "aniplaynow.live"

private const val PREF_SERVER_KEY = "server"
private val PREF_SERVER_ENTRIES = arrayOf("Kuro", "Yuki", "Yuno", "Anya")
private val PREF_SERVER_ENTRY_VALUES = arrayOf("kuro", "yuki", "yuno", "anya")
private val PREF_SERVER_ENTRIES = arrayOf("Kuro", "Anya", "Yuki", "Pahe")
private val PREF_SERVER_ENTRY_VALUES = arrayOf("kuro", "anya", "yuki", "pahe")
private const val PREF_SERVER_DEFAULT = "kuro"

private const val PREF_QUALITY_KEY = "quality"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@ data class EpisodeListResponse(
)
}

// Provider else
@Serializable
data class EpisodeData(
val source: String,
val language: String,
val response: VideoSourceResponse,
)

@Serializable
data class VideoSourceResponse(
val sources: List<Source>?,
val audio: List<Audio>?,
val intro: Timestamp?,
val outro: Timestamp?,
val subtitles: List<Subtitle>?,
val headers: Headers?,
) {
@Serializable
data class Source(
Expand All @@ -33,52 +45,36 @@ data class VideoSourceResponse(
)

@Serializable
data class Subtitle(
val url: String,
val lang: String?,
data class Audio(
val file: String,
val label: String?,
val kind: String?,
val default: Boolean?,
)
}

@Serializable
data class VideoSourceResponseYuki(
val sources: List<Source>?,
val tracks: List<Subtitle>?,
val anilistID: Int?,
val malID: Int?,
) {
@Serializable
data class Source(
val url: String,
val type: String?,
data class Timestamp(
val start: Int?,
val end: Int?,
)

@Serializable
data class Subtitle(
val file: String,
val label: String?,
val kind: String?,
val default: Boolean?,
val url: String?,
val lang: String?,
)

@Serializable
data class Headers(
val Referer: String?,
)
}

// Extra
@Serializable
data class EpisodeExtra(
val source: String,
val episodeNum: Float,
val episodeId: String,
val hasDub: Boolean,
)

@Serializable
data class EpisodeData(
val source: String,
val language: String,
val response: VideoSourceResponse,
)

@Serializable
data class EpisodeDataYuki(
val source: String,
val language: String,
val response: VideoSourceResponseYuki,
)
14 changes: 0 additions & 14 deletions src/en/asianload/build.gradle

This file was deleted.

Binary file removed src/en/asianload/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed src/en/asianload/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed src/en/asianload/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed src/en/asianload/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed src/en/asianload/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed src/en/asianload/res/play_store_512.png
Binary file not shown.
Loading

0 comments on commit a7fc7bd

Please sign in to comment.