diff options
| author | a1e7cb88 <[email protected]> | 2021-10-18 00:09:23 +0800 |
|---|---|---|
| committer | a1e7cb88 <[email protected]> | 2021-10-18 00:09:23 +0800 |
| commit | 113fd8f700015308e663c8904c95ddf374987b78 (patch) | |
| tree | 0b81a126554c24b298b6e5e038f73beef2494ae9 /mkvlib/shared.go | |
| parent | c0f88cb080950879bc8af5cf498ac3aa8a8c68fb (diff) | |
update mod
Diffstat (limited to 'mkvlib/shared.go')
| -rw-r--r-- | mkvlib/shared.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/mkvlib/shared.go b/mkvlib/shared.go new file mode 100644 index 0000000..b0cfb2f --- /dev/null +++ b/mkvlib/shared.go @@ -0,0 +1,54 @@ +package mkvlib + +import ( + "log" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" +) + +const libName = "mkvlib" +const libVer = "v1.0.2" + +const LibFName = libName + " " + libVer + +var _instance *mkvProcessor + +func GetInstance() *mkvProcessor { + ec := 0 + n := "PATH" + s := ":" + if runtime.GOOS == "windows" { + n = "path" + s = ";" + } + p := os.Getenv(n) + if !strings.HasSuffix(p, s) { + p += s + } + e, _ := os.Executable() + e, _ = filepath.Split(e) + p += e + _ = os.Setenv(n, p) + _, _ttx := exec.LookPath(ttx) + _, _pyftsubset := exec.LookPath(pyftsubset) + _, _mkvextract := exec.LookPath(mkvextract) + _, _mkvmerge := exec.LookPath(mkvmerge) + if _ttx != nil || _pyftsubset != nil { + log.Printf(`Missing dependency: fonttools (need "%s" & "%s").`, ttx, pyftsubset) + ec++ + } + if _mkvextract != nil || _mkvmerge != nil { + log.Printf(`Missing dependency: mkvtoolnix (need "%s" & "%s").`, mkvextract, mkvmerge) + ec++ + } + if ec > 0 { + return nil + } + if _instance == nil { + _instance = new(mkvProcessor) + } + return _instance +} |
