-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add live TV zapping interface #3216
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
Open
Wiojelt
wants to merge
7
commits into
recloudstream:master
Choose a base branch
from
Wiojelt:feature/live-tv-zapping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fcbb369
feat: add live TV zapping interface
Wiojelt 62b2933
refactor: integrate live zapping with player architecture
Wiojelt 425032a
fix: preserve live player dpad navigation
Wiojelt 1a1b4e6
fix: keep live playback running in channel popup
Wiojelt 0ffdf9d
fix: distinguish live channel selector
Wiojelt feb605b
fix: preserve player navigation during live zapping
Wiojelt dd49d5f
fix: add channel list to TV focus navigation
Wiojelt 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
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/lagradost/cloudstream3/ui/player/LiveZappingGenerator.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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package com.lagradost.cloudstream3.ui.player | ||
|
|
||
| import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull | ||
| import com.lagradost.cloudstream3.LiveStreamLoadResponse | ||
| import com.lagradost.cloudstream3.SearchResponse | ||
| import com.lagradost.cloudstream3.TvType | ||
| import com.lagradost.cloudstream3.mvvm.Resource | ||
| import com.lagradost.cloudstream3.ui.APIRepository | ||
| import com.lagradost.cloudstream3.ui.result.ResultEpisode | ||
| import com.lagradost.cloudstream3.ui.result.buildResultEpisode | ||
| import com.lagradost.cloudstream3.utils.ExtractorLinkType | ||
| import com.lagradost.cloudstream3.utils.ExtractorLink | ||
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| private data class LiveZappingChannel( | ||
| val name: String, | ||
| val url: String, | ||
| val apiName: String, | ||
| val poster: String?, | ||
| ) | ||
|
|
||
| private fun liveEpisode(index: Int, channel: LiveZappingChannel): ResultEpisode = buildResultEpisode( | ||
| headerName = channel.name, | ||
| name = channel.name, | ||
| poster = channel.poster, | ||
| episode = index, | ||
| data = channel.url, | ||
| apiName = channel.apiName, | ||
| id = "${channel.apiName}:${channel.url}".hashCode(), | ||
| index = index, | ||
| tvType = TvType.Live, | ||
| parentId = "${channel.apiName}:${channel.url}".hashCode(), | ||
| ) | ||
|
|
||
| /** | ||
| * A normal player generator whose entries are the live channels from one Home row. | ||
| * The player can therefore use its existing episode list and episode index handling. | ||
| */ | ||
| class LiveZappingGenerator private constructor( | ||
| channels: List<LiveZappingChannel>, | ||
| ) : VideoGenerator<ResultEpisode>(channels.mapIndexed(::liveEpisode)) { | ||
| companion object { | ||
| private val pending = ConcurrentHashMap<String, List<LiveZappingChannel>>() | ||
|
|
||
| private fun key(url: String, apiName: String) = "$apiName\n$url" | ||
|
|
||
| fun remember(response: SearchResponse, channels: List<SearchResponse>) { | ||
| pending[key(response.url, response.apiName)] = channels.map { | ||
| LiveZappingChannel(it.name, it.url, it.apiName, it.posterUrl) | ||
| } | ||
| } | ||
|
|
||
| fun take(url: String, apiName: String, name: String?): Pair<LiveZappingGenerator, Int>? { | ||
| val channels = pending.remove(key(url, apiName)) ?: return null | ||
| if (channels.isEmpty()) return null | ||
| val index = channels.indexOfFirst { it.url == url && it.apiName == apiName && (name == null || it.name == name) } | ||
| .takeIf { it >= 0 } | ||
| ?: channels.indexOfFirst { it.url == url && it.apiName == apiName } | ||
| if (index < 0) return null | ||
| return LiveZappingGenerator(channels) to index | ||
| } | ||
|
|
||
| fun discard(url: String, apiName: String) { | ||
| pending.remove(key(url, apiName)) | ||
| } | ||
| } | ||
|
|
||
| override val hasCache: Boolean = false | ||
| override val canSkipLoading: Boolean = false | ||
| override fun getId(index: Int): Int? = videos.getOrNull(index)?.id | ||
|
|
||
| override suspend fun generateLinks( | ||
| clearCache: Boolean, | ||
| sourceTypes: Set<ExtractorLinkType>, | ||
| callback: (Pair<ExtractorLink?, ExtractorUri?>) -> Unit, | ||
| subtitleCallback: (SubtitleData) -> Unit, | ||
| offset: Int, | ||
| isCasting: Boolean, | ||
| ): Boolean { | ||
| val episode = videos.getOrNull(offset) ?: return false | ||
| val api = getApiFromNameNull(episode.apiName) ?: return false | ||
| val loaded = APIRepository(api).load(episode.data) | ||
| val live = (loaded as? Resource.Success)?.value as? LiveStreamLoadResponse ?: return false | ||
| return APIRepository(api).loadLinks( | ||
| live.dataUrl, | ||
| isCasting, | ||
| subtitleCallback = { subtitleCallback(PlayerSubtitleHelper.getSubtitleData(it)) }, | ||
| callback = { link -> callback(link to null) }, | ||
| ) | ||
| } | ||
| } |
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
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.
Use AppSettings(context).player.zappingEnabled instead