@@ -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}
0 commit comments