Add mime_codec to subtitles in the transcoder

This commit is contained in:
Zoe Roux 2025-07-20 14:49:43 +02:00
parent 8d8facb2e6
commit 4afd5d3553
No known key found for this signature in database
3 changed files with 18 additions and 7 deletions

View File

@ -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?
@ -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,

View File

@ -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 {

View File

@ -38,6 +38,7 @@ outer:
sub := Subtitle{
Index: nil,
Codec: codec,
MimeCodec: OrNull(SubtitleMimes[codec]),
Extension: &ext,
IsExternal: true,
Path: &match,