From 1dbc72c60e4932e5b88ea608c668eea035ac7980 Mon Sep 17 00:00:00 2001 From: a1e7cb88 Date: Mon, 18 Oct 2021 01:05:57 +0800 Subject: update mod --- cexports/exports.go | 87 ----------------------------------------------------- cexports/go.mod | 16 ---------- cexports/main.go | 3 -- cexports/sdk.py | 35 --------------------- mkvlib/c/exports.go | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mkvlib/c/main.go | 3 ++ mkvlib/c/sdk.py | 35 +++++++++++++++++++++ 7 files changed, 125 insertions(+), 141 deletions(-) delete mode 100644 cexports/exports.go delete mode 100644 cexports/go.mod delete mode 100644 cexports/main.go delete mode 100644 cexports/sdk.py create mode 100644 mkvlib/c/exports.go create mode 100644 mkvlib/c/main.go create mode 100644 mkvlib/c/sdk.py diff --git a/cexports/exports.go b/cexports/exports.go deleted file mode 100644 index 93d8321..0000000 --- a/cexports/exports.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "C" - "encoding/json" - "github.com/KurenaiRyu/MkvAutoSubset/mkvlib" -) - -var _instance = mkvlib.GetInstance() - -//export CheckInstance -func CheckInstance() bool { - return _instance != nil -} - -//export GetMKVInfo -func GetMKVInfo(file *C.char) *C.char { - if !CheckInstance() { - return cs("") - } - obj := _instance.GetMKVInfo(gs(file)) - data, _ := json.Marshal(obj) - return cs(string(data)) -} - -//export DumpMKV -func DumpMKV(file, output *C.char, subset bool) bool { - if !CheckInstance() { - return false - } - return _instance.DumpMKV(gs(file), gs(output), subset) -} - -type checkSubset_R struct { - Subseted bool `json:"subseted"` - Error bool `json:"error"` -} - -//export CheckSubset -func CheckSubset(file *C.char) *C.char { - if !CheckInstance() { - return cs("") - } - a, b := _instance.CheckSubset(gs(file)) - data, _ := json.Marshal(checkSubset_R{a, b}) - return cs(string(data)) -} - -//export CreateMKV -func CreateMKV(file, tracks, attachments, output, slang, stitle *C.char, clean bool) bool { - if !CheckInstance() { - return false - } - a := make([]string, 0) - b := make([]string, 0) - err := json.Unmarshal([]byte(gs(tracks)), &a) - if err == nil { - _tracks := a - err = json.Unmarshal([]byte(gs(attachments)), &b) - if err == nil { - _attachments := b - return _instance.CreateMKV(gs(file), _tracks, _attachments, gs(output), gs(slang), gs(stitle), clean) - } - } - return false -} - -//export ASSFontSubset -func ASSFontSubset(files, fonts, output *C.char, dirSafe bool) bool { - if !CheckInstance() { - return false - } - obj := make([]string, 0) - if json.Unmarshal([]byte(gs(files)), &obj) == nil { - _files := obj - return _instance.ASSFontSubset(_files, gs(fonts), gs(output), dirSafe) - } - return false -} - -func cs(gs string) *C.char { - return C.CString(gs) -} - -func gs(cs *C.char) string { - return C.GoString(cs) -} diff --git a/cexports/go.mod b/cexports/go.mod deleted file mode 100644 index 824c3e7..0000000 --- a/cexports/go.mod +++ /dev/null @@ -1,16 +0,0 @@ -module github.com/KurenaiRyu/MkvAutoSubset/cexports - -go 1.17 - -require github.com/KurenaiRyu/MkvAutoSubset/mkvlib v0.0.0-20211017160923-113fd8f70001 - -require ( - github.com/antchfx/xmlquery v1.3.8 // indirect - github.com/antchfx/xpath v1.2.0 // indirect - github.com/asticode/go-astikit v0.20.0 // indirect - github.com/asticode/go-astisub v0.19.0 // indirect - github.com/asticode/go-astits v1.8.0 // indirect - github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect - golang.org/x/text v0.3.2 // indirect -) diff --git a/cexports/main.go b/cexports/main.go deleted file mode 100644 index 38dd16d..0000000 --- a/cexports/main.go +++ /dev/null @@ -1,3 +0,0 @@ -package main - -func main() {} diff --git a/cexports/sdk.py b/cexports/sdk.py deleted file mode 100644 index a48a55e..0000000 --- a/cexports/sdk.py +++ /dev/null @@ -1,35 +0,0 @@ -from ctypes import * -from json import * - -libpath="./mkvlib.so" -lib=CDLL(libpath) - -def checkInstance(): - call=lib.CheckInstance - return call() - -def getMKVInfo(file): - call=lib.GetMKVInfo - call.restype=c_char_p - return call(file.encode()) - -def dumpMKV(file,output,subset,dirSafe): - call=lib.DumpMKV - return call(file.encode(),output.encode(),subset,dirSafe) - -def checkSubset(file): - call=lib.CheckSubset - call.restype=c_char_p - return call(file.encode()) - -def createMKV(file,tracks,attachments,output,slang,stitle,clean): - call=lib.CreateMKV - _tracks=dumps(tracks) - _attachments=dumps(attachments) - return call(file.encode(),_tracks.encode(),_attachments.encode(),output.encode(),slang.encode(),stitle.encode(),clean) - -def assFontSubset(files,fonts,output,dirSafe): - call=lib.ASSFontSubset - _files=dumps(files) - return call(_files.encode(),fonts.encode(),output.encode(),dirSafe) - diff --git a/mkvlib/c/exports.go b/mkvlib/c/exports.go new file mode 100644 index 0000000..93d8321 --- /dev/null +++ b/mkvlib/c/exports.go @@ -0,0 +1,87 @@ +package main + +import ( + "C" + "encoding/json" + "github.com/KurenaiRyu/MkvAutoSubset/mkvlib" +) + +var _instance = mkvlib.GetInstance() + +//export CheckInstance +func CheckInstance() bool { + return _instance != nil +} + +//export GetMKVInfo +func GetMKVInfo(file *C.char) *C.char { + if !CheckInstance() { + return cs("") + } + obj := _instance.GetMKVInfo(gs(file)) + data, _ := json.Marshal(obj) + return cs(string(data)) +} + +//export DumpMKV +func DumpMKV(file, output *C.char, subset bool) bool { + if !CheckInstance() { + return false + } + return _instance.DumpMKV(gs(file), gs(output), subset) +} + +type checkSubset_R struct { + Subseted bool `json:"subseted"` + Error bool `json:"error"` +} + +//export CheckSubset +func CheckSubset(file *C.char) *C.char { + if !CheckInstance() { + return cs("") + } + a, b := _instance.CheckSubset(gs(file)) + data, _ := json.Marshal(checkSubset_R{a, b}) + return cs(string(data)) +} + +//export CreateMKV +func CreateMKV(file, tracks, attachments, output, slang, stitle *C.char, clean bool) bool { + if !CheckInstance() { + return false + } + a := make([]string, 0) + b := make([]string, 0) + err := json.Unmarshal([]byte(gs(tracks)), &a) + if err == nil { + _tracks := a + err = json.Unmarshal([]byte(gs(attachments)), &b) + if err == nil { + _attachments := b + return _instance.CreateMKV(gs(file), _tracks, _attachments, gs(output), gs(slang), gs(stitle), clean) + } + } + return false +} + +//export ASSFontSubset +func ASSFontSubset(files, fonts, output *C.char, dirSafe bool) bool { + if !CheckInstance() { + return false + } + obj := make([]string, 0) + if json.Unmarshal([]byte(gs(files)), &obj) == nil { + _files := obj + return _instance.ASSFontSubset(_files, gs(fonts), gs(output), dirSafe) + } + return false +} + +func cs(gs string) *C.char { + return C.CString(gs) +} + +func gs(cs *C.char) string { + return C.GoString(cs) +} diff --git a/mkvlib/c/main.go b/mkvlib/c/main.go new file mode 100644 index 0000000..38dd16d --- /dev/null +++ b/mkvlib/c/main.go @@ -0,0 +1,3 @@ +package main + +func main() {} diff --git a/mkvlib/c/sdk.py b/mkvlib/c/sdk.py new file mode 100644 index 0000000..a48a55e --- /dev/null +++ b/mkvlib/c/sdk.py @@ -0,0 +1,35 @@ +from ctypes import * +from json import * + +libpath="./mkvlib.so" +lib=CDLL(libpath) + +def checkInstance(): + call=lib.CheckInstance + return call() + +def getMKVInfo(file): + call=lib.GetMKVInfo + call.restype=c_char_p + return call(file.encode()) + +def dumpMKV(file,output,subset,dirSafe): + call=lib.DumpMKV + return call(file.encode(),output.encode(),subset,dirSafe) + +def checkSubset(file): + call=lib.CheckSubset + call.restype=c_char_p + return call(file.encode()) + +def createMKV(file,tracks,attachments,output,slang,stitle,clean): + call=lib.CreateMKV + _tracks=dumps(tracks) + _attachments=dumps(attachments) + return call(file.encode(),_tracks.encode(),_attachments.encode(),output.encode(),slang.encode(),stitle.encode(),clean) + +def assFontSubset(files,fonts,output,dirSafe): + call=lib.ASSFontSubset + _files=dumps(files) + return call(_files.encode(),fonts.encode(),output.encode(),dirSafe) + -- cgit v1.2.1