fixed subs on downloads

This commit is contained in:
LagradOst 2023-08-30 00:52:34 +02:00
parent ce1f48978b
commit 6089cbc484
3 changed files with 45 additions and 32 deletions

View file

@ -233,7 +233,7 @@ dependencies {
// To fix SSL fuckery on android 9 // To fix SSL fuckery on android 9
implementation("org.conscrypt:conscrypt-android:2.2.1") implementation("org.conscrypt:conscrypt-android:2.2.1")
// Util to skip the URI file fuckery 🙏 // Util to skip the URI file fuckery 🙏
implementation("com.github.LagradOst:SafeFile:0.0.3") implementation("com.github.LagradOst:SafeFile:0.0.5")
// API because cba maintaining it myself // API because cba maintaining it myself
implementation("com.uwetrottmann.tmdb2:tmdb-java:2.6.0") implementation("com.uwetrottmann.tmdb2:tmdb-java:2.6.0")

View file

@ -50,6 +50,10 @@ class DownloadFileGenerator(
return null return null
} }
fun cleanDisplayName(name: String): String {
return name.substringBeforeLast('.').trim()
}
override suspend fun generateLinks( override suspend fun generateLinks(
clearCache: Boolean, clearCache: Boolean,
isCasting: Boolean, isCasting: Boolean,
@ -58,39 +62,48 @@ class DownloadFileGenerator(
offset: Int, offset: Int,
): Boolean { ): Boolean {
val meta = episodes[currentIndex + offset] val meta = episodes[currentIndex + offset]
callback(Pair(null, meta)) callback(null to meta)
context?.let { ctx -> val ctx = context ?: return true
val relative = meta.relativePath val relative = meta.relativePath ?: return true
val display = meta.displayName val display = meta.displayName ?: return true
val cleanDisplay = cleanDisplayName(display)
if (display == null || relative == null) {
return@let
}
VideoDownloadManager.getFolder(ctx, relative, meta.basePath) VideoDownloadManager.getFolder(ctx, relative, meta.basePath)
?.forEach { file -> ?.forEach { (name, uri) ->
val name = display.removeSuffix(".mp4") // only these files are allowed, so no videos as subtitles
if (file.first != meta.displayName && file.first.startsWith(name)) { if (listOf(
val realName = file.first.removePrefix(name) ".vtt",
.removeSuffix(".vtt") ".srt",
.removeSuffix(".srt") ".txt",
.removeSuffix(".txt") ".ass",
.trim() ".ttml",
.removePrefix("(") ".sbv",
.removeSuffix(")") ".dfxp"
).none { name.contains(it, true) }
) return@forEach
// cant have the exact same file as a subtitle
if (name.equals(display, true)) return@forEach
val cleanName = cleanDisplayName(name)
// we only want files with the approx same name
if (!cleanName.startsWith(cleanDisplay, true)) return@forEach
val realName = cleanName.removePrefix(cleanDisplay)
subtitleCallback( subtitleCallback(
SubtitleData( SubtitleData(
realName.ifBlank { ctx.getString(R.string.default_subtitles) }, realName.ifBlank { ctx.getString(R.string.default_subtitles) },
file.second.toString(), uri.toString(),
SubtitleOrigin.DOWNLOADED_FILE, SubtitleOrigin.DOWNLOADED_FILE,
name.toSubtitleMimeType(), name.toSubtitleMimeType(),
emptyMap() emptyMap()
) )
) )
} }
}
}
return true return true
} }

View file

@ -505,7 +505,7 @@ object VideoDownloadManager {
): List<Pair<String, Uri>>? { ): List<Pair<String, Uri>>? {
val base = basePathToFile(context, basePath) val base = basePathToFile(context, basePath)
val folder = base?.gotoDirectory(relativePath, false) ?: return null val folder = base?.gotoDirectory(relativePath, false) ?: return null
if (folder.isDirectory() != false) return null //if (folder.isDirectory() != false) return null
return folder.listFiles() return folder.listFiles()
?.mapNotNull { (it.name() ?: "") to (it.uri() ?: return@mapNotNull null) } ?.mapNotNull { (it.name() ?: "") to (it.uri() ?: return@mapNotNull null) }