Skip to content
Merged
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 @@ -17,7 +17,8 @@ enum class SkipType(@StringRes val res: Int) {
MixedOpening(R.string.skip_type_mixed_op),
MixedEnding(R.string.skip_type_mixed_ed),
Credits(R.string.skip_type_creddits),
Intro(R.string.skip_type_creddits),
Intro(R.string.skip_type_intro),
Preview(R.string.skip_type_preview),
}

data class SkipStamp(
Expand Down Expand Up @@ -60,7 +61,7 @@ abstract class SkipAPI {
}

companion object {
private val skipApis: List<SkipAPI> = listOf(AniSkip(), IntroDbSkip())
private val skipApis: List<SkipAPI> = listOf(AniSkip(), TheIntroDBSkip(), IntroDbSkip())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Probably not for this PR in particular, but something I noticed is IntroDB is more particular about what it has, TIDB has more an often more accurate, but some things have start timestamps on TIDB but not IntroDB while having end timestamps on IntroDB but not TIDB. I wander if there is a way to mix what API it can get for different SkipStamp types...

Otherwise perhaps IntroDB should be tried first here since its smaller what it does have may in fact be better than TIDB at times...?

private val cachedStamps = ConcurrentHashMap<Int, List<VideoSkipStamp>>()

/** Get all video timestamps from an episode */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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.LoadResponse.Companion.getTMDbId
import com.lagradost.cloudstream3.LoadResponse.Companion.isMovie
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.ui.result.ResultEpisode
import com.lagradost.cloudstream3.app

/** https://theintrodb.org/docs */
class TheIntroDBSkip : SkipAPI() {
override val name = "TheIntroDB"
override val supportedTypes = setOf(
TvType.TvSeries, TvType.Cartoon, TvType.Anime, TvType.Movie,
TvType.AsianDrama
)

val mainUrl = "https://api.theintrodb.org"

override suspend fun stamps(
data: LoadResponse,
episode: ResultEpisode,
episodeDurationMs: Long
): List<SkipStamp>? {
val idSuffix =
data.getTMDbId()?.let { tmdbId -> "tmdb_id=$tmdbId" }
?: data.getImdbId()?.let { imdbId -> "imdb_id=$imdbId" }
?: return null

val url = if (data.isMovie()) {
"$mainUrl/v2/media?$idSuffix"
} else {
val season = episode.season ?: return null
"$mainUrl/v2/media?$idSuffix&season=$season&episode=${episode.episode}"
}
val root = app.get(url).parsed<Root>()

This comment was marked as resolved.

This comment was marked as resolved.

return arrayOf(
root.intro to SkipType.Intro,
root.credits to SkipType.Credits,
root.recap to SkipType.Recap,
root.preview to SkipType.Preview
).map { (list, type) ->
list.map { stamp ->
SkipStamp(
type,
stamp.startMs ?: 0L,
stamp.endMs ?: episodeDurationMs
)
}
}.flatten()
}

data class Root(
@JsonProperty("tmdb_id")
val tmdbId: Long,
@JsonProperty("type")
val type: String,
@JsonProperty("intro")
val intro: List<Stamp> = emptyList(),
@JsonProperty("recap")
val recap: List<Stamp> = emptyList(),
@JsonProperty("credits")
val credits: List<Stamp> = emptyList(),
@JsonProperty("preview")
val preview: List<Stamp> = emptyList(),
)

data class Stamp(
@JsonProperty("start_ms")
val startMs: Long?,
@JsonProperty("end_ms")
val endMs: Long?,
)
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
<string name="skip_type_mixed_ed">Mixed ending</string>
<string name="skip_type_mixed_op">Mixed opening</string>
<string name="skip_type_creddits">Credits</string>
<string name="skip_type_preview">Preview</string>
<string name="skip_type_intro">Intro</string>
<string name="clear_history">Clear history</string>
<string name="history">History</string>
Expand Down