From 1659f75ae6e491355e1d32f0f5e8b956ef70a797 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 22 Dec 2022 11:48:28 +0100 Subject: [feature] For video attachments, store + return fps, bitrate, duration (#1282) * start messing about with different mp4 metadata extraction * heyyooo it works * add test cow * move useful multierror to gtserror package * error out if video doesn't seem to be a real mp4 * test parsing mkv in disguise as mp4 * tidy up error handling * remove extraneous line * update framerate formatting * use float32 for aspect * fixy mctesterson --- internal/gtserror/multi.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 internal/gtserror/multi.go (limited to 'internal/gtserror/multi.go') diff --git a/internal/gtserror/multi.go b/internal/gtserror/multi.go new file mode 100644 index 000000000..1740d726c --- /dev/null +++ b/internal/gtserror/multi.go @@ -0,0 +1,45 @@ +/* + GoToSocial + Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package gtserror + +import ( + "errors" + "fmt" + "strings" +) + +// MultiError allows encapsulating multiple errors under a singular instance, +// which is useful when you only want to log on errors, not return early / bubble up. +type MultiError []string + +func (e *MultiError) Append(err error) { + *e = append(*e, err.Error()) +} + +func (e *MultiError) Appendf(format string, args ...any) { + *e = append(*e, fmt.Sprintf(format, args...)) +} + +// Combine converts this multiError to a singular error instance, returning nil if empty. +func (e MultiError) Combine() error { + if len(e) == 0 { + return nil + } + return errors.New(`"` + strings.Join(e, `","`) + `"`) +} -- cgit v1.2.3