File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,7 +33,16 @@ class YoutubeDownloader {
3333 ) : Promise < DownloadResult > {
3434 const fullOutFile = path . join ( targetDir , "video.mp4" ) ;
3535
36- const videoInfo = await this . #fetchVideoInfo( url ) ;
36+ let videoInfo ;
37+ try {
38+ videoInfo = await this . #fetchVideoInfo( url ) ;
39+ } catch {
40+ return {
41+ result : "error" ,
42+ message : "Failed to fetch video info." ,
43+ } ;
44+ }
45+
3746 const options = {
3847 ...this . #commonOptions,
3948 maxFilesize : String ( 100 * 1024 * 1024 ) , // 100 MB
@@ -43,13 +52,19 @@ class YoutubeDownloader {
4352 abortOnError : true ,
4453 } satisfies Flags ;
4554
46- await ytdl ( url , options , {
47- signal,
48- } ) ;
49-
50- if ( signal . aborted ) {
55+ try {
56+ await ytdl ( url , options , {
57+ signal,
58+ } ) ;
59+ } catch ( error ) {
60+ if ( signal . aborted ) {
61+ return {
62+ result : "aborted" ,
63+ } ;
64+ }
5165 return {
52- result : "aborted" ,
66+ result : "error" ,
67+ message : `Failed to download video. ${ error instanceof Error ? error . message : String ( error ) } ` ,
5368 } ;
5469 }
5570
You can’t perform that action at this time.
0 commit comments