mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-06-01 04:11:43 +02:00
feat: add stable cover cache keys, Qobuz album-search fallback, metadata filters and extended sort options
- Introduce coverCacheKey parameter through Go backend and Kotlin bridge for stable SAF cover caching - Add MetadataFromFilename flag to skip filename-only metadata and retry via temp-file copy - Add Qobuz album-search fallback between API search and store scraping - Extract buildReEnrichFFmpegMetadata to skip empty metadata fields - Add metadata completeness filter (complete, missing year/genre/album artist) - Add sort modes: artist, album, release date, genre (asc/desc) - Prune stale library cover cache files after full scan - Skip empty values and zero track/disc numbers in FFmpeg metadata - Add new l10n keys for metadata filter and sort options
This commit is contained in:
@@ -777,20 +777,32 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
return if (ext.isNullOrBlank()) "audio" else "audio$ext"
|
||||
}
|
||||
|
||||
private fun buildLibraryCoverCacheKey(stablePath: String, lastModified: Long): String {
|
||||
val normalizedPath = stablePath.trim()
|
||||
if (normalizedPath.isEmpty()) return ""
|
||||
return if (lastModified > 0L) "$normalizedPath|$lastModified" else normalizedPath
|
||||
}
|
||||
|
||||
private fun readAudioMetadataFromUri(
|
||||
uri: Uri,
|
||||
displayNameHint: String? = null,
|
||||
fallbackExt: String? = null,
|
||||
coverCacheKey: String = "",
|
||||
): JSONObject? {
|
||||
val displayName = buildUriDisplayName(uri, displayNameHint, fallbackExt)
|
||||
|
||||
try {
|
||||
contentResolver.openFileDescriptor(uri, "r")?.use { pfd ->
|
||||
val directPath = "/proc/self/fd/${pfd.fd}"
|
||||
val metadataJson = Gobackend.readAudioMetadataWithHintJSON(directPath, displayName)
|
||||
val metadataJson = Gobackend.readAudioMetadataWithHintAndCoverCacheKeyJSON(
|
||||
directPath,
|
||||
displayName,
|
||||
coverCacheKey,
|
||||
)
|
||||
if (metadataJson.isNotBlank()) {
|
||||
val obj = JSONObject(metadataJson)
|
||||
if (!obj.has("error")) {
|
||||
val filenameFallback = obj.optBoolean("metadataFromFilename", false)
|
||||
if (!obj.has("error") && !filenameFallback) {
|
||||
return obj
|
||||
}
|
||||
}
|
||||
@@ -813,7 +825,11 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
} ?: return null
|
||||
|
||||
try {
|
||||
val metadataJson = Gobackend.readAudioMetadataWithHintJSON(tempPath, displayName)
|
||||
val metadataJson = Gobackend.readAudioMetadataWithHintAndCoverCacheKeyJSON(
|
||||
tempPath,
|
||||
displayName,
|
||||
coverCacheKey,
|
||||
)
|
||||
if (metadataJson.isBlank()) return null
|
||||
val obj = JSONObject(metadataJson)
|
||||
return if (obj.has("error")) null else obj
|
||||
@@ -1190,6 +1206,11 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
val audioName = try { audioDoc.name ?: "audio.flac" } catch (_: Exception) { "audio.flac" }
|
||||
val audioExt = audioName.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
val fallbackAudioExt = if (audioExt.isNotBlank()) ".$audioExt" else null
|
||||
val audioLastModified = try { audioDoc.lastModified() } catch (_: Exception) { cueDoc.lastModified() }
|
||||
val coverCacheKey = buildLibraryCoverCacheKey(
|
||||
audioDoc.uri.toString(),
|
||||
audioLastModified,
|
||||
)
|
||||
|
||||
tempAudioPath = copyUriToTemp(audioDoc.uri, fallbackAudioExt)
|
||||
if (tempAudioPath == null) {
|
||||
@@ -1208,11 +1229,12 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
|
||||
val cueLastModified = try { cueDoc.lastModified() } catch (_: Exception) { 0L }
|
||||
|
||||
val cueResultsJson = Gobackend.scanCueSheetForLibrary(
|
||||
val cueResultsJson = Gobackend.scanCueSheetForLibraryWithCoverCacheKey(
|
||||
tempCuePath,
|
||||
tempDir,
|
||||
cueDoc.uri.toString(),
|
||||
cueLastModified
|
||||
cueLastModified,
|
||||
coverCacheKey,
|
||||
)
|
||||
|
||||
val cueArray = JSONArray(cueResultsJson)
|
||||
@@ -1264,13 +1286,19 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
val fallbackExt = if (ext.isNotBlank()) ".${ext}" else null
|
||||
val metadataObj = readAudioMetadataFromUri(doc.uri, name, fallbackExt)
|
||||
val lastModified = try { doc.lastModified() } catch (_: Exception) { 0L }
|
||||
val stableUri = doc.uri.toString()
|
||||
val coverCacheKey = buildLibraryCoverCacheKey(stableUri, lastModified)
|
||||
val metadataObj = readAudioMetadataFromUri(
|
||||
doc.uri,
|
||||
name,
|
||||
fallbackExt,
|
||||
coverCacheKey,
|
||||
)
|
||||
if (metadataObj == null) {
|
||||
errors++
|
||||
} else {
|
||||
try {
|
||||
val lastModified = try { doc.lastModified() } catch (_: Exception) { 0L }
|
||||
val stableUri = doc.uri.toString()
|
||||
metadataObj.put("id", buildStableLibraryId(stableUri))
|
||||
metadataObj.put("filePath", stableUri)
|
||||
metadataObj.put("fileModTime", lastModified)
|
||||
@@ -1538,6 +1566,11 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
val audioName = try { audioDoc.name ?: "audio.flac" } catch (_: Exception) { "audio.flac" }
|
||||
val audioExt = audioName.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
val fallbackAudioExt = if (audioExt.isNotBlank()) ".$audioExt" else null
|
||||
val audioLastModified = try { audioDoc.lastModified() } catch (_: Exception) { cueLastModified }
|
||||
val coverCacheKey = buildLibraryCoverCacheKey(
|
||||
audioDoc.uri.toString(),
|
||||
audioLastModified,
|
||||
)
|
||||
|
||||
tempAudioPath = copyUriToTemp(audioDoc.uri, fallbackAudioExt)
|
||||
if (tempAudioPath == null) {
|
||||
@@ -1554,11 +1587,12 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
tempAudioPath = renamedAudio.absolutePath
|
||||
}
|
||||
|
||||
val cueResultsJson = Gobackend.scanCueSheetForLibrary(
|
||||
val cueResultsJson = Gobackend.scanCueSheetForLibraryWithCoverCacheKey(
|
||||
tempCuePath,
|
||||
tempDir,
|
||||
cueDoc.uri.toString(),
|
||||
cueLastModified
|
||||
cueLastModified,
|
||||
coverCacheKey,
|
||||
)
|
||||
|
||||
val cueArray = JSONArray(cueResultsJson)
|
||||
@@ -1655,13 +1689,19 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
val fallbackExt = if (ext.isNotBlank()) ".${ext}" else null
|
||||
val metadataObj = readAudioMetadataFromUri(doc.uri, name, fallbackExt)
|
||||
val safeLastModified = try { doc.lastModified() } catch (_: Exception) { lastModified }
|
||||
val stableUri = doc.uri.toString()
|
||||
val coverCacheKey = buildLibraryCoverCacheKey(stableUri, safeLastModified)
|
||||
val metadataObj = readAudioMetadataFromUri(
|
||||
doc.uri,
|
||||
name,
|
||||
fallbackExt,
|
||||
coverCacheKey,
|
||||
)
|
||||
if (metadataObj == null) {
|
||||
errors++
|
||||
} else {
|
||||
try {
|
||||
val safeLastModified = try { doc.lastModified() } catch (_: Exception) { lastModified }
|
||||
val stableUri = doc.uri.toString()
|
||||
metadataObj.put("id", buildStableLibraryId(stableUri))
|
||||
metadataObj.put("filePath", stableUri)
|
||||
metadataObj.put("fileModTime", safeLastModified)
|
||||
|
||||
Reference in New Issue
Block a user