Adds track controller

This commit is contained in:
aarbit 2024-06-03 23:03:56 -05:00
parent 8b077be945
commit 0c7805eee3
3 changed files with 31 additions and 1 deletions

View File

@ -8,7 +8,7 @@ plugins {
}
group = "net.halfbinary"
version = "0.0.7-SNAPSHOT"
version = "0.0.8-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_21

View File

@ -0,0 +1,23 @@
package net.halfbinary.prettyplayerapi.controller
import com.mpatric.mp3agic.Mp3File
import net.halfbinary.prettyplayerapi.model.TrackInfo
import net.halfbinary.prettyplayerapi.service.MusicService
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
@RestController
@CrossOrigin
class TrackController(private val musicService: MusicService) {
@GetMapping("track/{albumHash}/{trackNumber}")
fun getTrackInfo(@PathVariable albumHash: String, @PathVariable trackNumber: Int): TrackInfo {
val file = musicService.getMusic(albumHash, trackNumber)
val trackFile = Mp3File(file)
trackFile.id3v2Tag.artist
trackFile.id3v2Tag.apply {
return TrackInfo(album, artist, title)
}
}
}

View File

@ -0,0 +1,7 @@
package net.halfbinary.prettyplayerapi.model
data class TrackInfo(
val albumTitle: String,
val artist: String,
val trackTitle: String
)