-
Notifications
You must be signed in to change notification settings - Fork 0
Use Uri.Builder for Uplynk connector
#75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd9cca3
Add Robolectric
MattiasBuelens 401afd9
Use `Uri` in UplynkSsaiDescriptionConverter
MattiasBuelens 30102bf
Rework URL building
MattiasBuelens 627bac7
Rework tests
MattiasBuelens 7a8a614
Use `.seconds`
MattiasBuelens 80f2976
Use `linkedMapOf`
MattiasBuelens deab0d0
Add `QueryParameter` type alias
MattiasBuelens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 58 additions & 23 deletions
81
...n/java/com/theoplayer/android/connector/uplynk/internal/UplynkSsaiDescriptionConverter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,94 @@ | ||
| package com.theoplayer.android.connector.uplynk.internal | ||
|
|
||
| import android.net.Uri | ||
| import androidx.core.net.toUri | ||
| import com.theoplayer.android.connector.uplynk.UplynkSsaiDescription | ||
| import kotlin.time.Duration | ||
|
|
||
| internal class UplynkSsaiDescriptionConverter { | ||
| private val DEFAULT_PREFIX = "https://content.uplynk.com" | ||
|
|
||
| fun buildPreplayVodUrl(ssaiDescription: UplynkSsaiDescription): String = with(ssaiDescription) { | ||
| val prefix = prefix ?: DEFAULT_PREFIX | ||
|
|
||
| return "$prefix/preplay/$urlAssetId?v=2$drmParameters$pingParameters$urlParameters" | ||
| } | ||
|
|
||
| fun buildPreplayLiveUrl(ssaiDescription: UplynkSsaiDescription): String = with(ssaiDescription) { | ||
| val prefix = prefix ?: DEFAULT_PREFIX | ||
| fun buildPreplayVodUrl(ssaiDescription: UplynkSsaiDescription): Uri = | ||
| with(ssaiDescription) { | ||
| return (prefix ?: DEFAULT_PREFIX).toUri().buildUpon().apply { | ||
| appendEncodedPath("preplay/$urlAssetId") | ||
| appendQueryParameter("v", "2") | ||
| drmParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| pingParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| preplayParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| }.build() | ||
| } | ||
|
|
||
| return "$prefix/preplay/$urlAssetType/$urlAssetId?v=2$drmParameters$pingParameters$urlParameters" | ||
| } | ||
| fun buildPreplayLiveUrl(ssaiDescription: UplynkSsaiDescription): Uri = | ||
| with(ssaiDescription) { | ||
| return (prefix ?: DEFAULT_PREFIX).toUri().buildUpon().apply { | ||
| appendEncodedPath("preplay/$urlAssetType/$urlAssetId") | ||
| appendQueryParameter("v", "2") | ||
| drmParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| pingParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| preplayParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| }.build() | ||
| } | ||
|
|
||
| fun buildPlaybackUrl(playUrl: String, ssaiDescription: UplynkSsaiDescription): String = with(ssaiDescription) { | ||
| return "$playUrl$playUrlParameters" | ||
| } | ||
| fun buildPlaybackUrl(playUrl: String, ssaiDescription: UplynkSsaiDescription): Uri = | ||
| with(ssaiDescription) { | ||
| return playUrl.toUri().buildUpon().apply { | ||
| playbackUrlParameters.forEach { (key, value) -> appendQueryParameter(key, value) } | ||
| }.build() | ||
| } | ||
|
|
||
| fun buildAssetInfoUrls( | ||
| ssaiDescription: UplynkSsaiDescription, | ||
| sessionId: String, | ||
| prefix: String | ||
| ): List<String> = with(ssaiDescription) { | ||
| ): List<Uri> = with(ssaiDescription) { | ||
| val urlList = when { | ||
| assetIds.isNotEmpty() -> assetIds.map { | ||
| "$prefix/player/assetinfo/$it.json" | ||
| "$prefix/player/assetinfo/$it.json".toUri() | ||
| } | ||
|
|
||
| externalIds.isNotEmpty() -> externalIds.map { | ||
| "$prefix/player/assetinfo/ext/$userId/$it.json" | ||
| "$prefix/player/assetinfo/ext/$userId/$it.json".toUri() | ||
| } | ||
|
|
||
| else -> emptyList() | ||
| } | ||
| return if (sessionId.isBlank()) { | ||
| urlList | ||
| } else { | ||
| urlList.map { "$it?pbs=$sessionId" } | ||
| urlList.map { url -> | ||
| url.buildUpon().apply { | ||
| appendQueryParameter("pbs", sessionId) | ||
| }.build() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun buildSeekedPingUrl( | ||
| prefix: String, sessionId: String, currentTime: Duration, seekStartTime: Duration | ||
| ) = buildPingUrl(prefix, sessionId, currentTime) + "&ev=seek&ft=${seekStartTime.inWholeSeconds}" | ||
| prefix: String, | ||
| sessionId: String, | ||
| currentTime: Duration, | ||
| seekStartTime: Duration | ||
| ): Uri = buildPingUrl(prefix, sessionId, currentTime).buildUpon().apply { | ||
| appendQueryParameter("ev", "seek") | ||
| appendQueryParameter("ft", seekStartTime.inWholeSeconds.toString()) | ||
| }.build() | ||
|
|
||
| fun buildStartPingUrl( | ||
| prefix: String, sessionId: String, currentTime: Duration | ||
| ) = buildPingUrl(prefix, sessionId, currentTime) + "&ev=start" | ||
| prefix: String, | ||
| sessionId: String, | ||
| currentTime: Duration | ||
| ): Uri = buildPingUrl(prefix, sessionId, currentTime).buildUpon().apply { | ||
| appendQueryParameter("ev", "start") | ||
| }.build() | ||
|
|
||
| fun buildPingUrl( | ||
| prefix: String, sessionId: String, currentTime: Duration | ||
| ) = "$prefix/session/ping/$sessionId.json?v=3&pt=${currentTime.inWholeSeconds}" | ||
| prefix: String, | ||
| sessionId: String, | ||
| currentTime: Duration | ||
| ): Uri = prefix.toUri().buildUpon().apply { | ||
| appendEncodedPath("session/ping/$sessionId.json") | ||
| appendQueryParameter("v", "3") | ||
| appendQueryParameter("pt", currentTime.inWholeSeconds.toString()) | ||
| }.build() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,34 +3,28 @@ package com.theoplayer.android.connector.uplynk.internal | |
| import com.theoplayer.android.connector.uplynk.UplynkAssetType | ||
| import com.theoplayer.android.connector.uplynk.UplynkSsaiDescription | ||
|
|
||
| internal val UplynkSsaiDescription.drmParameters: String | ||
| get() = if (contentProtected) { | ||
| "&manifest=mpd&rmt=wv" | ||
| } else { | ||
| "" | ||
| } | ||
| internal typealias QueryParameter = Pair<String, String> | ||
|
|
||
| internal val UplynkSsaiDescription.urlParameters | ||
| get() = if (preplayParameters.isNotEmpty()) { | ||
| preplayParameters.map { "${it.key}=${it.value}" }.joinToString("&", prefix = "&") | ||
| } else { | ||
| "" | ||
| } | ||
|
|
||
| internal val UplynkSsaiDescription.playUrlParameters | ||
| get() = if (playbackUrlParameters.isNotEmpty()) { | ||
| playbackUrlParameters.map { "${it.key}=${it.value}" }.joinToString("&", prefix = "?") | ||
| internal val UplynkSsaiDescription.drmParameters: List<QueryParameter> | ||
| get() = if (contentProtected) { | ||
| listOf( | ||
| "manifest" to "mpd", | ||
| "rmt" to "wv", | ||
| ) | ||
| } else { | ||
| "" | ||
| listOf() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| internal val UplynkSsaiDescription.pingParameters: String | ||
| internal val UplynkSsaiDescription.pingParameters: List<QueryParameter> | ||
| get() { | ||
| val feature = UplynkPingFeatures.from(this) | ||
| return if (feature == UplynkPingFeatures.NO_PING) { | ||
| "" | ||
| listOf() | ||
| } else { | ||
| "&ad.cping=1&ad.pingf=${feature.pingfValue}" | ||
| listOf( | ||
| "ad.cping" to "1", | ||
| "ad.pingf" to feature.pingfValue.toString() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍