Skip to content

Instantly share code, notes, and snippets.

@adrienshen
Last active December 30, 2023 19:10
Show Gist options
  • Save adrienshen/6a2ebb66bb87a6d85263279640718e84 to your computer and use it in GitHub Desktop.
Save adrienshen/6a2ebb66bb87a6d85263279640718e84 to your computer and use it in GitHub Desktop.
Simple method to pipe ytdl-node steam into Express endpoint POC
const ytdl = require('ytdl-core');
const express = require('express');
const app = express();
const videoID = 'http://www.youtube.com/watch?v=';
app.use('mp3', express.static(__dirname + '/mp3'));
app.get('/stream/:id', (req, res) => {
console.log('video url >> ', videoID + req.params.id);
const astream = ytdl(videoID + req.params.id, {
quality: 251
});
astream
.on('data', chunk => {
console.log('Data chunck received >> ', chunk);
// fs.appendFile('./mp3/new_media.m4a', chunk, err => {
// if(err) throw err;
// });
})
.pipe(res);
})
app.listen(3000, () => console.log('Example app listening on port 3000!'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment