Simplifies music track retrieval.
This commit is contained in:
parent
5cdcb1b7c5
commit
c167d5142f
@ -1,5 +1,7 @@
|
||||
package net.halfbinary.prettyplayerapi.service
|
||||
|
||||
import com.mpatric.mp3agic.Mp3File
|
||||
import net.halfbinary.prettyplayerapi.exception.AlbumFolderNotFoundException
|
||||
import net.halfbinary.prettyplayerapi.exception.AlbumHashNotFoundException
|
||||
import org.springframework.stereotype.Service
|
||||
import java.io.File
|
||||
@ -9,9 +11,14 @@ class MusicService(private val albumCacheService: AlbumCacheService) {
|
||||
fun getMusic(albumHash: String, trackNumber: Int): File {
|
||||
val albumInfo = albumCacheService.getAlbumCache()[albumHash]
|
||||
return if(albumInfo != null) {
|
||||
File(albumInfo.albumFolder).listFiles().sortedBy { it.name }[trackNumber-1]
|
||||
File(albumInfo.albumFolder)
|
||||
.listFiles()
|
||||
?.filter { it.name.endsWith(".mp3") }
|
||||
?.sortedBy { it.name }
|
||||
?.get(trackNumber)
|
||||
?: throw AlbumFolderNotFoundException(albumInfo.albumFolder)
|
||||
} else {
|
||||
throw AlbumHashNotFoundException("Album hash $albumHash not found")
|
||||
throw AlbumHashNotFoundException(albumHash)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user