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" "gopkg.in/vansante/go-ffprobe.v2"
) )
const InfoVersion = 2 const InfoVersion = 3
type Versions struct { type Versions struct {
Info int32 `json:"info"` Info int32 `json:"info"`
@ -112,6 +112,8 @@ type Subtitle struct {
Language *string `json:"language"` Language *string `json:"language"`
/// The codec of this stream. /// The codec of this stream.
Codec string `json:"codec"` Codec string `json:"codec"`
/// The codec of this stream (defined as the RFC 6381).
MimeCodec *string `json:"mimeCodec"`
/// The extension for the codec. /// The extension for the codec.
Extension *string `json:"extension"` Extension *string `json:"extension"`
/// Is this stream the default one of it's type? /// 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. /// The name of this chapter. This should be a human-readable name that could be presented to the user.
Name string `json:"name"` Name string `json:"name"`
/// The type value is used to mark special chapters (openning/credits...) /// The type value is used to mark special chapters (openning/credits...)
Type ChapterType `json:"type"` Type ChapterType `json:"type"`
} }
type ChapterType string type ChapterType string
@ -222,6 +224,12 @@ var SubtitleExtensions = map[string]string{
"vtt": "vtt", "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) { func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) {
defer utils.PrintExecTime("mediainfo for %s", path)() defer utils.PrintExecTime("mediainfo for %s", path)()
@ -288,6 +296,7 @@ func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) {
Title: OrNull(stream.Tags.Title), Title: OrNull(stream.Tags.Title),
Language: NullIfUnd(lang.String()), Language: NullIfUnd(lang.String()),
Codec: stream.CodecName, Codec: stream.CodecName,
MimeCodec: OrNull(SubtitleMimes[stream.CodecName]),
Extension: extension, Extension: extension,
IsDefault: stream.Disposition.Default != 0, IsDefault: stream.Disposition.Default != 0,
IsForced: stream.Disposition.Forced != 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( 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`, from subtitles as s where s.sha=$1`,
sha, sha,
) )
@ -250,7 +250,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro
} }
for rows.Next() { for rows.Next() {
var s Subtitle 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 { if err != nil {
return nil, err return nil, err
} }
@ -351,20 +351,21 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
} }
for _, s := range ret.Subtitles { for _, s := range ret.Subtitles {
tx.Exec(` tx.Exec(`
insert into subtitles(sha, idx, title, language, codec, extension, is_default, is_forced, is_hearing_impaired) 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) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
on conflict (sha, idx) do update set on conflict (sha, idx) do update set
sha = excluded.sha, sha = excluded.sha,
idx = excluded.idx, idx = excluded.idx,
title = excluded.title, title = excluded.title,
language = excluded.language, language = excluded.language,
codec = excluded.codec, codec = excluded.codec,
mime_codec = excluded.mime_codec,
extension = excluded.extension, extension = excluded.extension,
is_default = excluded.is_default, is_default = excluded.is_default,
is_forced = excluded.is_forced, is_forced = excluded.is_forced,
is_hearing_impaired = excluded.is_hearing_impaired 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 { for _, c := range ret.Chapters {

View File

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