all: reformat
This commit is contained in:
Submodule musikr/src/main/cpp/taglib updated: e831f0929f...9c042984d2
@@ -78,7 +78,7 @@ sealed interface Music {
|
||||
private constructor(
|
||||
private val format: Format,
|
||||
private val item: Item,
|
||||
private val uuid: UUID
|
||||
private val uuid: UUID,
|
||||
) : Parcelable {
|
||||
// Cache the hashCode for HashMap efficiency.
|
||||
@IgnoredOnParcel private var hashCode = format.hashCode()
|
||||
@@ -103,7 +103,7 @@ sealed interface Music {
|
||||
ALBUM(0xA10A),
|
||||
ARTIST(0xA109),
|
||||
GENRE(0xA108),
|
||||
PLAYLIST(0xA107)
|
||||
PLAYLIST(0xA107),
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ sealed interface Music {
|
||||
AUXIO("org.oxycblt.auxio"),
|
||||
|
||||
/** @see musicBrainz */
|
||||
MUSICBRAINZ("org.musicbrainz")
|
||||
MUSICBRAINZ("org.musicbrainz"),
|
||||
}
|
||||
|
||||
object TypeConverters {
|
||||
@@ -177,7 +177,8 @@ sealed interface Music {
|
||||
.or(digest[12].toLong().and(0xFF).shl(24))
|
||||
.or(digest[13].toLong().and(0xFF).shl(16))
|
||||
.or(digest[14].toLong().and(0xFF).shl(8))
|
||||
.or(digest[15].toLong().and(0xFF)))
|
||||
.or(digest[15].toLong().and(0xFF)),
|
||||
)
|
||||
return UID(Format.AUXIO, item, uuid)
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,8 @@ interface Musikr {
|
||||
config,
|
||||
ExploreStep.from(context, config),
|
||||
ExtractStep.from(context, config),
|
||||
EvaluateStep.new(context, config, config.interpretation))
|
||||
EvaluateStep.new(context, config, config.interpretation),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ private class MusikrImpl(
|
||||
private val config: Config,
|
||||
private val exploreStep: ExploreStep,
|
||||
private val extractStep: ExtractStep,
|
||||
private val evaluateStep: EvaluateStep
|
||||
private val evaluateStep: EvaluateStep,
|
||||
) : Musikr {
|
||||
override suspend fun run(onProgress: suspend (IndexingProgress) -> Unit) = coroutineScope {
|
||||
onProgress(IndexingProgress.Songs(0, 0))
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ data class CachedSong(
|
||||
* The time the song was added to the cache. Used for date added values. Should not be used for
|
||||
* cleanup since it is unlikely to be monotonic.
|
||||
*/
|
||||
val addedMs: Long
|
||||
val addedMs: Long,
|
||||
)
|
||||
|
||||
/** A result of a cache lookup. */
|
||||
|
||||
@@ -45,7 +45,10 @@ internal abstract class CacheDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
fun from(context: Context) =
|
||||
Room.databaseBuilder(
|
||||
context.applicationContext, CacheDatabase::class.java, "music_cache.db")
|
||||
context.applicationContext,
|
||||
CacheDatabase::class.java,
|
||||
"music_cache.db",
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
|
||||
+11
-4
@@ -52,7 +52,11 @@ class DBCache private constructor(private val readDao: CacheReadDao) : Cache {
|
||||
CachedSong(
|
||||
file,
|
||||
Properties(
|
||||
dbSong.mimeType, dbSong.durationMs, dbSong.bitrateKbps, dbSong.sampleRateHz),
|
||||
dbSong.mimeType,
|
||||
dbSong.durationMs,
|
||||
dbSong.bitrateKbps,
|
||||
dbSong.sampleRateHz,
|
||||
),
|
||||
ParsedTags(
|
||||
musicBrainzId = dbSong.musicBrainzId,
|
||||
name = dbSong.name,
|
||||
@@ -74,9 +78,11 @@ class DBCache private constructor(private val readDao: CacheReadDao) : Cache {
|
||||
albumArtistSortNames = dbSong.albumArtistSortNames,
|
||||
genreNames = dbSong.genreNames,
|
||||
replayGainTrackAdjustment = dbSong.replayGainTrackAdjustment,
|
||||
replayGainAlbumAdjustment = dbSong.replayGainAlbumAdjustment),
|
||||
replayGainAlbumAdjustment = dbSong.replayGainAlbumAdjustment,
|
||||
),
|
||||
coverId = dbSong.coverId,
|
||||
addedMs = dbSong.addedMs)
|
||||
addedMs = dbSong.addedMs,
|
||||
)
|
||||
return CacheResult.Hit(song)
|
||||
}
|
||||
|
||||
@@ -136,7 +142,8 @@ private constructor(private val inner: DBCache, private val writeDao: CacheWrite
|
||||
genreNames = cachedSong.tags.genreNames,
|
||||
replayGainTrackAdjustment = cachedSong.tags.replayGainTrackAdjustment,
|
||||
replayGainAlbumAdjustment = cachedSong.tags.replayGainAlbumAdjustment,
|
||||
coverId = cachedSong.coverId)
|
||||
coverId = cachedSong.coverId,
|
||||
)
|
||||
writeDao.updateSong(dbSong)
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +171,7 @@ class CoverCollection private constructor(val covers: List<Cover>) {
|
||||
.entries
|
||||
.sortedByDescending { it.key }
|
||||
.sortedByDescending { it.value.size }
|
||||
.map { it.value.first() })
|
||||
.map { it.value.first() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,22 +139,13 @@ class MutableFSCovers(private val context: Context) : MutableCovers<FDCover> {
|
||||
private companion object {
|
||||
private val preferredCoverNames = listOf("front", "art", "album", "folder", "cover")
|
||||
|
||||
private val preferredFormats =
|
||||
listOf(
|
||||
"image/webp",
|
||||
"image/jpg",
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
)
|
||||
private val preferredFormats = listOf("image/webp", "image/jpg", "image/jpeg", "image/png")
|
||||
|
||||
private val preferredExtensions = listOf("webp", "jpg", "jpeg", "png")
|
||||
}
|
||||
}
|
||||
|
||||
private data class FolderCoverImpl(
|
||||
private val context: Context,
|
||||
private val uri: Uri,
|
||||
) : FDCover {
|
||||
private data class FolderCoverImpl(private val context: Context, private val uri: Uri) : FDCover {
|
||||
override val id = PREFIX + uri.toString()
|
||||
|
||||
// Implies that client will manage freeing the resources themselves.
|
||||
|
||||
@@ -69,7 +69,7 @@ class StoredCovers(private val coverStorage: CoverStorage) : Covers<FDCover> {
|
||||
class MutableStoredCovers(
|
||||
private val src: MutableCovers<MemoryCover>,
|
||||
private val coverStorage: CoverStorage,
|
||||
private val transcoding: Transcoding
|
||||
private val transcoding: Transcoding,
|
||||
) : MutableCovers<FDCover> {
|
||||
private val base = StoredCovers(coverStorage)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ data class Directory(
|
||||
override val uri: Uri?,
|
||||
override val path: Path,
|
||||
val parent: Deferred<Directory>?,
|
||||
var children: List<File>
|
||||
var children: List<File>,
|
||||
) : FSEntry
|
||||
|
||||
data class File(
|
||||
@@ -48,7 +48,7 @@ data class File(
|
||||
val modifiedMs: Long,
|
||||
val mimeType: String,
|
||||
val size: Long,
|
||||
val parent: Deferred<Directory>?
|
||||
val parent: Deferred<Directory>?,
|
||||
) : FSEntry
|
||||
|
||||
sealed interface FSUpdate {
|
||||
|
||||
@@ -39,7 +39,8 @@ sealed class Location(val uri: Uri, val path: Path) {
|
||||
context.contentResolverSafe.takePersistableUriPermission(
|
||||
uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
// Not fully sure what happens if I'm disallowed to take the permission,
|
||||
// check for both circumstances (error or no-op)
|
||||
|
||||
@@ -27,10 +27,7 @@ import java.io.File
|
||||
* @param volume The volume that the path is on.
|
||||
* @param components The components of the path of the file, relative to the root of the volume.
|
||||
*/
|
||||
data class Path(
|
||||
val volume: Volume,
|
||||
val components: Components,
|
||||
) {
|
||||
data class Path(val volume: Volume, val components: Components) {
|
||||
/** The name of the file/directory. */
|
||||
val name: String?
|
||||
get() = components.name
|
||||
|
||||
@@ -50,7 +50,7 @@ class MediaStore
|
||||
private constructor(
|
||||
private val context: Context,
|
||||
private val volumeManager: VolumeManager,
|
||||
private val query: Query
|
||||
private val query: Query,
|
||||
) : FS {
|
||||
private val pathInterpreterFactory = MediaStorePathInterpreter.Factory.from(volumeManager)
|
||||
|
||||
@@ -93,49 +93,49 @@ private constructor(
|
||||
AOSPMediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
projection,
|
||||
selector,
|
||||
args.toTypedArray()) { cursor ->
|
||||
val pathInterpreter = pathInterpreterFactory.wrap(cursor)
|
||||
val idIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns._ID)
|
||||
val mimeTypeIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
val sizeIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.SIZE)
|
||||
val dateAddedIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.DATE_ADDED)
|
||||
val dateModifiedIndex =
|
||||
cursor.getColumnIndexOrThrow(
|
||||
AOSPMediaStore.Audio.AudioColumns.DATE_MODIFIED)
|
||||
args.toTypedArray(),
|
||||
) { cursor ->
|
||||
val pathInterpreter = pathInterpreterFactory.wrap(cursor)
|
||||
val idIndex = cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns._ID)
|
||||
val mimeTypeIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
val sizeIndex = cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.SIZE)
|
||||
val dateAddedIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.DATE_ADDED)
|
||||
val dateModifiedIndex =
|
||||
cursor.getColumnIndexOrThrow(AOSPMediaStore.Audio.AudioColumns.DATE_MODIFIED)
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
val path = pathInterpreter.extract() ?: continue
|
||||
while (cursor.moveToNext()) {
|
||||
val path = pathInterpreter.extract() ?: continue
|
||||
|
||||
val id = cursor.getLong(idIndex)
|
||||
val uri =
|
||||
Uri.withAppendedPath(
|
||||
AOSPMediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id.toString())
|
||||
val mimeType = cursor.getStringOrNull(mimeTypeIndex) ?: "audio/*"
|
||||
val size = cursor.getLong(sizeIndex)
|
||||
val dateAdded =
|
||||
cursor.getLong(dateAddedIndex) * 1000 // Convert to milliseconds
|
||||
val dateModified =
|
||||
cursor.getLong(dateModifiedIndex) * 1000 // Convert to milliseconds
|
||||
val id = cursor.getLong(idIndex)
|
||||
val uri =
|
||||
Uri.withAppendedPath(
|
||||
AOSPMediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
id.toString(),
|
||||
)
|
||||
val mimeType = cursor.getStringOrNull(mimeTypeIndex) ?: "audio/*"
|
||||
val size = cursor.getLong(sizeIndex)
|
||||
val dateAdded = cursor.getLong(dateAddedIndex) * 1000 // Convert to milliseconds
|
||||
val dateModified =
|
||||
cursor.getLong(dateModifiedIndex) * 1000 // Convert to milliseconds
|
||||
|
||||
// Create file with empty deferred parent
|
||||
val deviceFile =
|
||||
File(
|
||||
uri = uri,
|
||||
path = path,
|
||||
modifiedMs = dateModified,
|
||||
mimeType = mimeType,
|
||||
size = size,
|
||||
addedMs = ForwardDateAdded(dateAdded),
|
||||
parent = null)
|
||||
// Create file with empty deferred parent
|
||||
val deviceFile =
|
||||
File(
|
||||
uri = uri,
|
||||
path = path,
|
||||
modifiedMs = dateModified,
|
||||
mimeType = mimeType,
|
||||
size = size,
|
||||
addedMs = ForwardDateAdded(dateAdded),
|
||||
parent = null,
|
||||
)
|
||||
|
||||
allFiles.add(deviceFile)
|
||||
it.send(deviceFile)
|
||||
}
|
||||
allFiles.add(deviceFile)
|
||||
it.send(deviceFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,12 +150,12 @@ private constructor(
|
||||
data class Query(
|
||||
val mode: FilterMode,
|
||||
val filtered: List<Location.Unopened>,
|
||||
val excludeNonMusic: Boolean
|
||||
val excludeNonMusic: Boolean,
|
||||
)
|
||||
|
||||
enum class FilterMode {
|
||||
INCLUDE,
|
||||
EXCLUDE
|
||||
EXCLUDE,
|
||||
}
|
||||
|
||||
private class ForwardDateAdded(val dateAdded: Long) : AddedMs {
|
||||
@@ -165,7 +165,10 @@ private constructor(
|
||||
companion object {
|
||||
fun from(context: Context, query: Query) =
|
||||
MediaStore(
|
||||
context = context, volumeManager = VolumeManager.from(context), query = query)
|
||||
context = context,
|
||||
volumeManager = VolumeManager.from(context),
|
||||
query = query,
|
||||
)
|
||||
|
||||
/**
|
||||
* The base selector that works across all versions of android. Excludes files with zero
|
||||
@@ -180,6 +183,7 @@ private constructor(
|
||||
AOSPMediaStore.Audio.AudioColumns.DATE_ADDED,
|
||||
AOSPMediaStore.Audio.AudioColumns.DATE_MODIFIED,
|
||||
AOSPMediaStore.Audio.AudioColumns.SIZE,
|
||||
AOSPMediaStore.Audio.AudioColumns.MIME_TYPE)
|
||||
AOSPMediaStore.Audio.AudioColumns.MIME_TYPE,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ internal interface DocumentPathFactory {
|
||||
private class DocumentPathFactoryImpl(
|
||||
private val context: Context,
|
||||
private val volumeManager: VolumeManager,
|
||||
private val mediaStorePathInterpreterFactory: MediaStorePathInterpreter.Factory
|
||||
private val mediaStorePathInterpreterFactory: MediaStorePathInterpreter.Factory,
|
||||
) : DocumentPathFactory {
|
||||
override fun unpackDocumentUri(uri: Uri): Path? {
|
||||
val id = DocumentsContract.getDocumentId(uri)
|
||||
@@ -92,10 +92,12 @@ private class DocumentPathFactoryImpl(
|
||||
|
||||
val path =
|
||||
context.contentResolverSafe.useQuery(
|
||||
contentUri, mediaStorePathInterpreterFactory.projection) {
|
||||
it.moveToFirst()
|
||||
mediaStorePathInterpreterFactory.wrap(it).extract()
|
||||
}
|
||||
contentUri,
|
||||
mediaStorePathInterpreterFactory.projection,
|
||||
) {
|
||||
it.moveToFirst()
|
||||
mediaStorePathInterpreterFactory.wrap(it).extract()
|
||||
}
|
||||
|
||||
if (path != null) {
|
||||
return path
|
||||
@@ -113,7 +115,9 @@ private class DocumentPathFactoryImpl(
|
||||
// parsed into a Directory instance.
|
||||
val docUri =
|
||||
DocumentsContract.buildDocumentUriUsingTree(
|
||||
uri, DocumentsContract.getTreeDocumentId(uri))
|
||||
uri,
|
||||
DocumentsContract.getTreeDocumentId(uri),
|
||||
)
|
||||
val treeUri = DocumentsContract.getTreeDocumentId(docUri)
|
||||
return fromDocumentId(treeUri)
|
||||
}
|
||||
@@ -151,6 +155,7 @@ private class DocumentPathFactoryImpl(
|
||||
private val POSSIBLE_CONTENT_URI_PREFIXES =
|
||||
arrayOf(
|
||||
Uri.parse("content://downloads/public_downloads"),
|
||||
Uri.parse("content://downloads/my_downloads"))
|
||||
Uri.parse("content://downloads/my_downloads"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,9 @@ private constructor(private val cursor: Cursor, volumeManager: VolumeManager) :
|
||||
override val projection: Array<String>
|
||||
get() =
|
||||
arrayOf(
|
||||
MediaStore.Audio.AudioColumns.DISPLAY_NAME, MediaStore.Audio.AudioColumns.DATA)
|
||||
MediaStore.Audio.AudioColumns.DISPLAY_NAME,
|
||||
MediaStore.Audio.AudioColumns.DATA,
|
||||
)
|
||||
|
||||
override fun createSelector(
|
||||
paths: List<Path>
|
||||
@@ -200,7 +202,8 @@ private constructor(private val cursor: Cursor, volumeManager: VolumeManager) :
|
||||
// compared to DATA.
|
||||
MediaStore.Audio.AudioColumns.DISPLAY_NAME,
|
||||
MediaStore.Audio.AudioColumns.VOLUME_NAME,
|
||||
MediaStore.Audio.AudioColumns.RELATIVE_PATH)
|
||||
MediaStore.Audio.AudioColumns.RELATIVE_PATH,
|
||||
)
|
||||
|
||||
// The selector should be configured to compare both the volume name and relative path
|
||||
// of the given directories, albeit with some conversion to the analogous MediaStore
|
||||
|
||||
@@ -46,7 +46,7 @@ internal fun ContentResolver.safeQuery(
|
||||
uri: Uri,
|
||||
projection: Array<out String>,
|
||||
selector: String? = null,
|
||||
args: Array<String>? = null
|
||||
args: Array<String>? = null,
|
||||
) = requireNotNull(query(uri, projection, selector, args, null)) { "ContentResolver query failed" }
|
||||
|
||||
/**
|
||||
@@ -68,5 +68,5 @@ internal inline fun <reified R> ContentResolver.useQuery(
|
||||
projection: Array<out String>,
|
||||
selector: String? = null,
|
||||
args: Array<String>? = null,
|
||||
block: (Cursor) -> R
|
||||
block: (Cursor) -> R,
|
||||
) = safeQuery(uri, projection, selector, args).use(block)
|
||||
|
||||
@@ -52,7 +52,7 @@ class SAF
|
||||
private constructor(
|
||||
private val context: Context,
|
||||
private val contentResolver: ContentResolver,
|
||||
private val query: Query
|
||||
private val query: Query,
|
||||
) : FS {
|
||||
override suspend fun explore(files: Channel<File>): Deferred<Result<Unit>> = coroutineScope {
|
||||
tryAsyncWith(files, Dispatchers.Main) {
|
||||
@@ -64,7 +64,8 @@ private constructor(
|
||||
location.path,
|
||||
null,
|
||||
query.exclude.mapTo(mutableSetOf()) { it.path },
|
||||
files)
|
||||
files,
|
||||
)
|
||||
}
|
||||
.tryAwaitAll()
|
||||
}
|
||||
@@ -90,7 +91,7 @@ private constructor(
|
||||
relativePath: Path,
|
||||
parent: Deferred<Directory>?,
|
||||
exclude: Set<Path>,
|
||||
files: Channel<File>
|
||||
files: Channel<File>,
|
||||
): Deferred<Result<Unit>> =
|
||||
tryAsync(Dispatchers.IO) {
|
||||
// Make a kotlin future
|
||||
@@ -132,7 +133,14 @@ private constructor(
|
||||
if (mimeType == DocumentsContract.Document.MIME_TYPE_DIR) {
|
||||
recursive.add(
|
||||
exploreDirectoryImpl(
|
||||
rootUri, childId, newPath, directoryDeferred, exclude, files))
|
||||
rootUri,
|
||||
childId,
|
||||
newPath,
|
||||
directoryDeferred,
|
||||
exclude,
|
||||
files,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
val size = cursor.getLong(sizeIndex)
|
||||
val file =
|
||||
@@ -148,7 +156,8 @@ private constructor(
|
||||
JoinAddedMs(context, childUri)
|
||||
} else {
|
||||
NullAddedMs
|
||||
})
|
||||
},
|
||||
)
|
||||
children.add(file)
|
||||
files.send(file)
|
||||
}
|
||||
@@ -161,7 +170,7 @@ private constructor(
|
||||
data class Query(
|
||||
val source: List<Location.Opened>,
|
||||
val exclude: List<Location.Unopened>,
|
||||
val withHidden: Boolean
|
||||
val withHidden: Boolean,
|
||||
)
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.Q)
|
||||
@@ -174,15 +183,17 @@ private constructor(
|
||||
return null
|
||||
}
|
||||
return context.contentResolverSafe.useQuery(
|
||||
mediaUri, arrayOf(AOSPMediaStore.Files.FileColumns.DATE_ADDED)) {
|
||||
if (it.moveToFirst()) {
|
||||
val dateAddedIndex =
|
||||
it.getColumnIndexOrThrow(AOSPMediaStore.Files.FileColumns.DATE_ADDED)
|
||||
it.getLong(dateAddedIndex) * 1000
|
||||
} else {
|
||||
null
|
||||
}
|
||||
mediaUri,
|
||||
arrayOf(AOSPMediaStore.Files.FileColumns.DATE_ADDED),
|
||||
) {
|
||||
if (it.moveToFirst()) {
|
||||
val dateAddedIndex =
|
||||
it.getColumnIndexOrThrow(AOSPMediaStore.Files.FileColumns.DATE_ADDED)
|
||||
it.getLong(dateAddedIndex) * 1000
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +210,7 @@ private constructor(
|
||||
DocumentsContract.Document.COLUMN_DISPLAY_NAME,
|
||||
DocumentsContract.Document.COLUMN_MIME_TYPE,
|
||||
DocumentsContract.Document.COLUMN_SIZE,
|
||||
DocumentsContract.Document.COLUMN_LAST_MODIFIED)
|
||||
DocumentsContract.Document.COLUMN_LAST_MODIFIED,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.os.Looper
|
||||
internal class LocationObserver(
|
||||
private val context: Context,
|
||||
private val uri: Uri,
|
||||
private val onUpdate: () -> Unit
|
||||
private val onUpdate: () -> Unit,
|
||||
) : ContentObserver(Handler(Looper.getMainLooper())), Runnable {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ internal data class MusicGraph(
|
||||
val albumVertex: List<AlbumVertex>,
|
||||
val artistVertex: List<ArtistVertex>,
|
||||
val genreVertex: List<GenreVertex>,
|
||||
val playlistVertex: Set<PlaylistVertex>
|
||||
val playlistVertex: Set<PlaylistVertex>,
|
||||
) {
|
||||
interface Builder {
|
||||
fun add(preSong: PreSong)
|
||||
@@ -158,7 +158,8 @@ internal data class MusicGraph(
|
||||
val songIndex = this@MusicGraph.songVertex.indexOf(it)
|
||||
if (songIndex >= 0) {
|
||||
appendLine(
|
||||
" playlist_$playlistIndex -> song_$songIndex [color=orange];")
|
||||
" playlist_$playlistIndex -> song_$songIndex [color=orange];"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,7 +222,8 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
|
||||
preSong,
|
||||
albumVertex,
|
||||
songArtistVertices.toMutableList(),
|
||||
songGenreVertices.toMutableList())
|
||||
songGenreVertices.toMutableList(),
|
||||
)
|
||||
albumVertex.songVertices.add(songVertex)
|
||||
|
||||
songArtistVertices.forEach { artistVertex ->
|
||||
@@ -321,7 +323,8 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
|
||||
albumVertices.values.toList(),
|
||||
artistVertices.values.toList(),
|
||||
genreVertices.values.toList(),
|
||||
playlistVertices)
|
||||
playlistVertices,
|
||||
)
|
||||
|
||||
return graph
|
||||
}
|
||||
@@ -480,7 +483,8 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
|
||||
strippedMbidCluster.map {
|
||||
val noAlbumArtistPreAlbum =
|
||||
it.preAlbum.copy(
|
||||
preArtists = PreArtistsFrom.Individual(it.preAlbum.preArtists.preArtists))
|
||||
preArtists = PreArtistsFrom.Individual(it.preAlbum.preArtists.preArtists)
|
||||
)
|
||||
val simpleAlbumArtistVertex =
|
||||
albumVertices.getOrPut(noAlbumArtistPreAlbum) {
|
||||
AlbumVertex(noAlbumArtistPreAlbum, it.artistVertices.toMutableList())
|
||||
@@ -533,7 +537,7 @@ internal class SongVertex(
|
||||
val preSong: PreSong,
|
||||
var albumVertex: AlbumVertex,
|
||||
var artistVertices: MutableList<ArtistVertex>,
|
||||
var genreVertices: MutableList<GenreVertex>
|
||||
var genreVertices: MutableList<GenreVertex>,
|
||||
) : Vertex {
|
||||
override var tag: Any? = null
|
||||
|
||||
@@ -548,9 +552,7 @@ internal class AlbumVertex(val preAlbum: PreAlbum, var artistVertices: MutableLi
|
||||
override fun toString() = "AlbumVertex(preAlbum=$preAlbum)"
|
||||
}
|
||||
|
||||
internal class ArtistVertex(
|
||||
val preArtist: PreArtist,
|
||||
) : Vertex {
|
||||
internal class ArtistVertex(val preArtist: PreArtist) : Vertex {
|
||||
val songVertices = mutableSetOf<SongVertex>()
|
||||
val albumVertices = mutableSetOf<AlbumVertex>()
|
||||
val genreVertices = mutableSetOf<GenreVertex>()
|
||||
|
||||
@@ -23,7 +23,7 @@ data class Metadata(
|
||||
val xiph: Map<String, List<String>>,
|
||||
val mp4: Map<String, List<String>>,
|
||||
val cover: ByteArray?,
|
||||
val properties: Properties
|
||||
val properties: Properties,
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
||||
@@ -52,7 +52,8 @@ internal class ArtistImpl(private val core: ArtistCore) : Artist {
|
||||
override val durationMs = core.songs.sumOf { it.durationMs }
|
||||
override val covers =
|
||||
CoverCollection.from(
|
||||
core.songs.mapNotNull { it.cover }.ifEmpty { core.albums.flatMap { it.covers.covers } })
|
||||
core.songs.mapNotNull { it.cover }.ifEmpty { core.albums.flatMap { it.covers.covers } }
|
||||
)
|
||||
|
||||
private val hashCode =
|
||||
31 * (31 * uid.hashCode() + core.preArtist.hashCode()) * core.songs.hashCode()
|
||||
|
||||
@@ -38,7 +38,7 @@ internal interface LibraryFactory {
|
||||
fun create(
|
||||
graph: MusicGraph,
|
||||
storedPlaylists: StoredPlaylists,
|
||||
playlistInterpreter: PlaylistInterpreter
|
||||
playlistInterpreter: PlaylistInterpreter,
|
||||
): MutableLibrary
|
||||
|
||||
companion object {
|
||||
@@ -50,7 +50,7 @@ private class LibraryFactoryImpl() : LibraryFactory {
|
||||
override fun create(
|
||||
graph: MusicGraph,
|
||||
storedPlaylists: StoredPlaylists,
|
||||
playlistInterpreter: PlaylistInterpreter
|
||||
playlistInterpreter: PlaylistInterpreter,
|
||||
): MutableLibrary {
|
||||
val songs =
|
||||
graph.songVertex.mapTo(mutableSetOf()) { vertex ->
|
||||
@@ -73,7 +73,14 @@ private class LibraryFactoryImpl() : LibraryFactory {
|
||||
PlaylistImpl(PlaylistVertexCore(vertex))
|
||||
}
|
||||
return LibraryImpl(
|
||||
songs, albums, artists, genres, playlists, storedPlaylists, playlistInterpreter)
|
||||
songs,
|
||||
albums,
|
||||
artists,
|
||||
genres,
|
||||
playlists,
|
||||
storedPlaylists,
|
||||
playlistInterpreter,
|
||||
)
|
||||
}
|
||||
|
||||
private class SongVertexCore(private val vertex: SongVertex) : SongCore {
|
||||
|
||||
@@ -34,7 +34,7 @@ internal data class LibraryImpl(
|
||||
override val genres: Set<GenreImpl>,
|
||||
override val playlists: Set<PlaylistImpl>,
|
||||
private val storedPlaylists: StoredPlaylists,
|
||||
private val playlistInterpreter: PlaylistInterpreter
|
||||
private val playlistInterpreter: PlaylistInterpreter,
|
||||
) : MutableLibrary {
|
||||
private val songUidMap = songs.associateBy { it.uid }
|
||||
private val v400SongUidMap = songs.associateBy { it.v400Uid }
|
||||
@@ -116,6 +116,6 @@ internal data class LibraryImpl(
|
||||
|
||||
private class NewPlaylistCore(
|
||||
override val prePlaylist: PrePlaylistInfo,
|
||||
override val songs: List<Song>
|
||||
override val songs: List<Song>,
|
||||
) : PlaylistCore
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ internal interface EvaluateStep {
|
||||
TagInterpreter.new(interpretation),
|
||||
PlaylistInterpreter.new(interpretation),
|
||||
config.storage.storedPlaylists,
|
||||
LibraryFactory.new())
|
||||
LibraryFactory.new(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ private class EvaluateStepImpl(
|
||||
private val tagInterpreter: TagInterpreter,
|
||||
private val playlistInterpreter: PlaylistInterpreter,
|
||||
private val storedPlaylists: StoredPlaylists,
|
||||
private val libraryFactory: LibraryFactory
|
||||
private val libraryFactory: LibraryFactory,
|
||||
) : EvaluateStep {
|
||||
override suspend fun evaluate(extractedMusic: Channel<Extracted>): MutableLibrary {
|
||||
val builder = MusicGraph.builder()
|
||||
|
||||
@@ -48,7 +48,7 @@ internal interface ExploreStep {
|
||||
private class ExploreStepImpl(private val fs: FS, private val storage: Storage) : ExploreStep {
|
||||
override suspend fun explore(
|
||||
scope: CoroutineScope,
|
||||
explored: Channel<Explored>
|
||||
explored: Channel<Explored>,
|
||||
): Deferred<Result<Unit>> {
|
||||
val files = Channel<File>(Channel.UNLIMITED)
|
||||
val filesTask = fs.explore(files)
|
||||
@@ -73,8 +73,10 @@ private class ExploreStepImpl(private val fs: FS, private val storage: Storage)
|
||||
when (item) {
|
||||
is Finalized -> item
|
||||
is NeedsCover -> {
|
||||
when (val coverResult =
|
||||
item.cachedSong.coverId?.let { id -> storage.covers.obtain(id) }) {
|
||||
when (
|
||||
val coverResult =
|
||||
item.cachedSong.coverId?.let { id -> storage.covers.obtain(id) }
|
||||
) {
|
||||
is CoverResult.Hit ->
|
||||
Finalized(item.cachedSong.toRawSong(coverResult.cover))
|
||||
null -> Finalized(item.cachedSong.toRawSong(null))
|
||||
|
||||
@@ -40,7 +40,7 @@ internal interface ExtractStep {
|
||||
suspend fun extract(
|
||||
scope: CoroutineScope,
|
||||
explored: Channel<Explored>,
|
||||
extracted: Channel<Extracted>
|
||||
extracted: Channel<Extracted>,
|
||||
): Deferred<Result<Unit>>
|
||||
|
||||
companion object {
|
||||
@@ -49,7 +49,8 @@ internal interface ExtractStep {
|
||||
MetadataExtractor.from(context),
|
||||
TagParser.new(),
|
||||
config.storage.cache,
|
||||
config.storage.covers)
|
||||
config.storage.covers,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,12 +58,12 @@ private class ExtractStepImpl(
|
||||
private val metadataExtractor: MetadataExtractor,
|
||||
private val tagParser: TagParser,
|
||||
private val cache: MutableCache,
|
||||
private val covers: MutableCovers<out Cover>
|
||||
private val covers: MutableCovers<out Cover>,
|
||||
) : ExtractStep {
|
||||
override suspend fun extract(
|
||||
scope: CoroutineScope,
|
||||
explored: Channel<Explored>,
|
||||
extracted: Channel<Extracted>
|
||||
extracted: Channel<Extracted>,
|
||||
): Deferred<Result<Unit>> {
|
||||
val addingMs = System.currentTimeMillis()
|
||||
val extract = Channel<ParsedExtractItem>(PARALLELISM)
|
||||
@@ -104,7 +105,9 @@ private class ExtractStepImpl(
|
||||
// added query is basically free, it's only saf that has
|
||||
// it's slow hacky workaround that we must accommodate
|
||||
// here.)
|
||||
item.newSong.file.addedMs.resolve() ?: addingMs))
|
||||
item.newSong.file.addedMs.resolve() ?: addingMs,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,5 +53,5 @@ internal data class RawSong(
|
||||
val properties: Properties,
|
||||
val tags: ParsedTags,
|
||||
val cover: Cover?,
|
||||
val addedMs: Long
|
||||
val addedMs: Long,
|
||||
) : Explored.Known, Extracted.Valid
|
||||
|
||||
@@ -57,7 +57,10 @@ interface ExternalPlaylistManager {
|
||||
companion object {
|
||||
fun from(context: Context): ExternalPlaylistManager =
|
||||
ExternalPlaylistManagerImpl(
|
||||
context, DocumentPathFactory.from(context), M3U.from(context))
|
||||
context,
|
||||
DocumentPathFactory.from(context),
|
||||
M3U.from(context),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +90,7 @@ typealias PossiblePaths = List<Path>
|
||||
private class ExternalPlaylistManagerImpl(
|
||||
private val context: Context,
|
||||
private val documentPathFactory: DocumentPathFactory,
|
||||
private val m3u: M3U
|
||||
private val m3u: M3U,
|
||||
) : ExternalPlaylistManager {
|
||||
override suspend fun import(uri: Uri): ImportedPlaylist? {
|
||||
val filePath = documentPathFactory.unpackDocumentUri(uri) ?: return null
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.oxycblt.musikr.Song
|
||||
internal data class PlaylistFile(
|
||||
val name: String,
|
||||
val songPointers: List<SongPointer>,
|
||||
val handle: PlaylistHandle
|
||||
val handle: PlaylistHandle,
|
||||
)
|
||||
|
||||
internal sealed interface SongPointer {
|
||||
|
||||
@@ -38,7 +38,8 @@ import org.oxycblt.musikr.Music
|
||||
@Database(
|
||||
entities = [PlaylistInfo::class, PlaylistSong::class, PlaylistSongCrossRef::class],
|
||||
version = 30,
|
||||
exportSchema = false)
|
||||
exportSchema = false,
|
||||
)
|
||||
@TypeConverters(Music.UID.TypeConverters::class)
|
||||
internal abstract class PlaylistDatabase : RoomDatabase() {
|
||||
abstract fun playlistDao(): PlaylistDao
|
||||
@@ -46,7 +47,10 @@ internal abstract class PlaylistDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
fun from(context: Context) =
|
||||
Room.databaseBuilder(
|
||||
context.applicationContext, PlaylistDatabase::class.java, "user_music.db")
|
||||
context.applicationContext,
|
||||
PlaylistDatabase::class.java,
|
||||
"user_music.db",
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
@@ -83,8 +87,11 @@ internal abstract class PlaylistDao {
|
||||
insertRefs(
|
||||
rawPlaylist.songs.map {
|
||||
PlaylistSongCrossRef(
|
||||
playlistUid = rawPlaylist.playlistInfo.playlistUid, songUid = it.songUid)
|
||||
})
|
||||
playlistUid = rawPlaylist.playlistInfo.playlistUid,
|
||||
songUid = it.songUid,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +126,8 @@ internal abstract class PlaylistDao {
|
||||
open suspend fun insertPlaylistSongs(playlistUid: Music.UID, songs: List<PlaylistSong>) {
|
||||
insertSongs(songs)
|
||||
insertRefs(
|
||||
songs.map { PlaylistSongCrossRef(playlistUid = playlistUid, songUid = it.songUid) })
|
||||
songs.map { PlaylistSongCrossRef(playlistUid = playlistUid, songUid = it.songUid) }
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +142,8 @@ internal abstract class PlaylistDao {
|
||||
deleteRefs(playlistUid)
|
||||
insertSongs(songs)
|
||||
insertRefs(
|
||||
songs.map { PlaylistSongCrossRef(playlistUid = playlistUid, songUid = it.songUid) })
|
||||
songs.map { PlaylistSongCrossRef(playlistUid = playlistUid, songUid = it.songUid) }
|
||||
)
|
||||
}
|
||||
|
||||
/** Internal, do not use. */
|
||||
|
||||
@@ -36,8 +36,9 @@ internal data class RawPlaylist(
|
||||
@Relation(
|
||||
parentColumn = "playlistUid",
|
||||
entityColumn = "songUid",
|
||||
associateBy = Junction(PlaylistSongCrossRef::class))
|
||||
val songs: List<PlaylistSong>
|
||||
associateBy = Junction(PlaylistSongCrossRef::class),
|
||||
)
|
||||
val songs: List<PlaylistSong>,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -63,5 +64,5 @@ internal data class RawPlaylist(
|
||||
internal data class PlaylistSongCrossRef(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
@ColumnInfo(index = true) val playlistUid: Music.UID,
|
||||
@ColumnInfo(index = true) val songUid: Music.UID
|
||||
@ColumnInfo(index = true) val songUid: Music.UID,
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.oxycblt.musikr.playlist.PlaylistHandle
|
||||
|
||||
internal class StoredPlaylistHandle(
|
||||
private val playlistInfo: PlaylistInfo,
|
||||
private val playlistDao: PlaylistDao
|
||||
private val playlistDao: PlaylistDao,
|
||||
) : PlaylistHandle {
|
||||
override val uid = playlistInfo.playlistUid
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ private class StoredPlaylistsImpl(private val playlistDao: PlaylistDao) : Stored
|
||||
PlaylistFile(
|
||||
it.playlistInfo.name,
|
||||
it.songs.map { song -> SongPointer.UID(song.songUid) },
|
||||
StoredPlaylistHandle(it.playlistInfo, playlistDao))
|
||||
StoredPlaylistHandle(it.playlistInfo, playlistDao),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ private class PlaylistInterpreterImpl(private val naming: Naming) : PlaylistInte
|
||||
name = naming.name(file.name, null),
|
||||
rawName = file.name,
|
||||
handle = file.handle,
|
||||
songPointers = file.songPointers)
|
||||
songPointers = file.songPointers,
|
||||
)
|
||||
|
||||
override fun interpret(name: String, handle: PlaylistHandle): PostPlaylist =
|
||||
PostPlaylist(name = naming.name(name, null), rawName = name, handle = handle)
|
||||
|
||||
@@ -32,7 +32,7 @@ internal data class PrePlaylist(
|
||||
override val name: Name.Known,
|
||||
override val rawName: String?,
|
||||
override val handle: PlaylistHandle,
|
||||
val songPointers: List<SongPointer>
|
||||
val songPointers: List<SongPointer>,
|
||||
) : PrePlaylistInfo
|
||||
|
||||
internal data class PostPlaylist(
|
||||
|
||||
@@ -66,7 +66,7 @@ abstract class M3U {
|
||||
playlist: Playlist,
|
||||
outputStream: OutputStream,
|
||||
workingDirectory: Path,
|
||||
config: ExportConfig
|
||||
config: ExportConfig,
|
||||
)
|
||||
|
||||
companion object {
|
||||
@@ -143,13 +143,14 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
|
||||
else ->
|
||||
listOf(
|
||||
InterpretedPath(Components.parseUnix(path), false),
|
||||
InterpretedPath(Components.parseWindows(path), true))
|
||||
InterpretedPath(Components.parseWindows(path), true),
|
||||
)
|
||||
}
|
||||
|
||||
private fun expandInterpretation(
|
||||
path: InterpretedPath,
|
||||
workingDirectory: Path,
|
||||
volumes: List<Volume>
|
||||
volumes: List<Volume>,
|
||||
): List<Path> {
|
||||
val absoluteInterpretation = Path(workingDirectory.volume, path.components)
|
||||
val relativeInterpretation =
|
||||
@@ -172,7 +173,7 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
|
||||
playlist: Playlist,
|
||||
outputStream: OutputStream,
|
||||
workingDirectory: Path,
|
||||
config: ExportConfig
|
||||
config: ExportConfig,
|
||||
) {
|
||||
val writer = outputStream.bufferedWriter()
|
||||
// Try to be as compliant to the spec as possible while also cramming it full of extensions
|
||||
@@ -252,9 +253,11 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
|
||||
// and them combine them with the correct relative elements to make sure they
|
||||
// resolve the same.
|
||||
var commonIndex = 0
|
||||
while (commonIndex < components.size &&
|
||||
commonIndex < workingDirectory.components.size &&
|
||||
components[commonIndex] == workingDirectory.components[commonIndex]) {
|
||||
while (
|
||||
commonIndex < components.size &&
|
||||
commonIndex < workingDirectory.components.size &&
|
||||
components[commonIndex] == workingDirectory.components[commonIndex]
|
||||
) {
|
||||
++commonIndex
|
||||
}
|
||||
|
||||
@@ -267,7 +270,7 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
|
||||
}
|
||||
commonIndex == components.size -> {
|
||||
// The working directory is deeper in the path, backtrack.
|
||||
for (i in 0 ..< workingDirectory.components.size - commonIndex) {
|
||||
for (i in 0..<workingDirectory.components.size - commonIndex) {
|
||||
relativeComponents = relativeComponents.child("..")
|
||||
}
|
||||
}
|
||||
@@ -278,7 +281,7 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
|
||||
}
|
||||
else -> {
|
||||
// The paths are siblings. Backtrack and append as needed.
|
||||
for (i in 0 ..< workingDirectory.components.size - commonIndex) {
|
||||
for (i in 0..<workingDirectory.components.size - commonIndex) {
|
||||
relativeComponents = relativeComponents.child("..")
|
||||
}
|
||||
relativeComponents = relativeComponents.child(depth(commonIndex))
|
||||
|
||||
@@ -89,7 +89,7 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
|
||||
/** The earliest [Date] in the range. */
|
||||
val min: Date,
|
||||
/** the latest [Date] in the range. May be the same as [min]. ] */
|
||||
val max: Date
|
||||
val max: Date,
|
||||
) : Comparable<Range> {
|
||||
init {
|
||||
check(min <= max) { "Min date must be <= max date" }
|
||||
@@ -109,7 +109,8 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
|
||||
*/
|
||||
private val ISO8601_REGEX by lazy {
|
||||
Regex(
|
||||
"""^(\d{4})([-.](\d{2})([-.](\d{2})([T ](\d{2})([:.](\d{2})([:.](\d{2})(Z)?)?)?)?)?)?$""")
|
||||
"""^(\d{4})([-.](\d{2})([-.](\d{2})([T ](\d{2})([:.](\d{2})([:.](\d{2})(Z)?)?)?)?)?)?$"""
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +127,8 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
|
||||
from(
|
||||
stringYear.substring(0..3).toInt(),
|
||||
stringYear.substring(4..5).toInt(),
|
||||
stringYear.substring(6..7).toInt())
|
||||
stringYear.substring(6..7).toInt(),
|
||||
)
|
||||
} else {
|
||||
fromTokens(listOf(year))
|
||||
}
|
||||
|
||||
@@ -90,8 +90,10 @@ class Token internal constructor(internal val collationKey: CollationKey, intern
|
||||
|
||||
// Numeric strings must be ordered by magnitude, thus immediately short-circuit
|
||||
// the comparison if the lengths do not match.
|
||||
if (type == Type.NUMERIC &&
|
||||
collationKey.sourceString.length != other.collationKey.sourceString.length) {
|
||||
if (
|
||||
type == Type.NUMERIC &&
|
||||
collationKey.sourceString.length != other.collationKey.sourceString.length
|
||||
) {
|
||||
return collationKey.sourceString.length - other.collationKey.sourceString.length
|
||||
}
|
||||
|
||||
@@ -103,12 +105,12 @@ class Token internal constructor(internal val collationKey: CollationKey, intern
|
||||
/** Compare as a digit string, like "65". */
|
||||
NUMERIC,
|
||||
/** Compare as a standard alphanumeric string, like "65daysofstatic" */
|
||||
LEXICOGRAPHIC
|
||||
LEXICOGRAPHIC,
|
||||
}
|
||||
}
|
||||
|
||||
enum class Placeholder {
|
||||
ALBUM,
|
||||
ARTIST,
|
||||
GENRE
|
||||
GENRE,
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ sealed interface ReleaseType {
|
||||
LIVE,
|
||||
|
||||
/** A release consisting of another Artists remix of a prior performance. */
|
||||
REMIX
|
||||
REMIX,
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -145,7 +145,7 @@ sealed interface ReleaseType {
|
||||
*/
|
||||
private inline fun List<String>.parseSecondaryTypes(
|
||||
index: Int,
|
||||
convertRefinement: (Refinement?) -> ReleaseType
|
||||
convertRefinement: (Refinement?) -> ReleaseType,
|
||||
): ReleaseType {
|
||||
val secondary = getOrNull(index)
|
||||
return if (secondary.equals("compilation", true)) {
|
||||
@@ -169,7 +169,7 @@ sealed interface ReleaseType {
|
||||
*/
|
||||
private inline fun parseSecondaryTypeImpl(
|
||||
type: String?,
|
||||
convertRefinement: (Refinement?) -> ReleaseType
|
||||
convertRefinement: (Refinement?) -> ReleaseType,
|
||||
) =
|
||||
when {
|
||||
// Parse all the types that have no children
|
||||
|
||||
@@ -321,4 +321,5 @@ private val genreTable =
|
||||
"Psybient",
|
||||
|
||||
// Auxio's extensions, added because Future Garage is also a good genre.
|
||||
"Future Garage")
|
||||
"Future Garage",
|
||||
)
|
||||
|
||||
@@ -54,7 +54,7 @@ internal data class PreSong(
|
||||
val cover: Cover?,
|
||||
val preAlbum: PreAlbum,
|
||||
val preArtists: List<PreArtist>,
|
||||
val preGenres: List<PreGenre>
|
||||
val preGenres: List<PreGenre>,
|
||||
)
|
||||
|
||||
internal data class PreAlbum(
|
||||
@@ -91,7 +91,4 @@ internal data class PreArtist(val musicBrainzId: UUID?, val name: Name, val rawN
|
||||
?: Music.UID.auxio(Music.UID.Item.ARTIST) { update(rawName) }
|
||||
}
|
||||
|
||||
internal data class PreGenre(
|
||||
val name: Name,
|
||||
val rawName: String?,
|
||||
)
|
||||
internal data class PreGenre(val name: Name, val rawName: String?)
|
||||
|
||||
@@ -48,16 +48,23 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
|
||||
song.tags.artistMusicBrainzIds,
|
||||
song.tags.artistNames,
|
||||
song.tags.artistSortNames,
|
||||
interpretation)
|
||||
interpretation,
|
||||
)
|
||||
val albumPreArtists =
|
||||
makePreArtists(
|
||||
song.tags.albumArtistMusicBrainzIds,
|
||||
song.tags.albumArtistNames,
|
||||
song.tags.albumArtistSortNames,
|
||||
interpretation)
|
||||
interpretation,
|
||||
)
|
||||
val preAlbum =
|
||||
makePreAlbum(
|
||||
song.tags, song.file, individualPreArtists, albumPreArtists, interpretation)
|
||||
song.tags,
|
||||
song.file,
|
||||
individualPreArtists,
|
||||
albumPreArtists,
|
||||
interpretation,
|
||||
)
|
||||
val rawArtists =
|
||||
individualPreArtists.ifEmpty { albumPreArtists }.ifEmpty { listOf(unknownPreArtist()) }
|
||||
val rawGenres =
|
||||
@@ -146,7 +153,8 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
|
||||
preAlbum = preAlbum,
|
||||
preArtists = rawArtists,
|
||||
preGenres = rawGenres,
|
||||
cover = song.cover)
|
||||
cover = song.cover,
|
||||
)
|
||||
}
|
||||
|
||||
private fun makePreAlbum(
|
||||
@@ -154,7 +162,7 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
|
||||
deviceFile: File,
|
||||
individualPreArtists: List<PreArtist>,
|
||||
albumPreArtists: List<PreArtist>,
|
||||
interpretation: Interpretation
|
||||
interpretation: Interpretation,
|
||||
): PreAlbum {
|
||||
val name = parsedTags.albumName ?: deviceFile.path.directory.name
|
||||
return PreAlbum(
|
||||
@@ -167,14 +175,16 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
|
||||
preArtists =
|
||||
PreArtistsFrom.Album(albumPreArtists).takeIf { it.preArtists.isNotEmpty() }
|
||||
?: PreArtistsFrom.Individual(
|
||||
individualPreArtists.ifEmpty { listOf(unknownPreArtist()) }))
|
||||
individualPreArtists.ifEmpty { listOf(unknownPreArtist()) }
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun makePreArtists(
|
||||
rawMusicBrainzIds: List<String>,
|
||||
rawNames: List<String>,
|
||||
rawSortNames: List<String>,
|
||||
interpretation: Interpretation
|
||||
interpretation: Interpretation,
|
||||
): List<PreArtist> {
|
||||
val musicBrainzIds = interpretation.separators.split(rawMusicBrainzIds)
|
||||
val names = interpretation.separators.split(rawNames)
|
||||
@@ -188,7 +198,7 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
|
||||
musicBrainzId: String?,
|
||||
rawName: String?,
|
||||
sortName: String?,
|
||||
interpretation: Interpretation
|
||||
interpretation: Interpretation,
|
||||
): PreArtist {
|
||||
val name = interpretation.naming.name(rawName, sortName, Placeholder.ARTIST)
|
||||
val musicBrainzId = musicBrainzId?.toUuidOrNull()
|
||||
@@ -199,7 +209,7 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
|
||||
|
||||
private fun makePreGenres(
|
||||
parsedTags: ParsedTags,
|
||||
interpretation: Interpretation
|
||||
interpretation: Interpretation,
|
||||
): List<PreGenre> {
|
||||
val genreNames =
|
||||
parsedTags.genreNames.parseId3GenreNames()
|
||||
|
||||
@@ -41,5 +41,5 @@ data class ParsedTags(
|
||||
val albumArtistMusicBrainzIds: List<String> = listOf(),
|
||||
val albumArtistNames: List<String> = listOf(),
|
||||
val albumArtistSortNames: List<String> = listOf(),
|
||||
val genreNames: List<String> = listOf()
|
||||
val genreNames: List<String> = listOf(),
|
||||
)
|
||||
|
||||
@@ -48,15 +48,15 @@ internal fun Metadata.sortName() = (xiph["TITLESORT"] ?: mp4["sonm"] ?: id3v2["T
|
||||
internal fun Metadata.track() =
|
||||
(parseXiphPositionField(
|
||||
xiph["TRACKNUMBER"]?.first(),
|
||||
(xiph["TOTALTRACKS"] ?: xiph["TRACKTOTAL"] ?: xiph["TRACKC"])?.first())
|
||||
?: (mp4["trkn"] ?: id3v2["TRCK"])?.run { first().parseSlashPositionField() })
|
||||
(xiph["TOTALTRACKS"] ?: xiph["TRACKTOTAL"] ?: xiph["TRACKC"])?.first(),
|
||||
) ?: (mp4["trkn"] ?: id3v2["TRCK"])?.run { first().parseSlashPositionField() })
|
||||
|
||||
// Disc and it's subtitle name.
|
||||
internal fun Metadata.disc() =
|
||||
(parseXiphPositionField(
|
||||
xiph["DISCNUMBER"]?.first(),
|
||||
(xiph["TOTALDISCS"] ?: xiph["DISCTOTAL"] ?: xiph["DISCC"])?.run { first() })
|
||||
?: (mp4["disk"] ?: id3v2["TPOS"])?.run { first().parseSlashPositionField() })
|
||||
(xiph["TOTALDISCS"] ?: xiph["DISCTOTAL"] ?: xiph["DISCC"])?.run { first() },
|
||||
) ?: (mp4["disk"] ?: id3v2["TPOS"])?.run { first().parseSlashPositionField() })
|
||||
|
||||
internal fun Metadata.subtitle() = (xiph["DISCSUBTITLE"] ?: id3v2["TSST"])?.first()
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ private data object TagParserImpl : TagParser {
|
||||
?: listOf("Various Artists").takeIf { compilation }
|
||||
?: listOf(),
|
||||
albumArtistSortNames = metadata.albumArtistSortNames() ?: listOf(),
|
||||
genreNames = metadata.genreNames() ?: listOf())
|
||||
genreNames = metadata.genreNames() ?: listOf(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.oxycblt.musikr.tag.Date
|
||||
|
||||
fun CoroutineScope.tryAsync(
|
||||
context: CoroutineContext,
|
||||
block: suspend () -> Unit
|
||||
block: suspend () -> Unit,
|
||||
): Deferred<Result<Unit>> = async {
|
||||
try {
|
||||
block()
|
||||
|
||||
@@ -27,7 +27,8 @@ class DateTest {
|
||||
fun date_equals_varyingPrecision() {
|
||||
assertTrue(
|
||||
requireNotNull(Date.from("2016-08-16T00:01:02")) !=
|
||||
requireNotNull(Date.from("2016-08-16")))
|
||||
requireNotNull(Date.from("2016-08-16"))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,10 +49,7 @@ class DateTest {
|
||||
fun date_compareTo_varyingPrecision() {
|
||||
val a = requireNotNull(Date.from("2016-08-16T00:01:02"))
|
||||
val b = requireNotNull(Date.from("2016-08-16"))
|
||||
assertEquals(
|
||||
1,
|
||||
a.compareTo(b),
|
||||
)
|
||||
assertEquals(1, a.compareTo(b))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,7 +32,9 @@ class ReleaseTypeTest {
|
||||
@Test
|
||||
fun releaseType_parse_secondary() {
|
||||
assertEquals(
|
||||
ReleaseType.Compilation(null), ReleaseType.parse(listOf("album", "compilation")))
|
||||
ReleaseType.Compilation(null),
|
||||
ReleaseType.parse(listOf("album", "compilation")),
|
||||
)
|
||||
assertEquals(ReleaseType.Soundtrack, ReleaseType.parse(listOf("album", "soundtrack")))
|
||||
assertEquals(ReleaseType.Mix, ReleaseType.parse(listOf("album", "dj-mix")))
|
||||
assertEquals(ReleaseType.Mixtape, ReleaseType.parse(listOf("album", "mixtape/street")))
|
||||
@@ -43,30 +45,40 @@ class ReleaseTypeTest {
|
||||
fun releaseType_parse_modifiers() {
|
||||
assertEquals(
|
||||
ReleaseType.Album(ReleaseType.Refinement.LIVE),
|
||||
ReleaseType.parse(listOf("album", "live")))
|
||||
ReleaseType.parse(listOf("album", "live")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.Album(ReleaseType.Refinement.REMIX),
|
||||
ReleaseType.parse(listOf("album", "remix")))
|
||||
ReleaseType.parse(listOf("album", "remix")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.EP(ReleaseType.Refinement.LIVE), ReleaseType.parse(listOf("ep", "live")))
|
||||
ReleaseType.EP(ReleaseType.Refinement.LIVE),
|
||||
ReleaseType.parse(listOf("ep", "live")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.EP(ReleaseType.Refinement.REMIX), ReleaseType.parse(listOf("ep", "remix")))
|
||||
ReleaseType.EP(ReleaseType.Refinement.REMIX),
|
||||
ReleaseType.parse(listOf("ep", "remix")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.Single(ReleaseType.Refinement.LIVE),
|
||||
ReleaseType.parse(listOf("single", "live")))
|
||||
ReleaseType.parse(listOf("single", "live")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.Single(ReleaseType.Refinement.REMIX),
|
||||
ReleaseType.parse(listOf("single", "remix")))
|
||||
ReleaseType.parse(listOf("single", "remix")),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun releaseType_parse_secondaryModifiers() {
|
||||
assertEquals(
|
||||
ReleaseType.Compilation(ReleaseType.Refinement.LIVE),
|
||||
ReleaseType.parse(listOf("album", "compilation", "live")))
|
||||
ReleaseType.parse(listOf("album", "compilation", "live")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.Compilation(ReleaseType.Refinement.REMIX),
|
||||
ReleaseType.parse(listOf("album", "compilation", "remix")))
|
||||
ReleaseType.parse(listOf("album", "compilation", "remix")),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,8 +92,12 @@ class ReleaseTypeTest {
|
||||
@Test
|
||||
fun releaseType_parse_orphanedModifier() {
|
||||
assertEquals(
|
||||
ReleaseType.Album(ReleaseType.Refinement.LIVE), ReleaseType.parse(listOf("live")))
|
||||
ReleaseType.Album(ReleaseType.Refinement.LIVE),
|
||||
ReleaseType.parse(listOf("live")),
|
||||
)
|
||||
assertEquals(
|
||||
ReleaseType.Album(ReleaseType.Refinement.REMIX), ReleaseType.parse(listOf("remix")))
|
||||
ReleaseType.Album(ReleaseType.Refinement.REMIX),
|
||||
ReleaseType.parse(listOf("remix")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +36,15 @@ class SeparatorsTest {
|
||||
fun separators_split_withString_withMultipleChar() {
|
||||
assertEquals(
|
||||
listOf("a", "b", "c", "d", "e", "f"),
|
||||
Separators.from(",;/+&").split(listOf("a,b;c/d+e&f")))
|
||||
Separators.from(",;/+&").split(listOf("a,b;c/d+e&f")),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun separators_split_withList_withMultipleChar() {
|
||||
assertEquals(
|
||||
listOf("a,b;c/d", "e&f"), Separators.from(",;/+&").split(listOf("a,b;c/d", "e&f")))
|
||||
listOf("a,b;c/d", "e&f"),
|
||||
Separators.from(",;/+&").split(listOf("a,b;c/d", "e&f")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ class TagFieldsTest {
|
||||
createTestMetadata(
|
||||
id3v2Tags = mapOf("TIT2" to listOf("ID3 Title")),
|
||||
mp4Tags = mapOf("©nam" to listOf("MP4 Title")),
|
||||
xiphTags = mapOf("TITLE" to listOf("Xiph Title")))
|
||||
xiphTags = mapOf("TITLE" to listOf("Xiph Title")),
|
||||
)
|
||||
assertEquals("Xiph Title", metadata.name())
|
||||
}
|
||||
|
||||
@@ -73,13 +74,15 @@ class TagFieldsTest {
|
||||
// Test Xiph format
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
xiphTags = mapOf("TRACKNUMBER" to listOf("9"), "TOTALTRACKS" to listOf("15")))
|
||||
xiphTags = mapOf("TRACKNUMBER" to listOf("9"), "TOTALTRACKS" to listOf("15"))
|
||||
)
|
||||
assertEquals(9, metadata.track())
|
||||
|
||||
// Test Xiph alternative total tracks
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
xiphTags = mapOf("TRACKNUMBER" to listOf("8"), "TRACKTOTAL" to listOf("16")))
|
||||
xiphTags = mapOf("TRACKNUMBER" to listOf("8"), "TRACKTOTAL" to listOf("16"))
|
||||
)
|
||||
assertEquals(8, metadata.track())
|
||||
}
|
||||
|
||||
@@ -96,13 +99,15 @@ class TagFieldsTest {
|
||||
// Test Xiph format
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
xiphTags = mapOf("DISCNUMBER" to listOf("3"), "TOTALDISCS" to listOf("4")))
|
||||
xiphTags = mapOf("DISCNUMBER" to listOf("3"), "TOTALDISCS" to listOf("4"))
|
||||
)
|
||||
assertEquals(3, metadata.disc())
|
||||
|
||||
// Test Xiph alternative total discs
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
xiphTags = mapOf("DISCNUMBER" to listOf("2"), "DISCTOTAL" to listOf("5")))
|
||||
xiphTags = mapOf("DISCNUMBER" to listOf("2"), "DISCTOTAL" to listOf("5"))
|
||||
)
|
||||
assertEquals(2, metadata.disc())
|
||||
}
|
||||
|
||||
@@ -118,7 +123,8 @@ class TagFieldsTest {
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
id3v2Tags = mapOf("TSST" to listOf("ID3 Subtitle")),
|
||||
xiphTags = mapOf("DISCSUBTITLE" to listOf("Xiph Subtitle")))
|
||||
xiphTags = mapOf("DISCSUBTITLE" to listOf("Xiph Subtitle")),
|
||||
)
|
||||
assertEquals("Xiph Subtitle", metadata.subtitle())
|
||||
}
|
||||
|
||||
@@ -144,7 +150,8 @@ class TagFieldsTest {
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
xiphTags =
|
||||
mapOf("DATE" to listOf("2023-01-01"), "ORIGINALDATE" to listOf("2021-01-01")))
|
||||
mapOf("DATE" to listOf("2023-01-01"), "ORIGINALDATE" to listOf("2021-01-01"))
|
||||
)
|
||||
assertEquals("2021-01-01", metadata.date().toString())
|
||||
|
||||
// Test MP4 date
|
||||
@@ -161,8 +168,9 @@ class TagFieldsTest {
|
||||
mapOf(
|
||||
"TYER" to listOf("2019"),
|
||||
"TDAT" to listOf("0523"), // May 23
|
||||
"TIME" to listOf("2145") // 21:45
|
||||
))
|
||||
"TIME" to listOf("2145"), // 21:45
|
||||
)
|
||||
)
|
||||
val date = metadata.date()
|
||||
assertEquals(2019, date?.year)
|
||||
assertEquals(5, date?.month)
|
||||
@@ -179,7 +187,9 @@ class TagFieldsTest {
|
||||
mapOf(
|
||||
"TALB" to listOf("Album Name"),
|
||||
"TSOA" to listOf("Sort Album Name"),
|
||||
"TXXX:RELEASETYPE" to listOf("compilation")))
|
||||
"TXXX:RELEASETYPE" to listOf("compilation"),
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals("Album Name", metadata.albumName())
|
||||
assertEquals("Sort Album Name", metadata.albumSortName())
|
||||
@@ -195,7 +205,9 @@ class TagFieldsTest {
|
||||
"TPE1" to listOf("Artist 1"),
|
||||
"TPE2" to listOf("Album Artist 1"),
|
||||
"TSOP" to listOf("Artist 1 Sort"),
|
||||
"TSO2" to listOf("Album Artist 1 Sort")))
|
||||
"TSO2" to listOf("Album Artist 1 Sort"),
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(listOf("Artist 1"), metadata.artistNames())
|
||||
assertEquals(listOf("Album Artist 1"), metadata.albumArtistNames())
|
||||
@@ -211,7 +223,9 @@ class TagFieldsTest {
|
||||
xiphTags =
|
||||
mapOf(
|
||||
"MUSICBRAINZ_RELEASETRACKID" to listOf("track-mb-id"),
|
||||
"MUSICBRAINZ_ALBUMID" to listOf("album-mb-id")))
|
||||
"MUSICBRAINZ_ALBUMID" to listOf("album-mb-id"),
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals("track-mb-id", metadata.musicBrainzId())
|
||||
assertEquals("album-mb-id", metadata.albumMusicBrainzId())
|
||||
@@ -223,7 +237,9 @@ class TagFieldsTest {
|
||||
mapOf(
|
||||
"----:COM.APPLE.ITUNES:MUSICBRAINZ RELEASE TRACK ID" to
|
||||
listOf("track-mb-id-2"),
|
||||
"----:COM.APPLE.ITUNES:MUSICBRAINZ ALBUM ID" to listOf("album-mb-id-2")))
|
||||
"----:COM.APPLE.ITUNES:MUSICBRAINZ ALBUM ID" to listOf("album-mb-id-2"),
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals("track-mb-id-2", metadata2.musicBrainzId())
|
||||
assertEquals("album-mb-id-2", metadata2.albumMusicBrainzId())
|
||||
@@ -272,14 +288,14 @@ class TagFieldsTest {
|
||||
// Test MP4 ReplayGain tags
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
mp4Tags =
|
||||
mapOf("----:COM.APPLE.ITUNES:REPLAYGAIN_TRACK_GAIN" to listOf("-0.32 dB")))
|
||||
mp4Tags = mapOf("----:COM.APPLE.ITUNES:REPLAYGAIN_TRACK_GAIN" to listOf("-0.32 dB"))
|
||||
)
|
||||
assertEquals(-0.32f, metadata.replayGainTrackAdjustment())
|
||||
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
mp4Tags =
|
||||
mapOf("----:COM.APPLE.ITUNES:REPLAYGAIN_ALBUM_GAIN" to listOf("-8.72 dB")))
|
||||
mp4Tags = mapOf("----:COM.APPLE.ITUNES:REPLAYGAIN_ALBUM_GAIN" to listOf("-8.72 dB"))
|
||||
)
|
||||
assertEquals(-8.72f, metadata.replayGainAlbumAdjustment())
|
||||
}
|
||||
|
||||
@@ -303,7 +319,7 @@ class TagFieldsTest {
|
||||
durationMs: Long = 1000,
|
||||
bitrateKbps: Int = 320,
|
||||
sampleRateHz: Int = 44100,
|
||||
mimeType: String = "audio/mpeg"
|
||||
mimeType: String = "audio/mpeg",
|
||||
): Metadata {
|
||||
val properties = Properties(mimeType, durationMs, bitrateKbps, sampleRateHz)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, cover, properties)
|
||||
|
||||
@@ -45,7 +45,9 @@ class TagParserTest {
|
||||
"TYER" to listOf("2020"),
|
||||
"TRCK" to listOf("1/10"),
|
||||
"TPOS" to listOf("1/2"),
|
||||
"TCON" to listOf("Rock", "Electronic")))
|
||||
"TCON" to listOf("Rock", "Electronic"),
|
||||
)
|
||||
)
|
||||
|
||||
val tags = tagParser.parse(metadata)
|
||||
|
||||
@@ -66,7 +68,8 @@ class TagParserTest {
|
||||
createTestMetadata(
|
||||
id3v2Tags = mapOf("TIT2" to listOf("ID3 Song"), "TALB" to listOf("ID3 Album")),
|
||||
xiphTags = mapOf("TITLE" to listOf("Xiph Song"), "ALBUM" to listOf("Xiph Album")),
|
||||
mp4Tags = mapOf("©nam" to listOf("MP4 Song"), "©alb" to listOf("MP4 Album")))
|
||||
mp4Tags = mapOf("©nam" to listOf("MP4 Song"), "©alb" to listOf("MP4 Album")),
|
||||
)
|
||||
|
||||
val tags = tagParser.parse(metadata)
|
||||
|
||||
@@ -91,8 +94,8 @@ class TagParserTest {
|
||||
// Test compilation album with explicit release type
|
||||
val metadata =
|
||||
createTestMetadata(
|
||||
id3v2Tags =
|
||||
mapOf("TCMP" to listOf("1"), "TXXX:RELEASETYPE" to listOf("soundtrack")))
|
||||
id3v2Tags = mapOf("TCMP" to listOf("1"), "TXXX:RELEASETYPE" to listOf("soundtrack"))
|
||||
)
|
||||
|
||||
val tags = tagParser.parse(metadata)
|
||||
|
||||
@@ -120,7 +123,9 @@ class TagParserTest {
|
||||
"TXXX:MUSICBRAINZ RELEASE TRACK ID" to listOf("track-id-123"),
|
||||
"TXXX:MUSICBRAINZ ALBUM ID" to listOf("album-id-456"),
|
||||
"TXXX:MUSICBRAINZ ARTIST ID" to listOf("artist-id-789"),
|
||||
"TXXX:MUSICBRAINZ ALBUM ARTIST ID" to listOf("album-artist-id-012")))
|
||||
"TXXX:MUSICBRAINZ ALBUM ARTIST ID" to listOf("album-artist-id-012"),
|
||||
)
|
||||
)
|
||||
|
||||
val tags = tagParser.parse(metadata)
|
||||
|
||||
@@ -137,7 +142,9 @@ class TagParserTest {
|
||||
xiphTags =
|
||||
mapOf(
|
||||
"REPLAYGAIN_TRACK_GAIN" to listOf("-3.5 dB"),
|
||||
"REPLAYGAIN_ALBUM_GAIN" to listOf("-2.1 dB")))
|
||||
"REPLAYGAIN_ALBUM_GAIN" to listOf("-2.1 dB"),
|
||||
)
|
||||
)
|
||||
|
||||
val tags = tagParser.parse(metadata)
|
||||
|
||||
@@ -153,7 +160,7 @@ class TagParserTest {
|
||||
durationMs: Long = 1000,
|
||||
bitrateKbps: Int = 320,
|
||||
sampleRateHz: Int = 44100,
|
||||
mimeType: String = "audio/mpeg"
|
||||
mimeType: String = "audio/mpeg",
|
||||
): Metadata {
|
||||
val properties = Properties(mimeType, durationMs, bitrateKbps, sampleRateHz)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, cover, properties)
|
||||
|
||||
@@ -66,7 +66,9 @@ class TagParsingEdgeCasesTest {
|
||||
"TRCK" to listOf("not-a-number"),
|
||||
"TPOS" to listOf("also-not-a-number"),
|
||||
"TYER" to listOf("invalid-year"),
|
||||
"REPLAYGAIN_TRACK_GAIN" to listOf("not-a-float dB")))
|
||||
"REPLAYGAIN_TRACK_GAIN" to listOf("not-a-float dB"),
|
||||
)
|
||||
)
|
||||
val parsedTags = tagParser.parse(metadata)
|
||||
|
||||
// Verify all numeric fields are null when given invalid values
|
||||
@@ -83,7 +85,8 @@ class TagParsingEdgeCasesTest {
|
||||
createTestMetadata(
|
||||
id3v2Tags = mapOf("TIT2" to listOf("ID3 Title"), "TALB" to listOf("ID3 Album")),
|
||||
mp4Tags = mapOf("©nam" to listOf("MP4 Title"), "©alb" to listOf("MP4 Album")),
|
||||
xiphTags = mapOf("TITLE" to listOf("Xiph Title"), "ALBUM" to listOf("Xiph Album")))
|
||||
xiphTags = mapOf("TITLE" to listOf("Xiph Title"), "ALBUM" to listOf("Xiph Album")),
|
||||
)
|
||||
|
||||
// Individual field extraction
|
||||
assertEquals("Xiph Title", metadata.name())
|
||||
@@ -105,11 +108,13 @@ class TagParsingEdgeCasesTest {
|
||||
mapOf(
|
||||
"©nam" to listOf("MP4 Title")
|
||||
// No album in MP4
|
||||
),
|
||||
),
|
||||
xiphTags =
|
||||
mapOf(
|
||||
// No title in Xiph
|
||||
"ALBUM" to listOf("Xiph Album")))
|
||||
"ALBUM" to listOf("Xiph Album")
|
||||
),
|
||||
)
|
||||
|
||||
// Individual field extraction
|
||||
assertEquals("MP4 Title", metadata.name()) // Xiph missing, falls back to MP4
|
||||
@@ -134,7 +139,8 @@ class TagParsingEdgeCasesTest {
|
||||
// Case 2: Compilation flag with explicit album artist
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
id3v2Tags = mapOf("TCMP" to listOf("1"), "TPE2" to listOf("Custom Album Artist")))
|
||||
id3v2Tags = mapOf("TCMP" to listOf("1"), "TPE2" to listOf("Custom Album Artist"))
|
||||
)
|
||||
tags = tagParser.parse(metadata)
|
||||
assertEquals(listOf("Custom Album Artist"), tags.albumArtistNames)
|
||||
assertEquals(listOf("compilation"), tags.releaseTypes)
|
||||
@@ -142,8 +148,8 @@ class TagParsingEdgeCasesTest {
|
||||
// Case 3: Compilation flag with explicit release type
|
||||
metadata =
|
||||
createTestMetadata(
|
||||
id3v2Tags =
|
||||
mapOf("TCMP" to listOf("1"), "TXXX:RELEASETYPE" to listOf("soundtrack")))
|
||||
id3v2Tags = mapOf("TCMP" to listOf("1"), "TXXX:RELEASETYPE" to listOf("soundtrack"))
|
||||
)
|
||||
tags = tagParser.parse(metadata)
|
||||
assertEquals(listOf("Various Artists"), tags.albumArtistNames)
|
||||
assertEquals(listOf("soundtrack"), tags.releaseTypes)
|
||||
@@ -156,7 +162,8 @@ class TagParsingEdgeCasesTest {
|
||||
// Non-numeric characters filtered out
|
||||
var metadata =
|
||||
createTestMetadata(
|
||||
xiphTags = mapOf("REPLAYGAIN_TRACK_GAIN" to listOf("+2.5 dB some text")))
|
||||
xiphTags = mapOf("REPLAYGAIN_TRACK_GAIN" to listOf("+2.5 dB some text"))
|
||||
)
|
||||
assertEquals(2.5f, metadata.replayGainTrackAdjustment())
|
||||
|
||||
// Zero values filtered
|
||||
@@ -186,8 +193,10 @@ class TagParsingEdgeCasesTest {
|
||||
createTestMetadata(
|
||||
id3v2Tags =
|
||||
mapOf(
|
||||
"TYER" to listOf("2018"), "TDAT" to listOf("0315") // March 15
|
||||
))
|
||||
"TYER" to listOf("2018"),
|
||||
"TDAT" to listOf("0315"), // March 15
|
||||
)
|
||||
)
|
||||
assertEquals("2018-03-15", metadata.date().toString())
|
||||
|
||||
// Year, date and time
|
||||
@@ -197,8 +206,9 @@ class TagParsingEdgeCasesTest {
|
||||
mapOf(
|
||||
"TYER" to listOf("2018"),
|
||||
"TDAT" to listOf("0315"), // March 15
|
||||
"TIME" to listOf("1422") // 14:22
|
||||
))
|
||||
"TIME" to listOf("1422"), // 14:22
|
||||
)
|
||||
)
|
||||
assertEquals("2018-03-15T14:22Z", metadata.date().toString())
|
||||
|
||||
// Original year
|
||||
@@ -212,7 +222,9 @@ class TagParsingEdgeCasesTest {
|
||||
mapOf(
|
||||
"TYER" to listOf("2018"),
|
||||
"TDAT" to listOf("invalid"),
|
||||
"TIME" to listOf("invalid")))
|
||||
"TIME" to listOf("invalid"),
|
||||
)
|
||||
)
|
||||
assertEquals("2018", metadata.date().toString())
|
||||
|
||||
// Non-numeric date components
|
||||
@@ -228,7 +240,7 @@ class TagParsingEdgeCasesTest {
|
||||
durationMs: Long = 1000,
|
||||
bitrateKbps: Int = 320,
|
||||
sampleRateHz: Int = 44100,
|
||||
mimeType: String = "audio/mpeg"
|
||||
mimeType: String = "audio/mpeg",
|
||||
): Metadata {
|
||||
val properties = Properties(mimeType, durationMs, bitrateKbps, sampleRateHz)
|
||||
return Metadata(id3v2Tags, xiphTags, mp4Tags, cover, properties)
|
||||
|
||||
@@ -73,7 +73,9 @@ class TagUtilTest {
|
||||
@Test
|
||||
fun correctWhitespace_listOopsAllWhitespace() {
|
||||
assertEquals(
|
||||
listOf("tcp phagocyte"), listOf(" ", "", " tcp phagocyte").correctWhitespace())
|
||||
listOf("tcp phagocyte"),
|
||||
listOf(" ", "", " tcp phagocyte").correctWhitespace(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,14 +119,16 @@ class TagUtilTest {
|
||||
fun parseId3v2Genre_multi() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch").parseId3GenreNames())
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch").parseId3GenreNames(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseId3v2Genre_multiId3v1() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Glitch"),
|
||||
listOf("176", "178", "Glitch").parseId3GenreNames())
|
||||
listOf("176", "178", "Glitch").parseId3GenreNames(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,7 +140,8 @@ class TagUtilTest {
|
||||
fun parseId3v2Genre_singleId3v23() {
|
||||
assertEquals(
|
||||
listOf("Post-Rock", "Shoegaze", "Remix", "Cover", "Glitch"),
|
||||
listOf("(176)(178)(RX)(CR)Glitch").parseId3GenreNames())
|
||||
listOf("(176)(178)(RX)(CR)Glitch").parseId3GenreNames(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user