mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-17 23:55:21 +01:00
Merge pull request #1695 from gokadzev/tagger_fix
Refactor tag editor code and fix related issues
This commit is contained in:
commit
5586f94d4f
1 changed files with 24 additions and 4 deletions
|
@ -74,9 +74,16 @@ class TagWriter {
|
||||||
val audioFile = AudioFileIO.read(File(filePath))
|
val audioFile = AudioFileIO.read(File(filePath))
|
||||||
val tag = audioFile.tagOrCreateAndSetDefault
|
val tag = audioFile.tagOrCreateAndSetDefault
|
||||||
if (info.fieldKeyValueMap != null) {
|
if (info.fieldKeyValueMap != null) {
|
||||||
for ((key, value) in info.fieldKeyValueMap) {
|
for ((key, newValue) in info.fieldKeyValueMap) {
|
||||||
try {
|
try {
|
||||||
tag.setField(key, value)
|
val currentValue = tag.getFirst(key)
|
||||||
|
if (currentValue != newValue) {
|
||||||
|
if (newValue.isEmpty()) {
|
||||||
|
tag.deleteField(key)
|
||||||
|
} else {
|
||||||
|
tag.setField(key, newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: FieldDataInvalidException) {
|
} catch (e: FieldDataInvalidException) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
context.showToast(R.string.could_not_write_tags_to_file)
|
context.showToast(R.string.could_not_write_tags_to_file)
|
||||||
|
@ -127,6 +134,7 @@ class TagWriter {
|
||||||
val cacheFiles = mutableListOf<File>()
|
val cacheFiles = mutableListOf<File>()
|
||||||
var artwork: Artwork? = null
|
var artwork: Artwork? = null
|
||||||
var albumArtFile: File? = null
|
var albumArtFile: File? = null
|
||||||
|
|
||||||
if (info.artworkInfo?.artwork != null) {
|
if (info.artworkInfo?.artwork != null) {
|
||||||
try {
|
try {
|
||||||
albumArtFile = createAlbumArtFile(context).canonicalFile
|
albumArtFile = createAlbumArtFile(context).canonicalFile
|
||||||
|
@ -140,24 +148,36 @@ class TagWriter {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var wroteArtwork = false
|
var wroteArtwork = false
|
||||||
var deletedArtwork = false
|
var deletedArtwork = false
|
||||||
|
|
||||||
for (filePath in info.filePaths!!) {
|
for (filePath in info.filePaths!!) {
|
||||||
try {
|
try {
|
||||||
val originFile = File(filePath)
|
val originFile = File(filePath)
|
||||||
val cacheFile = File(context.cacheDir, originFile.name)
|
val cacheFile = File(context.cacheDir, originFile.name)
|
||||||
cacheFiles.add(cacheFile)
|
cacheFiles.add(cacheFile)
|
||||||
|
|
||||||
originFile.inputStream().use { input ->
|
originFile.inputStream().use { input ->
|
||||||
cacheFile.outputStream().use { output ->
|
cacheFile.outputStream().use { output ->
|
||||||
input.copyTo(output)
|
input.copyTo(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val audioFile = AudioFileIO.read(cacheFile)
|
val audioFile = AudioFileIO.read(cacheFile)
|
||||||
val tag = audioFile.tagOrCreateAndSetDefault
|
val tag = audioFile.tagOrCreateAndSetDefault
|
||||||
|
|
||||||
if (info.fieldKeyValueMap != null) {
|
if (info.fieldKeyValueMap != null) {
|
||||||
for ((key, value) in info.fieldKeyValueMap) {
|
for ((key, newValue) in info.fieldKeyValueMap) {
|
||||||
try {
|
try {
|
||||||
tag.setField(key, value)
|
val currentValue = tag.getFirst(key)
|
||||||
|
if (currentValue != newValue) {
|
||||||
|
if (newValue.isEmpty()) {
|
||||||
|
tag.deleteField(key)
|
||||||
|
} else {
|
||||||
|
tag.setField(key, newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: FieldDataInvalidException) {
|
} catch (e: FieldDataInvalidException) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
context.showToast(R.string.could_not_write_tags_to_file)
|
context.showToast(R.string.could_not_write_tags_to_file)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue