sync: check video file size during import process
This commit is contained in:
parent
2ac205bf83
commit
6042f9b477
@ -178,6 +178,12 @@ func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic
|
|||||||
if !i.exists(e.VideoURI) {
|
if !i.exists(e.VideoURI) {
|
||||||
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: no video file found at %s", edir, e.VideoURI))
|
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: no video file found at %s", edir, e.VideoURI))
|
||||||
e.VideoURI = ""
|
e.VideoURI = ""
|
||||||
|
} else if size, err := getFileSize(i, e.VideoURI); err != nil {
|
||||||
|
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: ", edir, err))
|
||||||
|
e.VideoURI = ""
|
||||||
|
} else if size == 0 {
|
||||||
|
errs = append(errs, fmt.Sprintf("%q: resolution.mp4: The file is empty!", edir))
|
||||||
|
e.VideoURI = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create or update the exercice
|
// Create or update the exercice
|
||||||
|
@ -39,6 +39,45 @@ type Importer interface {
|
|||||||
// GlobalImporter stores the main importer instance to use for global imports.
|
// GlobalImporter stores the main importer instance to use for global imports.
|
||||||
var GlobalImporter Importer
|
var GlobalImporter Importer
|
||||||
|
|
||||||
|
// getFileSize returns the size.
|
||||||
|
func getFileSize(i Importer, URI string) (size int64, err error) {
|
||||||
|
if i.exists(URI) {
|
||||||
|
if fi, err := i.stat(URI); err != nil {
|
||||||
|
return 0, err
|
||||||
|
} else {
|
||||||
|
return fi.Size(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dirname := path.Dir(URI)
|
||||||
|
if i.exists(dirname) {
|
||||||
|
filename := path.Base(URI)
|
||||||
|
if files, err := i.listDir(dirname); err != nil {
|
||||||
|
return size, err
|
||||||
|
} else {
|
||||||
|
for _, fname := range []string{filename, filename + "."} {
|
||||||
|
found := false
|
||||||
|
for _, file := range files {
|
||||||
|
if matched, _ := path.Match(fname + "[0-9][0-9]", file); matched {
|
||||||
|
found = true
|
||||||
|
if fi, err := i.stat(path.Join(dirname, file)); err != nil {
|
||||||
|
return size, err
|
||||||
|
} else {
|
||||||
|
size += fi.Size()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if found {
|
||||||
|
return size, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return size, errors.New(fmt.Sprintf("%q: no such file or directory", URI))
|
||||||
|
}
|
||||||
|
|
||||||
// getFile helps to manage huge file transfert by concatenating splitted (with split(1)) files.
|
// getFile helps to manage huge file transfert by concatenating splitted (with split(1)) files.
|
||||||
func getFile(i Importer, URI string, writer *bufio.Writer) error {
|
func getFile(i Importer, URI string, writer *bufio.Writer) error {
|
||||||
// Import file if it exists
|
// Import file if it exists
|
||||||
|
Loading…
x
Reference in New Issue
Block a user