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()
|
||||
|
||||
Reference in New Issue
Block a user