mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 14:55:26 +02:00
fix: Use one source of truth for the filename (instead of recalculating it, this doesn't work, as the date _time_ will differ)
Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
parent
a88507a905
commit
3cfbbdef1c
@ -40,18 +40,17 @@ class AudioBatchesFolder(
|
|||||||
override fun getOutputFileForFFmpeg(
|
override fun getOutputFileForFFmpeg(
|
||||||
date: LocalDateTime,
|
date: LocalDateTime,
|
||||||
extension: String,
|
extension: String,
|
||||||
|
fileName: String,
|
||||||
): String {
|
): String {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
BatchType.INTERNAL -> asInternalGetOutputFile(date, extension).absolutePath
|
BatchType.INTERNAL -> asInternalGetOutputFile(fileName).absolutePath
|
||||||
|
|
||||||
BatchType.CUSTOM -> {
|
BatchType.CUSTOM -> {
|
||||||
val name = getName(date, extension)
|
|
||||||
|
|
||||||
FFmpegKitConfig.getSafParameterForWrite(
|
FFmpegKitConfig.getSafParameterForWrite(
|
||||||
context,
|
context,
|
||||||
(customFolder!!.findFile(name) ?: customFolder.createFile(
|
(customFolder!!.findFile(fileName) ?: customFolder.createFile(
|
||||||
"audio/${extension}",
|
"audio/${extension}",
|
||||||
getName(date, extension),
|
fileName,
|
||||||
)!!).uri
|
)!!).uri
|
||||||
)!!
|
)!!
|
||||||
}
|
}
|
||||||
@ -59,7 +58,7 @@ class AudioBatchesFolder(
|
|||||||
BatchType.MEDIA -> {
|
BatchType.MEDIA -> {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
val mediaUri = getOrCreateMediaFile(
|
val mediaUri = getOrCreateMediaFile(
|
||||||
name = getName(date, extension),
|
name = fileName,
|
||||||
mimeType = "audio/$extension",
|
mimeType = "audio/$extension",
|
||||||
relativePath = BASE_SCOPED_STORAGE_RELATIVE_PATH + "/" + MEDIA_SUBFOLDER_NAME,
|
relativePath = BASE_SCOPED_STORAGE_RELATIVE_PATH + "/" + MEDIA_SUBFOLDER_NAME,
|
||||||
)
|
)
|
||||||
@ -72,7 +71,7 @@ class AudioBatchesFolder(
|
|||||||
val path = arrayOf(
|
val path = arrayOf(
|
||||||
Environment.getExternalStoragePublicDirectory(BASE_LEGACY_STORAGE_FOLDER),
|
Environment.getExternalStoragePublicDirectory(BASE_LEGACY_STORAGE_FOLDER),
|
||||||
MEDIA_SUBFOLDER_NAME,
|
MEDIA_SUBFOLDER_NAME,
|
||||||
getName(date, extension)
|
fileName,
|
||||||
).joinToString("/")
|
).joinToString("/")
|
||||||
return File(path)
|
return File(path)
|
||||||
.apply {
|
.apply {
|
||||||
|
@ -191,8 +191,8 @@ abstract class BatchesFolder(
|
|||||||
return "$name.$extension"
|
return "$name.$extension"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun asInternalGetOutputFile(date: LocalDateTime, extension: String): File {
|
fun asInternalGetOutputFile(fileName: String): File {
|
||||||
return File(getInternalFolder(), getName(date, extension))
|
return File(getInternalFolder(), fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun asMediaGetLegacyFile(name: String): File = File(
|
fun asMediaGetLegacyFile(name: String): File = File(
|
||||||
@ -203,16 +203,8 @@ abstract class BatchesFolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkIfOutputAlreadyExists(
|
fun checkIfOutputAlreadyExists(
|
||||||
date: LocalDateTime,
|
fileName: String,
|
||||||
extension: String
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val stem = date
|
|
||||||
.format(DateTimeFormatter.ISO_DATE_TIME)
|
|
||||||
.toString()
|
|
||||||
.replace(":", "-")
|
|
||||||
.replace(".", "_")
|
|
||||||
val fileName = "$stem.$extension"
|
|
||||||
|
|
||||||
return when (type) {
|
return when (type) {
|
||||||
BatchType.INTERNAL -> File(getInternalFolder(), fileName).exists()
|
BatchType.INTERNAL -> File(getInternalFolder(), fileName).exists()
|
||||||
|
|
||||||
@ -245,6 +237,7 @@ abstract class BatchesFolder(
|
|||||||
abstract fun getOutputFileForFFmpeg(
|
abstract fun getOutputFileForFFmpeg(
|
||||||
date: LocalDateTime,
|
date: LocalDateTime,
|
||||||
extension: String,
|
extension: String,
|
||||||
|
fileName: String,
|
||||||
): String
|
): String
|
||||||
|
|
||||||
abstract fun cleanup()
|
abstract fun cleanup()
|
||||||
@ -255,18 +248,17 @@ abstract class BatchesFolder(
|
|||||||
disableCache: Boolean? = null,
|
disableCache: Boolean? = null,
|
||||||
onNextParameterTry: (String) -> Unit = {},
|
onNextParameterTry: (String) -> Unit = {},
|
||||||
onProgress: (Float?) -> Unit = {},
|
onProgress: (Float?) -> Unit = {},
|
||||||
|
fileName: String,
|
||||||
): String {
|
): String {
|
||||||
val disableCache = disableCache ?: (type != BatchType.INTERNAL)
|
val disableCache = disableCache ?: (type != BatchType.INTERNAL)
|
||||||
val date = recording.getStartDateForFilename(filenameFormat)
|
val date = recording.getStartDateForFilename(filenameFormat)
|
||||||
|
|
||||||
if (!disableCache && checkIfOutputAlreadyExists(
|
if (!disableCache && checkIfOutputAlreadyExists(fileName)
|
||||||
recording.recordingStart,
|
|
||||||
recording.fileExtension
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return getOutputFileForFFmpeg(
|
return getOutputFileForFFmpeg(
|
||||||
date = recording.recordingStart,
|
date = recording.recordingStart,
|
||||||
extension = recording.fileExtension,
|
extension = recording.fileExtension,
|
||||||
|
fileName = fileName,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,6 +274,7 @@ abstract class BatchesFolder(
|
|||||||
val outputFile = getOutputFileForFFmpeg(
|
val outputFile = getOutputFileForFFmpeg(
|
||||||
date = date,
|
date = date,
|
||||||
extension = recording.fileExtension,
|
extension = recording.fileExtension,
|
||||||
|
fileName = fileName,
|
||||||
)
|
)
|
||||||
|
|
||||||
concatenationFunction(
|
concatenationFunction(
|
||||||
|
@ -39,18 +39,20 @@ class VideoBatchesFolder(
|
|||||||
|
|
||||||
private var customParcelFileDescriptor: ParcelFileDescriptor? = null
|
private var customParcelFileDescriptor: ParcelFileDescriptor? = null
|
||||||
|
|
||||||
override fun getOutputFileForFFmpeg(date: LocalDateTime, extension: String): String {
|
override fun getOutputFileForFFmpeg(
|
||||||
|
date: LocalDateTime,
|
||||||
|
extension: String,
|
||||||
|
fileName: String,
|
||||||
|
): String {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
BatchType.INTERNAL -> asInternalGetOutputFile(date, extension).absolutePath
|
BatchType.INTERNAL -> asInternalGetOutputFile(fileName).absolutePath
|
||||||
|
|
||||||
BatchType.CUSTOM -> {
|
BatchType.CUSTOM -> {
|
||||||
val name = getName(date, extension)
|
|
||||||
|
|
||||||
FFmpegKitConfig.getSafParameterForWrite(
|
FFmpegKitConfig.getSafParameterForWrite(
|
||||||
context,
|
context,
|
||||||
(customFolder!!.findFile(name) ?: customFolder.createFile(
|
(customFolder!!.findFile(fileName) ?: customFolder.createFile(
|
||||||
"video/${extension}",
|
"video/${extension}",
|
||||||
getName(date, extension),
|
fileName,
|
||||||
)!!).uri
|
)!!).uri
|
||||||
)!!
|
)!!
|
||||||
}
|
}
|
||||||
@ -58,7 +60,7 @@ class VideoBatchesFolder(
|
|||||||
BatchType.MEDIA -> {
|
BatchType.MEDIA -> {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
val mediaUri = getOrCreateMediaFile(
|
val mediaUri = getOrCreateMediaFile(
|
||||||
name = getName(date, extension),
|
name = fileName,
|
||||||
mimeType = "video/$extension",
|
mimeType = "video/$extension",
|
||||||
relativePath = BASE_SCOPED_STORAGE_RELATIVE_PATH + "/" + MEDIA_SUBFOLDER_NAME,
|
relativePath = BASE_SCOPED_STORAGE_RELATIVE_PATH + "/" + MEDIA_SUBFOLDER_NAME,
|
||||||
)
|
)
|
||||||
@ -71,7 +73,7 @@ class VideoBatchesFolder(
|
|||||||
val path = arrayOf(
|
val path = arrayOf(
|
||||||
Environment.getExternalStoragePublicDirectory(BASE_LEGACY_STORAGE_FOLDER),
|
Environment.getExternalStoragePublicDirectory(BASE_LEGACY_STORAGE_FOLDER),
|
||||||
MEDIA_SUBFOLDER_NAME,
|
MEDIA_SUBFOLDER_NAME,
|
||||||
getName(date, extension)
|
fileName,
|
||||||
).joinToString("/")
|
).joinToString("/")
|
||||||
return File(path)
|
return File(path)
|
||||||
.apply {
|
.apply {
|
||||||
|
@ -177,38 +177,33 @@ fun RecorderEventsHandler(
|
|||||||
else -> throw Exception("Unknown recorder type")
|
else -> throw Exception("Unknown recorder type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fileName = batchesFolder.getName(
|
||||||
|
recording.recordingStart,
|
||||||
|
recording.fileExtension,
|
||||||
|
)
|
||||||
|
|
||||||
batchesFolder.concatenate(
|
batchesFolder.concatenate(
|
||||||
recording,
|
recording,
|
||||||
filenameFormat = settings.filenameFormat,
|
filenameFormat = settings.filenameFormat,
|
||||||
|
fileName = fileName,
|
||||||
onProgress = { percentage ->
|
onProgress = { percentage ->
|
||||||
processingProgress = percentage
|
processingProgress = percentage
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
val name = batchesFolder.getName(
|
|
||||||
recording.recordingStart,
|
|
||||||
recording.fileExtension,
|
|
||||||
)
|
|
||||||
|
|
||||||
when (batchesFolder.type) {
|
when (batchesFolder.type) {
|
||||||
BatchesFolder.BatchType.INTERNAL -> {
|
BatchesFolder.BatchType.INTERNAL -> {
|
||||||
when (batchesFolder) {
|
when (batchesFolder) {
|
||||||
is AudioBatchesFolder -> {
|
is AudioBatchesFolder -> {
|
||||||
saveAudioFile(
|
saveAudioFile(
|
||||||
batchesFolder.asInternalGetOutputFile(
|
batchesFolder.asInternalGetOutputFile(fileName), fileName
|
||||||
recording.recordingStart,
|
|
||||||
recording.fileExtension,
|
|
||||||
), name
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is VideoBatchesFolder -> {
|
is VideoBatchesFolder -> {
|
||||||
saveVideoFile(
|
saveVideoFile(
|
||||||
batchesFolder.asInternalGetOutputFile(
|
batchesFolder.asInternalGetOutputFile(fileName), fileName
|
||||||
recording.recordingStart,
|
|
||||||
recording.fileExtension,
|
|
||||||
), name
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user