@@ -32,33 +32,39 @@ async function get(ws, url, name) {
3232 let totalLength = 0 ;
3333 return new Promise ( ( comp , err ) => {
3434 https . get ( url , res => {
35- res . pipe ( ws ) ;
36- if ( totalLength == 0 ) {
37- totalLength = + res . headers [ 'content-length' ] ;
35+ if ( res . statusCode === 301 || res . statusCode === 302 ) {
36+ err ( { name : 'RedirectError' , message : res . headers . location } ) ;
37+ } else {
38+ res . pipe ( ws ) ;
39+ if ( totalLength == 0 ) {
40+ totalLength = + res . headers [ 'content-length' ] ;
41+ }
42+ res . on ( 'end' , ( ) => {
43+ process . stdout . write ( `Downloaded 100% of '${ name } '. Total length ${ received } bytes.\n` ) ;
44+ comp ( ) ;
45+ } ) ;
46+ res . on ( 'error' , err ) ;
47+ res . on ( 'data' , x => {
48+ received += x . length ;
49+ process . stdout . write ( `Downloaded ${ received * 100 / totalLength | 0 } % of '${ name } '.\r` ) ;
50+ } ) ;
3851 }
39- res . on ( 'end' , ( ) => {
40- process . stdout . write ( `Downloaded 100% of '${ name } '. Total length ${ received } bytes.\n` ) ;
41- comp ( ) ;
42- } ) ;
43- res . on ( 'error' , err ) ;
44- res . on ( 'data' , x => {
45- received += x . length ;
46- process . stdout . write ( `Downloaded ${ received * 100 / totalLength | 0 } % of '${ name } '.\r` ) ;
47- } ) ;
4852 } ) . on ( 'error' , err ) ;
4953 } ) ;
5054}
5155
5256async function inflate ( rs , folder , name ) {
5357 const unzip = require ( 'unzipper' ) ;
54-
58+ const directory = await unzip . Open . file ( `${ folder } /${ name } .zip` ) ;
59+ const directoryName = directory . files [ 0 ] . path ;
5560 return new Promise ( ( comp , err ) => {
56- console . log ( `Unzipping '${ folder } /${ name } '.` ) ;
57- rs . pipe ( unzip . Extract ( { path : folder } ) ) ;
58- rs . on ( 'close' , ( ) => {
59- console . log ( `Unzipping of '${ folder } /${ name } ' completed.` ) ;
60- comp ( ) ;
61- } ) ;
61+ console . log ( `Unzipping '${ folder } /${ name } .zip'.` ) ;
62+ rs . pipe ( unzip . Extract ( { path : folder } ) . on ( 'close' , ( ) => {
63+ fs . rename ( `./${ folder } /${ directoryName } ` , `./${ folder } /${ name } ` , ( ) => {
64+ console . log ( `Unzipping of '${ folder } /${ name } .zip' completed.` ) ;
65+ comp ( ) ;
66+ } ) ;
67+ } ) ) ;
6268 rs . on ( 'error' , err ) ;
6369 } ) ;
6470}
@@ -71,21 +77,20 @@ async function win32() {
7177 if ( e . code === 'EEXIST' ) return ;
7278 else throw e ;
7379 } ) ;
74- await access ( 'ffmpeg/ffmpeg-4.2.1-win64-shared' , fs . constants . R_OK ) . catch ( async ( ) => {
75- let ws_shared = fs . createWriteStream ( 'ffmpeg/ffmpeg-4.2.1-win64-shared.zip' ) ;
76- await get ( ws_shared ,
77- 'https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-4.2.1-win64-shared.zip' ,
78- 'ffmpeg-4.2.1-win64-shared.zip' ) ;
79- let rs_shared = fs . createReadStream ( 'ffmpeg/ffmpeg-4.2.1-win64-shared.zip' ) ;
80- await inflate ( rs_shared , 'ffmpeg' , 'ffmpeg-4.2.1-win64-shared.zip' ) ;
81- } ) ;
82- await access ( 'ffmpeg/ffmpeg-4.2.1-win64-dev' , fs . constants . R_OK ) . catch ( async ( ) => {
83- let ws_dev = fs . createWriteStream ( 'ffmpeg/ffmpeg-4.2.1-win64-dev.zip' ) ;
84- await get ( ws_dev ,
85- 'https://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-4.2.1-win64-dev.zip' ,
86- 'ffmpeg-4.2.1-win64-dev.zip' ) ;
87- let rs_dev = fs . createReadStream ( 'ffmpeg/ffmpeg-4.2.1-win64-dev.zip' ) ;
88- console . log ( await inflate ( rs_dev , 'ffmpeg' , 'ffmpeg-4.2.1-win64-dev.zip' ) ) ;
80+
81+ const ffmpegFilename = 'ffmpeg-4.3.1-win64-shared' ;
82+ const downloadSource = 'https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2020-09-29-12-56/ffmpeg-n4.3.1-18-g6d886b6586-win64-gpl-shared.zip' ;
83+ await access ( `ffmpeg/${ ffmpegFilename } ` , fs . constants . R_OK ) . catch ( async ( ) => {
84+ let ws_shared = fs . createWriteStream ( `ffmpeg/${ ffmpegFilename } .zip` ) ;
85+ await get ( ws_shared , downloadSource , `${ ffmpegFilename } .zip` )
86+ . catch ( async ( err ) => {
87+ if ( err . name === 'RedirectError' ) {
88+ const redirectURL = err . message ;
89+ await get ( ws_shared , redirectURL , `${ ffmpegFilename } .zip` ) ;
90+ } else console . error ( err ) ;
91+ } ) ;
92+ let rs_shared = fs . createReadStream ( `ffmpeg/${ ffmpegFilename } .zip` ) ;
93+ await inflate ( rs_shared , 'ffmpeg' , `${ ffmpegFilename } ` ) ;
8994 } ) ;
9095}
9196
0 commit comments