@@ -27,37 +27,25 @@ export default async function (msg: Message) {
2727 return ;
2828 }
2929
30- getFbVideoInfo ( query )
31- . then ( async ( result ) => {
32- if ( ! result . url )
33- return await msg . reply ( "No video found at the provided URL." ) ;
34-
35- await axios
36- . get ( result . hd , { responseType : "arraybuffer" } )
37- . then ( async ( response ) => {
38- const tempDir = "./.temp" ;
39- await fs . mkdirSync ( tempDir , { recursive : true } ) ;
40-
41- const tempPath = `${ tempDir } /fbdl_${ Date . now ( ) } .mp4` ;
42- await fs . writeFileSync ( tempPath , response . data ) ;
43-
44- const audioBuffer = fs . readFileSync ( tempPath ) ;
45- const media = new MessageMedia (
46- "audio/mpeg" ,
47- audioBuffer . toString ( "base64" ) ,
48- `${ result . title } .mp4`
49- ) ;
50-
51- await msg . reply ( media , msg . from ) ;
52- await fs . promises . unlink ( tempPath ) ;
53- } )
54- . catch ( async ( error ) => {
55- log . error ( "fbdl" , `Error downloading video: ${ error . message } ` ) ;
56- await msg . reply ( "Error downloading video. Please try again later." ) ;
57- } ) ;
58- } )
59- . catch ( async ( err ) => {
60- log . error ( "fbdl" , `Error fetching video info: ${ err . message } ` ) ;
61- await msg . reply ( "Error fetching video info. Please try again later." ) ;
62- } ) ;
30+ const result = await getFbVideoInfo ( query ) ;
31+ if ( ! result . url )
32+ return await msg . reply ( "No video found at the provided URL." ) ;
33+
34+ const response = await axios . get ( result . hd , { responseType : "arraybuffer" } ) ;
35+
36+ const tempDir = "./.temp" ;
37+ await fs . mkdirSync ( tempDir , { recursive : true } ) ;
38+
39+ const tempPath = `${ tempDir } /fbdl_${ Date . now ( ) } .mp4` ;
40+ await fs . writeFileSync ( tempPath , response . data ) ;
41+
42+ const audioBuffer = fs . readFileSync ( tempPath ) ;
43+ const media = new MessageMedia (
44+ "audio/mpeg" ,
45+ audioBuffer . toString ( "base64" ) ,
46+ `${ result . title } .mp4`
47+ ) ;
48+
49+ await msg . reply ( media , msg . from ) ;
50+ await fs . promises . unlink ( tempPath ) ;
6351}
0 commit comments