mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Added player intent
This commit is contained in:
parent
019399952f
commit
9c40abc4d3
6 changed files with 47 additions and 8 deletions
|
@ -98,6 +98,16 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<!-- cloudstreamplayer://encodedUrl?name=Dune -->
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:scheme="cloudstreamplayer" />
|
||||||
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
@ -57,6 +58,7 @@ import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2Apis
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString
|
||||||
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringPlayer
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringResumeWatching
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringResumeWatching
|
||||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringSearch
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringSearch
|
||||||
|
@ -65,6 +67,9 @@ import com.lagradost.cloudstream3.ui.APIRepository
|
||||||
import com.lagradost.cloudstream3.ui.WatchType
|
import com.lagradost.cloudstream3.ui.WatchType
|
||||||
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
|
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
|
||||||
import com.lagradost.cloudstream3.ui.home.HomeViewModel
|
import com.lagradost.cloudstream3.ui.home.HomeViewModel
|
||||||
|
import com.lagradost.cloudstream3.ui.player.BasicLink
|
||||||
|
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
||||||
|
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
||||||
import com.lagradost.cloudstream3.ui.result.ResultViewModel2
|
import com.lagradost.cloudstream3.ui.result.ResultViewModel2
|
||||||
import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST
|
import com.lagradost.cloudstream3.ui.result.START_ACTION_RESUME_LATEST
|
||||||
import com.lagradost.cloudstream3.ui.result.setImage
|
import com.lagradost.cloudstream3.ui.result.setImage
|
||||||
|
@ -274,6 +279,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
isWebview: Boolean
|
isWebview: Boolean
|
||||||
): Boolean =
|
): Boolean =
|
||||||
with(activity) {
|
with(activity) {
|
||||||
|
// TODO MUCH BETTER HANDLING
|
||||||
|
|
||||||
// Invalid URIs can crash
|
// Invalid URIs can crash
|
||||||
fun safeURI(uri: String) = normalSafeApiCall { URI(uri) }
|
fun safeURI(uri: String) = normalSafeApiCall { URI(uri) }
|
||||||
|
|
||||||
|
@ -329,6 +336,20 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
// It might be better to use the QuickSearch.
|
// It might be better to use the QuickSearch.
|
||||||
nav_view?.selectedItemId = R.id.navigation_search
|
nav_view?.selectedItemId = R.id.navigation_search
|
||||||
nav_rail_view?.selectedItemId = R.id.navigation_search
|
nav_rail_view?.selectedItemId = R.id.navigation_search
|
||||||
|
} else if (safeURI(str)?.scheme == appStringPlayer) {
|
||||||
|
val uri = Uri.parse(str)
|
||||||
|
val name = uri.getQueryParameter("name")
|
||||||
|
val url = URLDecoder.decode(uri.authority, "UTF-8")
|
||||||
|
|
||||||
|
navigate(
|
||||||
|
R.id.global_to_navigation_player,
|
||||||
|
GeneratorPlayer.newInstance(
|
||||||
|
LinkGenerator(
|
||||||
|
listOf(BasicLink(url, name)),
|
||||||
|
extract = true,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
} else if (safeURI(str)?.scheme == appStringResumeWatching) {
|
} else if (safeURI(str)?.scheme == appStringResumeWatching) {
|
||||||
val id =
|
val id =
|
||||||
str.substringAfter("$appStringResumeWatching://").toIntOrNull()
|
str.substringAfter("$appStringResumeWatching://").toIntOrNull()
|
||||||
|
|
|
@ -45,6 +45,7 @@ abstract class AccountManager(private val defIndex: Int) : AuthAPI {
|
||||||
|
|
||||||
const val appString = "cloudstreamapp"
|
const val appString = "cloudstreamapp"
|
||||||
const val appStringRepo = "cloudstreamrepo"
|
const val appStringRepo = "cloudstreamrepo"
|
||||||
|
const val appStringPlayer = "cloudstreamplayer"
|
||||||
|
|
||||||
// Instantly start the search given a query
|
// Instantly start the search given a query
|
||||||
const val appStringSearch = "cloudstreamsearch"
|
const val appStringSearch = "cloudstreamsearch"
|
||||||
|
|
|
@ -24,7 +24,6 @@ import com.lagradost.cloudstream3.mvvm.observe
|
||||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
||||||
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
|
||||||
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
import com.lagradost.cloudstream3.ui.player.LinkGenerator
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
||||||
|
@ -40,6 +39,7 @@ import kotlinx.android.synthetic.main.stream_input.*
|
||||||
import android.text.format.Formatter.formatShortFileSize
|
import android.text.format.Formatter.formatShortFileSize
|
||||||
import androidx.core.widget.doOnTextChanged
|
import androidx.core.widget.doOnTextChanged
|
||||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
||||||
|
import com.lagradost.cloudstream3.ui.player.BasicLink
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ class DownloadFragment : Fragment() {
|
||||||
R.id.global_to_navigation_player,
|
R.id.global_to_navigation_player,
|
||||||
GeneratorPlayer.newInstance(
|
GeneratorPlayer.newInstance(
|
||||||
LinkGenerator(
|
LinkGenerator(
|
||||||
listOf(url),
|
listOf(BasicLink(url)),
|
||||||
extract = true,
|
extract = true,
|
||||||
referer = referer,
|
referer = referer,
|
||||||
isM3u8 = dialog.hls_switch?.isChecked
|
isM3u8 = dialog.hls_switch?.isChecked
|
||||||
|
|
|
@ -42,7 +42,7 @@ class DownloadedPlayerActivity : AppCompatActivity() {
|
||||||
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
|
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
|
||||||
LinkGenerator(
|
LinkGenerator(
|
||||||
listOf(
|
listOf(
|
||||||
url
|
BasicLink(url)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,8 +5,15 @@ import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to open the player more easily with the LinkGenerator
|
||||||
|
**/
|
||||||
|
data class BasicLink(
|
||||||
|
val url: String,
|
||||||
|
val name: String? = null,
|
||||||
|
)
|
||||||
class LinkGenerator(
|
class LinkGenerator(
|
||||||
private val links: List<String>,
|
private val links: List<BasicLink>,
|
||||||
private val extract: Boolean = true,
|
private val extract: Boolean = true,
|
||||||
private val referer: String? = null,
|
private val referer: String? = null,
|
||||||
private val isM3u8: Boolean? = null
|
private val isM3u8: Boolean? = null
|
||||||
|
@ -47,7 +54,7 @@ class LinkGenerator(
|
||||||
offset: Int
|
offset: Int
|
||||||
): Boolean {
|
): Boolean {
|
||||||
links.amap { link ->
|
links.amap { link ->
|
||||||
if (!extract || !loadExtractor(link, referer, {
|
if (!extract || !loadExtractor(link.url, referer, {
|
||||||
subtitleCallback(PlayerSubtitleHelper.getSubtitleData(it))
|
subtitleCallback(PlayerSubtitleHelper.getSubtitleData(it))
|
||||||
}) {
|
}) {
|
||||||
callback(it to null)
|
callback(it to null)
|
||||||
|
@ -57,11 +64,11 @@ class LinkGenerator(
|
||||||
callback(
|
callback(
|
||||||
ExtractorLink(
|
ExtractorLink(
|
||||||
"",
|
"",
|
||||||
link,
|
link.name ?: link.url,
|
||||||
unshortenLinkSafe(link), // unshorten because it might be a raw link
|
unshortenLinkSafe(link.url), // unshorten because it might be a raw link
|
||||||
referer ?: "",
|
referer ?: "",
|
||||||
Qualities.Unknown.value, isM3u8 ?: normalSafeApiCall {
|
Qualities.Unknown.value, isM3u8 ?: normalSafeApiCall {
|
||||||
URI(link).path?.substringAfterLast(".")?.contains("m3u")
|
URI(link.url).path?.substringAfterLast(".")?.contains("m3u")
|
||||||
} ?: false
|
} ?: false
|
||||||
) to null
|
) to null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue