@@ -10,6 +10,7 @@ import {
1010} from './geekyStreamsApi' ;
1111
1212const processName = "streamlink" ;
13+ const progressMarker = "[download]" ;
1314
1415export const download = (
1516 filename : string ,
@@ -45,32 +46,39 @@ export const download = (
4546 recordingOffset . recordingOffset
4647 ) ;
4748 }
48- console . log ( `${ processName } : ${ data } ` ) ;
49+
50+ handleDownloadOutput ( data as Buffer ) ;
4951 } ) ;
5052
51- const progressMarker = "[download]" ;
52-
5353 streamStart . stderr . on ( "data" , data => {
54- const dataAsString = ( data as Buffer ) . toString ( ) ;
55- if ( dataAsString . indexOf ( progressMarker ) === 1 ) {
56- readline . clearLine ( process . stdout , 0 ) ;
57- readline . cursorTo ( process . stdout , 0 ) ;
58- process . stderr . write (
59- // these magic substringing is based on streamlink version 0.14.2 output
60- // and may/will definitely break for outdated/future streamlink versions
61- dataAsString . substring (
62- dataAsString . lastIndexOf ( "]" ) + 2 ,
63- dataAsString . lastIndexOf ( ")" ) + 1
64- )
65- ) ;
66- } else if ( / ^ \s + $ / . test ( dataAsString ) ) {
67- // ignore
68- } else {
69- console . log ( `\n${ processName } ` , dataAsString ) ;
70- }
54+ handleDownloadOutput ( data as Buffer ) ;
7155 } ) ;
7256
7357 streamStart . on ( "close" , code => {
7458 console . log ( `${ processName } exited with code ${ code } ` ) ;
7559 } ) ;
7660} ;
61+
62+ const handleDownloadOutput = (
63+ data : Buffer
64+ ) => {
65+ const dataAsString = ( data as Buffer ) . toString ( ) ;
66+ const progressMarkerIndex = dataAsString . indexOf ( progressMarker ) ;
67+ if ( progressMarkerIndex > - 1 && progressMarkerIndex < 2 ) {
68+ readline . clearLine ( process . stdout , 0 ) ;
69+ readline . cursorTo ( process . stdout , 0 ) ;
70+
71+ // these magic substringing is based on streamlink version 0.14.2 output
72+ // and may/will definitely break for outdated/future streamlink versions
73+ const progressString = dataAsString . substring (
74+ dataAsString . lastIndexOf ( "]" ) + 2 ,
75+ dataAsString . lastIndexOf ( ")" ) + 1
76+ ) ;
77+
78+ process . stderr . write ( progressString ) ;
79+ } else if ( / ^ \s + $ / . test ( dataAsString ) ) {
80+ // ignore
81+ } else {
82+ console . log ( `\n${ processName } ${ dataAsString } ` ) ;
83+ }
84+ }
0 commit comments