History

parallel extraction

Sigrid Solveig Haflínudóttir committed 7 years ago

Commit d4e33f81 parent febdbf05 files · +37 −15Browse files

Unified · Split

5 files
  1. README.md +2 −3
  2. go.mod +4 −1
  3. go.sum +4 −0
  4. input.go +12 −5
  5. main.go +15 −6
README.md+2−3
@@ -2,8 +2,6 @@ · 1 unmodified line
2 2
3A command line tool for frame accurate FLAC image + cue sheet splitting.3A command line tool for frame accurate FLAC image + cue sheet splitting.
4 4
5WIP.
6
7This project is started mostly out of frustration over supporting5This project is started mostly out of frustration over supporting
8[split2flac](https://github.com/ftrvxmtrx/split2flac) with all the6[split2flac](https://github.com/ftrvxmtrx/split2flac) with all the
9external dependencies and their quirks.7external dependencies and their quirks.
@@ -17,7 +15,7 @@ Yeah, that's it. · 7 unmodified lines
17 15
18## TODO16## TODO
19 17
20 * parallel extraction18 * get the artist/performer/composer right (and support multiple)
21 * an option to format the output path in a specific way19 * an option to format the output path in a specific way
22 * detect cue sheet encoding and convert to utf820 * detect cue sheet encoding and convert to utf8
23 * copying cue, log, images over to the destination21 * copying cue, log, images over to the destination
@@ -29,6 +27,7 @@ Yeah, that's it. · 5 unmodified lines
29 * basic splitting27 * basic splitting
30 * tagging28 * tagging
31 * split to other formats (ogg/vorbis, mp3)29 * split to other formats (ogg/vorbis, mp3)
30 * parallel extraction
32 31
33## NOTES32## NOTES
34 33
go.mod+4−1
@@ -2,4 +2,7 @@ module github.com/ftrvxmtrx/unflac · 1 unmodified line
2 2
3go 1.123go 1.12
4 4
5require github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef5require (
6 github.com/gammazero/workerpool v0.0.0-20190608213748-0ed5e40ec55e
7 github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef
8)
go.sum+4−0
@@ -1,2 +1,6 @@
1github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622 h1:lxbhOGZ9pU3Kf8P6lFluUcE82yVZn2EqEf4+mWRNPV0=
2github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622/go.mod h1:D90+MBHVc9Sk1lJAbEVgws0eYEurY4mv2TDso3Nxh3w=
3github.com/gammazero/workerpool v0.0.0-20190608213748-0ed5e40ec55e h1:fqgNEGLc7p2Rz4xlDHp9WNw/pqqR3c2cLdIC4zASBzU=
4github.com/gammazero/workerpool v0.0.0-20190608213748-0ed5e40ec55e/go.mod h1:avlwxCMavNtjwf7NrfnzdIGU3OZYI5D1NFQ2Rn3nHKg=
1github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef h1:Aew4jNB16cG2gnlY1dGOW6Od/x0r3puwfpbwX7aO6r0=5github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef h1:Aew4jNB16cG2gnlY1dGOW6Od/x0r3puwfpbwX7aO6r0=
2github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef/go.mod h1:28Qi8YBLQu3Fb3xKnGR9ou2d/PfFz3ptpbZdtsCM++4=6github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef/go.mod h1:28Qi8YBLQu3Fb3xKnGR9ou2d/PfFz3ptpbZdtsCM++4=
input.go+12−5
@@ -7,6 +7,7 @@ import ( · 6 unmodified lines
7 "path/filepath"7 "path/filepath"
8 "strings"8 "strings"
9 9
10 "github.com/gammazero/workerpool"
10 "github.com/vchimishuk/chub/cue"11 "github.com/vchimishuk/chub/cue"
11)12)
12 13
@@ -145,17 +146,23 @@ func (in *Input) Dump() { · 132 unmodified lines
145 }146 }
146}147}
147 148
148func (in *Input) Split() (err error) {149func (in *Input) Split(pool *workerpool.WorkerPool, firstErr chan<- error) (err error) {
149 dirPath := filepath.Join(*outputDir, in.OutputPath())150 dirPath := filepath.Join(*outputDir, in.OutputPath())
150 if err = os.MkdirAll(dirPath, 0755); err != nil {151 if err = os.MkdirAll(dirPath, 0755); err != nil {
151 return152 return
152 }153 }
153 154
154 for _, t := range in.Tracks {155 for _, t := range in.Tracks {
155 trackPath := filepath.Join(dirPath, in.TrackFilename(t))156 pool.Submit(func(t *Track) func() {
156 if err = in.Audio.Extract(t, trackPath); err != nil {157 return func() {
157 return158 trackPath := filepath.Join(dirPath, in.TrackFilename(t))
158 }159 if err = in.Audio.Extract(t, trackPath); err != nil {
160 firstErr <- fmt.Errorf("%s: %s", trackPath, err)
161 } else if !*quiet {
162 fmt.Printf("%s\n", trackPath)
163 }
164 }
165 }(t))
159 }166 }
160 167
161 return168 return
main.go+15−6
@@ -3,11 +3,13 @@ package main · 2 unmodified lines
3import (3import (
4 "encoding/json"4 "encoding/json"
5 "flag"5 "flag"
6 "fmt"
7 "log"6 "log"
8 "os"7 "os"
9 "path/filepath"8 "path/filepath"
9 "runtime"
10 "strings"10 "strings"
11
12 "github.com/gammazero/workerpool"
11)13)
12 14
13var (15var (
@@ -80,15 +82,22 @@ func main() { · 66 unmodified lines
80 if len(inputs) == 0 {82 if len(inputs) == 0 {
81 log.Fatal("no input found")83 log.Fatal("no input found")
82 }84 }
85
86 wp := workerpool.New(runtime.NumCPU())
87 firstErr := make(chan error)
88 go func() {
89 log.Fatalf("%s", <-firstErr)
90 }()
91
83 for _, in := range inputs {92 for _, in := range inputs {
84 if !*quiet {
85 in.Dump()
86 fmt.Printf("\n")
87 }
88 if !*dryRun {93 if !*dryRun {
89 in.Split()94 if err := in.Split(wp, firstErr); err != nil {
95 log.Fatalf("%s: %s", in.Audio.Path, err)
96 }
90 }97 }
91 }98 }
99 wp.StopWait()
100
92 if *jsonDump {101 if *jsonDump {
93 json.NewEncoder(os.Stdout).Encode(inputs)102 json.NewEncoder(os.Stdout).Encode(inputs)
94 }103 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t