@@ -34,6 +34,7 @@ const (
3434 KeyCompleted = "completed"
3535 KeyUnknown = "unknown"
3636 KeyInfo = "info"
37+ KeyError = "error"
3738 KeyLinkStream = "link_stream"
3839)
3940
@@ -150,6 +151,12 @@ func (yt *Download) Work(j *jobs.Job) {
150151 err = yt .download (ctx , id , yt .OutCh , url )
151152 if err != nil {
152153 slog .Error ("download() error" , "error" , err )
154+ val := Misc {
155+ Id : id ,
156+ Msg : err .Error (),
157+ }
158+ m := util.Msg {Key : KeyError , Value : val }
159+ yt .OutCh <- m
153160 return
154161 }
155162
@@ -190,9 +197,7 @@ func (yt *Download) download(ctx context.Context, id int64, outCh chan<- util.Ms
190197 // Faster youtube downloads: this combined with -S proto:dash ensures that we get dash https://github.com/yt-dlp/yt-dlp/issues/7417
191198 //"--extractor-args", "youtube:formats=duplicate",
192199
193- // Added 2025-01-18 after finding very poor quality audio from the dash settings above.
194- // It seems Youtube has moved from 48kb/s to 32kb/s in their LQ files and it sounds awful!
195- // prefer best audio-only format, otherwise fallback to best any format
200+ // prefer best audio-only format, otherwise fallback to best any format
196201 "-f" , "bestaudio/best" ,
197202 }
198203
@@ -220,24 +225,38 @@ func (yt *Download) download(ctx context.Context, id int64, outCh chan<- util.Ms
220225 return err
221226 }
222227
223- infoFileName := ""
224- count := 0
225- for {
228+ infoFileName := diskFileNameTmp + ".info.json"
226229
227- infoFileName = diskFileNameTmp + ".info.json"
228-
229- time .Sleep (500 * time .Millisecond )
230- _ , err := os .Stat (infoFileName )
231- if err == nil {
232- break
233- } else if ! os .IsNotExist (err ) {
234- return err
230+ infoCheck := func () error {
231+ ticker := time .NewTicker (500 * time .Millisecond )
232+ count := 0
233+ for {
234+ select {
235+ case line := <- cmdOutCh :
236+ misc := Misc {
237+ Id : id ,
238+ Msg : line ,
239+ }
240+ m := util.Msg {Key : KeyUnknown , Value : misc }
241+ outCh <- m
242+ case <- ticker .C :
243+ _ , err := os .Stat (infoFileName )
244+ if err == nil {
245+ return nil
246+ } else if ! os .IsNotExist (err ) {
247+ return err
248+ }
249+ if count > 20 {
250+ return fmt .Errorf ("waited too long for info file" )
251+ }
252+ count ++
253+ }
235254 }
255+ }
236256
237- if count > 20 {
238- return fmt .Errorf ("waited too long for info file" )
239- }
240- count ++
257+ err = infoCheck ()
258+ if err != nil {
259+ return err
241260 }
242261
243262 raw , err := os .ReadFile (infoFileName )
0 commit comments