2022-07-04 17:31:58 +02:00
|
|
|
/*
|
|
|
|
* APIAlbumConverter.kt
|
|
|
|
* Copyright (C) 2009-2022 Ultrasonic developers
|
|
|
|
*
|
|
|
|
* Distributed under terms of the GNU GPLv3 license.
|
|
|
|
*/
|
|
|
|
|
2017-09-02 19:40:32 +02:00
|
|
|
// Converts Album entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
|
|
|
// to app domain entities.
|
|
|
|
@file:JvmName("APIAlbumConverter")
|
2018-02-17 20:36:19 +01:00
|
|
|
package org.moire.ultrasonic.domain
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
2022-03-27 14:57:07 +02:00
|
|
|
typealias DomainAlbum = org.moire.ultrasonic.domain.Album
|
2017-09-02 19:40:32 +02:00
|
|
|
|
2022-07-04 17:31:58 +02:00
|
|
|
fun Album.toDomainEntity(serverId: Int): DomainAlbum = Album(
|
2018-02-22 22:45:28 +01:00
|
|
|
id = this@toDomainEntity.id,
|
2022-07-04 17:31:58 +02:00
|
|
|
serverId = serverId,
|
2021-11-30 20:53:10 +01:00
|
|
|
title = this@toDomainEntity.name ?: this@toDomainEntity.title,
|
2021-11-30 00:46:48 +01:00
|
|
|
album = this@toDomainEntity.album,
|
2018-02-22 22:45:28 +01:00
|
|
|
coverArt = this@toDomainEntity.coverArt,
|
|
|
|
artist = this@toDomainEntity.artist,
|
|
|
|
artistId = this@toDomainEntity.artistId,
|
|
|
|
songCount = this@toDomainEntity.songCount.toLong(),
|
|
|
|
duration = this@toDomainEntity.duration,
|
|
|
|
created = this@toDomainEntity.created?.time,
|
|
|
|
year = this@toDomainEntity.year,
|
2021-10-06 17:25:30 +02:00
|
|
|
genre = this@toDomainEntity.genre,
|
|
|
|
starred = this@toDomainEntity.starredDate.isNotEmpty()
|
2018-02-22 22:45:28 +01:00
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
2022-07-04 17:31:58 +02:00
|
|
|
fun Album.toMusicDirectoryDomainEntity(serverId: Int): MusicDirectory = MusicDirectory().apply {
|
|
|
|
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toTrackEntity(serverId) })
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
2017-09-16 20:02:44 +02:00
|
|
|
|
2022-07-04 17:31:58 +02:00
|
|
|
fun List<Album>.toDomainEntityList(serverId: Int): List<DomainAlbum> = this.map {
|
|
|
|
it.toDomainEntity(serverId)
|
|
|
|
}
|