repochecker/videos: Also check grammar in subtitles
This commit is contained in:
parent
acdf0a6261
commit
5d716106c4
6 changed files with 192 additions and 105 deletions
47
repochecker/videos/subtitles.go
Normal file
47
repochecker/videos/subtitles.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/asticode/go-astisub"
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
)
|
||||
|
||||
func CheckGrammarSubtitleTrack(path 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))
|
||||
return
|
||||
}
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
// Extract subtitles
|
||||
err = ffmpeg.Input(path).
|
||||
Output(tmpfile.Name(), ffmpeg.KwArgs{"map": "0:s:0"}).
|
||||
OverWriteOutput().Run()
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("ffmpeg returns an error when extracting subtitles track: %w", err))
|
||||
}
|
||||
|
||||
subtitles, err := astisub.OpenFile(tmpfile.Name())
|
||||
if err != nil {
|
||||
log.Println("Unable to open subtitles file:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var lines []string
|
||||
for _, item := range subtitles.Items {
|
||||
lines = append(lines, item.String())
|
||||
}
|
||||
for _, e := range hooks.CallCustomHook("CheckGrammar", strings.Join(lines, "\n"), exceptions) {
|
||||
errs = append(errs, fmt.Errorf("subtitle-track: %w", e))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in a new issue