I FUCKING HATE EXOPLAYER SUBTITLES
This commit is contained in:
parent
ea96291bfc
commit
87a9df4c12
9 changed files with 257 additions and 50 deletions
|
@ -1,9 +1,11 @@
|
|||
package ani.dantotsu.parsers
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import ani.dantotsu.currContext
|
||||
import ani.dantotsu.download.DownloadsManager
|
||||
import ani.dantotsu.media.anime.AnimeNameAdapter
|
||||
import ani.dantotsu.tryWithSuspend
|
||||
import eu.kanade.tachiyomi.animesource.model.SAnime
|
||||
import eu.kanade.tachiyomi.animesource.model.SEpisode
|
||||
import eu.kanade.tachiyomi.animesource.model.SEpisodeImpl
|
||||
|
@ -11,6 +13,7 @@ import me.xdrop.fuzzywuzzy.FuzzySearch
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
||||
class OfflineAnimeParser : AnimeParser() {
|
||||
private val downloadManager = Injekt.get<DownloadsManager>()
|
||||
|
@ -34,6 +37,10 @@ class OfflineAnimeParser : AnimeParser() {
|
|||
val episodes = mutableListOf<Episode>()
|
||||
if (directory.exists()) {
|
||||
directory.listFiles()?.forEach {
|
||||
//put the title and episdode number in the extra data
|
||||
val extraData = mutableMapOf<String, String>()
|
||||
extraData["title"] = animeLink
|
||||
extraData["episode"] = it.name
|
||||
if (it.isDirectory) {
|
||||
val episode = Episode(
|
||||
it.name,
|
||||
|
@ -41,6 +48,7 @@ class OfflineAnimeParser : AnimeParser() {
|
|||
it.name,
|
||||
null,
|
||||
null,
|
||||
extra = extraData,
|
||||
sEpisode = SEpisodeImpl()
|
||||
)
|
||||
episodes.add(episode)
|
||||
|
@ -60,7 +68,8 @@ class OfflineAnimeParser : AnimeParser() {
|
|||
return listOf(
|
||||
VideoServer(
|
||||
episodeLink,
|
||||
offline = true
|
||||
offline = true,
|
||||
extraData = extra
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -81,6 +90,21 @@ class OfflineAnimeParser : AnimeParser() {
|
|||
return returnList
|
||||
}
|
||||
|
||||
override suspend fun loadByVideoServers(
|
||||
episodeUrl: String,
|
||||
extra: Map<String, String>?,
|
||||
sEpisode: SEpisode,
|
||||
callback: (VideoExtractor) -> Unit
|
||||
) {
|
||||
val server = loadVideoServers(episodeUrl, extra, sEpisode).first()
|
||||
OfflineVideoExtractor(server).apply {
|
||||
tryWithSuspend {
|
||||
load()
|
||||
}
|
||||
callback.invoke(this)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getVideoExtractor(server: VideoServer): VideoExtractor {
|
||||
return OfflineVideoExtractor(server)
|
||||
}
|
||||
|
@ -92,7 +116,10 @@ class OfflineVideoExtractor(val videoServer: VideoServer) : VideoExtractor() {
|
|||
get() = videoServer
|
||||
|
||||
override suspend fun extract(): VideoContainer {
|
||||
val sublist = emptyList<Subtitle>()
|
||||
val sublist = getSubtitle(
|
||||
videoServer.extraData?.get("title") ?: "",
|
||||
videoServer.extraData?.get("episode") ?: ""
|
||||
)?: emptyList()
|
||||
//we need to return a "fake" video so that the app doesn't crash
|
||||
val video = Video(
|
||||
null,
|
||||
|
@ -102,4 +129,33 @@ class OfflineVideoExtractor(val videoServer: VideoServer) : VideoExtractor() {
|
|||
return VideoContainer(listOf(video), sublist)
|
||||
}
|
||||
|
||||
private fun getSubtitle(title: String, episode: String): List<Subtitle>? {
|
||||
currContext()?.let {
|
||||
DownloadsManager.getDirectory(
|
||||
it,
|
||||
ani.dantotsu.download.DownloadedType.Type.ANIME,
|
||||
title,
|
||||
episode
|
||||
).listFiles()?.forEach {
|
||||
if (it.name.contains("subtitle")) {
|
||||
return listOf(
|
||||
Subtitle(
|
||||
"Downloaded Subtitle",
|
||||
Uri.fromFile(it).toString(),
|
||||
determineSubtitletype(it.absolutePath)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun determineSubtitletype(url: String): SubtitleType {
|
||||
return when {
|
||||
url.lowercase(Locale.ROOT).endsWith("ass") -> SubtitleType.ASS
|
||||
url.lowercase(Locale.ROOT).endsWith("vtt") -> SubtitleType.VTT
|
||||
else -> SubtitleType.SRT
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue