From 4afd5d355396d176adfc81c0379bcca604d12ab3 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 20 Jul 2025 14:49:43 +0200 Subject: [PATCH] Add `mime_codec` to subtitles in the transcoder --- transcoder/src/info.go | 13 +++++++++++-- transcoder/src/metadata.go | 11 ++++++----- transcoder/src/subtitles.go | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/transcoder/src/info.go b/transcoder/src/info.go index c6acf295..1d0a882d 100644 --- a/transcoder/src/info.go +++ b/transcoder/src/info.go @@ -17,7 +17,7 @@ import ( "gopkg.in/vansante/go-ffprobe.v2" ) -const InfoVersion = 2 +const InfoVersion = 3 type Versions struct { Info int32 `json:"info"` @@ -112,6 +112,8 @@ type Subtitle struct { Language *string `json:"language"` /// The codec of this stream. Codec string `json:"codec"` + /// The codec of this stream (defined as the RFC 6381). + MimeCodec *string `json:"mimeCodec"` /// The extension for the codec. Extension *string `json:"extension"` /// Is this stream the default one of it's type? @@ -136,7 +138,7 @@ type Chapter struct { /// The name of this chapter. This should be a human-readable name that could be presented to the user. Name string `json:"name"` /// The type value is used to mark special chapters (openning/credits...) - Type ChapterType `json:"type"` + Type ChapterType `json:"type"` } type ChapterType string @@ -222,6 +224,12 @@ var SubtitleExtensions = map[string]string{ "vtt": "vtt", } +var SubtitleMimes = map[string]string{ + "subrip": "application/x-subrip", + "ass": "text/x-ssa", + "vtt": "text/vtt", +} + func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) { defer utils.PrintExecTime("mediainfo for %s", path)() @@ -288,6 +296,7 @@ func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) { Title: OrNull(stream.Tags.Title), Language: NullIfUnd(lang.String()), Codec: stream.CodecName, + MimeCodec: OrNull(SubtitleMimes[stream.CodecName]), Extension: extension, IsDefault: stream.Disposition.Default != 0, IsForced: stream.Disposition.Forced != 0, diff --git a/transcoder/src/metadata.go b/transcoder/src/metadata.go index 254fdc14..ca20bdad 100644 --- a/transcoder/src/metadata.go +++ b/transcoder/src/metadata.go @@ -241,7 +241,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro } rows, err = s.database.Query( - `select s.idx, s.title, s.language, s.codec, s.extension, s.is_default, s.is_forced, s.is_hearing_impaired + `select s.idx, s.title, s.language, s.codec, s.mime_codec s.extension, s.is_default, s.is_forced, s.is_hearing_impaired from subtitles as s where s.sha=$1`, sha, ) @@ -250,7 +250,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro } for rows.Next() { var s Subtitle - err := rows.Scan(&s.Index, &s.Title, &s.Language, &s.Codec, &s.Extension, &s.IsDefault, &s.IsForced, &s.IsHearingImpaired) + err := rows.Scan(&s.Index, &s.Title, &s.Language, &s.Codec, &s.MimeCodec, &s.Extension, &s.IsDefault, &s.IsForced, &s.IsHearingImpaired) if err != nil { return nil, err } @@ -351,20 +351,21 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf } for _, s := range ret.Subtitles { tx.Exec(` - insert into subtitles(sha, idx, title, language, codec, extension, is_default, is_forced, is_hearing_impaired) - values ($1, $2, $3, $4, $5, $6, $7, $8, $9) + insert into subtitles(sha, idx, title, language, codec, mime_codec, extension, is_default, is_forced, is_hearing_impaired) + values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) on conflict (sha, idx) do update set sha = excluded.sha, idx = excluded.idx, title = excluded.title, language = excluded.language, codec = excluded.codec, + mime_codec = excluded.mime_codec, extension = excluded.extension, is_default = excluded.is_default, is_forced = excluded.is_forced, is_hearing_impaired = excluded.is_hearing_impaired `, - ret.Sha, s.Index, s.Title, s.Language, s.Codec, s.Extension, s.IsDefault, s.IsForced, s.IsHearingImpaired, + ret.Sha, s.Index, s.Title, s.Language, s.Codec, s.MimeCodec, s.Extension, s.IsDefault, s.IsForced, s.IsHearingImpaired, ) } for _, c := range ret.Chapters { diff --git a/transcoder/src/subtitles.go b/transcoder/src/subtitles.go index ad6bccc0..3a52d58a 100644 --- a/transcoder/src/subtitles.go +++ b/transcoder/src/subtitles.go @@ -38,6 +38,7 @@ outer: sub := Subtitle{ Index: nil, Codec: codec, + MimeCodec: OrNull(SubtitleMimes[codec]), Extension: &ext, IsExternal: true, Path: &match,