commit 10/10/2025
Restrukturisasi soundbank path di database
This commit is contained in:
12
src/Main.kt
12
src/Main.kt
@@ -7,6 +7,7 @@ import barix.TCP_Barix_Command_Server
|
||||
import codes.Somecodes
|
||||
import com.sun.jna.Platform
|
||||
import commandServer.TCP_Android_Command_Server
|
||||
import content.Category
|
||||
import content.Language
|
||||
import content.VoiceType
|
||||
import database.Log
|
||||
@@ -21,6 +22,7 @@ import org.tinylog.provider.ProviderRegistry
|
||||
import oshi.util.GlobalConfig
|
||||
import web.WebApp
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import kotlin.concurrent.fixedRateTimer
|
||||
import kotlin.io.path.absolutePathString
|
||||
|
||||
@@ -52,11 +54,17 @@ val contentCache = ContentCache()
|
||||
* Create necessary folders if not exist
|
||||
*/
|
||||
fun folder_preparation(){
|
||||
// sementara diset begini, nanti pake config file
|
||||
Somecodes.Soundbank_directory = Paths.get("c:\\soundbank")
|
||||
Files.createDirectories(Somecodes.SoundbankResult_directory)
|
||||
Files.createDirectories(Somecodes.PagingResult_directory)
|
||||
Files.createDirectories(Somecodes.Soundbank_directory)
|
||||
Somecodes.Soundbank_Languages_directory.forEach {
|
||||
Files.createDirectories(it)
|
||||
Language.entries.forEach { language ->
|
||||
VoiceType.entries.forEach { voice ->
|
||||
Category.entries.forEach { category ->
|
||||
Files.createDirectories(Somecodes.SoundbankDirectory(language, voice, category) )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package codes
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import content.Category
|
||||
import content.Language
|
||||
import content.ScheduleDay
|
||||
import content.VoiceType
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -25,15 +27,8 @@ import kotlin.io.path.name
|
||||
class Somecodes {
|
||||
companion object {
|
||||
val current_directory : String = System.getProperty("user.dir")
|
||||
val Soundbank_directory : Path = Path.of(current_directory,"Soundbank")
|
||||
val Soundbank_Languages_directory : List<Path> = listOf(
|
||||
Soundbank_directory.resolve(Language.INDONESIA.name),
|
||||
Soundbank_directory.resolve(Language.LOCAL.name),
|
||||
Soundbank_directory.resolve(Language.ENGLISH.name),
|
||||
Soundbank_directory.resolve(Language.CHINESE.name),
|
||||
Soundbank_directory.resolve(Language.JAPANESE.name),
|
||||
Soundbank_directory.resolve(Language.ARABIC.name)
|
||||
)
|
||||
var Soundbank_directory : Path = Path.of(current_directory,"Soundbank")
|
||||
|
||||
val SoundbankResult_directory : Path = Path.of(current_directory,"SoundbankResult")
|
||||
val PagingResult_directory : Path = Path.of(current_directory,"PagingResult")
|
||||
|
||||
@@ -56,6 +51,17 @@ class Somecodes {
|
||||
// regex for getting ann_id from Message, which is the number inside []
|
||||
private val ann_id_regex = Regex("\\[(\\d+)]")
|
||||
|
||||
/**
|
||||
* Get the directory path for a specific language, voice type, and category.
|
||||
* @param language The language.
|
||||
* @param voice The voice type.
|
||||
* @param category The category.
|
||||
* @return The path to the directory.
|
||||
*/
|
||||
fun SoundbankDirectory(language: Language, voice: VoiceType, category: Category) : Path{
|
||||
return Soundbank_directory.resolve(language.name).resolve(voice.name).resolve(category.name)
|
||||
}
|
||||
|
||||
fun ExtractFilesFromClassPath(resourcePath: String, outputDir: Path) {
|
||||
try {
|
||||
val resource = Somecodes::class.java.getResource(resourcePath)
|
||||
@@ -157,14 +163,13 @@ class Somecodes {
|
||||
/**
|
||||
* List all audio files (.mp3 and .wav) in the specified directory and its subdirectories.
|
||||
* Only files larger than 1KB are included.
|
||||
* @param dir The directory to search in (default is the current working directory).
|
||||
* @param p The directory Path to search in
|
||||
* @return A list of absolute paths to the audio files found.
|
||||
*/
|
||||
fun ListAudioFiles(dir: String = current_directory) : List<String>{
|
||||
fun ListAudioFiles(p: Path) : List<String>{
|
||||
return try{
|
||||
// find all files that ends with .mp3 or .wav
|
||||
// and find them recursively
|
||||
val p = Path.of(dir)
|
||||
if (Files.exists(p) && Files.isDirectory(p)){
|
||||
Files.walk(p)
|
||||
// cari file regular saja
|
||||
|
||||
@@ -219,7 +219,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
}
|
||||
get("ListFiles") {
|
||||
//TODO nanti ganti ke Soundbank_directory setelah revisi soundbank table di MySQL
|
||||
it.result(objectmapper.writeValueAsString(ListAudioFiles("C:\\soundbank")))
|
||||
it.result(objectmapper.writeValueAsString(ListAudioFiles(Somecodes.Soundbank_directory)))
|
||||
}
|
||||
get("AirlineTags") { ctx ->
|
||||
val value = db.soundDB.List
|
||||
|
||||
Reference in New Issue
Block a user