@@ -112,7 +112,10 @@ export class Video extends Attachment {
112112 await this . saveNfo ( ) . catch ( withContext ( `Saving .nfo file` ) ) . catch ( this . onError ) ;
113113 }
114114 if ( settings . extras . downloadArtwork ) {
115- await this . downloadArtwork ( ) . catch ( withContext ( `Saving artwork` ) ) . catch ( this . onError ) ;
115+ await this . downloadArtwork ( ) . catch ( withContext ( `Downloading artwork` ) ) . catch ( this . onError ) ;
116+ }
117+ if ( settings . extras . downloadCaptions ) {
118+ await this . downloadCaptions ( ) . catch ( withContext ( `Downloading captions` ) ) . catch ( this . onError ) ;
116119 }
117120 if ( ( await this . getState ( ) ) === Video . State . Muxed ) {
118121 this . logger . done ( chalk `{green Exists! Skipping}` ) ;
@@ -291,17 +294,21 @@ export class Video extends Attachment {
291294 this . logger . log ( "Saved artwork" ) ;
292295 }
293296
294- private async downloadCaptions ( ) {
297+ private * captionsFiles ( ) {
295298 if ( this . textTracks === undefined ) return ;
296299 const captions = this . textTracks . filter ( ( track ) => track . kind === "captions" ) ;
297300 if ( captions . length === 0 ) return ;
298- this . logger . log ( "Saving captions" ) ;
299-
300301 for ( const caption of captions ) {
301- const captionPath = `${ this . filePath } ${ caption . language ? `.${ caption . language } ` : "" } .vtt` ;
302- if ( await fileExists ( captionPath ) ) continue ;
303- const captionContent = await fetch ( caption . src ) . then ( ( res ) => res . text ( ) ) ;
304- await writeFile ( captionPath , captionContent , "utf8" ) ;
302+ const path = `${ this . filePath } ${ caption . language ? `.${ caption . language } ` : "" } .vtt` ;
303+ yield { ...caption , path } ;
304+ }
305+ }
306+ private async downloadCaptions ( ) {
307+ this . logger . log ( "Saving captions" ) ;
308+ for ( const { path, src } of this . captionsFiles ( ) ) {
309+ if ( await fileExists ( path ) ) continue ;
310+ const captionContent = await fetch ( src ) . then ( ( res ) => res . text ( ) ) ;
311+ await writeFile ( path , captionContent , "utf8" ) ;
305312 }
306313 this . logger . log ( "Saved captions" ) ;
307314 }
0 commit comments