-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathIntroDbSkip.kt
More file actions
80 lines (72 loc) · 3.17 KB
/
Copy pathIntroDbSkip.kt
File metadata and controls
80 lines (72 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.lagradost.cloudstream3.utils.videoskip
import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.LoadResponse.Companion.getImdbId
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.ui.result.ResultEpisode
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
class IntroDbSkip : SkipAPI() {
override val name = "IntroDb"
override val supportedTypes = setOf(TvType.TvSeries, TvType.AsianDrama)
override suspend fun stamps(
data: LoadResponse,
episode: ResultEpisode,
episodeDurationMs: Long
): List<SkipStamp>? {
val season = episode.season ?: return null
val imdbId = data.getImdbId() ?: return null
val url =
"https://api.introdb.app/segments?imdb_id=$imdbId&season=$season&episode=${episode.episode}"
val response = app.get(url).parsed<IntroDbResponse>()
return listOfNotNull(
response.intro?.let {
val start = it.startMs ?: return@let null
val end = it.endMs ?: return@let null
SkipStamp(
type = SkipType.Opening,
startMs = start,
endMs = end
)
},
response.recap?.let {
val start = it.startMs ?: return@let null
val end = it.endMs ?: return@let null
SkipStamp(
type = SkipType.Recap,
startMs = start,
endMs = end
)
},
response.outro?.let {
val start = it.startMs ?: return@let null
val end = it.endMs ?: return@let null
SkipStamp(
type = SkipType.Ending,
startMs = start,
endMs = end
)
}
)
}
@Serializable
data class IntroDbResponse(
@JsonProperty("imdb_id") @SerialName("imdb_id") val imdbId: String?,
@JsonProperty("season") @SerialName("season") val season: Int?,
@JsonProperty("episode") @SerialName("episode") val episode: Int?,
@JsonProperty("intro") @SerialName("intro") val intro: Segment?,
@JsonProperty("recap") @SerialName("recap") val recap: Segment?,
@JsonProperty("outro") @SerialName("outro") val outro: Segment?,
)
@Serializable
data class Segment(
@JsonProperty("start_sec") @SerialName("start_sec") val startSec: Double?,
@JsonProperty("end_sec") @SerialName("end_sec") val endSec: Double?,
@JsonProperty("start_ms") @SerialName("start_ms") val startMs: Long?,
@JsonProperty("end_ms") @SerialName("end_ms") val endMs: Long?,
@JsonProperty("confidence") @SerialName("confidence") val confidence: Double?,
@JsonProperty("submission_count") @SerialName("submission_count") val submissionCount: Int?,
@JsonProperty("updated_at") @SerialName("updated_at") val updatedAt: String?,
)
}