Skip to content

Commit 64b9a93

Browse files
committed
Added ResetCache=1 parameter to file list requests
1 parent caea093 commit 64b9a93

File tree

7 files changed

+93
-106
lines changed

7 files changed

+93
-106
lines changed

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/files/access/LibraryFileProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ class LibraryFileProvider(private val libraryConnections: ProvideLibraryConnecti
2929
override fun promiseAudioFiles(libraryId: LibraryId, query: String): Promise<List<ServiceFile>> =
3030
libraryConnections
3131
.promiseLibraryConnection(libraryId)
32-
.eventuallyFromDataAccess { it?.promiseFiles("[Media Type]=[Audio] $query").keepPromise(emptyList()) }
32+
.eventuallyFromDataAccess { it?.promiseFiles(query).keepPromise(emptyList()) }
3333
}

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/files/access/parameters/FileListParameters.kt

Lines changed: 0 additions & 36 deletions
This file was deleted.

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/files/access/parameters/IFileListParameterProvider.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.media3.datasource.okhttp.OkHttpDataSource
55
import com.lasthopesoftware.bluewater.BuildConfig
66
import com.lasthopesoftware.bluewater.client.access.RemoteLibraryAccess
77
import com.lasthopesoftware.bluewater.client.browsing.files.ServiceFile
8-
import com.lasthopesoftware.bluewater.client.browsing.files.access.parameters.FileListParameters
98
import com.lasthopesoftware.bluewater.client.browsing.files.access.stringlist.FileStringListUtilities
109
import com.lasthopesoftware.bluewater.client.browsing.files.properties.EditableFilePropertyDefinition
1110
import com.lasthopesoftware.bluewater.client.browsing.files.properties.FilePropertyHelpers.durationInMs
@@ -68,8 +67,11 @@ class LiveMediaCenterConnection(
6867
private const val browseFilesPath = "Browse/Files"
6968
private const val playlistFilesPath = "Playlist/Files"
7069
private const val searchFilesPath = "Files/Search"
71-
private const val browseLibraryParameter = "Browse/Children"
70+
private const val browseLibraryPath = "Browse/Children"
7271
private const val imageFormat = "jpg"
72+
private const val serializedFileListParameter = "Action=Serialize"
73+
private const val shuffleFileListParameter = "Shuffle=1"
74+
private const val resetCacheParameter = "ResetCache=1"
7375

7476
private val editableFilePropertyDefinitions by lazy { EditableFilePropertyDefinition.entries.toSet().toPromise() }
7577
}
@@ -258,29 +260,30 @@ class LiveMediaCenterConnection(
258260
override fun promiseFileStringList(itemId: ItemId?): Promise<String> =
259261
itemId
260262
?.run {
261-
promiseFileStringList(FileListParameters.Options.None, browseFilesPath, "ID=$id", "Version=2")
263+
promiseFileStringList(browseFilesPath, "ID=$id")
262264
}
263-
?: promiseFileStringList(FileListParameters.Options.None, browseFilesPath, "Version=2")
265+
?: promiseFileStringList(browseFilesPath)
264266

265-
override fun promiseFileStringList(playlistId: PlaylistId): Promise<String> = "".toPromise()
267+
override fun promiseFileStringList(playlistId: PlaylistId): Promise<String> =
268+
promiseFileStringList(playlistFilesPath, "Playlist=${playlistId.id}")
266269

267270
override fun promiseShuffledFileStringList(itemId: ItemId?): Promise<String> =
268271
itemId
269272
?.run {
270-
promiseFileStringList(FileListParameters.Options.Shuffled, browseFilesPath, "ID=$id", "Version=2")
273+
promiseFileStringList(browseFilesPath, "ID=$id", shuffleFileListParameter)
271274
}
272-
?: promiseFileStringList(FileListParameters.Options.Shuffled, browseFilesPath, "Version=2")
275+
?: promiseFileStringList(browseFilesPath, shuffleFileListParameter)
273276

274277
override fun promiseShuffledFileStringList(playlistId: PlaylistId): Promise<String> = "".toPromise()
275278

276279
override fun promiseFiles(): Promise<List<ServiceFile>> =
277-
promiseFilesAtPath(browseFilesPath, "Version=2")
280+
promiseFilesAtPath(browseFilesPath)
278281

279282
override fun promiseFiles(query: String): Promise<List<ServiceFile>> =
280-
promiseFilesAtPath(searchFilesPath, "Query=$query")
283+
promiseFilesAtPath(searchFilesPath, "Query=[Media Type]=[Audio] $query")
281284

282285
override fun promiseFiles(itemId: ItemId): Promise<List<ServiceFile>> =
283-
promiseFilesAtPath(browseFilesPath, "ID=${itemId.id}", "Version=2")
286+
promiseFilesAtPath(browseFilesPath, "ID=${itemId.id}")
284287

285288
override fun promiseFiles(playlistId: PlaylistId): Promise<List<ServiceFile>> =
286289
promiseFilesAtPath(playlistFilesPath, "Playlist=${playlistId.id}")
@@ -316,21 +319,20 @@ class LiveMediaCenterConnection(
316319

317320
private fun promiseFilesAtPath(path: String, vararg params: String): Promise<List<ServiceFile>> =
318321
Promise.Proxy { cp ->
319-
promiseFileStringList(FileListParameters.Options.None, path, *params)
322+
promiseFileStringList(path, *params)
320323
.also(cp::doCancel)
321324
.eventually(FileResponses)
322325
.also(cp::doCancel)
323326
.then(FileResponses)
324327
}
325328

326-
private fun promiseFileStringList(option: FileListParameters.Options, path: String, vararg params: String): Promise<String> =
329+
private fun promiseFileStringList(path: String, vararg params: String): Promise<String> =
327330
Promise.Proxy { cp ->
328331
promiseResponse(
329332
path,
330-
*FileListParameters.Helpers.processParams(
331-
option,
332-
*params
333-
)
333+
*params,
334+
serializedFileListParameter,
335+
resetCacheParameter,
334336
).also(cp::doCancel).promiseStringBody()
335337
}
336338

@@ -418,13 +420,13 @@ class LiveMediaCenterConnection(
418420
val promisedResponse = itemId
419421
?.run {
420422
promiseResponse(
421-
browseLibraryParameter,
423+
browseLibraryPath,
422424
"ID=$id",
423425
"Version=2",
424426
"ErrorOnMissing=1"
425427
)
426428
}
427-
?: promiseResponse(browseLibraryParameter, "Version=2", "ErrorOnMissing=1")
429+
?: promiseResponse(browseLibraryPath, "Version=2", "ErrorOnMissing=1")
428430

429431
proxy(
430432
promisedResponse
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.lasthopesoftware.bluewater.client.access.GivenAJRiverConnection.AndAPlaylistId
2+
3+
import com.lasthopesoftware.TestUrl
4+
import com.lasthopesoftware.bluewater.client.browsing.files.ServiceFile
5+
import com.lasthopesoftware.bluewater.client.browsing.items.playlists.PlaylistId
6+
import com.lasthopesoftware.bluewater.client.connection.MediaCenterConnectionDetails
7+
import com.lasthopesoftware.bluewater.client.connection.live.LiveMediaCenterConnection
8+
import com.lasthopesoftware.bluewater.client.connection.requests.FakeHttpConnection
9+
import com.lasthopesoftware.bluewater.client.connection.requests.FakeHttpConnectionProvider
10+
import com.lasthopesoftware.bluewater.client.connection.url.UrlBuilder.addParams
11+
import com.lasthopesoftware.bluewater.client.connection.url.UrlBuilder.addPath
12+
import com.lasthopesoftware.bluewater.client.connection.url.UrlBuilder.withMcApi
13+
import com.lasthopesoftware.bluewater.shared.promises.extensions.toExpiringFuture
14+
import com.lasthopesoftware.resources.PassThroughHttpResponse
15+
import io.mockk.mockk
16+
import org.assertj.core.api.Assertions.assertThat
17+
import org.junit.jupiter.api.BeforeAll
18+
import org.junit.jupiter.api.Test
19+
20+
class `When getting files` {
21+
22+
private val mut by lazy {
23+
val httpConnection = FakeHttpConnection().apply {
24+
mapResponse(TestUrl.withMcApi().addPath("Playlist/Files").addParams("Playlist=-466327", "Action=Serialize", "ResetCache=1")) {
25+
PassThroughHttpResponse(
26+
200,
27+
"OK",
28+
"2;20;-1;6830841;5772590;5667732;6385489;7477524;3685;937552;6271374;1167729;5204876;6515467;2338;6227150;937460;5691040;5729177;6271773;6241105;6628853;6082656".encodeToByteArray().inputStream()
29+
)
30+
}
31+
}
32+
33+
LiveMediaCenterConnection(
34+
MediaCenterConnectionDetails(TestUrl),
35+
FakeHttpConnectionProvider(httpConnection),
36+
mockk(),
37+
)
38+
}
39+
40+
private var items = emptyList<ServiceFile>()
41+
42+
@BeforeAll
43+
fun act() {
44+
items = mut.promiseFiles(PlaylistId("-466327")).toExpiringFuture().get()!!
45+
}
46+
47+
@Test
48+
fun `then the items are correct`() {
49+
assertThat(items).containsExactly(
50+
ServiceFile(key="6830841"),
51+
ServiceFile(key="5772590"),
52+
ServiceFile(key="5667732"),
53+
ServiceFile(key="6385489"),
54+
ServiceFile(key="7477524"),
55+
ServiceFile(key="3685"),
56+
ServiceFile(key="937552"),
57+
ServiceFile(key="6271374"),
58+
ServiceFile(key="1167729"),
59+
ServiceFile(key="5204876"),
60+
ServiceFile(key="6515467"),
61+
ServiceFile(key="2338"),
62+
ServiceFile(key="6227150"),
63+
ServiceFile(key="937460"),
64+
ServiceFile(key="5691040"),
65+
ServiceFile(key="5729177"),
66+
ServiceFile(key="6271773"),
67+
ServiceFile(key="6241105"),
68+
ServiceFile(key="6628853"),
69+
ServiceFile(key="6082656"),
70+
)
71+
}
72+
}

projectBlueWater/src/test/java/com/lasthopesoftware/bluewater/client/browsing/files/access/parameters/GivenATypicalItem/WhenGettingFileListParameters.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

projectBlueWater/src/test/java/com/lasthopesoftware/bluewater/client/browsing/files/access/parameters/GivenATypicalPlaylist/WhenGettingFileListParameters.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)