Exemple #1
0
// compromise: no method overloading
func (v *VideoReader) reset2(size uint8,
	tmpdir func() string,
	pathsep func() string,
	uniqnum func() int64) error {

	if util.IsEmpty(v.Filename) {
		return fmt.Errorf("Missing VideoReader.Filename")
	}

	var video string
	switch runtime.GOOS {
	case "windows":
		winp := strings.Split(v.Filename, string(os.PathSeparator))
		video = winp[len(winp)-1]
	case "linux":
		fallthrough
	default:
		video = path.Base(v.Filename)
	}

	parts := strings.Split(video, ".")
	if len(parts) < 2 {
		return fmt.Errorf("Invalid VideoReader.Filename")
	}
	name := strings.TrimSpace(parts[0])
	if util.IsEmpty(name) {
		return fmt.Errorf("Empty VideoReader.Filename")
	}
	v.Gif = name + ".gif"
	v.TmpDir = filepath.Join(tmpdir(), APPDIR, fmt.Sprintf("%d", (uniqnum())))
	v.PngDir = filepath.Join(v.TmpDir, PDIR)
	v.TmpFile = fmt.Sprintf("%s%0.2d%s", "img-%", size, "d.png")
	return nil
}
Exemple #2
0
func ParseDimension(raw string) (VideoSize, error) {
	EmptyVid := VideoSize{}
	if util.IsEmpty(raw) {
		return EmptyVid, InvalidVideoSize
	}

	raw = strings.TrimSpace(raw)
	if !Regex2.MatchString(raw) {
		return EmptyVid, InvalidVideoSize
	}

	matched := Regex2.ReplaceAllString(raw,
		fmt.Sprintf("${%s}", Regex2.SubexpNames()[2]))
	parts := strings.Split(matched, "x")
	if len(parts) != 2 {
		return EmptyVid, InvalidVideoSize
	}

	width, err0 := strconv.Atoi(parts[0])
	height, err1 := strconv.Atoi(parts[1])
	retval := VideoSize{uint16(width), uint16(height)}
	if err0 != nil || err1 != nil {
		return EmptyVid, err0
	}
	return retval, nil
}
Exemple #3
0
func ParseFps(raw string) (float32, error) {
	empty := float32(0.00)
	if util.IsEmpty(raw) {
		return empty, InvalidFps
	}

	raw = strings.TrimSpace(raw)

	fps1 := RegexFps1.MatchString(raw)
	fps2 := RegexFps2.MatchString(raw)

	if !fps1 && !fps2 {
		return empty, InvalidFps
	}

	if fps1 {
		matched := RegexFps1.ReplaceAllString(raw,
			fmt.Sprintf("${%s}", RegexFps1.SubexpNames()[2]))
		parts := strings.Split(matched, " ")
		f, _ := strconv.ParseFloat(parts[0], 32)
		return float32(f), nil
	}

	if fps2 {
		matched := RegexFps2.ReplaceAllString(raw,
			fmt.Sprintf("${%s}", RegexFps2.SubexpNames()[2]))
		parts := strings.Split(matched, " ")
		f, _ := strconv.ParseFloat(parts[0], 32)
		return float32(f), nil
	}

	return empty, InvalidFps
}
Exemple #4
0
func ParseDuration(raw string) (time.Duration, error) {
	if util.IsEmpty(raw) {
		return 0, InvalidDuration
	}

	raw = strings.TrimSpace(raw)

	if !Regex1.MatchString(raw) {
		return 0, InvalidDuration
	}

	matched := Regex1.ReplaceAllString(raw,
		fmt.Sprintf("${%s}", Regex1.SubexpNames()[1]))
	parts := strings.Split(matched, ":")
	if len(parts) != 3 {
		return 0, InvalidDuration
	}

	goduration := fmt.Sprintf("%sh%sm%ss", parts[0], parts[1], parts[2])
	retval, err := time.ParseDuration(goduration)
	if err != nil {
		return 0, err
	}
	return retval, nil
}
Exemple #5
0
func cleanup(vr *io.VideoReader) {
	if vr != nil && !util.IsEmpty(vr.PngDir) {
		if err := os.RemoveAll(vr.PngDir); err != nil {
			fmt.Printf("WARNING: Removing %s encountered errors\n", vr.PngDir)
			fmt.Printf("\t%s", err.Error())
		}
	}
}
Exemple #6
0
func (f FrameGenerator) combineVf(args *util.Arguments) (bool, string) {
	needSpeed := !util.IsEmpty(args.SpeedSpec)
	var vfarg string
	switch {
	case args.NeedScaling:
		vfarg += args.ScaleFilter
		if needSpeed {
			vfarg += "," + args.SpeedSpec
		}
		return true, vfarg
	case needSpeed:
		vfarg += args.SpeedSpec
		return true, vfarg
	}
	return false, ""
}
Exemple #7
0
func TestEmptyCheck(t *testing.T) {
	assert.True(t, util.IsEmpty("  "))
	assert.True(t, util.IsEmpty(""))
	assert.False(t, util.IsEmpty(" a "), "after trimming is length 1 is not empty")
	assert.False(t, util.IsEmpty("a"), "string of length 1 is not empty")
}
Exemple #8
0
func sayGoodbye(vr *io.VideoReader) {
	if vr != nil && !util.IsEmpty(vr.TmpDir) {
		fmt.Println("\n\nYour animated GIF is ready at location:")
		fmt.Printf("  %s\n\n", filepath.Join(vr.TmpDir, vr.Gif))
	}
}