Skip to content

Commit

Permalink
feat(anilib): opening timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
urFate committed Jan 20, 2025
1 parent e82ec8f commit 0a59b50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,22 @@ data class Player(
val translationType: TranslationType,
@SerialName("created_at")
val createdAt: String,
@SerialName("timecode")
val timeCode: List<TimeCode>,
@SerialName("video")
val video: Video? = null
)

@Serializable
data class TimeCode(
@SerialName("type")
val type: String,
@SerialName("from")
val from: String,
@SerialName("to")
val to: String
)

@Serializable
data class Subtitle(
@SerialName("filename")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class AniLibRepository : AbstractContentRepository(
}.singleOrNull()?.filter { it.number.toInt() in range }

val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", Locale.getDefault())
val timeCodeFormatter = SimpleDateFormat("mm:ss", Locale.getDefault())

episodesHeaders!!.forEach { headers ->

Expand Down Expand Up @@ -91,10 +92,12 @@ class AniLibRepository : AbstractContentRepository(
val entities = filteredPlayers.map { player ->
val createdAt = formatter.parse(player.createdAt)?.time ?: System.currentTimeMillis()
val streams = player.video!!.quality
val logoUrl = when(player.team.cover.filename) {
null -> ""
else -> "$url${player.team.cover.thumbnail}"
}
val timeCodes = player.timeCode.firstOrNull { it.type == "opening" }?.let {
val start = timeCodeFormatter.parse(it.from)?.time ?: -1L
val end = timeCodeFormatter.parse(it.to)?.time ?: -1L

start to end
} ?: (-1L to -1L)
val logoUrl = player.team.cover.default

EpisodeEntity(
Expand All @@ -104,6 +107,7 @@ class AniLibRepository : AbstractContentRepository(
name = name,
episode = number,
uploadTimestamp = createdAt,
videoMarkers = timeCodes,
videos = streams.associate {
Quality.valueOfInt(it.quality) to VIDEO_HOST_ENDPOINT+it.href
},
Expand Down

0 comments on commit 0a59b50

Please sign in to comment.