Skip to content

Commit

Permalink
Add SAM endpoints and CH/WW locations (#736)
Browse files Browse the repository at this point in the history
Co-authored-by: Joaquim Stähli <[email protected]>
  • Loading branch information
MGaetan89 and StaehliJ authored Oct 14, 2024
1 parent b155c6d commit 5dd18b0
Show file tree
Hide file tree
Showing 19 changed files with 870 additions and 581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
private val mediaItemBuilder = mediaItem.buildUpon()
private var urn: String = mediaItem.mediaId
private var host: URL = IlHost.DEFAULT
private var forceSAM: Boolean = false
private var forceLocation: String? = null
private var vector: String = Vector.MOBILE

init {
urn = mediaItem.mediaId
mediaItem.localConfiguration?.uri?.let { uri ->
mediaItem.localConfiguration?.let { localConfiguration ->
val uri = localConfiguration.uri
val urn = uri.lastPathSegment
if (uri.toString().contains(PATH) && urn.isValidMediaUrn()) {
uri.host?.let { hostname -> host = URL(Uri.Builder().scheme(host.protocol).authority(hostname).build().toString()) }
this.urn = urn!!
uri.getQueryParameter("vector")?.let { vector = it }
this.forceSAM = uri.getQueryParameter(PARAM_FORCE_SAM)?.toBooleanStrictOrNull() ?: false
this.forceLocation = uri.getQueryParameter(PARAM_FORCE_LOCATION)
uri.getQueryParameter(PARAM_VECTOR)?.let { vector = it }
}
}
}
Expand Down Expand Up @@ -74,6 +79,28 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
return this
}

/**
* Set force SAM
*
* @param forceSAM `true` to force the use of the SAM backend, `false` otherwise.
* @return this for convenience
*/
fun setForceSAM(forceSAM: Boolean): SRGMediaItemBuilder {
this.forceSAM = forceSAM
return this
}

/**
* Set force location
*
* @param forceLocation The location to use on the IL/SAM backend calls. Can be `null`, `CH`, or `WW`.
* @return this for convenience
*/
fun setForceLocation(forceLocation: String?): SRGMediaItemBuilder {
this.forceLocation = forceLocation
return this
}

/**
* Set vector
*
Expand All @@ -98,8 +125,17 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
val uri = Uri.Builder().apply {
scheme(host.protocol)
authority(host.host)
if (forceSAM) {
appendEncodedPath("sam")
}
appendEncodedPath(PATH)
appendEncodedPath(urn)
if (forceSAM) {
appendQueryParameter(PARAM_FORCE_SAM, true.toString())
}
if (!forceLocation.isNullOrBlank()) {
appendQueryParameter(PARAM_FORCE_LOCATION, forceLocation)
}
if (vector.isNotBlank()) {
appendQueryParameter(PARAM_VECTOR, vector)
}
Expand All @@ -112,6 +148,8 @@ class SRGMediaItemBuilder(mediaItem: MediaItem) {
private companion object {
private const val PATH = "integrationlayer/2.1/mediaComposition/byUrn/"
private const val PARAM_ONLY_CHAPTERS = "onlyChapters"
private const val PARAM_FORCE_SAM = "forceSAM"
private const val PARAM_FORCE_LOCATION = "forceLocation"
private const val PARAM_VECTOR = "vector"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@ import ch.srgssr.pillarbox.core.business.integrationlayer.data.Resource
*/
internal class ResourceSelector {
/**
* Select the first resource from chapter that is playable by the Player.
* Select the first resource from [chapter] that is playable by the Player.
*
* @param chapter
* @param chapter The [Chapter].
* @return null if no compatible resource is found.
*/
@Suppress("SwallowedException")
fun selectResourceFromChapter(chapter: Chapter): Resource? {
return try {
chapter.listResource?.first {
(it.type == Resource.Type.DASH || it.type == Resource.Type.HLS || it.type == Resource.Type.PROGRESSIVE) &&
(it.drmList == null || it.drmList.any { drm -> drm.type == Drm.Type.WIDEVINE })
}
} catch (e: NoSuchElementException) {
null
return chapter.listResource?.find {
(it.type == Resource.Type.DASH || it.type == Resource.Type.HLS || it.type == Resource.Type.PROGRESSIVE) &&
(it.drmList.isNullOrEmpty() || it.drmList.any { drm -> drm.type == Drm.Type.WIDEVINE })
}
}
}

This file was deleted.

Loading

0 comments on commit 5dd18b0

Please sign in to comment.