Skip to content

Commit 5dd18b0

Browse files
MGaetan89StaehliJ
andauthored
Add SAM endpoints and CH/WW locations (#736)
Co-authored-by: Joaquim Stähli <[email protected]>
1 parent b155c6d commit 5dd18b0

File tree

19 files changed

+870
-581
lines changed

19 files changed

+870
-581
lines changed

pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/SRGMediaItemBuilder.kt

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
2222
private val mediaItemBuilder = mediaItem.buildUpon()
2323
private var urn: String = mediaItem.mediaId
2424
private var host: URL = IlHost.DEFAULT
25+
private var forceSAM: Boolean = false
26+
private var forceLocation: String? = null
2527
private var vector: String = Vector.MOBILE
2628

2729
init {
2830
urn = mediaItem.mediaId
29-
mediaItem.localConfiguration?.uri?.let { uri ->
31+
mediaItem.localConfiguration?.let { localConfiguration ->
32+
val uri = localConfiguration.uri
3033
val urn = uri.lastPathSegment
3134
if (uri.toString().contains(PATH) && urn.isValidMediaUrn()) {
3235
uri.host?.let { hostname -> host = URL(Uri.Builder().scheme(host.protocol).authority(hostname).build().toString()) }
3336
this.urn = urn!!
34-
uri.getQueryParameter("vector")?.let { vector = it }
37+
this.forceSAM = uri.getQueryParameter(PARAM_FORCE_SAM)?.toBooleanStrictOrNull() ?: false
38+
this.forceLocation = uri.getQueryParameter(PARAM_FORCE_LOCATION)
39+
uri.getQueryParameter(PARAM_VECTOR)?.let { vector = it }
3540
}
3641
}
3742
}
@@ -74,6 +79,28 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
7479
return this
7580
}
7681

82+
/**
83+
* Set force SAM
84+
*
85+
* @param forceSAM `true` to force the use of the SAM backend, `false` otherwise.
86+
* @return this for convenience
87+
*/
88+
fun setForceSAM(forceSAM: Boolean): SRGMediaItemBuilder {
89+
this.forceSAM = forceSAM
90+
return this
91+
}
92+
93+
/**
94+
* Set force location
95+
*
96+
* @param forceLocation The location to use on the IL/SAM backend calls. Can be `null`, `CH`, or `WW`.
97+
* @return this for convenience
98+
*/
99+
fun setForceLocation(forceLocation: String?): SRGMediaItemBuilder {
100+
this.forceLocation = forceLocation
101+
return this
102+
}
103+
77104
/**
78105
* Set vector
79106
*
@@ -98,8 +125,17 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
98125
val uri = Uri.Builder().apply {
99126
scheme(host.protocol)
100127
authority(host.host)
128+
if (forceSAM) {
129+
appendEncodedPath("sam")
130+
}
101131
appendEncodedPath(PATH)
102132
appendEncodedPath(urn)
133+
if (forceSAM) {
134+
appendQueryParameter(PARAM_FORCE_SAM, true.toString())
135+
}
136+
if (!forceLocation.isNullOrBlank()) {
137+
appendQueryParameter(PARAM_FORCE_LOCATION, forceLocation)
138+
}
103139
if (vector.isNotBlank()) {
104140
appendQueryParameter(PARAM_VECTOR, vector)
105141
}
@@ -112,6 +148,8 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
112148
private companion object {
113149
private const val PATH = "integrationlayer/2.1/mediaComposition/byUrn/"
114150
private const val PARAM_ONLY_CHAPTERS = "onlyChapters"
151+
private const val PARAM_FORCE_SAM = "forceSAM"
152+
private const val PARAM_FORCE_LOCATION = "forceLocation"
115153
private const val PARAM_VECTOR = "vector"
116154
}
117155
}

pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/integrationlayer/ResourceSelector.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ import ch.srgssr.pillarbox.core.business.integrationlayer.data.Resource
1313
*/
1414
internal class ResourceSelector {
1515
/**
16-
* Select the first resource from chapter that is playable by the Player.
16+
* Select the first resource from [chapter] that is playable by the Player.
1717
*
18-
* @param chapter
18+
* @param chapter The [Chapter].
1919
* @return null if no compatible resource is found.
2020
*/
21-
@Suppress("SwallowedException")
2221
fun selectResourceFromChapter(chapter: Chapter): Resource? {
23-
return try {
24-
chapter.listResource?.first {
25-
(it.type == Resource.Type.DASH || it.type == Resource.Type.HLS || it.type == Resource.Type.PROGRESSIVE) &&
26-
(it.drmList == null || it.drmList.any { drm -> drm.type == Drm.Type.WIDEVINE })
27-
}
28-
} catch (e: NoSuchElementException) {
29-
null
22+
return chapter.listResource?.find {
23+
(it.type == Resource.Type.DASH || it.type == Resource.Type.HLS || it.type == Resource.Type.PROGRESSIVE) &&
24+
(it.drmList.isNullOrEmpty() || it.drmList.any { drm -> drm.type == Drm.Type.WIDEVINE })
3025
}
3126
}
3227
}

pillarbox-core-business/src/test/java/ch/srgssr/pillarbox/core/business/MediaItemUrnTest.kt

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

0 commit comments

Comments
 (0)