Skip to content

Commit a7f5f9a

Browse files
authored
Feat: TheIntroDBSkip + Bugfix (#2631)
1 parent d7b030e commit a7f5f9a

3 files changed

Lines changed: 80 additions & 2 deletions

File tree

app/src/main/java/com/lagradost/cloudstream3/utils/videoskip/SkipAPI.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ enum class SkipType(@StringRes val res: Int) {
1717
MixedOpening(R.string.skip_type_mixed_op),
1818
MixedEnding(R.string.skip_type_mixed_ed),
1919
Credits(R.string.skip_type_creddits),
20-
Intro(R.string.skip_type_creddits),
20+
Intro(R.string.skip_type_intro),
21+
Preview(R.string.skip_type_preview),
2122
}
2223

2324
data class SkipStamp(
@@ -60,7 +61,7 @@ abstract class SkipAPI {
6061
}
6162

6263
companion object {
63-
private val skipApis: List<SkipAPI> = listOf(AniSkip(), IntroDbSkip())
64+
private val skipApis: List<SkipAPI> = listOf(AniSkip(), TheIntroDBSkip(), IntroDbSkip())
6465
private val cachedStamps = ConcurrentHashMap<Int, List<VideoSkipStamp>>()
6566

6667
/** Get all video timestamps from an episode */
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.lagradost.cloudstream3.utils.videoskip
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty
4+
import com.lagradost.cloudstream3.LoadResponse
5+
import com.lagradost.cloudstream3.LoadResponse.Companion.getImdbId
6+
import com.lagradost.cloudstream3.LoadResponse.Companion.getTMDbId
7+
import com.lagradost.cloudstream3.LoadResponse.Companion.isMovie
8+
import com.lagradost.cloudstream3.TvType
9+
import com.lagradost.cloudstream3.ui.result.ResultEpisode
10+
import com.lagradost.cloudstream3.app
11+
12+
/** https://theintrodb.org/docs */
13+
class TheIntroDBSkip : SkipAPI() {
14+
override val name = "TheIntroDB"
15+
override val supportedTypes = setOf(
16+
TvType.TvSeries, TvType.Cartoon, TvType.Anime, TvType.Movie,
17+
TvType.AsianDrama
18+
)
19+
20+
val mainUrl = "https://api.theintrodb.org"
21+
22+
override suspend fun stamps(
23+
data: LoadResponse,
24+
episode: ResultEpisode,
25+
episodeDurationMs: Long
26+
): List<SkipStamp>? {
27+
val idSuffix =
28+
data.getTMDbId()?.let { tmdbId -> "tmdb_id=$tmdbId" }
29+
?: data.getImdbId()?.let { imdbId -> "imdb_id=$imdbId" }
30+
?: return null
31+
32+
val url = if (data.isMovie()) {
33+
"$mainUrl/v2/media?$idSuffix"
34+
} else {
35+
val season = episode.season ?: return null
36+
"$mainUrl/v2/media?$idSuffix&season=$season&episode=${episode.episode}"
37+
}
38+
val root = app.get(url).parsed<Root>()
39+
return arrayOf(
40+
root.intro to SkipType.Intro,
41+
root.credits to SkipType.Credits,
42+
root.recap to SkipType.Recap,
43+
root.preview to SkipType.Preview
44+
).map { (list, type) ->
45+
list.map { stamp ->
46+
SkipStamp(
47+
type,
48+
stamp.startMs ?: 0L,
49+
stamp.endMs ?: episodeDurationMs
50+
)
51+
}
52+
}.flatten()
53+
}
54+
55+
data class Root(
56+
@JsonProperty("tmdb_id")
57+
val tmdbId: Long,
58+
@JsonProperty("type")
59+
val type: String,
60+
@JsonProperty("intro")
61+
val intro: List<Stamp> = emptyList(),
62+
@JsonProperty("recap")
63+
val recap: List<Stamp> = emptyList(),
64+
@JsonProperty("credits")
65+
val credits: List<Stamp> = emptyList(),
66+
@JsonProperty("preview")
67+
val preview: List<Stamp> = emptyList(),
68+
)
69+
70+
data class Stamp(
71+
@JsonProperty("start_ms")
72+
val startMs: Long?,
73+
@JsonProperty("end_ms")
74+
val endMs: Long?,
75+
)
76+
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@
560560
<string name="skip_type_mixed_ed">Mixed ending</string>
561561
<string name="skip_type_mixed_op">Mixed opening</string>
562562
<string name="skip_type_creddits">Credits</string>
563+
<string name="skip_type_preview">Preview</string>
563564
<string name="skip_type_intro">Intro</string>
564565
<string name="clear_history">Clear history</string>
565566
<string name="history">History</string>

0 commit comments

Comments
 (0)