music: add texttags tests

Add tests for the TextTags processing wrapper.
This commit is contained in:
Alexander Capehart
2023-01-05 14:24:30 -07:00
parent 502dd8ccc4
commit 782b570b38
5 changed files with 113 additions and 14 deletions
@@ -160,9 +160,9 @@ class Task(context: Context, private val raw: Song.Raw) {
val metadata = format.metadata
if (metadata != null) {
val tags = Tags(metadata)
populateWithId3v2(tags.id3v2)
populateWithVorbis(tags.vorbis)
val textTags = TextTags(metadata)
populateWithId3v2(textTags.id3v2)
populateWithVorbis(textTags.vorbis)
} else {
logD("No metadata could be extracted for ${raw.name}")
}
@@ -24,11 +24,11 @@ import com.google.android.exoplayer2.metadata.vorbis.VorbisComment
import org.oxycblt.auxio.music.parsing.correctWhitespace
/**
* Processing wrapper for [Metadata] that allows access to more organized music tags.
* Processing wrapper for [Metadata] that allows organized access to text-based audio tags.
* @param metadata The [Metadata] to wrap.
* @author Alexander Capehart (OxygenCobalt)
*/
class Tags(metadata: Metadata) {
class TextTags(metadata: Metadata) {
private val _id3v2 = mutableMapOf<String, List<String>>()
/** The ID3v2 text identification frames found in the file. Can have more than one value. */
val id3v2: Map<String, List<String>>
@@ -65,6 +65,10 @@ class Tags(metadata: Metadata) {
is VorbisComment -> {
// Vorbis comment keys can be in any case, make them uppercase for simplicity.
val id = tag.key.sanitize().lowercase()
if (id == "metadata_block_picture") {
// Picture, we don't care about these
continue
}
val value = tag.value.sanitize().correctWhitespace()
if (value != null) {
_vorbis.getOrPut(id) { mutableListOf() }.add(value)
@@ -30,7 +30,7 @@ import java.nio.ByteBuffer
import kotlin.math.pow
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.Album
import org.oxycblt.auxio.music.extractor.Tags
import org.oxycblt.auxio.music.extractor.TextTags
import org.oxycblt.auxio.playback.state.PlaybackStateManager
import org.oxycblt.auxio.settings.Settings
import org.oxycblt.auxio.util.logD
@@ -166,23 +166,23 @@ class ReplayGainAudioProcessor(private val context: Context) :
* @return A [Adjustment] adjustment, or null if there were no valid adjustments.
*/
private fun parseReplayGain(format: Format): Adjustment? {
val tags = Tags(format.metadata ?: return null)
val textTags = TextTags(format.metadata ?: return null)
var trackGain = 0f
var albumGain = 0f
// Most ReplayGain tags are formatted as a simple decibel adjustment in a custom
// replaygain_*_gain tag.
if (format.sampleMimeType != MimeTypes.AUDIO_OPUS) {
tags.id3v2["TXXX:$TAG_RG_TRACK_GAIN"]
textTags.id3v2["TXXX:$TAG_RG_TRACK_GAIN"]
?.run { first().parseReplayGainAdjustment() }
?.let { trackGain = it }
tags.id3v2["TXXX:$TAG_RG_ALBUM_GAIN"]
textTags.id3v2["TXXX:$TAG_RG_ALBUM_GAIN"]
?.run { first().parseReplayGainAdjustment() }
?.let { albumGain = it }
tags.vorbis[TAG_RG_ALBUM_GAIN]
textTags.vorbis[TAG_RG_ALBUM_GAIN]
?.run { first().parseReplayGainAdjustment() }
?.let { trackGain = it }
tags.vorbis[TAG_RG_TRACK_GAIN]
textTags.vorbis[TAG_RG_TRACK_GAIN]
?.run { first().parseReplayGainAdjustment() }
?.let { albumGain = it }
} else {
@@ -191,10 +191,10 @@ class ReplayGainAudioProcessor(private val context: Context) :
// intrinsic to the format to create the normalized adjustment. That base adjustment
// is already handled by the media framework, so we just need to apply the more
// specific adjustments.
tags.vorbis[TAG_R128_TRACK_GAIN]
textTags.vorbis[TAG_R128_TRACK_GAIN]
?.run { first().parseReplayGainAdjustment() }
?.let { trackGain = it / 256f }
tags.vorbis[TAG_R128_ALBUM_GAIN]
textTags.vorbis[TAG_R128_ALBUM_GAIN]
?.run { first().parseReplayGainAdjustment() }
?.let { albumGain = it / 256f }
}