diff --git a/README.md b/README.md index 19f3fd5..d67dddd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ # NCMconverter NCMconverter将ncm文件转换为mp3或者flac文件 + +实现参考了[yoki123/ncmdump][1],重构了代码,并且添加了多线程支持 + +## 使用 + +* `NCMconverter [options] ` + +* `--output value, -o value 指定输出目录,默认为原音频文件夹 + --tag, -t 是否使用给转换后的文件添加meta信息(有bug,这个参数没有用) + --deepth value, -d value 文件目录寻找的最大深度,默认为0,无视目录 + --thread value, -n value 线程数 + --help, -h help + --version, -v version` + +--- +[1]:https://github.com/yoki123/ncmdump \ No newline at end of file diff --git a/converter/converter.go b/converter/converter.go index 7939f6a..cd84452 100644 --- a/converter/converter.go +++ b/converter/converter.go @@ -7,7 +7,7 @@ import ( "math" "sync" - "github.com/closetool/NCMConverter/ncm" + "github.com/closetool/NCMconverter/ncm" ) var ( diff --git a/converter/converter_test.go b/converter/converter_test.go index ac51a3d..84c09b8 100644 --- a/converter/converter_test.go +++ b/converter/converter_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/closetool/NCMConverter/ncm" + "github.com/closetool/NCMconverter/ncm" ) var nf *ncm.NcmFile diff --git a/go.mod b/go.mod index 6ece864..29eabfa 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,10 @@ -module github.com/closetool/NCMConverter +module github.com/closetool/NCMconverter go 1.13 require ( github.com/bogem/id3v2 v1.2.0 + github.com/closetool/NCMConverter v0.0.0-20200906080438-4b25103209d7 github.com/go-flac/flacpicture v0.2.0 github.com/go-flac/flacvorbis v0.1.0 github.com/go-flac/go-flac v0.3.1 diff --git a/go.sum b/go.sum index d487ddd..00feb34 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,8 @@ github.com/bogem/id3v2 v1.2.0/go.mod h1:t78PK5AQ56Q47kizpYiV6gtjj3jfxlz87oFpty8D github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/closetool/NCMConverter v0.0.0-20200906080438-4b25103209d7 h1:0JimkEHlfgs+9LzRb0UgCRnuQWoeUakvlvKTlT7Gpu8= +github.com/closetool/NCMConverter v0.0.0-20200906080438-4b25103209d7/go.mod h1:rIsIRw1Q71CQ71m4ayUnappD5Ju4vwjg9Lf3IUjZbZU= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= diff --git a/main.go b/main.go index d9070e7..78e6211 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,10 @@ import ( "os" "strings" - "github.com/closetool/NCMConverter/converter" - "github.com/closetool/NCMConverter/ncm" - "github.com/closetool/NCMConverter/path" - "github.com/closetool/NCMConverter/tag" + "github.com/closetool/NCMconverter/converter" + "github.com/closetool/NCMconverter/ncm" + "github.com/closetool/NCMconverter/path" + "github.com/closetool/NCMconverter/tag" "github.com/urfave/cli/v2" "github.com/xxjwxc/gowp/workpool" ) @@ -54,10 +54,10 @@ func main() { Destination: &cmd.deepth, }, &cli.IntFlag{ - Name: "thread", - Aliases: []string{"n"}, - Value: 10, - Usage: "max thread count", + Name: "thread", + Aliases: []string{"n"}, + Value: 10, + Usage: "max thread count", Destination: &cmd.thread, }, }, @@ -95,15 +95,14 @@ func action(c *cli.Context) error { pool = workpool.New(cmd.thread) //files := make([]strings, 0) - res,err := resolvePath(args) + res, err := resolvePath(args) if err != nil { - log.Printf("resolving file path failed: %v",err) + log.Printf("resolving file path failed: %v", err) } - for _, pt := range res { p := pt - pool.Do(func()error{ + pool.Do(func() error { err := convert(p, cmd.output) if err != nil { log.Printf("Convert %v failed: %v", p, err) @@ -115,7 +114,7 @@ func action(c *cli.Context) error { return nil } -func resolvePath(args []string) ([]string ,error){ +func resolvePath(args []string) ([]string, error) { var res []string for _, arg := range args { info, err := os.Stat(arg) @@ -124,7 +123,7 @@ func resolvePath(args []string) ([]string ,error){ continue } if info.IsDir() { - res ,err = findNCMInDir(arg, cmd.deepth) + res, err = findNCMInDir(arg, cmd.deepth) if err != nil { log.Printf("find ncm file in %s failed: %v", arg, err) } @@ -132,7 +131,7 @@ func resolvePath(args []string) ([]string ,error){ res = append(res, arg) } } - return res,nil + return res, nil } func convert(filePath, dir string) error { @@ -179,9 +178,9 @@ func convert(filePath, dir string) error { } func writeToFile(dst string, data []byte) error { - info,err :=os.Stat(path.Dir(dst)) + info, err := os.Stat(path.Dir(dst)) if err != nil && info == nil { - os.MkdirAll(path.Dir(dst),0644) + os.MkdirAll(path.Dir(dst), 0644) } fd, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { @@ -207,21 +206,21 @@ func Tag(path string, imageData []byte, meta *converter.Meta) error { return err } -func findNCMInDir(dir string, deepth int)([]string, error){ +func findNCMInDir(dir string, deepth int) ([]string, error) { if deepth <= 0 { - return nil,nil + return nil, nil } infos, err := ioutil.ReadDir(dir) if err != nil { - return nil,err + return nil, err } - res := make([]string,0) + res := make([]string, 0) for _, info := range infos { if info.IsDir() { - tmp,_ := findNCMInDir(path.Join(dir, info.Name()), deepth-1) + tmp, _ := findNCMInDir(path.Join(dir, info.Name()), deepth-1) if tmp != nil { - res = append(res,tmp...) + res = append(res, tmp...) } } else { if strings.HasSuffix(info.Name(), ".ncm") { @@ -229,5 +228,5 @@ func findNCMInDir(dir string, deepth int)([]string, error){ } } } - return res,nil + return res, nil } diff --git a/ncm/ncm.go b/ncm/ncm.go index 47df2f4..cf9d1cd 100644 --- a/ncm/ncm.go +++ b/ncm/ncm.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "github.com/closetool/NCMConverter/path" + "github.com/closetool/NCMconverter/path" ) const ( diff --git a/tag/tag.go b/tag/tag.go index a289a57..24390db 100644 --- a/tag/tag.go +++ b/tag/tag.go @@ -5,9 +5,9 @@ import ( "log" "strings" - "github.com/closetool/NCMConverter/converter" - "github.com/closetool/NCMConverter/tag/flac" - "github.com/closetool/NCMConverter/tag/mp3" + "github.com/closetool/NCMconverter/converter" + "github.com/closetool/NCMconverter/tag/flac" + "github.com/closetool/NCMconverter/tag/mp3" ) const (