Skip to content

Commit a2eb002

Browse files
author
sentinelweb
committed
#482 refactor rewrite url ids
1 parent 5ea017f commit a2eb002

File tree

7 files changed

+66
-51
lines changed

7 files changed

+66
-51
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import uk.co.sentinelweb.cuer.domain.ChannelDomain
1+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier.Locator
2+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
3+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source.REMOTE
4+
import uk.co.sentinelweb.cuer.domain.*
25

36
fun ChannelDomain.summarise(): String = """
47
CHANNEL: id: $id, platform: $platform - $platformId, title: $title
58
""".trimIndent()
9+
10+
fun ChannelDomain.rewriteIdsToSource(source: Source, locator: Locator?) = this.copy(
11+
id = this.id?.copy(source = source, locator = locator)
12+
)

domain/src/commonMain/kotlin/uk/co/sentinelweb/cuer/domain/ext/MediaDomainExt.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package uk.co.sentinelweb.cuer.domain.ext
22

3+
import rewriteIdsToSource
34
import summarise
4-
import uk.co.sentinelweb.cuer.domain.MediaDomain
5+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier.Locator
6+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
7+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source.REMOTE
8+
import uk.co.sentinelweb.cuer.domain.*
59

610
fun MediaDomain.stringMedia(): String = "id=$id title=$title platform=$platform platformId=$platformId"
711

@@ -20,3 +24,8 @@ fun MediaDomain.startPosition(): Long {
2024
fun MediaDomain.summarise(): String = """
2125
MEDIA: id: $id,platform: $platform - $platformId, title: $title, [channel: ${channelData.summarise()}]
2226
""".trimIndent()
27+
28+
fun MediaDomain.rewriteIdsToSource(source: Source, locator: Locator?) = this.copy(
29+
id = this.id?.copy(source = source, locator = locator),
30+
channelData = this.channelData.rewriteIdsToSource(source, locator)
31+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package uk.co.sentinelweb.cuer.domain.ext
2+
3+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier.Locator
4+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
5+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source.REMOTE
6+
import uk.co.sentinelweb.cuer.domain.PlaylistAndChildrenDomain
7+
8+
fun PlaylistAndChildrenDomain.rewriteIdsToSource(source: Source, locator: Locator?) = copy(
9+
playlist = this.playlist.rewriteIdsToSource(source, locator),
10+
children = this.children.map { childPlaylist ->
11+
childPlaylist.copy(
12+
id = childPlaylist.id?.copy(source = REMOTE, locator = locator)
13+
)
14+
}
15+
)

domain/src/commonMain/kotlin/uk/co/sentinelweb/cuer/domain/ext/PlaylistDomainExt.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package uk.co.sentinelweb.cuer.domain.ext
22

3+
import rewriteIdsToSource
34
import summarise
45
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier
6+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier.Locator
7+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
58
import uk.co.sentinelweb.cuer.domain.*
69

710
fun PlaylistDomain.currentItem() =
@@ -217,4 +220,11 @@ fun PlaylistDomain.orderIsAscending() =
217220
?: false
218221
acc && lastIsBefore
219222
} else acc
220-
}
223+
}
224+
225+
226+
fun PlaylistDomain.rewriteIdsToSource(source: Source, locator: Locator?) = this.copy(
227+
id = this.id?.copy(source = source, locator = locator),
228+
items = this.items.map { it.rewriteIdsToSource(source, locator) },
229+
channelData = this.channelData?.rewriteIdsToSource(source, locator)
230+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier.Locator
2+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
13
import uk.co.sentinelweb.cuer.domain.PlaylistItemDomain
4+
import uk.co.sentinelweb.cuer.domain.ext.rewriteIdsToSource
25
import uk.co.sentinelweb.cuer.domain.ext.summarise
36

47
fun PlaylistItemDomain.summarise(): String =
58
"ITEM: id: $id, order: $order, playlistId: $playlistId, media: ${media.summarise()}"
9+
10+
11+
fun PlaylistItemDomain.rewriteIdsToSource(source: Source, locator: Locator?) = this.copy(
12+
id = this.id?.copy(source = source, locator = locator),
13+
media = this.media.rewriteIdsToSource(source, locator)
14+
)

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

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ import kotlinx.coroutines.Dispatchers
1919
import kotlinx.coroutines.withContext
2020
import org.koin.core.component.KoinComponent
2121
import org.koin.core.component.inject
22+
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Identifier.Locator
2223
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source
2324
import uk.co.sentinelweb.cuer.app.orchestrator.OrchestratorContract.Source.*
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
29-
import uk.co.sentinelweb.cuer.domain.PlaylistAndChildrenDomain
30+
import uk.co.sentinelweb.cuer.domain.*
3031
import uk.co.sentinelweb.cuer.domain.ext.deserialisePlaylistItem
3132
import uk.co.sentinelweb.cuer.domain.ext.domainMessageJsonSerializer
33+
import uk.co.sentinelweb.cuer.domain.ext.rewriteIdsToSource
3234
import uk.co.sentinelweb.cuer.domain.ext.serialise
3335
import uk.co.sentinelweb.cuer.domain.system.ErrorDomain
3436
import uk.co.sentinelweb.cuer.domain.system.ErrorDomain.Level.ERROR
@@ -329,7 +331,7 @@ class JvmRemoteWebServer(
329331
val path = call.parameters[FOLDER_LIST_API.P_PARAM]
330332
logWrapper.d("Folder: $path")
331333
getFolderListUseCase.getFolderList(path)
332-
?.let { rewriteIdsToRemote(it) } // todo rewrite platformid -> http
334+
?.rewriteIdsToSource(LOCAL_NETWORK, localRepository.localNode.locator())
333335
?.let { ResponseDomain(it) }
334336
?.apply { call.respondText(serialise(), ContentType.Application.Json) }
335337
?: apply {
@@ -384,43 +386,6 @@ class JvmRemoteWebServer(
384386
}
385387
}
386388
}
387-
388-
private fun rewriteIdsToRemote(it: PlaylistAndChildrenDomain) = it.copy(
389-
playlist = it.playlist.copy(
390-
id = it.playlist.id?.copy(
391-
source = LOCAL_NETWORK,
392-
locator = localRepository.localNode.locator()
393-
),
394-
items = it.playlist.items.map {
395-
it.copy(
396-
id = it.id?.copy(
397-
source = LOCAL_NETWORK,
398-
locator = localRepository.localNode.locator()
399-
),
400-
media = it.media.copy(
401-
id = it.media.id?.copy(
402-
source = LOCAL_NETWORK,
403-
locator = localRepository.localNode.locator()
404-
),
405-
channelData = it.media.channelData.copy(
406-
id = it.media.channelData.id?.copy(
407-
source = LOCAL_NETWORK,
408-
locator = localRepository.localNode.locator()
409-
)
410-
)
411-
)
412-
)
413-
}
414-
),
415-
children = it.children.map { child ->
416-
child.copy(
417-
id = child.id?.copy(
418-
source = REMOTE,
419-
locator = localRepository.localNode.locator()
420-
)
421-
)
422-
}
423-
)
424389
}
425390

426391

shared/src/commonMain/kotlin/uk/co/sentinelweb/cuer/app/util/cuercast/CuerCastPlayerWatcher.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class CuerCastPlayerWatcher(
147147
withContext(coroutines.Main) {
148148
result.takeIf { it.isSuccessful }
149149
?.data
150-
?.let { addBlankRemoteIdToItem(it) }
150+
//?.let { addBlankRemoteIdToItem(it) }
151151
?.let { addThumbnailToMedia(it) }
152152
?.apply { mainPlayerControls?.setPlayerState(playbackState) }
153153
?.apply { mainPlayerControls?.setPlaylistItem(item) }
@@ -208,14 +208,14 @@ class CuerCastPlayerWatcher(
208208
)
209209
} else it
210210

211-
private fun addBlankRemoteIdToItem(it: PlayerSessionContract.PlayerStatusMessage) =
212-
if (it.item.id == null) {
213-
it.copy(
214-
item = it.item.copy(
215-
id = Identifier(GUID(""), LOCAL_NETWORK, remoteNode?.locator())
216-
)
217-
)
218-
} else it
211+
// private fun addBlankRemoteIdToItem(it: PlayerSessionContract.PlayerStatusMessage) =
212+
// if (it.item.id == null) {
213+
// it.copy(
214+
// item = it.item.copy(
215+
// id = Identifier(GUID(""), LOCAL_NETWORK, remoteNode?.locator())
216+
// )
217+
// )
218+
// } else it
219219

220220

221221
private val controlsListener = object : PlayerContract.PlayerControls.Listener {

0 commit comments

Comments
 (0)