Ah! Because it's a readable stream it will emit the data event with chunks of the data which you can write into your writable stream. Something like this should work:
constfile=fs.createWriteStream("shortvid.flv");constreadable=ytdl(shortVideoUrl);readable.addEventListener('data',chunk=>{file.write(chunk);});readable.addEventListener('progress',(chunkByteLength,totalBytesDownloaded,totalBytes)=>{console.log(`Downloaded ${totalBytesDownloaded} out of ${totalBytes}`);})readable.addEventListener('end',()=>{file.end();});
But, if you've switched to Python and you're happy with that, then that's cool too!
If only the Twilio dev evang team could answer all of my Javascript queries 🤣
So just for my learning opportunity here - when you call file.write(chunk), it's appending those bytes to the file, and calling file.end() will close that file write stream and result in the video file automagically?
Side note about python: It's been awesome to stand up my hack. The last step of adding a message queue (which I thought would be the hardest) has been the easiest. Gotta love learning!
Yes, that is the gist of it! Using the data and end events of the readable and calling write and end of the writeable is actually the equivalent of using readable.pipe(writeable). But, the documentation suggests you don't want to mix pipe and event based operations and using the progress event would mess that up.
I'm happy to answer JS questions if I can! I just happened to work with other readables/writeables a couple of weeks ago, so it was sort of fresh.
It's good to hear that the Python version has come on nicely for you. I love hackathons for the learning potential!
Brilliant! Well I followed you so be expecting some in the future.
Python for whatever reason (or perhaps the competitive nature of the Hackathon) has me more excited about developing than I’ve been in a while, so thanks for that!
And thanks again for your assistance.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ah! Because it's a readable stream it will emit the data event with chunks of the data which you can write into your writable stream. Something like this should work:
But, if you've switched to Python and you're happy with that, then that's cool too!
If only the Twilio dev evang team could answer all of my Javascript queries 🤣
So just for my learning opportunity here - when you call
file.write(chunk)
, it's appending those bytes to the file, and callingfile.end()
will close that file write stream and result in the video file automagically?Side note about python: It's been awesome to stand up my hack. The last step of adding a message queue (which I thought would be the hardest) has been the easiest. Gotta love learning!
Yes, that is the gist of it! Using the
data
andend
events of the readable and callingwrite
andend
of the writeable is actually the equivalent of usingreadable.pipe(writeable)
. But, the documentation suggests you don't want to mixpipe
and event based operations and using theprogress
event would mess that up.I'm happy to answer JS questions if I can! I just happened to work with other readables/writeables a couple of weeks ago, so it was sort of fresh.
It's good to hear that the Python version has come on nicely for you. I love hackathons for the learning potential!
Brilliant! Well I followed you so be expecting some in the future.
Python for whatever reason (or perhaps the competitive nature of the Hackathon) has me more excited about developing than I’ve been in a while, so thanks for that!
And thanks again for your assistance.