Skip to content

Commit

Permalink
A media file can have more than one video tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsixface committed Jan 20, 2025
1 parent 8666e05 commit f678a71
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class VideoFileEntity(id: EntityID<Int>) : IntEntity(id) {
var path by VideoFilesTable.path
var name by VideoFilesTable.name
var sizeMb by VideoFilesTable.sizeMb
val videoStream by VideoEntity backReferencedOn VideosTable.videoFile
val videoStream by VideoEntity referrersOn VideosTable.videoFile
val audioStreams by AudioEntity referrersOn AudiosTable.videoFile
val subtitles by SubtitleEntity referrersOn SubtitlesTable.videoFile
var modified by VideoFilesTable.modified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class VideoFilesRepo(private val db: Database) : IVideoFilesRepo {
dbQuery {
val v = get(id)
logger.debug("deleting video file: ${v?.path}")
v?.videoStream?.delete()
v?.videoStream?.forEach { it.delete() }
v?.audioStreams?.forEach { it.delete() }
v?.subtitles?.forEach { it.delete() }
v?.delete()
Expand All @@ -93,7 +93,7 @@ class VideoFilesRepo(private val db: Database) : IVideoFilesRepo {

override suspend fun update(videoInfo: ProbeInfo, entity: VideoFileEntity) = dbQuery {
try {
entity.videoStream.delete()
entity.videoStream.forEach { it.delete() }
entity.audioStreams.forEach { it.delete() }
entity.subtitles.forEach { it.delete() }
videoInfo.streams.forEach { createStream(it, entity) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ fun AudioEntity.updateInfo(stream: ProbeStream) {
fun Float.shortString() = if (this == toInt().toFloat()) this.toInt().toString() else "%.2f".format(this)

fun VideoFileEntity.toVideoFile(): VideoFile = transaction {
val videoTrack = videoStream.toMediaTrack()
val videoTracks = videoStream.map { it.toMediaTrack() }
val audioTracks = audioStreams.map { it.toMediaTrack() }
val subtitleTracks = subtitles.map { it.toMediaTrack() }
VideoFile(
path = path,
fileName = name,
modifiedTime = modified,
audios = audioTracks,
videos = listOf(videoTrack),
videos = videoTracks,
subtitles = subtitleTracks,
)
}
Expand Down

0 comments on commit f678a71

Please sign in to comment.