(ctx context.Context, jobs <-chan FileJob, results chan<- FileResult, wg *sync.WaitGroup, cfg *config.Config)
| 252 | } |
| 253 | |
| 254 | func worker(ctx context.Context, jobs <-chan FileJob, results chan<- FileResult, wg *sync.WaitGroup, cfg *config.Config) { |
| 255 | defer wg.Done() |
| 256 | |
| 257 | editor := mp3.NewTagEditor() |
| 258 | |
| 259 | var lyricsFetcher fetcher.LyricsFetcher |
| 260 | if cfg.GeniusAPIKey != "" { |
| 261 | lyricsFetcher = fetcher.NewLyricsFetcherWithConfig(cfg.GeniusAPIKey) |
| 262 | } else { |
| 263 | lyricsFetcher = fetcher.NewLyricsFetcher() |
| 264 | } |
| 265 | |
| 266 | artworkFetcher := fetcher.NewArtworkFetcher() |
| 267 | |
| 268 | for job := range jobs { |
| 269 | select { |
| 270 | case <-ctx.Done(): |
| 271 | return |
| 272 | default: |
| 273 | result := processFile(job.filepath, editor, lyricsFetcher, artworkFetcher) |
| 274 | results <- result |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | func processFile(filePath string, editor mp3.TagEditor, lyricsFetcher fetcher.LyricsFetcher, artworkFetcher fetcher.ArtworkFetcher) FileResult { |
| 280 | result := FileResult{filepath: filePath} |
no test coverage detected