Skip to content

Commit

Permalink
'修改了mod文件,添加了markdown'
Browse files Browse the repository at this point in the history
  • Loading branch information
kilosonc committed Sep 6, 2020
1 parent 4b25103 commit 055eccd
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 31 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# NCMconverter
NCMconverter将ncm文件转换为mp3或者flac文件

实现参考了[yoki123/ncmdump][1],重构了代码,并且添加了多线程支持

## 使用

* `NCMconverter [options] <files/dirs>`

* `--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
2 changes: 1 addition & 1 deletion converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"math"
"sync"

"github.com/closetool/NCMConverter/ncm"
"github.com/closetool/NCMconverter/ncm"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/closetool/NCMConverter/ncm"
"github.com/closetool/NCMconverter/ncm"
)

var nf *ncm.NcmFile
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
47 changes: 23 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -124,15 +123,15 @@ 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)
}
} else {
res = append(res, arg)
}
}
return res,nil
return res, nil
}

func convert(filePath, dir string) error {
Expand Down Expand Up @@ -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 {
Expand All @@ -207,27 +206,27 @@ 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") {
res = append(res, path.Join(dir, info.Name()))
}
}
}
return res,nil
return res, nil
}
2 changes: 1 addition & 1 deletion ncm/ncm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

"github.com/closetool/NCMConverter/path"
"github.com/closetool/NCMconverter/path"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 055eccd

Please sign in to comment.