repochecker/videos: Improve checks when dealing with translated exercices
This commit is contained in:
parent
6b74674123
commit
a7309b6a00
|
@ -14,7 +14,7 @@ import (
|
|||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func CheckGrammarSubtitleTrack(path string, exercice *fic.Exercice, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
func CheckGrammarSubtitleTrack(path string, index uint, exercice *fic.Exercice, 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))
|
||||
|
@ -24,7 +24,7 @@ func CheckGrammarSubtitleTrack(path string, exercice *fic.Exercice, exceptions *
|
|||
|
||||
// Extract subtitles
|
||||
err = ffmpeg.Input(path).
|
||||
Output(tmpfile.Name(), ffmpeg.KwArgs{"map": "0:s:0"}).
|
||||
Output(tmpfile.Name(), ffmpeg.KwArgs{"map": fmt.Sprintf("0:%d", index)}).
|
||||
OverWriteOutput().Run()
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("ffmpeg returns an error when extracting subtitles track: %w", err))
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
type VideoInfo struct {
|
||||
Streams []struct {
|
||||
Index uint `json:"index"`
|
||||
CodecType string `json:"codec_type"`
|
||||
CodecName string `json:"codec_name"`
|
||||
CodecLongName string `json:"codec_long_name"`
|
||||
|
@ -22,6 +23,7 @@ type VideoInfo struct {
|
|||
NbFrames string `json:"nb_frames"`
|
||||
Width int
|
||||
Height int
|
||||
Tags map[string]string `json:"tags"`
|
||||
} `json:"streams"`
|
||||
}
|
||||
|
||||
|
@ -79,11 +81,11 @@ func checkResolutionVideo(e *fic.Exercice, exceptions *sync.CheckExceptions) (er
|
|||
panic(err)
|
||||
}
|
||||
|
||||
video_seen := false
|
||||
subtitles_seen := false
|
||||
for _, s := range vInfo.Streams {
|
||||
video_seen := []int{}
|
||||
subtitles_seen := []int{}
|
||||
for idx, s := range vInfo.Streams {
|
||||
if s.CodecType == "video" {
|
||||
video_seen = true
|
||||
video_seen = append(video_seen, idx)
|
||||
if (s.Width > 1920 || s.Height > 1080) && !exceptions.HasException(":size:above_maximum") {
|
||||
errs = append(errs, fmt.Errorf("video track is too wide: %dx%d (maximum allowed: 1920x1080)", s.Width, s.Height))
|
||||
}
|
||||
|
@ -110,7 +112,7 @@ func checkResolutionVideo(e *fic.Exercice, exceptions *sync.CheckExceptions) (er
|
|||
errs = append(errs, fmt.Errorf("invalid track duration: %q", s.Duration))
|
||||
}
|
||||
} else if s.CodecType == "subtitle" {
|
||||
subtitles_seen = true
|
||||
subtitles_seen = append(subtitles_seen, idx)
|
||||
|
||||
if s.CodecName != "mov_text" {
|
||||
errs = append(errs, fmt.Errorf("subtitle format has to be MOV text/3GPP Timed Text (currently: %s)", s.CodecLongName))
|
||||
|
@ -137,13 +139,26 @@ func checkResolutionVideo(e *fic.Exercice, exceptions *sync.CheckExceptions) (er
|
|||
}
|
||||
}
|
||||
|
||||
if !video_seen {
|
||||
if len(video_seen) == 0 {
|
||||
errs = append(errs, fmt.Errorf("no video track found"))
|
||||
} else if len(video_seen) > 1 {
|
||||
errs = append(errs, fmt.Errorf("%d video tracks found, is it expected?", len(video_seen)))
|
||||
}
|
||||
if !subtitles_seen && !exceptions.HasException(":subtitle:no_track") {
|
||||
if len(subtitles_seen) == 0 && !exceptions.HasException(":subtitle:no_track") {
|
||||
errs = append(errs, fmt.Errorf("no subtitles track found"))
|
||||
} else if subtitles_seen {
|
||||
errs = append(errs, CheckGrammarSubtitleTrack(path, e, exceptions)...)
|
||||
} else if len(subtitles_seen) > 0 {
|
||||
for _, idx := range subtitles_seen {
|
||||
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))
|
||||
}
|
||||
|
||||
errs = append(errs, CheckGrammarSubtitleTrack(path, vInfo.Streams[idx].Index, e, exceptions)...)
|
||||
}
|
||||
|
||||
if e.Language != "" && len(subtitles_seen) < 2 {
|
||||
errs = append(errs, fmt.Errorf("subtitle tracks must exist in original language and translated, only one subtitle track found"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue