Skip to content

Commit 079fc43

Browse files
author
sentinelweb
committed
#482 rewrite ids -> Remote when serving files out
1 parent 73f35fa commit 079fc43

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

hub/src/main/kotlin/uk/co/sentinelweb/cuer/hub/ui/player/vlc/VlcPlayerUiCoordinator.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import uk.co.sentinelweb.cuer.app.util.mediasession.MediaSessionContract
3737
import uk.co.sentinelweb.cuer.core.providers.CoroutineContextProvider
3838
import uk.co.sentinelweb.cuer.core.wrapper.LogWrapper
3939
import uk.co.sentinelweb.cuer.domain.*
40+
import uk.co.sentinelweb.cuer.domain.ext.serialise
4041
import uk.co.sentinelweb.cuer.hub.ui.home.HomeUiCoordinator
4142
import uk.co.sentinelweb.cuer.hub.util.extension.DesktopScopeComponent
4243
import uk.co.sentinelweb.cuer.hub.util.extension.desktopScopeWithSource
@@ -81,7 +82,7 @@ class VlcPlayerUiCoordinator(
8182
scope.get<VlcPlayerSwingWindow>(VlcPlayerSwingWindow::class)
8283
.apply { assemble(screen) }
8384
.also { SleepPreventer.preventSleep() }
84-
} else throw IllegalStateException("Can't find VLC")
85+
} else error("Can't find VLC")
8586
}
8687

8788
override fun destroy() {
@@ -148,6 +149,7 @@ class VlcPlayerUiCoordinator(
148149
if (playlist.id?.source == MEMORY) {
149150
playlistOrchestrator.save(playlist, playlist.id!!.deepOptions())
150151
}
152+
log.d("showPlayer: play itemId:${item.id?.serialise()}")
151153
playerItemLoader.setPlaylistAndItem(
152154
PlaylistAndItemDomain(
153155
playlistId = playlist.id,

remote/src/jvmAndAndroid/kotlin/uk/co/sentinelweb/cuer/remote/server/JvmRemoteWebServer.kt

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import org.koin.core.component.KoinComponent
2121
import org.koin.core.component.inject
2222
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
2323
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source.LOCAL
24+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source.REMOTE
2425
import uk.co.sentinelweb.cuer.app.orchestrator.toGuidIdentifier
2526
import uk.co.sentinelweb.cuer.app.service.remote.RemoteServerContract
2627
import uk.co.sentinelweb.cuer.app.usecase.GetFolderListUseCase
2728
import uk.co.sentinelweb.cuer.core.providers.PlayerConfigProvider
2829
import uk.co.sentinelweb.cuer.core.wrapper.LogWrapper
30+
import uk.co.sentinelweb.cuer.domain.PlaylistAndChildrenDomain
2931
import uk.co.sentinelweb.cuer.domain.ext.deserialisePlaylistItem
3032
import uk.co.sentinelweb.cuer.domain.ext.domainMessageJsonSerializer
3133
import uk.co.sentinelweb.cuer.domain.ext.serialise
@@ -305,8 +307,9 @@ class JvmRemoteWebServer(
305307
val postData = call.receiveText()
306308
try {
307309
(postData)
310+
.also { logWrapper.d("launchitem: postdata: ${it}") }
308311
.let { deserialisePlaylistItem(it) }
309-
// .let {it.copy(media = it.media.copy())}
312+
.also { logWrapper.d("launchitem: ${it.id?.serialise()}") }
310313
.let { item ->
311314
remotePlayerLaunchHost.launchVideo(
312315
item,
@@ -326,6 +329,7 @@ class JvmRemoteWebServer(
326329
val path = call.parameters[FOLDER_LIST_API.P_PARAM]
327330
logWrapper.d("Folder: $path")
328331
getFolderListUseCase.getFolderList(path)
332+
?.let { rewriteIdsToRemote(it) } // todo rewrite platformid -> http
329333
?.let { ResponseDomain(it) }
330334
?.apply { call.respondText(serialise(), ContentType.Application.Json) }
331335
?: apply {
@@ -336,7 +340,7 @@ class JvmRemoteWebServer(
336340
get("/video-stream/{filePath}") {
337341
val filePath = call.parameters["filePath"]
338342
// ?.substring("/video-stream".length)
339-
?.replace(":::::","/")
343+
?.replace(":::::", "/")
340344
if (filePath == null) {
341345
call.respond(HttpStatusCode.BadRequest, "File filePath is missing")
342346
return@get
@@ -345,8 +349,8 @@ class JvmRemoteWebServer(
345349

346350
val parentPath = filePath.substring(0, filePath.lastIndexOf("/"))
347351
val item = getFolderListUseCase.getFolderList(parentPath)
348-
?.children?.filter { it.platformId?.endsWith(filePath)?:false }
349-
val fullPath = getFolderListUseCase.truncatedToFullFolderPath(filePath)
352+
?.children?.filter { it.platformId?.endsWith(filePath) ?: false }
353+
val fullPath = getFolderListUseCase.truncatedToFullFolderPath(filePath)
350354
logWrapper.d("/video-stream/filepath: $fullPath")
351355

352356
val file = File(fullPath)
@@ -379,6 +383,43 @@ class JvmRemoteWebServer(
379383
}
380384
}
381385
}
386+
387+
private fun rewriteIdsToRemote(it: PlaylistAndChildrenDomain) = it.copy(
388+
playlist = it.playlist.copy(
389+
id = it.playlist.id?.copy(
390+
source = REMOTE,
391+
locator = localRepository.localNode.locator()
392+
),
393+
items = it.playlist.items.map {
394+
it.copy(
395+
id = it.id?.copy(
396+
source = REMOTE,
397+
locator = localRepository.localNode.locator()
398+
),
399+
media = it.media.copy(
400+
id = it.media.id?.copy(
401+
source = REMOTE,
402+
locator = localRepository.localNode.locator()
403+
),
404+
channelData = it.media.channelData.copy(
405+
id = it.media.channelData.id?.copy(
406+
source = REMOTE,
407+
locator = localRepository.localNode.locator()
408+
)
409+
)
410+
)
411+
)
412+
}
413+
),
414+
children = it.children.map { child ->
415+
child.copy(
416+
id = child.id?.copy(
417+
source = REMOTE,
418+
locator = localRepository.localNode.locator()
419+
)
420+
)
421+
}
422+
)
382423
}
383424

384425

0 commit comments

Comments
 (0)