Skip to content

Commit 1d03b05

Browse files
authored
Refactor: New SkipAPI for SkipStamp (#2601)
1 parent f51885f commit 1d03b05

File tree

9 files changed

+271
-252
lines changed

9 files changed

+271
-252
lines changed

app/src/main/java/com/lagradost/cloudstream3/ui/player/AbstractPlayerFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
5454
import com.lagradost.cloudstream3.utils.AppContextUtils
5555
import com.lagradost.cloudstream3.utils.AppContextUtils.requestLocalAudioFocus
5656
import com.lagradost.cloudstream3.utils.DataStoreHelper
57-
import com.lagradost.cloudstream3.utils.EpisodeSkip
5857
import com.lagradost.cloudstream3.utils.UIHelper
5958
import com.lagradost.cloudstream3.utils.UIHelper.hideSystemUI
6059
import com.lagradost.cloudstream3.utils.UIHelper.popCurrentPage
60+
import com.lagradost.cloudstream3.utils.videoskip.VideoSkipStamp
6161
import java.net.SocketTimeoutException
6262

6363
enum class PlayerResize(@StringRes val nameRes: Int) {
@@ -127,11 +127,11 @@ abstract class AbstractPlayerFragment(
127127
throw NotImplementedError()
128128
}
129129

130-
open fun onTimestamp(timestamp: EpisodeSkip.SkipStamp?) {
130+
open fun onTimestamp(timestamp: VideoSkipStamp?) {
131131

132132
}
133133

134-
open fun onTimestampSkipped(timestamp: EpisodeSkip.SkipStamp) {
134+
open fun onTimestampSkipped(timestamp: VideoSkipStamp) {
135135

136136
}
137137

app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
9595
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
9696
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
9797
import com.lagradost.cloudstream3.utils.DrmExtractorLink
98-
import com.lagradost.cloudstream3.utils.EpisodeSkip
9998
import com.lagradost.cloudstream3.utils.ExtractorLink
10099
import com.lagradost.cloudstream3.utils.ExtractorLinkPlayList
101100
import com.lagradost.cloudstream3.utils.ExtractorLinkType
102101
import com.lagradost.cloudstream3.utils.PLAYREADY_UUID
103102
import com.lagradost.cloudstream3.utils.SubtitleHelper.fromTagToLanguageName
104103
import com.lagradost.cloudstream3.utils.WIDEVINE_UUID
105-
import io.github.anilbeesetti.nextlib.media3ext.ffdecoder.NextRenderersFactory
104+
import com.lagradost.cloudstream3.utils.videoskip.VideoSkipStamp
106105
import kotlinx.coroutines.delay
107106
import okhttp3.Interceptor
108107
import org.chromium.net.CronetEngine
@@ -884,10 +883,10 @@ class CS3IPlayer : IPlayer {
884883
private var currentTextRenderer: TextRenderer? = null
885884
}
886885

887-
private fun getCurrentTimestamp(writePosition: Long? = null): EpisodeSkip.SkipStamp? {
886+
private fun getCurrentTimestamp(writePosition: Long? = null): VideoSkipStamp? {
888887
val position = writePosition ?: this@CS3IPlayer.getPosition() ?: return null
889888
for (lastTimeStamp in lastTimeStamps) {
890-
if (lastTimeStamp.startMs <= position && (position + (toleranceBeforeUs / 1000L) + 1) < lastTimeStamp.endMs) {
889+
if (lastTimeStamp.timestamp.startMs <= position && (position + (toleranceBeforeUs / 1000L) + 1) < lastTimeStamp.timestamp.endMs) {
891890
return lastTimeStamp
892891
}
893892
}
@@ -999,7 +998,7 @@ class CS3IPlayer : IPlayer {
999998
if (lastTimeStamp.skipToNextEpisode) {
1000999
handleEvent(CSPlayerEvent.NextEpisode, source)
10011000
} else {
1002-
seekTo(lastTimeStamp.endMs + 1L)
1001+
seekTo(lastTimeStamp.timestamp.endMs + 1L)
10031002
}
10041003
event(TimestampSkippedEvent(timestamp = lastTimeStamp, source = source))
10051004
}
@@ -1578,9 +1577,9 @@ class CS3IPlayer : IPlayer {
15781577
}
15791578
}
15801579

1581-
private var lastTimeStamps: List<EpisodeSkip.SkipStamp> = emptyList()
1580+
private var lastTimeStamps: List<VideoSkipStamp> = emptyList()
15821581

1583-
override fun addTimeStamps(timeStamps: List<EpisodeSkip.SkipStamp>) {
1582+
override fun addTimeStamps(timeStamps: List<VideoSkipStamp>) {
15841583
lastTimeStamps = timeStamps
15851584
timeStamps.forEach { timestamp ->
15861585
exoPlayer?.createMessage { _, _ ->
@@ -1589,7 +1588,7 @@ class CS3IPlayer : IPlayer {
15891588
// onTimestampInvoked?.invoke(payload)
15901589
}
15911590
?.setLooper(Looper.getMainLooper())
1592-
?.setPosition(timestamp.startMs)
1591+
?.setPosition(timestamp.timestamp.startMs)
15931592
//?.setPayload(timestamp)
15941593
?.setDeleteAfterDelivery(false)
15951594
?.send()

app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
106106
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
107107
import com.lagradost.cloudstream3.utils.DataStoreHelper
108108
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
109-
import com.lagradost.cloudstream3.utils.EpisodeSkip
110109
import com.lagradost.cloudstream3.utils.ExtractorLink
111110
import com.lagradost.cloudstream3.utils.ExtractorLinkType
112111
import com.lagradost.cloudstream3.utils.Qualities
@@ -124,6 +123,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.toPx
124123
import com.lagradost.cloudstream3.utils.downloader.DownloadUtils.getImageBitmapFromUrl
125124
import com.lagradost.cloudstream3.utils.setText
126125
import com.lagradost.cloudstream3.utils.txt
126+
import com.lagradost.cloudstream3.utils.videoskip.VideoSkipStamp
127127
import com.lagradost.safefile.SafeFile
128128
import kotlinx.coroutines.Job
129129
import kotlinx.coroutines.delay
@@ -2052,11 +2052,11 @@ class GeneratorPlayer : FullScreenPlayer() {
20522052
}
20532053
}
20542054

2055-
override fun onTimestampSkipped(timestamp: EpisodeSkip.SkipStamp) {
2055+
override fun onTimestampSkipped(timestamp: VideoSkipStamp) {
20562056
displayTimeStamp(false)
20572057
}
20582058

2059-
override fun onTimestamp(timestamp: EpisodeSkip.SkipStamp?) {
2059+
override fun onTimestamp(timestamp: VideoSkipStamp?) {
20602060
if (timestamp != null) {
20612061
playerBinding?.skipChapterButton?.setText(timestamp.uiText)
20622062
displayTimeStamp(true)

app/src/main/java/com/lagradost/cloudstream3/ui/player/IPlayer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import android.content.Context
44
import android.graphics.Bitmap
55
import android.util.Rational
66
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
7-
import com.lagradost.cloudstream3.utils.EpisodeSkip
87
import com.lagradost.cloudstream3.utils.ExtractorLink
8+
import com.lagradost.cloudstream3.utils.videoskip.VideoSkipStamp
99

1010
enum class PlayerEventType(val value: Int) {
1111
Pause(0),
@@ -86,13 +86,13 @@ data class ErrorEvent(
8686

8787
/** Event when timestamps appear, null when it should disappear */
8888
data class TimestampInvokedEvent(
89-
val timestamp: EpisodeSkip.SkipStamp,
89+
val timestamp: VideoSkipStamp,
9090
override val source: PlayerEventSource = PlayerEventSource.Player,
9191
) : PlayerEvent()
9292

9393
/** Event for when a chapter is skipped, aka when event is handled (or for future use when skip automatically ads/sponsor) */
9494
data class TimestampSkippedEvent(
95-
val timestamp: EpisodeSkip.SkipStamp,
95+
val timestamp: VideoSkipStamp,
9696
override val source: PlayerEventSource = PlayerEventSource.Player,
9797
) : PlayerEvent()
9898

@@ -254,7 +254,7 @@ interface IPlayer {
254254
fun updateSubtitleStyle(style: SaveCaptionStyle)
255255
fun saveData()
256256

257-
fun addTimeStamps(timeStamps: List<EpisodeSkip.SkipStamp>)
257+
fun addTimeStamps(timeStamps: List<VideoSkipStamp>)
258258

259259
fun loadPlayer(
260260
context: Context,

app/src/main/java/com/lagradost/cloudstream3/ui/player/PlayerGeneratorViewModel.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import com.lagradost.cloudstream3.mvvm.safe
1313
import com.lagradost.cloudstream3.mvvm.safeApiCall
1414
import com.lagradost.cloudstream3.ui.result.ResultEpisode
1515
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
16-
import com.lagradost.cloudstream3.utils.EpisodeSkip
1716
import com.lagradost.cloudstream3.utils.ExtractorLink
1817
import com.lagradost.cloudstream3.utils.ExtractorLinkType
18+
import com.lagradost.cloudstream3.utils.videoskip.SkipAPI
19+
import com.lagradost.cloudstream3.utils.videoskip.VideoSkipStamp
1920
import kotlinx.coroutines.Job
2021
import kotlinx.coroutines.launch
2122

@@ -35,8 +36,8 @@ class PlayerGeneratorViewModel : ViewModel() {
3536
private val _loadingLinks = MutableLiveData<Resource<Boolean?>>()
3637
val loadingLinks: LiveData<Resource<Boolean?>> = _loadingLinks
3738

38-
private val _currentStamps = MutableLiveData<List<EpisodeSkip.SkipStamp>>(emptyList())
39-
val currentStamps: LiveData<List<EpisodeSkip.SkipStamp>> = _currentStamps
39+
private val _currentStamps = MutableLiveData<List<VideoSkipStamp>>(emptyList())
40+
val currentStamps: LiveData<List<VideoSkipStamp>> = _currentStamps
4041

4142
private val _currentSubtitleYear = MutableLiveData<Int?>(null)
4243
val currentSubtitleYear: LiveData<Int?> = _currentSubtitleYear
@@ -181,7 +182,7 @@ class PlayerGeneratorViewModel : ViewModel() {
181182
if (page != null && meta is ResultEpisode) {
182183
_currentStamps.postValue(listOf())
183184
_currentStamps.postValue(
184-
EpisodeSkip.getStamps(
185+
SkipAPI.videoStamps(
185186
page,
186187
meta,
187188
duration,

0 commit comments

Comments
 (0)