Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ object RepositoryManager {

suspend fun parseRepoUrl(url: String): String? {
val fixedUrl = url.trim()
val githubRepoRegex = Regex("""^https?://github\.com/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?.*$""", RegexOption.IGNORE_CASE)
val ghMatch = githubRepoRegex.find(fixedUrl)
if (ghMatch != null && !fixedUrl.endsWith(".json")) {
val (user, repoName) = ghMatch.destructured
return "https://raw.githubusercontent.com/$user/$repoName/builds/repo.json"
}

return if (fixedUrl.contains("^https?://".toRegex())) {
fixedUrl
} else if (fixedUrl.contains("^(cloudstreamrepo://)|(https://cs\\.repo/\\??)".toRegex())) {
Expand Down Expand Up @@ -239,8 +246,18 @@ object RepositoryManager {
}
}

val LIVE_HUB_REPO = RepositoryData(
iconUrl = "https://raw.githubusercontent.com/sika200581/cloudstream-live-hub/builds/icon.png",
name = "CloudStream Live Hub (Kick/Twitch/YouTube)",
url = "https://raw.githubusercontent.com/sika200581/cloudstream-live-hub/builds/repo.json"
)

fun getRepositories(): Array<RepositoryData> {
return getKey<Array<RepositoryData>>(REPOSITORIES_KEY) ?: emptyArray()
val repos = getKey<Array<RepositoryData>>(REPOSITORIES_KEY) ?: emptyArray()
if (repos.isEmpty()) {
return arrayOf(LIVE_HUB_REPO)
}
return repos
}

// Don't want to read before we write in another thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,14 @@ class DownloadQueueService : Service() {
override fun onBind(intent: Intent?): IBinder? = null

override fun onTimeout(reason: Int) {
stopSelf()
Log.e(TAG, "Service stopped due to timeout: $reason")
isRunning = false
_downloadInstances.value.forEach { instance ->
safe {
instance.cancelDownload()
}
}
stopSelf()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,27 @@ class WebviewFragment : BaseFragment<FragmentWebviewBinding>(
view: WebView?,
request: WebResourceRequest?
): Boolean {
val requestUrl = request?.url.toString()
val requestUrl = request?.url?.toString() ?: return false
val performedAction = MainActivity.handleAppIntentUrl(activity, requestUrl, true)
if (performedAction) {
findNavController().popBackStack()
return true
}

if (!requestUrl.startsWith("http://") && !requestUrl.startsWith("https://") &&
!requestUrl.startsWith("about:") && !requestUrl.startsWith("javascript:")) {
return try {
val intent = android.content.Intent.parseUri(requestUrl, android.content.Intent.URI_INTENT_SCHEME)
if (activity != null && intent.resolveActivity(activity!!.packageManager) != null) {
activity?.startActivity(intent)
}
true
} catch (e: Throwable) {
com.lagradost.cloudstream3.mvvm.logError(e)
true
}
}

return super.shouldOverrideUrlLoading(view, request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,16 @@ class DownloadFragment : BaseFragment<FragmentDownloadsBinding>(
if (!preventAutoSwitching) activateSwitchOnHls(text?.toString(), binding)
}

(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager)?.primaryClip?.getItemAt(
0
)?.text?.toString()?.let { copy ->
val fixedText = copy.trim()
binding.streamUrl.setText(fixedText)
activateSwitchOnHls(fixedText, binding)
safe {
val clipboard = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
val primaryClip = clipboard?.primaryClip
if (primaryClip != null && primaryClip.itemCount > 0) {
primaryClip.getItemAt(0)?.text?.toString()?.let { copy ->
val fixedText = copy.trim()
binding.streamUrl.setText(fixedText)
activateSwitchOnHls(fixedText, binding)
}
}
}

binding.applyBtt.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
docs: Chip?,
movies: Chip?,
asian: Chip?,
shortDrama: Chip?,
livestream: Chip?,
torrent: Chip?,
nsfw: Chip?,
Expand All @@ -296,6 +297,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
Pair(tvs, listOf(TvType.TvSeries)),
Pair(anime, listOf(TvType.Anime, TvType.OVA, TvType.AnimeMovie)),
Pair(asian, listOf(TvType.AsianDrama)),
Pair(shortDrama, listOf(TvType.ShortDrama, TvType.AsianDrama)),
Pair(cartoons, listOf(TvType.Cartoon)),
Pair(docs, listOf(TvType.Documentary)),
Pair(livestream, listOf(TvType.Live)),
Expand All @@ -312,6 +314,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(
header.homeSelectDocumentaries,
header.homeSelectMovies,
header.homeSelectAsian,
header.homeSelectShortDrama,
header.homeSelectLivestreams,
header.homeSelectTorrents,
header.homeSelectNsfw,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.lagradost.cloudstream3.ui.BaseAdapter
import com.lagradost.cloudstream3.ui.BaseDiffCallback
import com.lagradost.cloudstream3.ui.ViewHolderState
import com.lagradost.cloudstream3.ui.newSharedPool
import com.lagradost.cloudstream3.ui.player.MultiPlayerManager
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
Expand Down Expand Up @@ -95,13 +96,17 @@ open class ParentItemAdapter(
val binding = holder.view
if (binding !is HomepageParentBinding) return
val info = item.list
val sectionClickCallback: (SearchClickCallback) -> Unit = { click ->
MultiPlayerManager.setCurrentHomeSection(info.name, info.list)
clickCallback(click)
}
binding.apply {
val currentAdapter = homeChildRecyclerview.adapter as? HomeChildItemAdapter
if (currentAdapter == null) {
homeChildRecyclerview.setRecycledViewPool(HomeChildItemAdapter.sharedPool)
homeChildRecyclerview.adapter = HomeChildItemAdapter(
id = id + position + 100,
clickCallback = clickCallback,
clickCallback = sectionClickCallback,
nextFocusUp = homeChildRecyclerview.nextFocusUpId,
nextFocusDown = homeChildRecyclerview.nextFocusDownId,
).apply {
Expand All @@ -113,7 +118,7 @@ open class ParentItemAdapter(
currentAdapter.apply {
isHorizontal = info.isHorizontalImages
hasNext = item.hasNext
this.clickCallback = this@ParentItemAdapter.clickCallback
this.clickCallback = sectionClickCallback
nextFocusUp = homeChildRecyclerview.nextFocusUpId
nextFocusDown = homeChildRecyclerview.nextFocusDownId
submitIncomparableList(item.list.list)
Expand Down Expand Up @@ -190,4 +195,4 @@ open class ParentItemAdapter(
@Suppress("DEPRECATION")
inline fun <reified T> Bundle.getSafeParcelable(key: String): T? =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) getParcelable(key)
else getParcelable(key, T::class.java)
else getParcelable(key, T::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ class CS3IPlayer : IPlayer {
override fun getPosition(): Long? = exoPlayer?.currentPosition
override fun getIsPlaying(): Boolean = isPlaying
override fun getPlaybackSpeed(): Float = playBackSpeed
override fun getCurrentLink(): ExtractorLink? = currentLink
override fun getExoPlayer(): ExoPlayer? = exoPlayer
override var volume: Float
get() = exoPlayer?.volume ?: 1.0f
set(value) {
val clamped = value.coerceIn(0f, 1f)
exoPlayer?.volume = clamped
}

/**
* Tracks reported to be used by exoplayer, since sometimes it has a mind of it's own when selecting subs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@ open class FullScreenPlayer : AbstractPlayerFragment<FragmentPlayerBinding>(
throw NotImplementedError()
}

open fun openMultiView() {
val act = activity as? androidx.appcompat.app.AppCompatActivity ?: return
val activeLink = player.getCurrentLink()
val activeTitle = playerBinding?.playerVideoTitle?.text?.toString()?.takeIf { it.isNotBlank() } ?: activeLink?.name ?: "Main Stream"

if (activeLink != null) {
MultiPlayerManager.setMainStream(activeLink, activeTitle)
}

player.handleEvent(CSPlayerEvent.Pause)

act.supportFragmentManager.beginTransaction()
.replace(android.R.id.content, MultiViewPlayerFragment())
.addToBackStack("MultiViewPlayer")
.commit()
}

open fun showTracksDialogue() {
throw NotImplementedError()
}
Expand Down Expand Up @@ -1549,6 +1566,10 @@ open class FullScreenPlayer : AbstractPlayerFragment<FragmentPlayerBinding>(
showMirrorsDialogue()
}

view?.findViewById<View>(R.id.player_multiview_btn)?.setOnClickListener {
openMultiView()
}

playerTracksBtt.setOnClickListener {
showTracksDialogue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,27 @@ class GeneratorPlayer : FullScreenPlayer() {
}


override fun openMultiView() {
val sources = viewModel.state.links.mapNotNull { it.first }
val episodes = allMeta ?: emptyList()
MultiPlayerManager.setAvailableSourcesAndEpisodes(sources, episodes)

// The last home row clicked is global state. Only keep it when it belongs to
// the extension that provided the item currently playing.
val currentProvider = (currentMeta as? ResultEpisode)?.apiName
?: player.getCurrentLink()?.source
val matchingHomeStreams = currentProvider?.let { provider ->
MultiPlayerManager.currentHomeSectionStreams.filter {
it.apiName.equals(provider, ignoreCase = true)
}
}.orEmpty()
MultiPlayerManager.setCurrentHomeSection(
if (matchingHomeStreams.isEmpty()) "" else MultiPlayerManager.currentHomeSectionName.orEmpty(),
matchingHomeStreams
)
super.openMultiView()
}

override fun showMirrorsDialogue() {
try {
currentSelectedSubtitles = player.getCurrentPreferredSubtitle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ interface IPlayer {
fun setPlaybackSpeed(speed: Float)

fun getIsPlaying(): Boolean
var volume: Float
fun getCurrentLink(): ExtractorLink? = null
fun getExoPlayer(): androidx.media3.exoplayer.ExoPlayer? = null
/** Current player duration in milliseconds */
fun getDuration(): Long?
/** Current player position in milliseconds */
Expand Down
Loading
Loading