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
22
33 A command line tool for frame accurate FLAC image + cue sheet splitting.
44
5−WIP.
6−
75 This project is started mostly out of frustration over supporting
86 [split2flac](https://github.com/ftrvxmtrx/split2flac) with all the
97 external dependencies and their quirks.
@@ -17,7 +15,7 @@ Yeah, that's it. · 7 unmodified lines
1715
1816 ## TODO
1917
20− * parallel extraction
18+ * get the artist/performer/composer right (and support multiple)
2119 * an option to format the output path in a specific way
2220 * detect cue sheet encoding and convert to utf8
2321 * copying cue, log, images over to the destination
@@ -29,6 +27,7 @@ Yeah, that's it. · 5 unmodified lines
2927 * basic splitting
3028 * tagging
3129 * split to other formats (ogg/vorbis, mp3)
30+ * parallel extraction
3231
3332 ## NOTES
3433
go.mod+4−1
@@ -2,4 +2,7 @@ module github.com/ftrvxmtrx/unflac · 1 unmodified line
22
33 go 1.12
44
5−require github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef
5+require (
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 @@
1+github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622 h1:lxbhOGZ9pU3Kf8P6lFluUcE82yVZn2EqEf4+mWRNPV0=
2+github.com/gammazero/deque v0.0.0-20190521012701-46e4ffb7a622/go.mod h1:D90+MBHVc9Sk1lJAbEVgws0eYEurY4mv2TDso3Nxh3w=
3+github.com/gammazero/workerpool v0.0.0-20190608213748-0ed5e40ec55e h1:fqgNEGLc7p2Rz4xlDHp9WNw/pqqR3c2cLdIC4zASBzU=
4+github.com/gammazero/workerpool v0.0.0-20190608213748-0ed5e40ec55e/go.mod h1:avlwxCMavNtjwf7NrfnzdIGU3OZYI5D1NFQ2Rn3nHKg=
15 github.com/vchimishuk/chub v0.0.0-20190501162134-36f1f5f7c9ef h1:Aew4jNB16cG2gnlY1dGOW6Od/x0r3puwfpbwX7aO6r0=
26 github.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
77 "path/filepath"
88 "strings"
99
10+ "github.com/gammazero/workerpool"
1011 "github.com/vchimishuk/chub/cue"
1112 )
1213
@@ -145,17 +146,23 @@ func (in *Input) Dump() { · 132 unmodified lines
145146 }
146147 }
147148
148−func (in *Input) Split() (err error) {
149+func (in *Input) Split(pool *workerpool.WorkerPool, firstErr chan<- error) (err error) {
149150 dirPath := filepath.Join(*outputDir, in.OutputPath())
150151 if err = os.MkdirAll(dirPath, 0755); err != nil {
151152 return
152153 }
153154
154155 for _, t := range in.Tracks {
155− trackPath := filepath.Join(dirPath, in.TrackFilename(t))
156− if err = in.Audio.Extract(t, trackPath); err != nil {
157− return
158− }
156+ pool.Submit(func(t *Track) func() {
157+ return func() {
158+ trackPath := filepath.Join(dirPath, in.TrackFilename(t))
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))
159166 }
160167
161168 return
main.go+15−6
@@ -3,11 +3,13 @@ package main · 2 unmodified lines
33 import (
44 "encoding/json"
55 "flag"
6− "fmt"
76 "log"
87 "os"
98 "path/filepath"
9+ "runtime"
1010 "strings"
11+
12+ "github.com/gammazero/workerpool"
1113 )
1214
1315 var (
@@ -80,15 +82,22 @@ func main() { · 66 unmodified lines
8082 if len(inputs) == 0 {
8183 log.Fatal("no input found")
8284 }
85+
86+ wp := workerpool.New(runtime.NumCPU())
87+ firstErr := make(chan error)
88+ go func() {
89+ log.Fatalf("%s", <-firstErr)
90+ }()
91+
8392 for _, in := range inputs {
84− if !*quiet {
85− in.Dump()
86− fmt.Printf("\n")
87− }
8893 if !*dryRun {
89− in.Split()
94+ if err := in.Split(wp, firstErr); err != nil {
95+ log.Fatalf("%s: %s", in.Audio.Path, err)
96+ }
9097 }
9198 }
99+ wp.StopWait()
100+
92101 if *jsonDump {
93102 json.NewEncoder(os.Stdout).Encode(inputs)
94103 }

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