From 0c7805eee38a4fed6603934798797e90dad2bf0c Mon Sep 17 00:00:00 2001 From: aarbit Date: Mon, 3 Jun 2024 23:03:56 -0500 Subject: [PATCH] Adds track controller --- build.gradle.kts | 2 +- .../controller/TrackController.kt | 23 +++++++++++++++++++ .../prettyplayerapi/model/TrackInfo.kt | 7 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/net/halfbinary/prettyplayerapi/controller/TrackController.kt create mode 100644 src/main/kotlin/net/halfbinary/prettyplayerapi/model/TrackInfo.kt diff --git a/build.gradle.kts b/build.gradle.kts index f6b56a8..a7b99dc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "net.halfbinary" -version = "0.0.7-SNAPSHOT" +version = "0.0.8-SNAPSHOT" java { sourceCompatibility = JavaVersion.VERSION_21 diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/TrackController.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/TrackController.kt new file mode 100644 index 0000000..6498c97 --- /dev/null +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/controller/TrackController.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/net/halfbinary/prettyplayerapi/model/TrackInfo.kt b/src/main/kotlin/net/halfbinary/prettyplayerapi/model/TrackInfo.kt new file mode 100644 index 0000000..03ad95d --- /dev/null +++ b/src/main/kotlin/net/halfbinary/prettyplayerapi/model/TrackInfo.kt @@ -0,0 +1,7 @@ +package net.halfbinary.prettyplayerapi.model + +data class TrackInfo( + val albumTitle: String, + val artist: String, + val trackTitle: String +)