44 "context"
55 "fmt"
66 "io"
7- "log"
87 "os"
98 "os/exec"
109 "path/filepath"
@@ -38,7 +37,12 @@ func (dl *Downloader) getOutputFile(v *youtube.Video, format *youtube.Format, ou
3837
3938// Download : Starting download video by arguments.
4039func (dl * Downloader ) Download (ctx context.Context , v * youtube.Video , format * youtube.Format , outputFile string ) error {
41- dl .logf ("Video '%s' - Quality '%s' - Codec '%s'" , v .Title , format .QualityLabel , format .MimeType )
40+ youtube .Logger .Info (
41+ "Downloading video" ,
42+ "id" , v .ID ,
43+ "quality" , format .Quality ,
44+ "mimeType" , format .MimeType ,
45+ )
4246 destFile , err := dl .getOutputFile (v , format , outputFile )
4347 if err != nil {
4448 return err
@@ -51,7 +55,6 @@ func (dl *Downloader) Download(ctx context.Context, v *youtube.Video, format *yo
5155 }
5256 defer out .Close ()
5357
54- dl .logf ("Download to file=%s" , destFile )
5558 return dl .videoDLWorker (ctx , out , v , format )
5659}
5760
@@ -62,7 +65,15 @@ func (dl *Downloader) DownloadComposite(ctx context.Context, outputFile string,
6265 return err1
6366 }
6467
65- dl .logf ("Video '%s' - Quality '%s' - Video Codec '%s' - Audio Codec '%s'" , v .Title , videoFormat .QualityLabel , videoFormat .MimeType , audioFormat .MimeType )
68+ log := youtube .Logger .With ("id" , v .ID )
69+
70+ log .Info (
71+ "Downloading composite video" ,
72+ "videoQuality" , videoFormat .QualityLabel ,
73+ "videoMimeType" , videoFormat .MimeType ,
74+ "audioMimeType" , audioFormat .MimeType ,
75+ )
76+
6677 destFile , err := dl .getOutputFile (v , videoFormat , outputFile )
6778 if err != nil {
6879 return err
@@ -83,13 +94,13 @@ func (dl *Downloader) DownloadComposite(ctx context.Context, outputFile string,
8394 }
8495 defer os .Remove (audioFile .Name ())
8596
86- dl . logf ("Downloading video file..." )
97+ log . Debug ("Downloading video file..." )
8798 err = dl .videoDLWorker (ctx , videoFile , v , videoFormat )
8899 if err != nil {
89100 return err
90101 }
91102
92- dl . logf ("Downloading audio file..." )
103+ log . Debug ("Downloading audio file..." )
93104 err = dl .videoDLWorker (ctx , audioFile , v , audioFormat )
94105 if err != nil {
95106 return err
@@ -106,7 +117,7 @@ func (dl *Downloader) DownloadComposite(ctx context.Context, outputFile string,
106117 )
107118 ffmpegVersionCmd .Stderr = os .Stderr
108119 ffmpegVersionCmd .Stdout = os .Stdout
109- dl . logf ("merging video and audio to %s " , destFile )
120+ log . Info ("merging video and audio" , "output " , destFile )
110121
111122 return ffmpegVersionCmd .Run ()
112123}
@@ -184,9 +195,3 @@ func (dl *Downloader) videoDLWorker(ctx context.Context, out *os.File, video *yo
184195 progress .Wait ()
185196 return nil
186197}
187-
188- func (dl * Downloader ) logf (format string , v ... interface {}) {
189- if dl .Debug {
190- log .Printf (format , v ... )
191- }
192- }
0 commit comments