repochecker/videos: Use subtitle track language as grammar check lang

This commit is contained in:
nemunaire 2023-01-18 19:25:27 +01:00
parent a7309b6a00
commit 1720906ec8
2 changed files with 6 additions and 4 deletions

View File

@ -11,10 +11,9 @@ import (
ffmpeg "github.com/u2takey/ffmpeg-go"
"srs.epita.fr/fic-server/admin/sync"
"srs.epita.fr/fic-server/libfic"
)
func CheckGrammarSubtitleTrack(path string, index uint, exercice *fic.Exercice, exceptions *sync.CheckExceptions) (errs []error) {
func CheckGrammarSubtitleTrack(path string, index uint, lang string, exceptions *sync.CheckExceptions) (errs []error) {
tmpfile, err := ioutil.TempFile("", "resolution-*.srt")
if err != nil {
errs = append(errs, fmt.Errorf("unable to create a temporary file: %w", err))
@ -43,7 +42,7 @@ func CheckGrammarSubtitleTrack(path string, index uint, exercice *fic.Exercice,
for _, e := range hooks.CallCustomHook("CheckGrammar", struct {
Str string
Language string
}{Str: strings.Join(lines, "\n"), Language: exercice.Language}, exceptions) {
}{Str: strings.Join(lines, "\n"), Language: lang[:2]}, exceptions) {
errs = append(errs, fmt.Errorf("subtitle-track: %w", e))
}

View File

@ -148,11 +148,14 @@ func checkResolutionVideo(e *fic.Exercice, exceptions *sync.CheckExceptions) (er
errs = append(errs, fmt.Errorf("no subtitles track found"))
} else if len(subtitles_seen) > 0 {
for _, idx := range subtitles_seen {
language := e.Language
if lang, ok := vInfo.Streams[idx].Tags["language"]; e.Language != "" && (!ok || lang == "" || lang == "und") {
errs = append(errs, fmt.Errorf("subtitles track %d with no language defined", vInfo.Streams[idx].Index))
} else {
language = lang
}
errs = append(errs, CheckGrammarSubtitleTrack(path, vInfo.Streams[idx].Index, e, exceptions)...)
errs = append(errs, CheckGrammarSubtitleTrack(path, vInfo.Streams[idx].Index, language, exceptions)...)
}
if e.Language != "" && len(subtitles_seen) < 2 {