Kickassanime & Hianime: Fix subtitles (#937)
* Fix subtitles * Update PlaylistUtils.kt * Update MegaCloudExtractor.kt * Update AniPlay.kt * Update MegaCloudExtractor.kt * Fix regex * Fix subtitles for kickassanime * Update build.gradle * Update build.gradle * Update build.gradle.kts * Update build.gradle.kts * Update build.gradle * Update build.gradle
This commit is contained in:
parent
ac1938c1e4
commit
f57e2ea5af
4 changed files with 35 additions and 5 deletions
|
@ -47,7 +47,7 @@ class MegaCloudExtractor(
|
|||
private var shouldUpdateKey = false
|
||||
private const val PREF_KEY_KEY = "megacloud_key_"
|
||||
private const val PREF_KEY_DEFAULT = "[[0, 0]]"
|
||||
|
||||
|
||||
private inline fun <reified R> runLocked(crossinline block: () -> R) = runBlocking(Dispatchers.IO) {
|
||||
MUTEX.withLock { block() }
|
||||
}
|
||||
|
@ -132,6 +132,7 @@ class MegaCloudExtractor(
|
|||
?.filter { it.kind == "captions" }
|
||||
?.map { Track(it.file, it.label) }
|
||||
.orEmpty()
|
||||
.let { playlistUtils.fixSubtitles(it) }
|
||||
return playlistUtils.extractFromHls(
|
||||
masterUrl,
|
||||
videoNameGen = { "$name - $it - $type" },
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.lib.playlistutils
|
||||
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.animesource.model.Track
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
|
@ -8,6 +9,7 @@ import okhttp3.Headers
|
|||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.internal.commonEmptyHeaders
|
||||
import java.io.File
|
||||
import kotlin.math.abs
|
||||
|
||||
class PlaylistUtils(private val client: OkHttpClient, private val headers: Headers = commonEmptyHeaders) {
|
||||
|
@ -342,7 +344,32 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade
|
|||
return "${result}p"
|
||||
}
|
||||
|
||||
private fun cleanSubtitleData(matchResult: MatchResult): String {
|
||||
val lineCount = matchResult.groupValues[1].count { it == '\n' }
|
||||
return "\n" + " \n".repeat(lineCount - 1)
|
||||
}
|
||||
|
||||
fun fixSubtitles(subtitleList: List<Track>): List<Track> {
|
||||
return subtitleList.mapNotNull {
|
||||
try {
|
||||
val subData = client.newCall(GET(it.url)).execute().body.string()
|
||||
|
||||
val file = File.createTempFile("subs", "vtt")
|
||||
.also(File::deleteOnExit)
|
||||
|
||||
file.writeText(FIX_SUBTITLE_REGEX.replace(subData, ::cleanSubtitleData))
|
||||
val uri = Uri.fromFile(file)
|
||||
|
||||
Track(uri.toString(), it.lang)
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val FIX_SUBTITLE_REGEX = Regex("""${'$'}(\n{2,})(?!(?:\d+:)*\d+(?:\.\d+)?\s-+>\s(?:\d+:)*\d+(?:\.\d+)?)""", RegexOption.MULTILINE)
|
||||
|
||||
private const val PLAYLIST_SEPARATOR = "#EXT-X-STREAM-INF:"
|
||||
|
||||
private val SUBTITLE_REGEX by lazy { Regex("""#EXT-X-MEDIA:TYPE=SUBTITLES.*?NAME="(.*?)".*?URI="(.*?)"""") }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue