admin/sync: import resolution movies

This commit is contained in:
nemunaire 2018-01-06 16:41:33 +01:00
parent 2aa1d6eeca
commit fc902e1063

View File

@ -25,6 +25,23 @@ func getExercices(i Importer, theme fic.Theme) ([]string, error) {
return exercices, nil
}
func findResolutionMovie(i Importer, exPath string) (videoURI string, err error) {
var files []string
if files, err = i.listDir(path.Join(exPath, "resolution")); err != nil {
return
} else {
for _, fname := range files {
switch strings.ToLower(path.Ext(fname)) {
case ".mkv", ".mp4", ".webm", ".ogv", ".avi", ".mov", ".flv":
videoURI = path.Join("/resolution", exPath, "resolution", fname)
}
}
}
return
}
func SyncExercices(i Importer, theme fic.Theme) []string {
var errs []string
@ -64,8 +81,13 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
// TODO: calculate gain
var gain int64 = 42
// TODO: handle video
videoURI := ""
// Handle video
videoURI, err := findResolutionMovie(i, path.Join(theme.Name, edir))
if err != nil {
errs = append(errs, fmt.Sprintf("%q: resolution: %s", edir, err))
} else if len(videoURI) == 0 {
errs = append(errs, fmt.Sprintf("%q: resolution: no video file found.", edir))
}
if e, err := theme.GetExerciceByTitle(ename); err != nil {
if ex, err := theme.AddExercice(ename, path.Join(theme.Name, edir), statement, overview, nil, gain, videoURI); err != nil {