@@ -32,33 +32,39 @@ async function get(ws, url, name) {
32
32
let totalLength = 0 ;
33
33
return new Promise ( ( comp , err ) => {
34
34
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
+ } ) ;
38
51
}
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
- } ) ;
48
52
} ) . on ( 'error' , err ) ;
49
53
} ) ;
50
54
}
51
55
52
56
async function inflate ( rs , folder , name ) {
53
57
const unzip = require ( 'unzipper' ) ;
54
-
58
+ const directory = await unzip . Open . file ( `${ folder } /${ name } .zip` ) ;
59
+ const directoryName = directory . files [ 0 ] . path ;
55
60
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
+ } ) ) ;
62
68
rs . on ( 'error' , err ) ;
63
69
} ) ;
64
70
}
@@ -71,21 +77,20 @@ async function win32() {
71
77
if ( e . code === 'EEXIST' ) return ;
72
78
else throw e ;
73
79
} ) ;
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 } ` ) ;
89
94
} ) ;
90
95
}
91
96
0 commit comments