MCPcopy Create free account
hub / github.com/capable-average/tagTonic / processBatchBoth

Method processBatchBoth

tui/batch.go:110–165  ·  view source on GitHub ↗
(filePaths []string, index int)

Source from the content-addressed store, hash-verified

108}
109
110func (a *App) processBatchBoth(filePaths []string, index int) tea.Cmd {
111 if index >= len(filePaths) {
112 return nil
113 }
114
115 filePath := filePaths[index]
116
117 return func() tea.Msg {
118 te := mp3.NewTagEditor()
119 lf := fetcher.NewLyricsFetcher()
120 af := fetcher.NewArtworkFetcher()
121
122 tags, err := te.ReadTags(filePath)
123 if err != nil {
124 return BatchProcessMsg{
125 FilePath: filePath,
126 Success: false,
127 Error: err,
128 }
129 }
130
131 var lyrics string
132 var artwork []byte
133
134 lyrics, err = lf.Fetch(tags.Title, tags.Artist)
135 if err != nil {
136 logrus.Debugf("Failed to fetch lyrics for %s: %v", filepath.Base(filePath), err)
137 }
138
139 artwork, err = af.Fetch(tags.Title, tags.Artist, tags.Album)
140 if err != nil {
141 logrus.Debugf("Failed to fetch artwork for %s: %v", filepath.Base(filePath), err)
142 }
143
144 if lyrics != "" || len(artwork) > 0 {
145 updates := mp3.TagUpdates{
146 Lyrics: lyrics,
147 Artwork: artwork,
148 }
149 err = te.EditTags(filePath, updates)
150 if err != nil {
151 return BatchProcessMsg{
152 FilePath: filePath,
153 Success: false,
154 Error: err,
155 }
156 }
157 }
158
159 return BatchProcessMsg{
160 FilePath: filePath,
161 Success: true,
162 Error: nil,
163 }
164 }
165}

Callers 2

batchFetchBothMethod · 0.95
UpdateMethod · 0.95

Calls 7

ReadTagsMethod · 0.95
FetchMethod · 0.95
FetchMethod · 0.95
EditTagsMethod · 0.95
NewTagEditorFunction · 0.92
NewLyricsFetcherFunction · 0.92
NewArtworkFetcherFunction · 0.92

Tested by

no test coverage detected