Created
April 10, 2018 02:10
-
-
Save kgilmer/82847da739a5585a1766170b18b2520c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun extractMetadataOrNull(audioFile: AudioFile): JsonObject? { | |
val js = JsonObject() | |
with(audioFile.tag ?: return null) { | |
js["title"] = getFirst(FieldKey.TITLE) ?: return null | |
js["artist"] = getFirst(FieldKey.ARTIST) ?: getFirst(FieldKey.ALBUM_ARTIST) ?: return null | |
js["album"] = getFirst(FieldKey.ALBUM) ?: return null | |
js["genre"] = if (getFirst(FieldKey.GENRE).isNullOrBlank()) "unknown" else getFirst(FieldKey.GENRE) | |
js["source"] = audioFile.file.absolutePath | |
js["image"] = "" | |
js["trackNumber"] = getFirst(FieldKey.TRACK).toIntOrNull() ?: 0 | |
js["totalTrackCount"] = getFirst(FieldKey.TRACK_TOTAL).toIntOrNull() ?: 0 | |
js["duration"] = audioFile.audioHeader.trackLength | |
js["site"] = getFirst(FieldKey.URL_WIKIPEDIA_RELEASE_SITE) | |
?: getFirst(FieldKey.URL_WIKIPEDIA_ARTIST_SITE) | |
?: getFirst(FieldKey.URL_DISCOGS_ARTIST_SITE) | |
?: getFirst(FieldKey.URL_OFFICIAL_ARTIST_SITE) | |
?: "" | |
return js | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment