Merge pull request #3435 from Bnyro/master

Support sharing `live` links to LibreTube
This commit is contained in:
Bnyro 2023-03-28 18:24:22 +02:00 committed by GitHub
commit 81bbbda173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 15 deletions

View File

@ -264,6 +264,7 @@
<data android:pathPrefix="/embed/" /> <data android:pathPrefix="/embed/" />
<data android:pathPrefix="/watch" /> <data android:pathPrefix="/watch" />
<data android:pathPrefix="/shorts/" /> <data android:pathPrefix="/shorts/" />
<data android:pathPrefix="/live/" />
<!-- channel prefix --> <!-- channel prefix -->
<data android:pathPrefix="/channel/" /> <data android:pathPrefix="/channel/" />
<data android:pathPrefix="/user/" /> <data android:pathPrefix="/user/" />

View File

@ -18,8 +18,8 @@ class RouterActivity : BaseActivity() {
// start processing the given text // start processing the given text
handleSendText(Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!)) handleSendText(Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!))
} else if (intent.data != null) { } else if (intent.data != null) {
val uri = intent.data // link shared as text to the app
handleSendText(uri!!) handleSendText(intent.data!!)
} else { } else {
// start app as normal if unknown action, shouldn't be reachable // start app as normal if unknown action, shouldn't be reachable
NavigationHelper.restartMainActivity(this) NavigationHelper.restartMainActivity(this)
@ -30,6 +30,8 @@ class RouterActivity : BaseActivity() {
* Resolve the uri and return a bundle with the arguments * Resolve the uri and return a bundle with the arguments
*/ */
private fun resolveType(intent: Intent, uri: Uri): Intent { private fun resolveType(intent: Intent, uri: Uri): Intent {
val channelNamePaths = listOf("/c/", "/user/")
val videoPaths = listOf("/shorts/", "/embed/", "/v/", "/live/")
when { when {
uri.path!!.contains("/channel/") -> { uri.path!!.contains("/channel/") -> {
val channelId = uri.path!! val channelId = uri.path!!
@ -37,10 +39,12 @@ class RouterActivity : BaseActivity() {
intent.putExtra(IntentData.channelId, channelId) intent.putExtra(IntentData.channelId, channelId)
} }
uri.path!!.contains("/c/") || uri.path!!.contains("/user/") -> { channelNamePaths.any { uri.path!!.contains(it) } -> {
val channelName = uri.path!! var channelName = uri.path!!
.replace("/c/", "")
.replace("/user/", "") channelNamePaths.forEach {
channelName = channelName.replace(it, "")
}
intent.putExtra(IntentData.channelName, channelName) intent.putExtra(IntentData.channelName, channelName)
} }
@ -49,16 +53,17 @@ class RouterActivity : BaseActivity() {
intent.putExtra(IntentData.playlistId, playlistId) intent.putExtra(IntentData.playlistId, playlistId)
} }
uri.path!!.contains("/shorts/") || videoPaths.any { uri.path!!.contains(it) } -> {
uri.path!!.contains("/embed/") || var videoId = uri.path!!
uri.path!!.contains("/v/")
-> { videoPaths.forEach {
val videoId = uri.path!! videoId = videoId.replace(it, "")
.replace("/shorts/", "") }
.replace("/v/", "")
.replace("/embed/", "")
intent.putExtra(IntentData.videoId, videoId) intent.putExtra(IntentData.videoId, videoId)
uri.getQueryParameter("t")
?.let { intent.putExtra(IntentData.timeStamp, it.toTimeInSeconds()) }
} }
uri.path!!.contains("/watch") && uri.query != null -> { uri.path!!.contains("/watch") && uri.query != null -> {
val videoId = uri.getQueryParameter("v") val videoId = uri.getQueryParameter("v")

View File

@ -334,7 +334,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
if (PlayerHelper.swipeGestureEnabled) { if (PlayerHelper.swipeGestureEnabled) {
binding.playerMotionLayout.addSwipeUpListener { binding.playerMotionLayout.addSwipeUpListener {
if(this::streams.isInitialized) { if (this::streams.isInitialized) {
binding.player.hideController() binding.player.hideController()
setFullscreen() setFullscreen()
} }