diff options
Diffstat (limited to 'mkvlib')
| -rw-r--r-- | mkvlib/ass.go | 56 | ||||
| -rw-r--r-- | mkvlib/ass2pgs.go | 3 | ||||
| -rw-r--r-- | mkvlib/mkv.go | 40 | ||||
| -rw-r--r-- | mkvlib/shared.go | 22 |
4 files changed, 64 insertions, 57 deletions
diff --git a/mkvlib/ass.go b/mkvlib/ass.go index bb61c0a..07a8e4e 100644 --- a/mkvlib/ass.go +++ b/mkvlib/ass.go @@ -106,7 +106,7 @@ func (self *assProcessor) parse() bool { } } if ec > 0 { - printLog(self.lcb, `Failed to read the ass file: "%s"`, file) + printLog(self.lcb, LogError, `Failed to read the ass file: "%s"`, file) } _ = f.Close() } @@ -121,7 +121,7 @@ func (self *assProcessor) parse() bool { subtitle, err := parser.ReadFromSSAWithOptions(strings.NewReader(v), opt) if err != nil { ec++ - printLog(self.lcb, `Failed to parse the ass file: "%s" [%s]`, k, err) + printLog(self.lcb, LogError, `Failed to parse the ass file: "%s" [%s]`, k, err) continue } for _, item := range subtitle.Items { @@ -164,7 +164,7 @@ func (self *assProcessor) parse() bool { _b = *s.InlineStyle.SSABold _i = *s.InlineStyle.SSAItalic } else { - printLog(self.lcb, `Not found style in the ass file:"%s" [%s].`, k, v[2]) + printLog(self.lcb, LogError, `Not found style in the ass file:"%s" [%s].`, k, v[2]) ec++ } break @@ -206,9 +206,9 @@ func (self *assProcessor) parse() bool { self.m[k].oldName = strings.Split(k, "^")[0] } } - } - if len(self.m) == 0 { - printLog(self.lcb, `Not found item in the ass file(s): "%d"`, len(self.files)) + if len(self.m) == 0 { + printLog(self.lcb, LogWarning, `Not found item in the ass file(s): "%d"`, len(self.files)) + } } return ec == 0 } @@ -250,7 +250,7 @@ func (self *assProcessor) dumpFont(file, out string) bool { } } if !ok { - printLog(self.lcb, `Failed to dump font: "%s".`, n) + printLog(self.lcb, LogError, `Failed to dump font: "%s".`, n) } return ok } @@ -308,7 +308,7 @@ func (self *assProcessor) getFontName(p string) [][]map[string]bool { _f, err := c.Font(i) if err == nil { if g, _ := _f.GlyphIndex(nil, '\u0020'); g == 0 { - printLog(self.lcb, `Font: "%s"[%d] is not defined '\u0020',skip.`, p, i) + printLog(self.lcb, LogWarning, `Font: "%s"[%d] is not defined '\u0020',skip.`, p, i) } else { fonts = append(fonts, _f) } @@ -319,7 +319,7 @@ func (self *assProcessor) getFontName(p string) [][]map[string]bool { _f, err := sfnt.Parse(data) if err == nil { if g, _ := _f.GlyphIndex(nil, '\u0020'); g == 0 { - printLog(self.lcb, `Font: "%s" is not defined '\u0020',skip.`, p) + printLog(self.lcb, LogWarning, `Font: "%s" is not defined '\u0020',skip.`, p) } else { fonts = append(fonts, _f) } @@ -402,7 +402,7 @@ func (self *assProcessor) checkFontMissing(f *fontInfo, i int, c bool) bool { } if _str != "" { _str = stringDeduplication(_str) - printLog(self.lcb, `{%s%02d}Font [%s] -> "%s"[%d] missing normal char(s): "%s"`, h, i, f.oldName, f.file, f.index, _str) + printLog(self.lcb, LogWarning, `{%s%02d}Font [%s] -> "%s"[%d] missing normal char(s): "%s"`, h, i, f.oldName, f.file, f.index, _str) } if len(_runes) > 0 { _str = "" @@ -410,7 +410,7 @@ func (self *assProcessor) checkFontMissing(f *fontInfo, i int, c bool) bool { _str += fmt.Sprintf(`,0x%x`, _rune) } _str = _str[1:] - printLog(self.lcb, `{%s%02d}Font [%s] -> "%s"[%d] missing special char(s): "%s"`, h, i, f.oldName, f.file, f.index, _str) + printLog(self.lcb, LogWarning, `{%s%02d}Font [%s] -> "%s"[%d] missing special char(s): "%s"`, h, i, f.oldName, f.file, f.index, _str) } return _str == "" && len(_runes) == 0 } @@ -428,7 +428,7 @@ func (self *assProcessor) matchFonts() []string { } if fb > 0 && _k[1] != "Regular" { if fb == 1 { - printLog(self.lcb, `#Warning# Font fallback:[%s^%s] -> [%s^Regular]`, _k[0], _k[1], _k[0]) + printLog(self.lcb, LogWarning, `Font fallback:[%s^%s] -> [%s^Regular]`, _k[0], _k[1], _k[0]) } _k[1] = "Regular" } @@ -479,7 +479,7 @@ func (self *assProcessor) matchFonts() []string { for k, _ := range self.m { if self.m[k].file == "" { el = append(el, k) - printLog(self.lcb, `Missing the font: "%s".`, k) + printLog(self.lcb, LogError, `Missing the font: "%s".`, k) } } return el @@ -529,12 +529,12 @@ func (self *assProcessor) matchFontName(m []map[string]bool, _k []string, b bool fmailies = append(fmailies, family) } if len(fmailies) > 1 { - printLog(self.lcb, `#!Warning!# Font bottom fallback:[%s^%s] -> [%s^(%s)]`, _k[0], _k[1], _k[0], strings.Join(fmailies, ",")) + printLog(self.lcb, LogSWarning, `Font bottom fallback:[%s^%s] -> [%s^(%s)]`, _k[0], _k[1], _k[0], strings.Join(fmailies, ",")) } else { - printLog(self.lcb, `#!Warning!# Font bottom fallback:[%s^%s] -> [%s^%s]`, _k[0], _k[1], _k[0], fmailies[0]) + printLog(self.lcb, LogSWarning, `Font bottom fallback:[%s^%s] -> [%s^%s]`, _k[0], _k[1], _k[0], fmailies[0]) } } else { - printLog(self.lcb, `#!Warning!# Font bottom fallback:[%s^%s] -> [%s]`, _k[0], _k[1], _k[0]) + printLog(self.lcb, LogSWarning, `Font bottom fallback:[%s^%s] -> [%s]`, _k[0], _k[1], _k[0]) } return true } @@ -557,7 +557,7 @@ func (self *assProcessor) reMap() { } } for _, v := range m { - printLog(self.lcb, `Font selected:[%s] -> "%s"[%d]`, v.oldName, v.file, v.index) + printLog(self.lcb, LogInfo, `Font selected:[%s] -> "%s"[%d]`, v.oldName, v.file, v.index) } self.m = m } @@ -573,7 +573,7 @@ func (self *assProcessor) createFontSubset(font *fontInfo) bool { e = ".ttf" } if os.MkdirAll(self.output, os.ModePerm) != nil { - printLog(self.lcb, "Failed to create the output folder.") + printLog(self.lcb, LogError, "Failed to create the output folder.") return false } str := string(font.runes) @@ -597,13 +597,13 @@ func (self *assProcessor) createFontSubset(font *fontInfo) bool { ok = err == nil && s.ExitCode() == 0 } if !ok { - printLog(self.lcb, `Failed to subset font: "%s"[%d].`, font.oldName, font.index) + printLog(self.lcb, LogError, `Failed to subset font: "%s"[%d].`, font.oldName, font.index) } else { font.sFont = _fn } } else { - printLog(self.lcb, `Failed to write the font text: "%s".`, n) + printLog(self.lcb, LogError, `Failed to write the font text: "%s".`, n) } return ok } @@ -612,7 +612,7 @@ func (self *assProcessor) createFontsSubset() bool { self.reMap() err := os.RemoveAll(self.output) if !(err == nil || err == os.ErrNotExist) { - printLog(self.lcb, "Failed to clean the output folder.") + printLog(self.lcb, LogError, "Failed to clean the output folder.") return false } ok := 0 @@ -691,11 +691,11 @@ func (self *assProcessor) changeFontName(font *fontInfo) bool { ec++ _, n, _, _ := splitPath(font.sFont) _ = os.Remove(font.sFont) - printLog(self.lcb, `Failed to compile the font: "%s".`, n) + printLog(self.lcb, LogError, `Failed to compile the font: "%s".`, n) } } } else { - printLog(self.lcb, `Failed to change the font name: "%s".`, font.oldName) + printLog(self.lcb, LogError, `Failed to change the font name: "%s".`, font.oldName) } } } @@ -781,7 +781,7 @@ func (self *assProcessor) replaceFontNameInAss() bool { } if !ok { ec++ - printLog(self.lcb, `Failed to write the new ass file: "%s".`, fn) + printLog(self.lcb, LogError, `Failed to write the new ass file: "%s".`, fn) } } return ec == 0 @@ -829,7 +829,7 @@ func (self *assProcessor) createFontsCache(output string) []string { if c != nil { ok++ cache = append(cache, *c) - printLog(self.lcb, "Cache font (%d/%d) done.", ok, l) + printLog(self.lcb, LogProgress, "Cache font (%d/%d) done.", ok, l) } else { el = append(el, _item) } @@ -856,7 +856,7 @@ func (self *assProcessor) createFontsCache(output string) []string { d, _, _, _ := splitPath(output) _ = os.MkdirAll(d, os.ModePerm) if ioutil.WriteFile(output, data, os.ModePerm) != nil { - printLog(self.lcb, `Failed to write cache file: "%s"`, output) + printLog(self.lcb, LogError, `Failed to write cache file: "%s"`, output) } } return el @@ -874,11 +874,11 @@ func (self *assProcessor) copyFontsFromCache() bool { fn = path.Join(self.output, fn) if copyFile(v.file, fn) == nil { i++ - printLog(self.lcb, "Copy (%d/%d) done.", i, l) + printLog(self.lcb, LogProgress, "Copy (%d/%d) done.", i, l) } } else { ec++ - printLog(self.lcb, `Missing the font: "%s".`, k) + printLog(self.lcb, LogError, `Missing the font: "%s".`, k) } } } diff --git a/mkvlib/ass2pgs.go b/mkvlib/ass2pgs.go index 166db1e..6eb6e6d 100644 --- a/mkvlib/ass2pgs.go +++ b/mkvlib/ass2pgs.go @@ -1,7 +1,6 @@ package mkvlib import ( - "fmt" "os" "path" ) @@ -23,7 +22,7 @@ func ass2Pgs(input []string, resolution, frameRate, fontsDir, output string, lcb s, err := p.Wait() r = err == nil && s.ExitCode() == 0 if !r { - printLog(lcb, fmt.Sprintf(`Failed to Ass2Pgs:"%s"`, item)) + printLog(lcb, LogError, `Failed to Ass2Pgs:"%s"`, item) _ = os.Remove(fn) } } diff --git a/mkvlib/mkv.go b/mkvlib/mkv.go index 01034fa..cad2cc4 100644 --- a/mkvlib/mkv.go +++ b/mkvlib/mkv.go @@ -67,7 +67,7 @@ func (self *mkvProcessor) DumpMKV(file, output string, subset bool, lcb logCallb ec := 0 obj := self.GetMKVInfo(file) if obj == nil { - printLog(lcb, `Failed to get the file info: "%s".`, file) + printLog(lcb, LogError, `Failed to get the file info: "%s".`, file) return false } attachments := make([]string, 0) @@ -124,7 +124,7 @@ func (self *mkvProcessor) DumpMKV(file, output string, subset bool, lcb logCallb ec++ } } else { - printLog(lcb, `This file is not has the subtitles & attachments: "%s"`, file) + printLog(lcb, LogInfo, `This file is not has the subtitles & attachments: "%s"`, file) } return ec == 0 } @@ -132,7 +132,7 @@ func (self *mkvProcessor) DumpMKV(file, output string, subset bool, lcb logCallb func (self *mkvProcessor) CheckSubset(file string, lcb logCallback) (bool, bool) { obj := self.GetMKVInfo(file) if obj == nil { - printLog(lcb, `Failed to get the file info: "%s".`, file) + printLog(lcb, LogError, `Failed to get the file info: "%s".`, file) return false, true } ass := false @@ -210,10 +210,10 @@ func (self *mkvProcessor) DumpMKVs(dir, output string, subset bool, lcb logCallb p = path.Join(output, d, f) if !self.DumpMKV(item, p, subset, lcb) { ok = false - printLog(lcb, `Failed to dump the file: "%s".`, item) + printLog(lcb, LogError, `Failed to dump the file: "%s".`, item) } else { _ok++ - printLog(lcb, "Dump (%d/%d) done.", _ok, l) + printLog(lcb, LogProgress, "Dump (%d/%d) done.", _ok, l) } } return ok @@ -226,11 +226,11 @@ func (self *mkvProcessor) QueryFolder(dir string, lcb logCallback) []string { for i, file := range files { a, b := self.CheckSubset(file, lcb) if b { - printLog(lcb, `Failed to check subset for file: "%s".`, file) + printLog(lcb, LogError, `Failed to check subset for file: "%s".`, file) } else if !a { lines = append(lines, file) } - printLog(lcb, "Query (%d/%d) done.", i+1, l) + printLog(lcb, LogProgress, "Query (%d/%d) done.", i+1, l) } return lines } @@ -258,9 +258,9 @@ func (self *mkvProcessor) CreateMKVs(vDir, sDir, fDir, tDir, oDir, slang, stitle fn += ".mkv" } if _a, _ := isExists(fn); _a && self.noverwrite { - printLog(lcb, `@Warning@ Existing file: "%s",skip.`, fn) + printLog(lcb, LogInfo, `Existing file: "%s",skip.`, fn) _ok++ - printLog(lcb, "Create (%d/%d) done.", _ok, l) + printLog(lcb, LogProgress, "Create (%d/%d) done.", _ok, l) continue } for _, sub := range tmp { @@ -292,10 +292,10 @@ func (self *mkvProcessor) CreateMKVs(vDir, sDir, fDir, tDir, oDir, slang, stitle } if ec > 0 { ok = false - printLog(lcb, `Failed to create the file: "%s".`, item) + printLog(lcb, LogError, `Failed to create the file: "%s".`, item) } else { _ok++ - printLog(lcb, "Create (%d/%d) done.", _ok, l) + printLog(lcb, LogInfo, "Create (%d/%d) done.", _ok, l) } } _ = os.RemoveAll(tDir) @@ -317,9 +317,9 @@ func (self *mkvProcessor) MakeMKVs(dir, data, output, slang, stitle string, lcb fn += ".mkv" } if _a, _ := isExists(fn); _a && self.noverwrite { - printLog(lcb, `@Warning@ Existing file: "%s",skip.`, fn) + printLog(lcb, LogInfo, `Existing file: "%s",skip.`, fn) _ok++ - printLog(lcb, "Make (%d/%d) done.", _ok, l) + printLog(lcb, LogProgress, "Make (%d/%d) done.", _ok, l) continue } p = path.Join(data, d, f) @@ -330,10 +330,10 @@ func (self *mkvProcessor) MakeMKVs(dir, data, output, slang, stitle string, lcb tracks := append(subs, asses...) if !self.CreateMKV(item, tracks, attachments, fn, slang, stitle, true) { ok = false - printLog(lcb, `Failed to make the file: "%s".`, item) + printLog(lcb, LogError, `Failed to make the file: "%s".`, item) } else { _ok++ - printLog(lcb, "Make (%d/%d) done.", _ok, l) + printLog(lcb, LogProgress, "Make (%d/%d) done.", _ok, l) } } return ok @@ -515,11 +515,11 @@ func (self *mkvProcessor) CreateTestVideo(asses []string, s, fontdir, enc string ok := self.CreateBlankOrBurnVideo(0, s, enc, v, fontdir, _output) if !ok { ec++ - printLog(lcb, `Failed to create the test video file: "%s"`, _output) + printLog(lcb, LogError, `Failed to create the test video file: "%s"`, _output) _ = os.Remove(_output) } else { _ok++ - printLog(lcb, "CT (%d/%d) done.", _ok, l) + printLog(lcb, LogProgress, "CT (%d/%d) done.", _ok, l) } } return ec == 0 @@ -542,16 +542,16 @@ func (self *mkvProcessor) CreateTestVideo(asses []string, s, fontdir, enc string s = path.Join(d, fmt.Sprintf("%s.mp4", n)) if !self.CreateBlankOrBurnVideo(t.Milliseconds(), "", enc, "", "", s) { ok = false - printLog(lcb, `Failed to create the temp video file: "%s".`, s) + printLog(lcb, LogError, `Failed to create the temp video file: "%s".`, s) } } if ok { output := path.Join(d, fmt.Sprintf("%s.mkv", n)) if !self.CreateMKV(s, asses, _fonts, output, "", "", true) { ok = false - printLog(lcb, `Failed to create the test video file: "%s".`, output) + printLog(lcb, LogError, `Failed to create the test video file: "%s".`, output) } else { - printLog(lcb, "CT done.") + printLog(lcb, LogProgress, "CT done.") } } if _t { diff --git a/mkvlib/shared.go b/mkvlib/shared.go index e1c2a2f..e8b2be4 100644 --- a/mkvlib/shared.go +++ b/mkvlib/shared.go @@ -15,7 +15,15 @@ const libVer = "v2.1.5" const LibFName = libName + " " + libVer -type logCallback func(string) +const ( + LogInfo = iota + LogWarning + LogSWarning + LogError + LogProgress +) + +type logCallback func(int, string) type processorGetter struct { checked bool @@ -54,21 +62,21 @@ func (self *processorGetter) InitProcessorInstance(lcb logCallback) bool { _, _ass2bdnxml := exec.LookPath(ass2bdnxml) _, _ffmpeg := exec.LookPath(ffmpeg) if _ttx != nil || _pyftsubset != nil { - printLog(lcb, `Missing dependency: fonttools (need "%s" & "%s").`, ttx, pyftsubset) + printLog(lcb, LogError, `Missing dependency: fonttools (need "%s" & "%s").`, ttx, pyftsubset) ec++ } if _mkvextract != nil || _mkvmerge != nil { - printLog(lcb, `Missing dependency: mkvtoolnix (need "%s" & "%s").`, mkvextract, mkvmerge) + printLog(lcb, LogError, `Missing dependency: mkvtoolnix (need "%s" & "%s").`, mkvextract, mkvmerge) ec++ } if _ass2bdnxml != nil { - printLog(lcb, `Missing dependency: ass2bdnxml.`) + printLog(lcb, LogWarning, `Missing dependency: ass2bdnxml.`) //ec++ } if _ffmpeg != nil { - printLog(lcb, `Missing dependency: ffmpeg.`) + printLog(lcb, LogWarning, `Missing dependency: ffmpeg.`) //ec++ } @@ -90,9 +98,9 @@ func (self *processorGetter) GetProcessorInstance() *mkvProcessor { return nil } -func printLog(lcb logCallback, f string, v ...interface{}) { +func printLog(lcb logCallback, l int, f string, v ...interface{}) { if lcb != nil { - lcb(fmt.Sprintf(f, v...)) + lcb(l, fmt.Sprintf(f, v...)) } else { log.Printf(f, v...) } |
