Skip to content

Commit 4c10471

Browse files
authored
Merge pull request #609 from namehillsoftware/bugfix/navidrome-subsonic-fields
[Bugfix] Subsonic Field Mappings
2 parents b813a93 + 254a9e2 commit 4c10471

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/connection/live/LiveSubsonicConnection.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class LiveSubsonicConnection(
8080
const val replayGain = "replayGain"
8181
const val trackGain = "trackGain"
8282
const val peakGain = "trackPeak"
83+
const val userRating = "userRating"
84+
const val playCount = "playCount"
85+
const val duration = "duration"
8386
}
8487

8588
private val promisedRootItem by lazy {
@@ -217,7 +220,7 @@ class LiveSubsonicConnection(
217220
logger.debug("rest/scrobble responded with a response code of {}", responseCode)
218221
}
219222

220-
if (responseCode < 200 || responseCode >= 300) throw HttpResponseException(responseCode)
223+
if (responseCode !in 200..<300) throw HttpResponseException(responseCode)
221224
}
222225
}
223226

@@ -249,7 +252,7 @@ class LiveSubsonicConnection(
249252
throw SubsonicServerException(jsonTranslator.parseJson<ErrorResponse>(json))
250253
}
251254

252-
jsonTranslator.parseJson<T>(json)
255+
if (!cs.isCancelled) jsonTranslator.parseJson<T>(json) else null
253256
}
254257
}
255258

@@ -265,6 +268,9 @@ class LiveSubsonicConnection(
265268
NormalizedFileProperties.Name to KnownFileProperties.title,
266269
NormalizedFileProperties.VolumeLevelReplayGain to KnownFileProperties.trackGain,
267270
NormalizedFileProperties.PeakLevel to KnownFileProperties.peakGain,
271+
NormalizedFileProperties.Rating to KnownFileProperties.userRating,
272+
NormalizedFileProperties.NumberPlays to KnownFileProperties.playCount,
273+
NormalizedFileProperties.Duration to KnownFileProperties.duration,
268274
)
269275
}
270276

projectBlueWater/src/test/java/com/lasthopesoftware/bluewater/client/access/GivenASubsonicConnection/AndNoStoredFileProperties/WhenGettingFileProperties.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WhenGettingFileProperties {
3333
PassThroughHttpResponse(
3434
200,
3535
"Alright",
36-
"""{"subsonic-response":{"status":"ok","version":"1.16.1","type":"navidrome","serverVersion":"0.53.3 (13af8ed4)","openSubsonic":true,"song":{"id":"3c00a4d5a48b0790d8e2288faf6fc93c","parent":"9022600b4f57592edd8e8bfc9048fe38","isDir":false,"title":"How Will You Meet Your End","album":"American Hearts","artist":"A.A. Bondy","track":1,"year":2007,"genre":"Americana","coverArt":"mf-3c00a4d5a48b0790d8e2288faf6fc93c_6728cffb","size":25331533,"contentType":"audio/flac","suffix":"flac","duration":242,"bitRate":827,"path":"A.A. Bondy/American Hearts/01 - How Will You Meet Your End.flac","discNumber":1,"created":"2025-02-10T04:25:55.814140973Z","albumId":"9022600b4f57592edd8e8bfc9048fe38","artistId":"563727e73731392260da4a787f534387","type":"music","isVideo":false,"bpm":128,"comment":"Visit http://aabondy.bandcamp.com","sortName":"","mediaType":"song","musicBrainzId":"4fefe475-a23e-44e5-a46a-ce2d4167e108","genres":[{"name":"Americana"}],"replayGain":{"trackGain":-2.34,"trackPeak":0.933,"albumPeak":1},"channelCount":2,"samplingRate":44100}}}""".toByteArray()
36+
"""{"subsonic-response":{"status":"ok","version":"1.16.1","type":"navidrome","serverVersion":"0.53.3 (13af8ed4)","openSubsonic":true,"song":{"id":"3c00a4d5a48b0790d8e2288faf6fc93c","parent":"9022600b4f57592edd8e8bfc9048fe38","isDir":false,"title":"How Will You Meet Your End","album":"American Hearts","artist":"A.A. Bondy","track":1,"year":2007,"genre":"Americana","coverArt":"mf-3c00a4d5a48b0790d8e2288faf6fc93c_6728cffb","size":25331533,"playCount":364,"contentType":"audio/flac","suffix":"flac","duration":242,"bitRate":827,"path":"A.A. Bondy/American Hearts/01 - How Will You Meet Your End.flac","discNumber":1,"created":"2025-02-10T04:25:55.814140973Z","albumId":"9022600b4f57592edd8e8bfc9048fe38","artistId":"563727e73731392260da4a787f534387","type":"music","isVideo":false,"bpm":128,"comment":"Visit http://aabondy.bandcamp.com","userRating":3,"sortName":"","mediaType":"song","musicBrainzId":"4fefe475-a23e-44e5-a46a-ce2d4167e108","genres":[{"name":"Americana"}],"replayGain":{"trackGain":-2.34,"trackPeak":0.933,"albumPeak":1},"channelCount":2,"samplingRate":44100}}}""".toByteArray()
3737
.inputStream()
3838
)
3939
}
@@ -108,12 +108,32 @@ class WhenGettingFileProperties {
108108
)
109109
}
110110

111+
@Test
112+
fun `then the number of plays is correct`() {
113+
assertThat(fileProperties?.get(NormalizedFileProperties.NumberPlays)).isEqualTo(
114+
ReadOnlyFileProperty(
115+
NormalizedFileProperties.NumberPlays,
116+
"364"
117+
)
118+
)
119+
}
120+
121+
@Test
122+
fun `then the date is correct`() {
123+
assertThat(fileProperties?.get(NormalizedFileProperties.Duration)).isEqualTo(
124+
ReadOnlyFileProperty(
125+
NormalizedFileProperties.Duration,
126+
"242",
127+
)
128+
)
129+
}
130+
111131
@Test
112132
fun `then the rating is editable`() {
113133
assertThat(fileProperties?.rating).isEqualTo(
114134
EditableFileProperty(
115135
NormalizedFileProperties.Rating,
116-
"0",
136+
"3",
117137
FilePropertyType.Integer,
118138
)
119139
)

0 commit comments

Comments
 (0)