small fix

This commit is contained in:
LagradOst 2023-08-24 21:17:42 +02:00
parent 9b4701fe91
commit 1a4cbcaea0
2 changed files with 24 additions and 7 deletions

View file

@ -591,7 +591,7 @@ class ResultViewModel2 : ViewModel() {
link, link,
"$fileName ${link.name}", "$fileName ${link.name}",
folder, folder,
if (link.url.contains(".srt")) ".srt" else "vtt", if (link.url.contains(".srt")) "srt" else "vtt",
false, false,
null, createNotificationCallback = {} null, createNotificationCallback = {}
) )
@ -719,7 +719,7 @@ class ResultViewModel2 : ViewModel() {
) )
) )
} }
.map { ExtractorSubtitleLink(it.name, it.url, "") } .map { ExtractorSubtitleLink(it.name, it.url, "") }.take(3)
.forEach { link -> .forEach { link ->
val fileName = VideoDownloadManager.getFileName(context, meta) val fileName = VideoDownloadManager.getFileName(context, meta)
downloadSubtitle(context, link, fileName, folder) downloadSubtitle(context, link, fileName, folder)

View file

@ -13,6 +13,7 @@ import com.hippo.unifile.UniRandomAccessFile
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import okhttp3.internal.closeQuietly import okhttp3.internal.closeQuietly
import java.io.File import java.io.File
import java.io.FileNotFoundException
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
@ -65,6 +66,10 @@ class MediaFile(
private val external: Boolean = true, private val external: Boolean = true,
absolutePath: String, absolutePath: String,
) : SafeFile { ) : SafeFile {
override fun toString(): String {
return sanitizedAbsolutePath
}
// this is the path relative to the download directory so "/hello/text.txt" = "hello/text.txt" is in fact "Download/hello/text.txt" // this is the path relative to the download directory so "/hello/text.txt" = "hello/text.txt" is in fact "Download/hello/text.txt"
private val sanitizedAbsolutePath: String = private val sanitizedAbsolutePath: String =
replaceDuplicateFileSeparators(absolutePath) replaceDuplicateFileSeparators(absolutePath)
@ -130,7 +135,7 @@ class MediaFile(
// VideoDownloadManager.sanitizeFilename(path.replace(File.separator, "")) // VideoDownloadManager.sanitizeFilename(path.replace(File.separator, ""))
// in case of duplicate path, aka Download -> Download // in case of duplicate path, aka Download -> Download
if(relativePath == path) return this if (relativePath == path) return this
val newPath = val newPath =
sanitizedAbsolutePath + path + if (folder) File.separator else "" sanitizedAbsolutePath + path + if (folder) File.separator else ""
@ -246,12 +251,24 @@ class MediaFile(
override fun length(): Long? { override fun length(): Long? {
if (isDir) return null if (isDir) return null
val length = query()?.length ?: return null val query = query()
if(length <= 0) { val length = query?.length ?: return null
val inputStream : InputStream = openInputStream() ?: return null if (length <= 0) {
try {
contentResolver.openFileDescriptor(query.uri, "r")
.use {
it?.statSize
}?.let {
return it
}
} catch (e: FileNotFoundException) {
return null
}
val inputStream: InputStream = openInputStream() ?: return null
return try { return try {
inputStream.available().toLong() inputStream.available().toLong()
} catch (t : Throwable) { } catch (t: Throwable) {
null null
} finally { } finally {
inputStream.closeQuietly() inputStream.closeQuietly()