mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-13 10:52:28 -04:00
Add earing Impaired suptitle flag support (#754)
This commit is contained in:
+11
-8
@@ -123,6 +123,8 @@ type Subtitle struct {
|
||||
IsDefault bool `json:"isDefault"`
|
||||
/// Is this stream tagged as forced?
|
||||
IsForced bool `json:"isForced"`
|
||||
/// Is this stream tagged as hearing impaired?
|
||||
IsHearingImpaired bool `json:"isHearingImpaired"`
|
||||
/// Is this an external subtitle (as in stored in a different file)
|
||||
IsExternal bool `json:"isExternal"`
|
||||
/// Where the subtitle is stored (null if stored inside the video)
|
||||
@@ -287,14 +289,15 @@ func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) {
|
||||
lang, _ := language.Parse(stream.Tags.Language)
|
||||
idx := uint32(i)
|
||||
return Subtitle{
|
||||
Index: &idx,
|
||||
Title: OrNull(stream.Tags.Title),
|
||||
Language: NullIfUnd(lang.String()),
|
||||
Codec: stream.CodecName,
|
||||
Extension: extension,
|
||||
IsDefault: stream.Disposition.Default != 0,
|
||||
IsForced: stream.Disposition.Forced != 0,
|
||||
Link: &link,
|
||||
Index: &idx,
|
||||
Title: OrNull(stream.Tags.Title),
|
||||
Language: NullIfUnd(lang.String()),
|
||||
Codec: stream.CodecName,
|
||||
Extension: extension,
|
||||
IsDefault: stream.Disposition.Default != 0,
|
||||
IsForced: stream.Disposition.Forced != 0,
|
||||
IsHearingImpaired: stream.Disposition.HearingImpaired != 0,
|
||||
Link: &link,
|
||||
}
|
||||
}),
|
||||
Chapters: Map(mi.Chapters, func(c *ffprobe.Chapter, _ int) Chapter {
|
||||
|
||||
@@ -162,7 +162,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
|
||||
`select s.idx, s.title, s.language, s.codec, s.extension, s.is_default, s.is_forced, s.is_hearing_impaired
|
||||
from subtitles as s where s.sha=$1`,
|
||||
sha,
|
||||
)
|
||||
@@ -171,7 +171,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)
|
||||
err := rows.Scan(&s.Index, &s.Title, &s.Language, &s.Codec, &s.Extension, &s.IsDefault, &s.IsForced, &s.IsHearingImpaired)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -273,8 +273,8 @@ 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)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
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)
|
||||
on conflict (sha, idx) do update set
|
||||
sha = excluded.sha,
|
||||
idx = excluded.idx,
|
||||
@@ -283,9 +283,10 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
|
||||
codec = excluded.codec,
|
||||
extension = excluded.extension,
|
||||
is_default = excluded.is_default,
|
||||
is_forced = excluded.is_forced
|
||||
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,
|
||||
ret.Sha, s.Index, s.Title, s.Language, s.Codec, s.Extension, s.IsDefault, s.IsForced, s.IsHearingImpaired,
|
||||
)
|
||||
}
|
||||
for _, c := range ret.Chapters {
|
||||
|
||||
@@ -43,26 +43,45 @@ outer:
|
||||
Path: &match,
|
||||
Link: &link,
|
||||
}
|
||||
flags := separator.Split(match[len(base_path):], -1)
|
||||
flags_str := strings.ToLower(match[len(base_path):])
|
||||
flags := separator.Split(flags_str, -1)
|
||||
|
||||
// remove extension from flags
|
||||
flags = flags[:len(flags)-1]
|
||||
|
||||
for _, flag := range flags {
|
||||
switch strings.ToLower(flag) {
|
||||
switch flag {
|
||||
case "default":
|
||||
sub.IsDefault = true
|
||||
case "forced":
|
||||
sub.IsForced = true
|
||||
case "hi", "sdh", "cc":
|
||||
sub.IsHearingImpaired = true
|
||||
default:
|
||||
lang, err := language.Parse(flag)
|
||||
if err == nil && lang != language.Und {
|
||||
lang := lang.String()
|
||||
sub.Language = &lang
|
||||
langStr := lang.String()
|
||||
sub.Language = &langStr
|
||||
} else {
|
||||
sub.Title = &flag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Hindi (hi) collision with Hearing Impaired (hi):
|
||||
// "hi" by itself means a language code, but when combined with other lang flags it means Hearing Impaired.
|
||||
// In case Hindi was not detected before, but "hi" is present, assume it is Hindi.
|
||||
if sub.Language == nil {
|
||||
hiCount := Count(flags, "hi")
|
||||
if hiCount > 0 {
|
||||
languageStr := language.Hindi.String()
|
||||
sub.Language = &languageStr
|
||||
}
|
||||
if hiCount == 1 {
|
||||
sub.IsHearingImpaired = false
|
||||
}
|
||||
}
|
||||
|
||||
mi.Subtitles = append(mi.Subtitles, sub)
|
||||
continue outer
|
||||
}
|
||||
|
||||
@@ -25,3 +25,14 @@ func Filter[E any](s []E, f func(E) bool) []E {
|
||||
}
|
||||
return s2
|
||||
}
|
||||
|
||||
// Count returns the number of elements in s that are equal to e.
|
||||
func Count[S []E, E comparable](s S, e E) int {
|
||||
var n int
|
||||
for _, v := range s {
|
||||
if v == e {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user